业务代理商页面动态渲染0.3
This commit is contained in:
parent
81b485d46c
commit
8f8873c5c6
50
api/agents.js
Normal file
50
api/agents.js
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
import { post } from '@/utils/request'
|
||||||
|
import { get } from '../utils/request'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代理商相关API接口
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请成为代理商
|
||||||
|
* @param {Object} data - 代理商申请信息
|
||||||
|
* @param {string} data.name - 姓名
|
||||||
|
* @param {string} data.phone - 手机号
|
||||||
|
* @param {string} data.idCard - 身份证号
|
||||||
|
* @param {string} data.regionId - 行政区ID
|
||||||
|
* @param {string} data.address - 详细地址
|
||||||
|
* @returns {Promise} 返回申请结果
|
||||||
|
*/
|
||||||
|
export function applyForAgent(data) {
|
||||||
|
return post('/app/agent', data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取代理商申请状态
|
||||||
|
* @param {string} phone - 手机号
|
||||||
|
* @returns {Promise} 返回申请状态
|
||||||
|
*/
|
||||||
|
export function getAgentApplicationStatus(phone) {
|
||||||
|
return post('/app/agent/status', { phone })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取代理商协议
|
||||||
|
* @returns {Promise} 返回协议内容
|
||||||
|
*/
|
||||||
|
export function getAgentAgreement() {
|
||||||
|
return (
|
||||||
|
get('/app/article/getNew'),
|
||||||
|
{
|
||||||
|
type: 3, // 3表示代理商协议
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取服务区域列表
|
||||||
|
* @returns {Promise} 返回区域列表
|
||||||
|
*/
|
||||||
|
export function getServiceAreas() {
|
||||||
|
return get('/app/region')
|
||||||
|
}
|
||||||
|
|
@ -79,8 +79,8 @@
|
||||||
|
|
||||||
<!-- 提交按钮 -->
|
<!-- 提交按钮 -->
|
||||||
<view class="submit-section">
|
<view class="submit-section">
|
||||||
<button :disabled="!canSubmit" class="submit-btn" @click="submitApplication">
|
<button :disabled="!canSubmit || submitting" class="submit-btn" @click="submitApplication">
|
||||||
申请成为代理商
|
{{ submitting ? '提交中...' : '申请成为代理商' }}
|
||||||
</button>
|
</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
@ -90,6 +90,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import commonEnum from '../../enum/commonEnum'
|
import commonEnum from '../../enum/commonEnum'
|
||||||
|
import { applyForAgent, getAgentAgreement, getServiceAreas } from '@/api/agents'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'AgentsPage',
|
name: 'AgentsPage',
|
||||||
|
|
@ -104,12 +105,15 @@ export default {
|
||||||
this.formData.idCard &&
|
this.formData.idCard &&
|
||||||
this.formData.serviceArea &&
|
this.formData.serviceArea &&
|
||||||
this.formData.detailAddress &&
|
this.formData.detailAddress &&
|
||||||
this.formData.agreed
|
this.formData.agreed &&
|
||||||
|
!this.submitting
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
// 页面加载时的逻辑
|
// 页面加载时获取服务区域列表和协议内容
|
||||||
|
this.loadServiceAreas()
|
||||||
|
this.loadAgreement()
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
|
@ -121,26 +125,91 @@ export default {
|
||||||
detailAddress: '太姥山镇秦屿大道2号',
|
detailAddress: '太姥山镇秦屿大道2号',
|
||||||
agreed: true,
|
agreed: true,
|
||||||
},
|
},
|
||||||
|
submitting: false,
|
||||||
|
serviceAreas: [],
|
||||||
|
agreementContent: '',
|
||||||
|
// 区域ID映射
|
||||||
|
areaIdMap: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 选择服务区域
|
// 加载服务区域列表
|
||||||
selectServiceArea() {
|
async loadServiceAreas() {
|
||||||
uni.showActionSheet({
|
try {
|
||||||
itemList: [
|
const response = await getServiceAreas()
|
||||||
|
if (response.code === 200 && response.data) {
|
||||||
|
// 处理服务器返回的区域数据,提取所有区域名称和ID映射
|
||||||
|
const { names, idMap } = this.extractRegionData(response.data)
|
||||||
|
this.serviceAreas = names
|
||||||
|
this.areaIdMap = idMap
|
||||||
|
console.log('获取到的区域列表:', this.serviceAreas)
|
||||||
|
console.log('区域ID映射:', this.areaIdMap)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取服务区域失败:', error)
|
||||||
|
// 使用默认区域列表
|
||||||
|
this.serviceAreas = [
|
||||||
'福建省宁德市福鼎市',
|
'福建省宁德市福鼎市',
|
||||||
'福建省宁德市霞浦县',
|
'福建省宁德市霞浦县',
|
||||||
'福建省宁德市古田县',
|
'福建省宁德市古田县',
|
||||||
'福建省宁德市屏南县',
|
'福建省宁德市屏南县',
|
||||||
],
|
]
|
||||||
|
// 默认区域ID映射
|
||||||
|
this.areaIdMap = {
|
||||||
|
'福建省宁德市福鼎市': 8,
|
||||||
|
'福建省宁德市霞浦县': 9,
|
||||||
|
'福建省宁德市古田县': 10,
|
||||||
|
'福建省宁德市屏南县': 11,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 从区域数据中提取区域名称和ID映射
|
||||||
|
extractRegionData(regions) {
|
||||||
|
const names = []
|
||||||
|
const idMap = {}
|
||||||
|
|
||||||
|
const extractData = (regionList) => {
|
||||||
|
regionList.forEach(region => {
|
||||||
|
names.push(region.name)
|
||||||
|
idMap[region.name] = region.id
|
||||||
|
if (region.children && region.children.length > 0) {
|
||||||
|
extractData(region.children)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
extractData(regions)
|
||||||
|
return { names, idMap }
|
||||||
|
},
|
||||||
|
|
||||||
|
// 加载代理商协议
|
||||||
|
async loadAgreement() {
|
||||||
|
try {
|
||||||
|
const response = await getAgentAgreement()
|
||||||
|
if (response.code === 200 && response.data) {
|
||||||
|
this.agreementContent = response.data.content || '这里是代理商协议的详细内容...'
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取代理商协议失败:', error)
|
||||||
|
this.agreementContent = '这里是代理商协议的详细内容...'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 选择服务区域
|
||||||
|
selectServiceArea() {
|
||||||
|
if (this.serviceAreas.length === 0) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '暂无可用区域',
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.showActionSheet({
|
||||||
|
itemList: this.serviceAreas,
|
||||||
success: res => {
|
success: res => {
|
||||||
const areas = [
|
this.formData.serviceArea = this.serviceAreas[res.tapIndex]
|
||||||
'福建省宁德市福鼎市',
|
|
||||||
'福建省宁德市霞浦县',
|
|
||||||
'福建省宁德市古田县',
|
|
||||||
'福建省宁德市屏南县',
|
|
||||||
]
|
|
||||||
this.formData.serviceArea = areas[res.tapIndex]
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
@ -154,40 +223,143 @@ export default {
|
||||||
showAgreement() {
|
showAgreement() {
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '代理商协议',
|
title: '代理商协议',
|
||||||
content: '这里是代理商协议的详细内容...',
|
content: this.agreementContent,
|
||||||
showCancel: false,
|
showCancel: false,
|
||||||
confirmText: '我知道了',
|
confirmText: '我知道了',
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 提交申请
|
// 验证表单数据
|
||||||
submitApplication() {
|
validateForm() {
|
||||||
if (!this.canSubmit) {
|
if (!this.formData.name.trim()) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '请完善所有必填信息',
|
title: '请输入姓名',
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
})
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.formData.phone.trim()) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请输入手机号',
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证手机号格式
|
||||||
|
const phoneRegex = /^1[3-9]\d{9}$/
|
||||||
|
if (!phoneRegex.test(this.formData.phone)) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请输入正确的手机号',
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.formData.idCard.trim()) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请输入身份证号',
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证身份证号格式
|
||||||
|
const idCardRegex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
|
||||||
|
if (!idCardRegex.test(this.formData.idCard)) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请输入正确的身份证号',
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.formData.serviceArea) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请选择服务区域',
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.formData.detailAddress.trim()) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请输入详细地址',
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.formData.agreed) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请先同意代理商协议',
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
|
||||||
|
// 提交申请
|
||||||
|
async submitApplication() {
|
||||||
|
if (!this.validateForm()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uni.showLoading({
|
this.submitting = true
|
||||||
title: '提交中...',
|
|
||||||
})
|
|
||||||
|
|
||||||
// 模拟提交
|
try {
|
||||||
setTimeout(() => {
|
// 构建请求数据
|
||||||
uni.hideLoading()
|
const regionId = this.areaIdMap[this.formData.serviceArea]
|
||||||
uni.showModal({
|
if (!regionId) {
|
||||||
title: '提交成功',
|
uni.showToast({
|
||||||
content: '您的代理商申请已提交,我们将在3个工作日内审核并联系您。',
|
title: '无效的服务区域,请重新选择',
|
||||||
showCancel: false,
|
icon: 'none',
|
||||||
confirmText: '确定',
|
})
|
||||||
success: () => {
|
return
|
||||||
// 重置表单
|
}
|
||||||
this.resetForm()
|
|
||||||
},
|
const requestData = {
|
||||||
|
name: this.formData.name.trim(),
|
||||||
|
phone: this.formData.phone.trim(),
|
||||||
|
idCard: this.formData.idCard.trim(),
|
||||||
|
regionId: regionId,
|
||||||
|
address: this.formData.detailAddress.trim(),
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('提交代理商申请:', requestData)
|
||||||
|
console.log('选择的区域:', this.formData.serviceArea, '对应ID:', regionId)
|
||||||
|
|
||||||
|
const response = await applyForAgent(requestData)
|
||||||
|
|
||||||
|
if (response.code === 200) {
|
||||||
|
uni.showModal({
|
||||||
|
title: '申请成功',
|
||||||
|
content: '您的代理商申请已提交,我们将在3个工作日内审核并联系您。',
|
||||||
|
showCancel: false,
|
||||||
|
confirmText: '确定',
|
||||||
|
success: () => {
|
||||||
|
// 重置表单
|
||||||
|
this.resetForm()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title: response.msg || '申请失败,请重试',
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('提交代理商申请失败:', error)
|
||||||
|
uni.showToast({
|
||||||
|
title: '网络错误,请重试',
|
||||||
|
icon: 'none',
|
||||||
})
|
})
|
||||||
}, 2000)
|
} finally {
|
||||||
|
this.submitting = false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 重置表单
|
// 重置表单
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user