新版交易所前段管理后台
1
PC-20250623MANY\Administrator
2025-09-29 2503cce21fbe5520305c3fa7ee1ae9b19dace403
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
<template>
  <div class="shop-transcity-add-or-update">
    <el-dialog
      :modal="false"
      title="选择配送区域"
      :close-on-click-modal="false"
      :visible.sync="visible">
      <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px" style="height:400px">
        <el-scrollbar style="height:100%">
          <el-form-item size="mini" label="配送区域">
            <el-tree
              :data="menuList"
              :props="menuListTreeProps"
              node-key="areaId"
              ref="menuListTree"
              show-checkbox
              v-if="visible">
            </el-tree>
          </el-form-item>
        </el-scrollbar>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
  import { treeDataTranslate } from '@/utils'
  export default {
    data () {
      return {
        type: 0,
        visible: false,
        menuList: [],
        rowIndex: 0,
        menuListTreeProps: {
          label: 'areaName',
          children: 'children'
        },
        dataForm: {
          transfeeId: 0
        }
      }
    },
    methods: {
      init (rowIndex, cityList, allSelectCityList, type) {
        this.type = type
        this.rowIndex = rowIndex
        if (this.menuList.length === 0) {
          // 获取所有省和市
          this.$http({
            url: this.$http.adornUrl('/admin/area/list'),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({data}) => {
            this.menuList = treeDataTranslate(data, 'areaId', 'parentId')
          }).then(() => {
            this.visible = true
            this.disabledNodes(cityList, allSelectCityList)
            this.$nextTick(() => {
              this.$refs['dataForm'].resetFields()
              this.$refs.menuListTree.setCheckedNodes(cityList)
            })
          })
        } else {
          this.visible = true
          this.disabledNodes(cityList, allSelectCityList)
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.$refs.menuListTree.setCheckedNodes(cityList)
          })
        }
      },
      disabledNodes (cityList, allSelectCityList) {
        for (let i = 0; i < this.menuList.length; i++) {
          const childrens = this.menuList[i].children
          this.menuList[i].disabled = false
          let disabledNum = 0
          for (let j = 0; j < childrens.length; j++) {
            const city = childrens[j]
            this.menuList[i].children[j].disabled = false
            let allHasCity = allSelectCityList.findIndex((item) => city.areaId === item.areaId) > -1
            let listHasCity = cityList.findIndex((item) => city.areaId === item.areaId) > -1
            if (allHasCity && !listHasCity) {
              this.menuList[i].children[j].disabled = true
              disabledNum++
            }
          }
          if (disabledNum === this.menuList[i].children.length) {
            this.menuList[i].disabled = true
          }
        }
      },
      // 表单提交
      dataFormSubmit () {
        this.$emit('refreshDataList', this.rowIndex, this.$refs.menuListTree.getCheckedNodes(true), this.type)
        this.visible = false
      }
    }
  }
</script>
 
<style  lang="scss" scoped>
.shop-transcity-add-or-update {
  .el-scrollbar__wrap{overflow-x:hidden;}
}
</style>