|
|
@@ -336,12 +336,18 @@
|
|
336
|
336
|
|
|
337
|
337
|
<script>
|
|
338
|
338
|
import { listMerchant, getMerchant, addMerchant, updateMerchant, delMerchant, deleteMerchantCheck, adminUserOptions, memberOptions } from "@/api/agri/merchant"
|
|
339
|
|
-import { getRegionTree } from "@/api/agri/region"
|
|
|
339
|
+import regionCascaderMixin from "@/mixins/regionCascader"
|
|
340
|
340
|
import MerchantDetail from "./detail"
|
|
341
|
341
|
|
|
|
342
|
+const REGION_CASCADER_FIELDS = [
|
|
|
343
|
+ { codeKey: "regRegionCode", cascaderKey: "regRegionCascader" },
|
|
|
344
|
+ { codeKey: "bizRegionCode", cascaderKey: "bizRegionCascader" }
|
|
|
345
|
+]
|
|
|
346
|
+
|
|
342
|
347
|
export default {
|
|
343
|
348
|
name: "AgriMerchant",
|
|
344
|
349
|
components: { MerchantDetail },
|
|
|
350
|
+ mixins: [regionCascaderMixin],
|
|
345
|
351
|
data() {
|
|
346
|
352
|
return {
|
|
347
|
353
|
loading: true,
|
|
|
@@ -356,14 +362,6 @@ export default {
|
|
356
|
362
|
bindSearchLoading: false,
|
|
357
|
363
|
adminUserList: [],
|
|
358
|
364
|
memberList: [],
|
|
359
|
|
- regionTree: [],
|
|
360
|
|
- regionTreeLoaded: false,
|
|
361
|
|
- regionCascaderProps: {
|
|
362
|
|
- value: "code",
|
|
363
|
|
- label: "name",
|
|
364
|
|
- children: "children",
|
|
365
|
|
- emitPath: true
|
|
366
|
|
- },
|
|
367
|
365
|
queryParams: {
|
|
368
|
366
|
pageNum: 1,
|
|
369
|
367
|
pageSize: 10,
|
|
|
@@ -509,7 +507,7 @@ export default {
|
|
509
|
507
|
if (data.licenseValidType === "1" && data.licenseValidStart && data.licenseValidEnd) {
|
|
510
|
508
|
this.form.licenseValidRange = [data.licenseValidStart, data.licenseValidEnd]
|
|
511
|
509
|
}
|
|
512
|
|
- this.syncRegionCascaderFromForm()
|
|
|
510
|
+ this.syncRegionCascaderFromForm(REGION_CASCADER_FIELDS)
|
|
513
|
511
|
this.activeTab = "subject"
|
|
514
|
512
|
this.open = true
|
|
515
|
513
|
this.title = "编辑商户"
|
|
|
@@ -528,62 +526,6 @@ export default {
|
|
528
|
526
|
this.adminUserList = []
|
|
529
|
527
|
this.memberList = []
|
|
530
|
528
|
},
|
|
531
|
|
- /** 加载省市区树 */
|
|
532
|
|
- loadRegionTree() {
|
|
533
|
|
- if (this.regionTreeLoaded) {
|
|
534
|
|
- return Promise.resolve()
|
|
535
|
|
- }
|
|
536
|
|
- return getRegionTree().then(response => {
|
|
537
|
|
- this.regionTree = response.data || []
|
|
538
|
|
- this.regionTreeLoaded = true
|
|
539
|
|
- }).catch(() => {
|
|
540
|
|
- this.regionTree = []
|
|
541
|
|
- })
|
|
542
|
|
- },
|
|
543
|
|
- /** 根据区县 code 回显级联选中路径 */
|
|
544
|
|
- findRegionPath(nodes, targetCode, path) {
|
|
545
|
|
- if (!nodes || !nodes.length) {
|
|
546
|
|
- return null
|
|
547
|
|
- }
|
|
548
|
|
- for (let i = 0; i < nodes.length; i++) {
|
|
549
|
|
- const node = nodes[i]
|
|
550
|
|
- const nextPath = (path || []).concat(node.code)
|
|
551
|
|
- if (String(node.code) === String(targetCode)) {
|
|
552
|
|
- return nextPath
|
|
553
|
|
- }
|
|
554
|
|
- if (node.children && node.children.length) {
|
|
555
|
|
- const found = this.findRegionPath(node.children, targetCode, nextPath)
|
|
556
|
|
- if (found) {
|
|
557
|
|
- return found
|
|
558
|
|
- }
|
|
559
|
|
- }
|
|
560
|
|
- }
|
|
561
|
|
- return null
|
|
562
|
|
- },
|
|
563
|
|
- /** 根据级联 code 路径拼地区名称 */
|
|
564
|
|
- getRegionNamesByCodes(codes) {
|
|
565
|
|
- const names = []
|
|
566
|
|
- let nodes = this.regionTree
|
|
567
|
|
- for (let i = 0; i < codes.length; i++) {
|
|
568
|
|
- const code = codes[i]
|
|
569
|
|
- const node = (nodes || []).find(item => String(item.code) === String(code))
|
|
570
|
|
- if (!node) {
|
|
571
|
|
- break
|
|
572
|
|
- }
|
|
573
|
|
- names.push(node.name)
|
|
574
|
|
- nodes = node.children || []
|
|
575
|
|
- }
|
|
576
|
|
- return names
|
|
577
|
|
- },
|
|
578
|
|
- /** 编辑回显:把库里的 code 转成 cascader 路径 */
|
|
579
|
|
- syncRegionCascaderFromForm() {
|
|
580
|
|
- if (this.form.regRegionCode && this.regionTree.length) {
|
|
581
|
|
- this.form.regRegionCascader = this.findRegionPath(this.regionTree, this.form.regRegionCode) || []
|
|
582
|
|
- }
|
|
583
|
|
- if (this.form.bizRegionCode && this.regionTree.length) {
|
|
584
|
|
- this.form.bizRegionCascader = this.findRegionPath(this.regionTree, this.form.bizRegionCode) || []
|
|
585
|
|
- }
|
|
586
|
|
- },
|
|
587
|
529
|
/** 企业注册地区变更:写入 regRegionCode / regRegionName */
|
|
588
|
530
|
handleRegRegionChange(codes) {
|
|
589
|
531
|
this.applyRegionSelection(codes, "reg")
|
|
|
@@ -592,19 +534,6 @@ export default {
|
|
592
|
534
|
handleBizRegionChange(codes) {
|
|
593
|
535
|
this.applyRegionSelection(codes, "biz")
|
|
594
|
536
|
},
|
|
595
|
|
- /** 级联选择落库:code=区县 code,name=省/市/区县用 / 连接 */
|
|
596
|
|
- applyRegionSelection(codes, prefix) {
|
|
597
|
|
- const codeKey = prefix + "RegionCode"
|
|
598
|
|
- const nameKey = prefix + "RegionName"
|
|
599
|
|
- if (!codes || !codes.length) {
|
|
600
|
|
- this.form[codeKey] = undefined
|
|
601
|
|
- this.form[nameKey] = undefined
|
|
602
|
|
- return
|
|
603
|
|
- }
|
|
604
|
|
- const names = this.getRegionNamesByCodes(codes)
|
|
605
|
|
- this.form[codeKey] = String(codes[codes.length - 1])
|
|
606
|
|
- this.form[nameKey] = names.join("/")
|
|
607
|
|
- },
|
|
608
|
537
|
formatAdminOption(item) {
|
|
609
|
538
|
const parts = [item.nickName || item.userName, item.userName]
|
|
610
|
539
|
if (item.phonenumber) {
|