Commit a87452c2 authored by chicheng's avatar chicheng

要货添加企业团购渠道相关逻辑

parent dbdccfc4
......@@ -20,12 +20,16 @@
"type" : "uni-app:app-android"
},
{
"playground" : "custom",
"playground" : "standard",
"type" : "uni-app:app-ios"
},
{
"openVueDevtools" : false,
"type" : "uni-app:h5"
},
{
"playground" : "standard",
"type" : "uni-app:app-ios_simulator"
}
]
}
......@@ -344,21 +344,28 @@
...res.data.operator
}
});
this.$uStore({
name: 'userBpData',
value: {
...res.data.userBpData
}
});
const isChildCustomer = res.data.userBpData.ROLES.some(user => user.ROLE_ID === 'WLY027');
this.$uStore({
name: 'isChildCustomer',
value: isChildCustomer
});
// 保存客户详细信息,包含客户类型等信息
if (res.data.customerDetails) {
this.$uStore({
name: 'userBpData',
value: {
...res.data.userBpData
}
});
const isChildCustomer = res.data.userBpData.ROLES.some(user => user.ROLE_ID === 'WLY027');
this.$uStore({
name: 'isChildCustomer',
value: isChildCustomer
});
this.$uStore({
name: 'vuex_token',
value: res.data.token
name: 'customerDetails',
value: res.data.customerDetails
});
}
this.$uStore({
name: 'vuex_token',
value: res.data.token
});
uni.switchTab({
url: '/pages/home/home'
});
......
......@@ -38,9 +38,9 @@
<view class="middle-date-address uni-list picker-year">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker class="picker-block" @change="bindPickerChange($event,'channelType')" :value="orderItem.channelsType"
range-key='name' mode="selector" :range="channelTypeArr">
<text class="uni-input">{{orderItem.channelTypeName}}</text>
<picker class="picker-block" @change="bindPickerChange($event,'channelType')" :value="channelTypeIndex"
range-key='name' mode="selector" :range="channelTypeArr" :disabled="isV032NormalApply">
<text class="uni-input">{{orderItem.channelTypeName || '请选择'}}</text>
</picker>
</view>
</view>
......@@ -237,7 +237,8 @@
significanceArr : [],
marketPlaceArr : [],
manifestArr : [],
pcjArr: [{value:'0',name: '否'}, {value:'1',name: '是'}]
pcjArr: [{value:'0',name: '否'}, {value:'1',name: '是'}],
channelTypeIndex: 0 // 渠道类型选择器的索引
}
},
props: {
......@@ -269,7 +270,13 @@
'height': `${this.sysinfo.safeArea.top + 44}px`
}
},
...mapState(['sysinfo'])
// 是否为V032客户类型且为普通要货申请
isV032NormalApply() {
// 优先从 store 中获取客户类型
const customerType = this.customerDetails?.info?.zzfld000016
return customerType === 'V032' && this.orderItem.demandType !== 'ZDZG'
},
...mapState(['sysinfo', 'customerDetails'])
},
mounted() {
console.log('监听到事件来自 update');
......@@ -293,6 +300,38 @@
_this.orderItem.city = data.selectTerminal.cityName
_this.orderItem.district = data.selectTerminal.districtName
})
// V032普通要货申请,初始化渠道类型
this.$nextTick(() => {
if (this.isV032NormalApply && this.channelTypeArr && this.channelTypeArr.length > 0) {
// 确保只有H选项并设置默认值
setTimeout(() => {
const hasH = this.channelTypeArr.some(item => item.value === 'H')
if (hasH) {
// 只保留H选项
if (this.channelTypeArr.length > 1) {
this.channelTypeArr = this.channelTypeArr.filter(item => item.value === 'H')
}
// 设置默认值为H
if (!this.orderItem.channelsType || this.orderItem.channelsType !== 'H') {
this.$set(this.orderItem, 'channelsType', 'H')
this.$set(this.orderItem, 'channelTypeName', '行业团购')
}
// 设置选择器索引
const hIndex = this.channelTypeArr.findIndex(item => item.value === 'H')
if (hIndex >= 0) {
this.channelTypeIndex = hIndex
}
} else {
// 如果没有H选项,添加H选项
this.channelTypeArr = [{ value: 'H', name: '行业团购' }]
this.$set(this.orderItem, 'channelsType', 'H')
this.$set(this.orderItem, 'channelTypeName', '行业团购')
this.channelTypeIndex = 0
}
}, 100)
}
})
},
onUnload() {
uni.$off('selectSalePlaceAccountInfo')
......@@ -319,6 +358,63 @@
// 'orderItem.planType':function(res,res1){
// res && this.getChannelType()
// }
// 监听渠道类型数组变化,如果是V032普通要货申请,设置默认值
channelTypeArr: {
handler(newVal) {
if (this.isV032NormalApply && newVal && newVal.length > 0) {
this.$nextTick(() => {
// 确保只有H选项
const hasH = newVal.some(item => item.value === 'H')
if (hasH) {
// 设置默认值为H
if (!this.orderItem.channelsType || this.orderItem.channelsType !== 'H') {
this.$set(this.orderItem, 'channelsType', 'H')
this.$set(this.orderItem, 'channelTypeName', '行业团购')
}
// 设置选择器索引
const hIndex = newVal.findIndex(item => item.value === 'H')
if (hIndex >= 0) {
this.channelTypeIndex = hIndex
}
} else {
// 如果没有H选项,通知父组件添加H选项
this.$emit('updateChannelType', [{ value: 'H', name: '行业团购' }])
this.$set(this.orderItem, 'channelsType', 'H')
this.$set(this.orderItem, 'channelTypeName', '行业团购')
this.channelTypeIndex = 0
}
})
}
},
immediate: true
},
// 监听客户类型和要货类型变化
isV032NormalApply: {
handler(newVal) {
if (newVal && this.channelTypeArr && this.channelTypeArr.length > 0) {
this.$nextTick(() => {
// 确保只有H选项并设置默认值
const hasH = this.channelTypeArr.some(item => item.value === 'H')
if (hasH) {
// 设置默认值为H
this.$set(this.orderItem, 'channelsType', 'H')
this.$set(this.orderItem, 'channelTypeName', '行业团购')
const hIndex = this.channelTypeArr.findIndex(item => item.value === 'H')
if (hIndex >= 0) {
this.channelTypeIndex = hIndex
}
} else {
// 如果没有H选项,通知父组件添加H选项
this.$emit('updateChannelType', [{ value: 'H', name: '行业团购' }])
this.$set(this.orderItem, 'channelsType', 'H')
this.$set(this.orderItem, 'channelTypeName', '行业团购')
this.channelTypeIndex = 0
}
})
}
},
immediate: true
}
},
methods: {
goTerminal() {
......@@ -381,6 +477,11 @@
this.orderItem.planType = this.deliveryPlanArr[index].name
break;
case 'channelType':
// V032普通要货申请不允许修改渠道类型
if (this.isV032NormalApply) {
return
}
this.channelTypeIndex = index
this.orderItem.channelsType = this.channelTypeArr[index].value
this.orderItem.channelTypeName = this.channelTypeArr[index].name
// 渠道类型变化时,如果是终端要货则清空终端信息
......@@ -454,10 +555,49 @@
},
async getChannelType(){
const res = await getChannelType({'salePlan': this.orderItem.planType})
this.channelTypeArr = res.data
this.channelTypeArr = res.data || []
if (!this.channelTypeArr.length) {
this.channelTypeArr = [{ value: 'S', name: '社会化渠道' }]
}
}
// V032普通要货申请,确保只有H-行业团购选项,并默认设置
if (this.isV032NormalApply) {
// 检查是否已有H选项
const hasH = this.channelTypeArr.some(item => item.value === 'H')
if (!hasH) {
// 如果没有H选项,添加H-行业团购选项
this.channelTypeArr = [{ value: 'H', name: '行业团购' }]
} else {
// 如果已有H选项,只保留H选项
this.channelTypeArr = this.channelTypeArr.filter(item => item.value === 'H')
}
// 设置默认值为H
this.$set(this.orderItem, 'channelsType', 'H')
this.$set(this.orderItem, 'channelTypeName', '行业团购')
// 设置选择器索引
const hIndex = this.channelTypeArr.findIndex(item => item.value === 'H')
if (hIndex >= 0) {
this.channelTypeIndex = hIndex
}
// 使用 $nextTick 确保数据更新
this.$nextTick(() => {
setTimeout(() => {
if (this.orderItem.channelsType !== 'H') {
this.$set(this.orderItem, 'channelsType', 'H')
this.$set(this.orderItem, 'channelTypeName', '行业团购')
}
}, 100)
})
} else {
// 非V032普通要货申请,初始化选择器索引
if (this.orderItem.channelsType && this.channelTypeArr.length > 0) {
const index = this.channelTypeArr.findIndex(item => item.value === this.orderItem.channelsType)
this.channelTypeIndex = index >= 0 ? index : 0
}
}
},
// 渠道类型变化处理,参考PC端逻辑
onChannelsTypeChange(value) {
......
......@@ -8,9 +8,9 @@
<view class="middle-date-des uni-list picker-year">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker class="picker-block" @change="changeArea($event,'city')" :value="terminalAdd.REGION"
<picker class="picker-block" @change="changeArea($event,'city')" :value="regionIndex"
range-key='BEZEI' mode="selector" :range="selectDataOptions['regionList']">
<text class="uni-input">{{terminalAdd.REGION_TEXT}}</text>
<text class="uni-input">{{terminalAdd.REGION_TEXT || '请选择'}}</text>
</picker>
</view>
</view>
......@@ -22,9 +22,9 @@
<view class="middle-date-des uni-list picker-year">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker class="picker-block" @change="changeArea($event,'street')" :value="terminalAdd.CITY_CODE"
<picker class="picker-block" @change="changeArea($event,'street')" :value="cityIndex"
range-key='CITY_NAME' mode="selector" :range="selectDataOptions['cityList']">
<text class="uni-input">{{terminalAdd.CITY_TEXT}}</text>
<text class="uni-input">{{terminalAdd.CITY_TEXT || '请选择'}}</text>
</picker>
</view>
</view>
......@@ -36,9 +36,9 @@
<view class="middle-date-des uni-list picker-year">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker class="picker-block" @change="changeArea($event,'q')" :value="terminalAdd.STREET_CODE"
<picker class="picker-block" @change="changeArea($event,'q')" :value="streetIndex"
range-key='MC_STREET' mode="selector" :range="selectDataOptions['streetList']">
<text class="uni-input">{{terminalAdd.STREET_TEXT}}</text>
<text class="uni-input">{{terminalAdd.STREET_TEXT || '请选择'}}</text>
</picker>
</view>
</view>
......@@ -74,6 +74,7 @@
export default {
data() {
return {
isCommon: false, // 是否为普通要货申请的地址选择
terminalAdd: {
REGION: '',
REGION_TEXT: '',
......@@ -81,13 +82,18 @@
CITY_TEXT: '',
STREET_CODE: '',
STREET_TEXT: '',
STREET: ''
STREET: '',
CONTACT_PERSON: '', // 联系人
CONTACT_NUMBER: '' // 联系电话
},
selectDataOptions: {
cityList: [],
streetList: [],
regionList: []
},
regionIndex: 0,
cityIndex: 0,
streetIndex: 0
}
},
computed: {
......@@ -109,7 +115,39 @@
},
},
onLoad() {
onLoad(options) {
console.log('select-address onLoad options:', options)
// 检查是否是普通要货申请的地址选择(isCommon=true)
if (options.isCommon === 'true' || options.isCommon === true) {
this.isCommon = true
console.log('设置为普通要货申请地址选择模式')
// 如果有传入的订单数据,初始化地址信息
if (options.order) {
try {
const orderData = JSON.parse(decodeURIComponent(options.order))
console.log('解析订单数据:', orderData)
if (orderData.region || orderData.cityCode || orderData.streetcode) {
// 初始化地址数据
this.terminalAdd.REGION = orderData.region || ''
this.terminalAdd.CITY_CODE = orderData.cityCode || ''
this.terminalAdd.STREET_CODE = orderData.streetcode || ''
// 如果有联系人信息,也初始化
if (orderData.contacPerson) {
this.terminalAdd.CONTACT_PERSON = orderData.contacPerson
}
if (orderData.contactNumber) {
this.terminalAdd.CONTACT_NUMBER = orderData.contactNumber
}
// 加载对应的省市区数据
this.initAddressData()
}
} catch (e) {
console.error('解析订单数据失败:', e)
}
}
} else {
this.isCommon = false
}
},
created() {
this.getAreaArr()
......@@ -117,36 +155,79 @@
methods: {
// 省
async getAreaArr(){
await getArea('','region',"ZDZG").then(res => {
// 普通要货申请不传 ZDZG 参数
const mode = this.isCommon ? '' : 'ZDZG'
await getArea('','region', mode).then(res => {
this.selectDataOptions['regionList'] = res.DATA
})
},
// 初始化地址数据(当有初始地址时)
async initAddressData() {
if (this.terminalAdd.REGION) {
// 加载省数据
await this.getAreaArr()
// 找到对应的省
const regionItem = this.selectDataOptions['regionList'].find(item => item.BLAND === this.terminalAdd.REGION)
if (regionItem) {
this.terminalAdd.REGION_TEXT = regionItem.BEZEI
// 加载市数据
const cityRes = await getArea(this.terminalAdd.REGION, 'city', this.isCommon ? '' : 'ZDZG')
this.selectDataOptions.cityList = cityRes.DATA || []
if (this.terminalAdd.CITY_CODE) {
const cityItem = this.selectDataOptions['cityList'].find(item => item.CITY_CODE === this.terminalAdd.CITY_CODE)
if (cityItem) {
this.terminalAdd.CITY_TEXT = cityItem.CITY_NAME
// 加载区数据
const streetRes = await getArea(this.terminalAdd.CITY_CODE, 'street', this.isCommon ? '' : 'ZDZG')
this.selectDataOptions.streetList = streetRes.DATA || []
if (this.terminalAdd.STREET_CODE) {
const streetItem = this.selectDataOptions['streetList'].find(item => item.STRT_CODE === this.terminalAdd.STREET_CODE)
if (streetItem) {
this.terminalAdd.STREET_TEXT = streetItem.MC_STREET
}
}
}
}
}
}
},
async changeArea(e, type) {
if (e) {
console.log('picker发送选择改变,携带值为', e.detail.value)
const index = e.detail.value || 0
// 普通要货申请不传 ZDZG 参数
const mode = this.isCommon ? '' : 'ZDZG'
if (type === 'city') {
const code = this.selectDataOptions['regionList'][index].BLAND
const { DATA } = await getArea(code, type,"ZDZG")
this.selectDataOptions.cityList = DATA
this.terminalAdd.REGION_TEXT = this.selectDataOptions['regionList'].find(v => v.BLAND === code)?.BEZEI
this.terminalAdd.REGION = code
this.regionIndex = index
const { DATA } = await getArea(code, type, mode)
this.selectDataOptions.cityList = DATA || []
this.terminalAdd.REGION_TEXT = this.selectDataOptions['regionList'].find(v => v.BLAND === code)?.BEZEI || ''
this.terminalAdd.CITY_CODE = ''
this.terminalAdd.STREET_CODE = ''
this.terminalAdd.CITY_TEXT = ''
this.terminalAdd.STREET_TEXT = ''
this.terminalAdd.STREET = ''
this.selectDataOptions.streetList = []
this.cityIndex = 0
this.streetIndex = 0
} else if (type === 'street') {
const code = this.selectDataOptions['cityList'][index].CITY_CODE
const { DATA } = await getArea(code, type)
this.selectDataOptions.streetList = DATA
this.terminalAdd.CITY_CODE = code
this.cityIndex = index
const { DATA } = await getArea(code, type, mode)
this.selectDataOptions.streetList = DATA || []
this.terminalAdd.STREET_CODE = ''
this.terminalAdd.STREET_TEXT = ''
this.terminalAdd.STREET = ''
this.terminalAdd.CITY_TEXT = this.selectDataOptions['cityList'].find(v => v.CITY_CODE === code)?.CITY_NAME
this.terminalAdd.CITY_TEXT = this.selectDataOptions['cityList'].find(v => v.CITY_CODE === code)?.CITY_NAME || ''
this.streetIndex = 0
} else {
const code = this.selectDataOptions['streetList'][index].STRT_CODE
this.terminalAdd.STREET_TEXT = this.selectDataOptions['streetList'].find(v => v.STRT_CODE === code)?.MC_STREET
this.terminalAdd.STREET_CODE = code
this.streetIndex = index
this.terminalAdd.STREET_TEXT = this.selectDataOptions['streetList'].find(v => v.STRT_CODE === code)?.MC_STREET || ''
}
}
},
......@@ -183,9 +264,44 @@
});
return
}
uni.$emit('selectTerminalAddress', {
selectTerminalAddress: this.terminalAdd
})
// 确保所有编码字段都已保存
if (!this.terminalAdd.REGION && this.terminalAdd.REGION_TEXT) {
// 如果只有名称没有编码,尝试从列表中找到编码
const regionItem = this.selectDataOptions['regionList'].find(item => item.BEZEI === this.terminalAdd.REGION_TEXT)
if (regionItem) {
this.terminalAdd.REGION = regionItem.BLAND
}
}
if (!this.terminalAdd.CITY_CODE && this.terminalAdd.CITY_TEXT) {
const cityItem = this.selectDataOptions['cityList'].find(item => item.CITY_NAME === this.terminalAdd.CITY_TEXT)
if (cityItem) {
this.terminalAdd.CITY_CODE = cityItem.CITY_CODE
}
}
if (!this.terminalAdd.STREET_CODE && this.terminalAdd.STREET_TEXT) {
const streetItem = this.selectDataOptions['streetList'].find(item => item.MC_STREET === this.terminalAdd.STREET_TEXT)
if (streetItem) {
this.terminalAdd.STREET_CODE = streetItem.STRT_CODE
}
}
// 调试日志
console.log('地址选择完成,发送数据:', this.terminalAdd)
console.log('isCommon:', this.isCommon)
// 根据 isCommon 参数决定发送哪个事件
if (this.isCommon) {
// 普通要货申请,发送 selectCommonAddress 事件
uni.$emit('selectCommonAddress', {
selectCommonAddress: { ...this.terminalAdd }
})
} else {
// 终端直配,发送 selectTerminalAddress 事件
uni.$emit('selectTerminalAddress', {
selectTerminalAddress: { ...this.terminalAdd }
})
}
uni.navigateBack()
},
}
......
......@@ -12,7 +12,7 @@ try {
}
// 需要永久存储,且下次APP启动需要取出的,在state中的变量名
let saveStateKeys = ['vuex_user', 'vuex_token', 'userInfo', 'userBpData', 'isChildCustomer'];
let saveStateKeys = ['vuex_user', 'vuex_token', 'userInfo', 'userBpData', 'isChildCustomer', 'customerDetails'];
// 保存变量到本地存储中
const saveLifeData = function(key, value) {
......@@ -71,7 +71,11 @@ const store = new Vuex.Store({
'baseinfo': {}
},
// 从本地存储恢复登录信息,避免热重载时丢失
isChildCustomer: lifeData.isChildCustomer !== undefined ? lifeData.isChildCustomer : false
isChildCustomer: lifeData.isChildCustomer !== undefined ? lifeData.isChildCustomer : false,
// 客户详细信息,包含客户类型等信息
customerDetails: lifeData.customerDetails ? lifeData.customerDetails : {
info: {}
}
},
getters: {
// 获取角色信息,包含 USER_BP 和 ROLE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment