flagDialog.vue
8.23 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<!-- 门店标签 -->
<template>
<baseDialog :dialog-config="dialogConfig"
:is-show.sync="visible"
class="accountDailog"
@handleClick="handleAddConfirm">
<div class="detail-dialog">
<el-form ref="flagFrom"
class="flagFrom d2-container-content"
:model="infoForm"
label-width="250px"
v-loading="$store.state.d2admin.loading.value">
<el-form-item label="门店名称:"
class="flag-div">
{{info.merchantName}}
</el-form-item>
<el-form-item label="商户号:"
class="flag-div">
{{info.merchantId}}
</el-form-item>
<el-form-item label=""
v-for="(item, index1) in commLabelUnitList"
v-if="item.commLabelGroupInfo.groupType == '2'"
class="flag-div">
<span class="tips-block"
slot="label">
<span class="tips-label">{{item.commLabelGroupInfo.groupName}}</span>
<el-tooltip popper-class="tooltip-class"
effect="dark"
placement="right">
<div slot="content">{{item.commLabelGroupInfo.groupDesc}}</div>
<span class="tips-icon" />
</el-tooltip>:
</span>
<span v-for="(obj, index2) in item.commLabelList"
class="label-span">{{obj.labelName}}</span>
</el-form-item>
<div class="div_g">
<el-form-item label=""
v-for="(item, index1) in groupUnitList"
v-if="item.groupType == '1'"
class="flag-div">
<span class="tips-block"
slot="label">
<span class="tips-label">{{item.groupName}}</span>
<el-tooltip popper-class="tooltip-class"
effect="dark"
placement="right">
<div slot="content">{{item.groupDesc}}</div>
<span class="tips-icon" />
</el-tooltip>:
</span>
<span v-for="(obj, index2) in item.labelUnitList"
class="label-span"
:class="{ 'label-span-choose': obj.choose }"
@click="chooseLabel(index1,index2,obj,item)">{{obj.labelName}}</span>
</el-form-item>
</div>
</el-form>
</div>
</baseDialog>
</template>
<script>
// import { sceneCodeList, transferTypeList } from '@/common/constants.js'
import { Util, deepClone } from '@/common/util'
import { queryLabelGroupTree, shopLabelDetail, updateShopLabel } from '@/api/shopConfig.js'
export default {
name: 'FlagDialog',
data() {
return {
userInfo: this.$store.state.d2admin.user.info,
infoForm: {
},
dialogConfig: {
title: '门店标签',
width: '1080px'
},
editChildRef: 'editChildRef',
baseData: {
},
groupUnitList: [],
commLabelUnitList: []
}
},
props: {
flagVisible: {
type: Boolean,
default: false
},
info: {
type: Object,
default: null
}
},
watch: {
},
computed: {
visible: {
get() {
return this.flagVisible
},
set(newVal) {
this.$emit('dialogClose', { flag: newVal, attrName: 'flagVisible' })
}
},
},
mounted() {
this.queryLabelGroupTree()
},
methods: {
queryLabelGroupTree() {
var params = {}
params.pageSize = 100
queryLabelGroupTree(params).then(res => {
console.log(res);
this.groupUnitList = deepClone(res.groupUnitList)
this.shopLabelDetail()
})
},
shopLabelDetail() {
var params = {}
params.merchantId = this.info.merchantId
shopLabelDetail(params).then(res => {
this.commLabelUnitList = deepClone(res.commLabelUnitList)
let baseModifiableIds = []//返回的已标记标签ID集合
this.commLabelUnitList && this.commLabelUnitList.forEach((item) => {
if (item.commLabelGroupInfo.groupType == '1') {
item.commLabelList.forEach(obj => {
baseModifiableIds.push(obj.labelId)
})
}
})
//判断需要回显的标签
this.groupUnitList = this.groupUnitList.map(item => {
if (item.groupType == '1') {//可标识标签
item.labelUnitList = item.labelUnitList.map(el => {
if (baseModifiableIds.findIndex(o => o == el.labelId) != -1) {
el.choose = true
} else {
el.choose = false
}
return el
})
}
return item
})
})
},
chooseLabel(idx1, idx2, obj, group) {
if (group.groupType == '1') {
this.groupUnitList[idx1].labelUnitList[idx2].choose = !obj.choose
this.groupUnitList = deepClone(this.groupUnitList)
}
},
handleAddConfirm() {
var info = deepClone(this.info)
var params = {}
params.merchantId = info.merchantId
params.labelIdAddList = []//需新增的标签id列表
params.labelIdDelList = []//需取消的标签id列表
let baseModifiableIds = []//返回的已标记标签ID集合
this.commLabelUnitList && this.commLabelUnitList.forEach((item) => {
if (item.commLabelGroupInfo.groupType == '1') {
item.commLabelList.forEach(obj => {
baseModifiableIds.push(obj.labelId)
})
}
})
console.log('baseModifiableIds', baseModifiableIds);
let flagItem = []//这次更改过标记的标签ID集合
this.groupUnitList.forEach((item) => {
if (item.groupType == '1') {
item.labelUnitList.forEach(obj => {
if (obj.hasOwnProperty("choose"))
flagItem.push(obj)
})
}
})
console.log('flagItem', flagItem);
let flagItem_ids_Y = [] //这次已标识
let flagItem_ids_N = [] //这次取消标识
flagItem && flagItem.forEach((item) => {
if (item.choose) {
flagItem_ids_Y.push(item.labelId)
} else {
flagItem_ids_N.push(item.labelId)
}
})
console.log('flagItem_ids_Y', flagItem_ids_Y);
console.log('flagItem_ids_N', flagItem_ids_N);
//拿这次标识的标签ID集合和之前返回的标签做对比,如果这次标识为已标记状态的ID没有在返回的标签里,则是这次新增的
flagItem_ids_Y && flagItem_ids_Y.map(item => {
if (baseModifiableIds.findIndex(o => o == item) == -1) {
params.labelIdAddList.push(item)
}
})
//拿这次标识的标签ID集合和之前返回的标签做对比,如果这次标识为取消标记状态的ID在返回的标签里,则是这次取消掉的
flagItem_ids_N && flagItem_ids_N.map(item => {
if (baseModifiableIds.findIndex(o => o == item) != -1) {
params.labelIdDelList.push(item)
}
})
console.log('params.labelIdAddList', params.labelIdAddList);
console.log('params.labelIdDelList', params.labelIdDelList);
updateShopLabel(params).then(res => {
this.notice.okTips('操作成功')
this.visible = true
})
},
}
}
</script>
<style lang="scss" scoped>
.flagFrom.d2-container-content {
margin-top: 0 !important;
}
.detail-dialog {
// margin: 20px 0;
.flag-div {
// height: 40rpx;
// font-family: PingFangSC-Regular;
// font-weight: 400;
// font-size: 28rpx;
// line-height: 40rpx;
.label-span {
margin-right: 10px;
max-width: 250px;
height: 26px;
background: #fafbfe;
border: 1px solid #e8e8ea;
border-radius: 4px;
font-family: PingFangSC-Regular;
font-weight: 400;
font-size: 14px;
color: #666666;
padding: 4px 8px;
}
.label-span-choose {
margin-right: 10px;
max-width: 250px;
height: 26px;
border: 1px solid #185efe;
border-radius: 4px;
font-family: PingFangSC-Regular;
font-weight: 400;
font-size: 14px;
color: #185efe;
padding: 4px 8px;
}
}
.div_g {
padding-top: 20px;
border-top: 1px solid #eaeef7;
border-bottom: 1px solid #eaeef7;
}
}
</style>