subShopMerchant.js
4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import api from '../../api/api.js'
// components/subShopMerchant/subShopMerchant.js
Component({
/**
* 组件的属性列表
*/
properties: {
show: Boolean,
title: String,
selectedSelesMerchantId: {
type: String,
observer: function (n) {
if (n) {
this.getSubShopMerchantList(n)
}
}
},
selectedCustomerInfo: {
type: String,
observer: function (n) {
// 选择客户 销售顾问所在门店无变化 需做校验
let thisPage = wx.$router.getPageInstance()
let { orderObj } = thisPage.data
let { subShopMerchantList } = this.data
if (n) {
// 校验历史订单二级流量方是否在配置的二级流量方数据中包含 不包含清空二级流量方重新选择
let hasSubShopMerchantId = subShopMerchantList.some(item=> item.subMerchantId == orderObj.subShopMerchantId)
if (!hasSubShopMerchantId && subShopMerchantList.length) {
delete orderObj?.subShopMerchantId
delete orderObj?.subShopMerchantName
}
thisPage.setData({
orderObj
})
this.setData({
orderObj: {}
})
}
}
},
selectedSubShopMerchantId: {
type: String,
observer: function () {
let thisPage = wx.$router.getPageInstance()
let { orderObj } = thisPage.data
let { subShopMerchantList } = this.data
subShopMerchantList.map(i => {
i.active = false
if (i.subMerchantId == orderObj.subShopMerchantId) {
i.active = true
}
return i
})
this.setData({
subShopMerchantList
})
}
}
},
/**
* 组件的初始数据
*/
data: {
subShopMerchantList: [],
orderObj: {},
},
/**
* 组件的方法列表
*/
methods: {
getSubShopMerchantList(id) {
let thisPage = wx.$router.getPageInstance()
let { requiredList, orderObj } = thisPage.data
api.getSubShopMerchantList({merchantId: id}).then(res => {
let {code, data} = res
if (code == '0') {
// 有二级流量方数据 添加必填二级流量方字段
if (data?.length) {
if (!requiredList?.includes('subShopMerchantId')) requiredList?.unshift('subShopMerchantId')
data.map(i => {
i.active = false
if (i.subMerchantId == orderObj.subShopMerchantId) {
i.active = true
}
return i
})
// 校验历史订单二级流量方是否在配置的二级流量方数据中包含 不包含清空二级流量方重新选择
let hasSubShopMerchantId = data.some(item=> item.subMerchantId == orderObj.subShopMerchantId)
if (!hasSubShopMerchantId) {
delete orderObj?.subShopMerchantId
delete orderObj?.subShopMerchantName
}
thisPage.setData({
requiredList,
isShowSubShopMerchant: true,
orderObj
})
this.setData({
subShopMerchantList: data,
orderObj: {}
})
} else {
// 无二级流量方字段时 清空选择的二级流量方字段
delete orderObj?.subShopMerchantId
delete orderObj?.subShopMerchantName
if (requiredList?.includes('subShopMerchantId')) requiredList?.splice(requiredList?.indexOf('subShopMerchantId'), 1)
thisPage.setData({
isShowSubShopMerchant: false,
requiredList,
orderObj
})
}
}
})
},
changeMerchant(e) {
let { index, item } = e.currentTarget.dataset
let { subShopMerchantList, orderObj } = this.data
let subShopMerchantId = item.subMerchantId
if (subShopMerchantId == orderObj.subShopMerchantId) return
let selectedSubShopMerchantObj = {
subShopMerchantId: item.subMerchantId,
subShopMerchantName: item.subMerchantName
}
orderObj = (orderObj || selectedSubShopMerchantObj) ? Object.assign(orderObj, selectedSubShopMerchantObj) : selectedSubShopMerchantObj
subShopMerchantList.map(i => (i.active = false))
subShopMerchantList[index].active = true
this.setData({
subShopMerchantList,
orderObj
})
},
async confirm() {
let data = this.data.orderObj
let thisPage = wx.$router.getPageInstance()
let { orderObj } = thisPage.data
orderObj = (orderObj || data) ? Object.assign(orderObj, data) : orderObj
thisPage.setData({
orderObj
})
this.setData({
show: false
})
},
}
})