|
|
@@ -72,7 +72,7 @@
|
|
72
|
72
|
<image-upload v-model="form.shopAvatar" :limit="1" :file-size="5" :file-type="['png', 'jpg', 'jpeg']" />
|
|
73
|
73
|
</el-form-item>
|
|
74
|
74
|
<el-form-item label="商家电话" prop="shopPhone">
|
|
75
|
|
- <el-input v-model="form.shopPhone" placeholder="请输入商家电话" maxlength="20" />
|
|
|
75
|
+ <el-input v-model="form.shopPhone" :placeholder="form.shopId ? '请输入商家电话' : '选填'" maxlength="20" />
|
|
76
|
76
|
</el-form-item>
|
|
77
|
77
|
<el-form-item label="店铺描述" prop="shopDesc">
|
|
78
|
78
|
<el-input v-model="form.shopDesc" type="textarea" :rows="3" maxlength="1000" show-word-limit placeholder="选填" />
|
|
|
@@ -82,19 +82,23 @@
|
|
82
|
82
|
<el-option v-for="item in merchantOptions" :key="item.merchantId" :label="item.merchantName || item.unitName" :value="item.merchantId" />
|
|
83
|
83
|
</el-select>
|
|
84
|
84
|
</el-form-item>
|
|
85
|
|
- <el-form-item v-else label="所属商户">
|
|
86
|
|
- <span class="readonly-text">{{ form.merchantName || '—' }}</span>
|
|
|
85
|
+ <el-form-item v-if="!form.shopId && merchantAccountHint" label="经营账号">
|
|
|
86
|
+ <span class="readonly-text">{{ merchantAccountHint }}</span>
|
|
|
87
|
+ <div class="form-tip">经营账号由商户入驻时绑定,开店沿用该账号</div>
|
|
87
|
88
|
</el-form-item>
|
|
88
|
|
- <el-form-item v-if="!form.shopId" label="登录名" prop="loginName">
|
|
89
|
|
- <el-input v-model="form.loginName" placeholder="经营账号登录名(手机号)" maxlength="20" :disabled="accountLocked" />
|
|
|
89
|
+ <el-form-item v-else-if="form.shopId" label="所属商户">
|
|
|
90
|
+ <span class="readonly-text">{{ form.merchantName || '—' }}</span>
|
|
90
|
91
|
</el-form-item>
|
|
91
|
|
- <el-form-item v-if="!form.shopId" label="管理员姓名" prop="adminName">
|
|
92
|
|
- <el-input v-model="form.adminName" placeholder="管理员姓名" maxlength="64" :disabled="accountLocked" />
|
|
|
92
|
+ <el-form-item v-if="form.shopId" label="经营账号">
|
|
|
93
|
+ <span class="readonly-text">{{ form.accountAdminName || '—' }} / {{ form.accountLoginName || '—' }}</span>
|
|
|
94
|
+ <div class="form-tip">如需修改请使用「账号管理」</div>
|
|
93
|
95
|
</el-form-item>
|
|
94
|
|
- <el-form-item v-if="!form.shopId" label="初始密码" prop="password">
|
|
95
|
|
- <el-input v-model="form.password" type="password" placeholder="首家店必填;已有账号可留空" maxlength="20" show-password>
|
|
96
|
|
- <el-button slot="append" @click="generateRandomPwd">随机密码</el-button>
|
|
97
|
|
- </el-input>
|
|
|
96
|
+ <el-form-item v-if="!form.shopId" label="店铺状态" prop="shopStatus">
|
|
|
97
|
+ <el-radio-group v-model="form.shopStatus">
|
|
|
98
|
+ <el-radio label="0">开业</el-radio>
|
|
|
99
|
+ <el-radio label="1">停业</el-radio>
|
|
|
100
|
+ </el-radio-group>
|
|
|
101
|
+ <div class="form-tip">未选择时默认开业</div>
|
|
98
|
102
|
</el-form-item>
|
|
99
|
103
|
<el-form-item v-if="form.shopId" label="店铺状态" prop="shopStatus">
|
|
100
|
104
|
<el-radio-group v-model="form.shopStatus">
|
|
|
@@ -111,11 +115,16 @@
|
|
111
|
115
|
</el-dialog>
|
|
112
|
116
|
|
|
113
|
117
|
<!-- 店铺账号管理弹窗 -->
|
|
114
|
|
- <el-dialog title="店铺账号管理" :visible.sync="accountOpen" width="520px" append-to-body>
|
|
|
118
|
+ <el-dialog title="店铺账号管理" :visible.sync="accountOpen" width="560px" append-to-body>
|
|
115
|
119
|
<el-form ref="accountForm" :model="accountForm" :rules="accountRules" label-width="100px">
|
|
116
|
120
|
<el-alert v-if="accountForm.shops && accountForm.shops.length" type="info" :closable="false" class="mb12">
|
|
117
|
121
|
修改后将同步至该商户下全部店铺(共 {{ accountForm.shops.length }} 家)
|
|
118
|
122
|
</el-alert>
|
|
|
123
|
+ <div v-if="accountForm.shops && accountForm.shops.length" class="shop-tags mb12">
|
|
|
124
|
+ <el-tag v-for="item in accountForm.shops" :key="item.shopId" size="small" class="shop-tag" :type="item.shopStatus === '0' ? 'success' : 'info'">
|
|
|
125
|
+ {{ item.shopName }}
|
|
|
126
|
+ </el-tag>
|
|
|
127
|
+ </div>
|
|
119
|
128
|
<el-form-item label="登录名" prop="loginNameRaw">
|
|
120
|
129
|
<el-input v-model="accountForm.loginNameRaw" placeholder="登录名" maxlength="20" />
|
|
121
|
130
|
</el-form-item>
|
|
|
@@ -135,12 +144,19 @@
|
|
135
|
144
|
</template>
|
|
136
|
145
|
|
|
137
|
146
|
<script>
|
|
138
|
|
-import { listShop, getShop, addShop, updateShop, delShop, getShopAccount, updateShopAccount } from "@/api/agri/shop"
|
|
139
|
|
-import { selectMerchantList } from "@/api/agri/merchant"
|
|
|
147
|
+import { listShop, getShop, addShop, updateShop, delShop, deleteShopCheck, getShopAccount, updateShopAccount } from "@/api/agri/shop"
|
|
|
148
|
+import { selectMerchantList, openShopCheck } from "@/api/agri/merchant"
|
|
140
|
149
|
|
|
141
|
150
|
export default {
|
|
142
|
151
|
name: "AgriShop",
|
|
143
|
152
|
data() {
|
|
|
153
|
+ const validateShopPhone = (rule, value, callback) => {
|
|
|
154
|
+ if (this.form.shopId && !value) {
|
|
|
155
|
+ callback(new Error("请输入商家电话"))
|
|
|
156
|
+ } else {
|
|
|
157
|
+ callback()
|
|
|
158
|
+ }
|
|
|
159
|
+ }
|
|
144
|
160
|
return {
|
|
145
|
161
|
loading: true,
|
|
146
|
162
|
showSearch: true,
|
|
|
@@ -149,8 +165,9 @@ export default {
|
|
149
|
165
|
title: "",
|
|
150
|
166
|
open: false,
|
|
151
|
167
|
accountOpen: false,
|
|
152
|
|
- accountLocked: false,
|
|
153
|
168
|
merchantOptions: [],
|
|
|
169
|
+ merchantAccountHint: null,
|
|
|
170
|
+ merchantAccountOk: false,
|
|
154
|
171
|
currentMerchantId: null,
|
|
155
|
172
|
originalShopStatus: "0",
|
|
156
|
173
|
queryParams: {
|
|
|
@@ -165,10 +182,8 @@ export default {
|
|
165
|
182
|
rules: {
|
|
166
|
183
|
shopName: [{ required: true, message: "请输入店铺名称", trigger: "blur" }],
|
|
167
|
184
|
shopAvatar: [{ required: true, message: "请上传店铺头像", trigger: "change" }],
|
|
168
|
|
- shopPhone: [{ required: true, message: "请输入商家电话", trigger: "blur" }],
|
|
169
|
|
- merchantId: [{ required: true, message: "请选择商户", trigger: "change" }],
|
|
170
|
|
- loginName: [{ required: true, message: "请输入登录名", trigger: "blur" }],
|
|
171
|
|
- adminName: [{ required: true, message: "请输入管理员姓名", trigger: "blur" }]
|
|
|
185
|
+ shopPhone: [{ validator: validateShopPhone, trigger: "blur" }],
|
|
|
186
|
+ merchantId: [{ required: true, message: "请选择商户", trigger: "change" }]
|
|
172
|
187
|
},
|
|
173
|
188
|
accountRules: {
|
|
174
|
189
|
loginNameRaw: [{ required: true, message: "请输入登录名", trigger: "blur" }],
|
|
|
@@ -213,11 +228,11 @@ export default {
|
|
213
|
228
|
shopStatus: "0",
|
|
214
|
229
|
merchantId: undefined,
|
|
215
|
230
|
merchantName: undefined,
|
|
216
|
|
- loginName: undefined,
|
|
217
|
|
- adminName: undefined,
|
|
218
|
|
- password: undefined
|
|
|
231
|
+ accountAdminName: undefined,
|
|
|
232
|
+ accountLoginName: undefined
|
|
219
|
233
|
}
|
|
220
|
|
- this.accountLocked = false
|
|
|
234
|
+ this.merchantAccountHint = null
|
|
|
235
|
+ this.merchantAccountOk = false
|
|
221
|
236
|
this.resetForm("form")
|
|
222
|
237
|
},
|
|
223
|
238
|
/** 取消弹窗 */
|
|
|
@@ -251,30 +266,53 @@ export default {
|
|
251
|
266
|
this.title = "编辑店铺"
|
|
252
|
267
|
})
|
|
253
|
268
|
},
|
|
254
|
|
- /** 选择商户后带出已有经营账号 */
|
|
|
269
|
+ /** 选择商户后校验可开店并展示已有经营账号 */
|
|
255
|
270
|
handleMerchantChange(merchantId) {
|
|
|
271
|
+ this.merchantAccountHint = null
|
|
|
272
|
+ this.merchantAccountOk = false
|
|
256
|
273
|
if (!merchantId) {
|
|
257
|
274
|
return
|
|
258
|
275
|
}
|
|
259
|
|
- getShopAccount(merchantId).then(response => {
|
|
260
|
|
- const data = response.data || {}
|
|
261
|
|
- if (data.loginName || data.adminName) {
|
|
262
|
|
- this.form.loginName = data.loginNameRaw || data.loginName
|
|
263
|
|
- this.form.adminName = data.adminName
|
|
264
|
|
- this.accountLocked = true
|
|
265
|
|
- } else {
|
|
266
|
|
- this.accountLocked = false
|
|
|
276
|
+ openShopCheck(merchantId).then(response => {
|
|
|
277
|
+ const check = response.data || {}
|
|
|
278
|
+ if (!check.allowed) {
|
|
|
279
|
+ this.$modal.msgWarning(check.reason || "请先完善该商户的经营与结算信息")
|
|
|
280
|
+ this.form.merchantId = undefined
|
|
|
281
|
+ return
|
|
267
|
282
|
}
|
|
268
|
|
- }).catch(() => {})
|
|
|
283
|
+ getShopAccount(merchantId).then(res => {
|
|
|
284
|
+ const data = res.data || {}
|
|
|
285
|
+ if (!data.loginName && !data.adminName) {
|
|
|
286
|
+ this.$modal.msgWarning("该商户尚未配置经营账号,请先在商户管理中完成入驻绑定")
|
|
|
287
|
+ this.form.merchantId = undefined
|
|
|
288
|
+ return
|
|
|
289
|
+ }
|
|
|
290
|
+ this.merchantAccountHint = (data.adminName || "—") + " / " + (data.loginName || "—")
|
|
|
291
|
+ this.merchantAccountOk = true
|
|
|
292
|
+ }).catch(() => {
|
|
|
293
|
+ this.form.merchantId = undefined
|
|
|
294
|
+ })
|
|
|
295
|
+ }).catch(() => {
|
|
|
296
|
+ this.form.merchantId = undefined
|
|
|
297
|
+ })
|
|
269
|
298
|
},
|
|
270
|
|
- /** 生成随机密码 */
|
|
271
|
|
- generateRandomPwd() {
|
|
272
|
|
- const chars = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789"
|
|
273
|
|
- let pwd = ""
|
|
274
|
|
- for (let i = 0; i < 10; i++) {
|
|
275
|
|
- pwd += chars.charAt(Math.floor(Math.random() * chars.length))
|
|
|
299
|
+ /** 构建添加店铺请求体(不含经营账号字段) */
|
|
|
300
|
+ buildAddPayload() {
|
|
|
301
|
+ const payload = {
|
|
|
302
|
+ shopName: this.form.shopName,
|
|
|
303
|
+ shopAvatar: this.form.shopAvatar,
|
|
|
304
|
+ merchantId: this.form.merchantId
|
|
|
305
|
+ }
|
|
|
306
|
+ if (this.form.shopPhone) {
|
|
|
307
|
+ payload.shopPhone = this.form.shopPhone
|
|
276
|
308
|
}
|
|
277
|
|
- this.form.password = pwd
|
|
|
309
|
+ if (this.form.shopDesc) {
|
|
|
310
|
+ payload.shopDesc = this.form.shopDesc
|
|
|
311
|
+ }
|
|
|
312
|
+ if (this.form.shopStatus && this.form.shopStatus !== "0") {
|
|
|
313
|
+ payload.shopStatus = this.form.shopStatus
|
|
|
314
|
+ }
|
|
|
315
|
+ return payload
|
|
278
|
316
|
},
|
|
279
|
317
|
/** 提交店铺表单 */
|
|
280
|
318
|
submitForm() {
|
|
|
@@ -285,7 +323,11 @@ export default {
|
|
285
|
323
|
if (this.form.shopId) {
|
|
286
|
324
|
this.doUpdateShop()
|
|
287
|
325
|
} else {
|
|
288
|
|
- addShop(this.form).then(() => {
|
|
|
326
|
+ if (!this.merchantAccountOk) {
|
|
|
327
|
+ this.$modal.msgWarning("请先选择已绑定经营账号的商户")
|
|
|
328
|
+ return
|
|
|
329
|
+ }
|
|
|
330
|
+ addShop(this.buildAddPayload()).then(() => {
|
|
289
|
331
|
this.$modal.msgSuccess("添加成功")
|
|
290
|
332
|
this.open = false
|
|
291
|
333
|
this.getList()
|
|
|
@@ -352,13 +394,21 @@ export default {
|
|
352
|
394
|
})
|
|
353
|
395
|
})
|
|
354
|
396
|
},
|
|
355
|
|
- /** 删除店铺 */
|
|
|
397
|
+ /** 删除店铺(先预检再确认) */
|
|
356
|
398
|
handleDelete(row) {
|
|
357
|
|
- this.$modal.confirm("删除后不可恢复,是否继续?").then(() => {
|
|
358
|
|
- return delShop(row.shopId)
|
|
359
|
|
- }).then(() => {
|
|
360
|
|
- this.$modal.msgSuccess("删除成功")
|
|
361
|
|
- this.getList()
|
|
|
399
|
+ deleteShopCheck(row.shopId).then(response => {
|
|
|
400
|
+ const data = response.data || {}
|
|
|
401
|
+ if (data.canDelete === false) {
|
|
|
402
|
+ const reasons = (data.reasons || []).join(";")
|
|
|
403
|
+ this.$modal.msgWarning(reasons || "当前店铺不满足删除条件")
|
|
|
404
|
+ return
|
|
|
405
|
+ }
|
|
|
406
|
+ this.$modal.confirm("删除后不可恢复,是否继续?").then(() => {
|
|
|
407
|
+ return delShop(row.shopId)
|
|
|
408
|
+ }).then(() => {
|
|
|
409
|
+ this.$modal.msgSuccess("删除成功")
|
|
|
410
|
+ this.getList()
|
|
|
411
|
+ }).catch(() => {})
|
|
362
|
412
|
}).catch(() => {})
|
|
363
|
413
|
}
|
|
364
|
414
|
}
|
|
|
@@ -380,4 +430,11 @@ export default {
|
|
380
|
430
|
.mb12 {
|
|
381
|
431
|
margin-bottom: 12px;
|
|
382
|
432
|
}
|
|
|
433
|
+.shop-tags {
|
|
|
434
|
+ padding-left: 100px;
|
|
|
435
|
+}
|
|
|
436
|
+.shop-tag {
|
|
|
437
|
+ margin-right: 8px;
|
|
|
438
|
+ margin-bottom: 4px;
|
|
|
439
|
+}
|
|
383
|
440
|
</style>
|