subordinateMerchantDialog.vue
7.89 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
<!-- 质保卡 -->
<template>
<d2-dialog title="下级商户设置" :is-visible="subordinateMerchantVisible" class="accountDailog" @closeDialog="handleClose"
width="800px" @confirmDialog="handleAddConfirm">
<div class="container">
<el-form ref="editSubordinateMerchantFrom" class="editSubordinateMerchantFrom d2-container-content" :model="form"
label-width="150px" v-loading="$store.state.d2admin.loading.value">
<el-table :data="form.tableData" border>
<el-table-column type="index" label="序号" :index="index => index + 1" width="50" align="center" />
<el-table-column label="商户名称" width="400" align="center">
<template slot-scope="scope">
<div class="inputCol">
<el-form-item :prop="'tableData.' + scope.$index + '.merchantNo'"
:rules="[{ required: true, message: '请选择二级流量方', trigger: 'change' }]">
<!-- <el-autocomplete style="width: 350px;"
v-model="scope.row.merchantName"
:fetch-suggestions="querySearchAsync"
placeholder="请选择二级流量方"
@select="handleSelect"></el-autocomplete> -->
<el-select v-model="scope.row.merchantNo" filterable remote reserve-keyword placeholder="请输入关键字"
style="width: 350px" :remote-method="remoteMethod" @change="changeOpt" :loading="loading">
<el-option v-for="(item, index) in options" :key="index" :label="item.merchantName"
:value="item.merchantNo" :disabled="setDisabled(item.merchantNo)">
</el-option>
</el-select>
</el-form-item>
</div>
</template>
</el-table-column>
<el-table-column label="商户号" align="center" prop="merchantNo" width="140" />
<el-table-column label="操作" align="center" width="100">
<template slot-scope="scope">
<el-button type="text" style="color: red;" @click="handleDelMerchant(scope.$index)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="add-btn">
<el-button type="primary" @click="handleAddMerchant">添加新的一行</el-button>
</div>
</el-form>
</div>
</d2-dialog>
</template>
<script>
import { getDiversionMerchantRef, serviceGetMerchantList, insertOrUpdateDiversionMerchantRef } from '@api/merchant'
import { deepClone } from '@/common/util'
export default {
name: 'WarrantyCardDialog',
data() {
return {
userInfo: this.$store.state.d2admin.user.info,
form: {
tableData: []
},
// tableData: [],
subShopMerchantList: [],
timeout: null,
loading: false,
options: []
}
},
props: {
subordinateMerchantVisible: {
type: Boolean,
default: false
},
subShopMerchantInfo: {
type: Object,
default: null
}
},
watch: {
},
created() {
},
components: {},
mounted() {
if (this.subShopMerchantInfo) {
this.getInfo(this.subShopMerchantInfo.merchantId)
}
},
methods: {
getInfo(merchantId) {
getDiversionMerchantRef({
merchantId: merchantId
}).then(res => {
this.subShopMerchantList = res || []
if (this.subShopMerchantList.length > 0) {
this.form.tableData = deepClone(this.subShopMerchantList)
this.form.tableData = this.form.tableData.map(item => {
const item_new = {
id: item.id,
merchantName: item.subMerchantName,
merchantNo: item.subMerchantId
}
this.options.push(item_new)
return item_new
})
}
})
},
handleAddConfirm() {
this.$refs.editSubordinateMerchantFrom.validate(valid => {
if (valid) {
var params = {}
params.merchantId = this.subShopMerchantInfo.merchantId
params.merchantName = this.subShopMerchantInfo.merchantName
const list = []
let info
this.form.tableData.forEach(item => {
// info = {}
// if (item.id) {
// info.id = item.id
// }
// info.subMerchantId = item.merchantNo
// info.subMerchantName = item.merchantName
// info.merchantAccountLevel = item.merchantAccountLevel
// info.merchantLoginAccount = item.merchantLoginAccount
// info.channelType = item.channelType
// info.createdTime = item.createdTime
info = deepClone(item)
info.subMerchantId = info.merchantNo
info.subMerchantName = info.merchantName
list.push(info)
})
params.list = list
insertOrUpdateDiversionMerchantRef(params).then(res => {
this.notice.okTips('操作成功')
this.handleClose(true)
})
}
})
},
handleAddMerchant() {
this.options = []
this.form.tableData.push({
// merchantName: '',
merchantNo: ''
})
},
handleDelMerchant(index) {
this.form.tableData.splice(index, 1)
},
// querySearchAsync(queryString, cb) {
// if (queryString) {
// // 请求接口
// var params = { currentPage: 1, pageSize: 100, merchantIdName: queryString }
// serviceGetMerchantList(params).then(res => {
// let result = res.list || []
// result = result.map(item => {
// return { 'value': item.merchantName, 'address': item.merchantNo }
// })
// console.log(result);
// clearTimeout(this.timeout);
// this.timeout = setTimeout(() => {
// cb(result);
// }, 1000 * Math.random());
// })
// }
// },
// handleSelect(item) {
// console.log(item)
// console.log(this.form.tableData);
// },
remoteMethod(queryString) {
if (queryString) {
this.loading = true
setTimeout(() => {
this.loading = false
var params = { currentPage: 1, pageSize: 1000, merchantIdName: queryString }
serviceGetMerchantList(params).then(res => {
this.options = res.list || []
})
}, 200)
} else {
this.options = []
}
},
setDisabled(val) {
const info = this.form.tableData.find(item => item.merchantNo == val)
if (info) {
return true
} else {
return false
}
},
changeOpt(val) {
const info = this.options.find(item => item.merchantNo == val)
console.log(info)
this.form.tableData = this.form.tableData.map(item => {
if (item.merchantNo == info.merchantNo) {
const id = deepClone(item.id)
delete info.id
item = deepClone(info)
if (id) {
item.id = id
// return item = Object.assign(info, { id: item.id })
}
}
return item
})
console.log(this.form.tableData)
},
handleClose(flag) {
this.$emit('dialogClose', flag)
}
}
}
</script>
<style scoped lang="scss">
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.add-btn {
width: 100%;
display: flex;
margin-top: 15px;
}
.accountDailog .el-dialog {
margin-top: 20vh !important;
min-width: 1000px;
}
.accountDailog .el-select-dropdown__item {
width: 395px !important;
}
.inputCol {
box-sizing: border-box;
display: flex;
flex-direction: column;
justify-content: center;
padding: 0 20px;
line-height: 80px;
::v-deep.el-form-item__content {
margin-left: 0 !important;
}
/* height: 70px;
*/
/* padding: 0 40px; */
/* */
}
// .formItemCla {
// margin-left: 0px !important;
// }
</style>