无人机管理后台前端(已迁走)
rain
2025-04-28 e67160b34db938e487ddf152738fe1b4bdc72b9c
机构管理省市级行政区划名称回显
1 files modified
49 ■■■■ changed files
src/views/system/dept.vue 49 ●●●● patch | view | raw | blame | history
src/views/system/dept.vue
@@ -482,23 +482,31 @@
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
// 修改 beforeOpen 方法
      beforeOpen(done, type) {
        if (['add', 'edit'].includes(type)) {
          this.initData();
        }
        if (['edit', 'view'].includes(type)) {
          getDept(this.form.id).then((res) => {
            const areaCode = res.data.data.areaCode;
            const areaName = res.data.data.areaName;
      const data = res.data.data;
      const areaCode = data.areaCode;
      const areaName = data.areaName;
            
            // 生成完整的行政区划代码
      // 生成完整的行政区划代码(考虑不同级别)
            const fullAreaCode = this.getFullAreaCode(areaCode);
            
            this.form = Object.assign({}, res.data.data, {
      this.form = Object.assign({}, data, {
              hasChildren: this.form.hasChildren,
              // 使用完整的行政区划代码
              areaCode: fullAreaCode,
              areaName: areaName || '',
      });
      // 调试输出
      console.log('回显数据:', {
        originalAreaCode: areaCode,
        fullAreaCode: fullAreaCode,
        areaName: areaName
            });
          });
        } else if (type === 'add') {
@@ -559,13 +567,30 @@
          resolve(res.data.data);
        });
      },
      // 新增:获取完整的行政区划代码
      getFullAreaCode(countyCode) {
        if (!countyCode) return '';
        // 县级代码是12位,省级代码取前2位,市级代码取前4位
        const provinceCode = countyCode.substring(0, 2) + '0000000000';
        const cityCode = countyCode.substring(0, 4) + '00000000';
        return `${provinceCode},${cityCode},${countyCode}`;
// 修改 getFullAreaCode 方法
getFullAreaCode(areaCode) {
  if (!areaCode) return '';
  // 根据编码长度判断层级
  const code = areaCode.toString();
  // 如果已经是完整的逗号分隔格式,直接返回
  if (code.includes(',')) return code;
  // 处理不同级别的编码
  if (code.endsWith('0000000000')) {
    // 省级编码
    return code;
  } else if (code.endsWith('00000000') && !code.endsWith('0000000000')) {
    // 市级编码
    const provinceCode = code.substring(0, 2) + '0000000000';
    return `${provinceCode},${code}`;
  } else {
    // 县级编码
    const provinceCode = code.substring(0, 2) + '0000000000';
    const cityCode = code.substring(0, 4) + '00000000';
    return `${provinceCode},${cityCode},${code}`;
  }
      },
    },
  };