zhouwx
2024-08-02 ba09ccd7346a2e0aa8a1ac55b5cc46eb9cb057af
src/views/Admin/components/contactorsMod.vue
@@ -46,13 +46,22 @@
                :tree-data="areaData"
                placeholder="行政区划"
                :replaceFields="replaceFields"
                disabled
                @change="changeArea"
            />
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="组织架构">
            <a-input v-model="orgName" disabled/>
            <a-select
                v-model.trim="form.orgStructureId"
                placeholder="选择组织架构"
                style="width: 100%"
                allowClear
                show-search
            >
              <a-select-option v-for="item in orgData" :value="item.id" :key="item.id">{{item.orgName}}</a-select-option>
            </a-select>
<!--            <a-input v-model="orgName" />-->
          </a-form-model-item>
        </a-col>
      </a-row>
@@ -95,11 +104,14 @@
</template>
<script>
import {addContactors,updateContactors} from '@/api/contactBook'
import {addContactors, getStructure, updateContactors} from '@/api/contactBook'
import {verifySimplePhone} from "@/util/validate";
import {getDistrictInfo} from "@/api/login";
import subMenu from "@/views/Admin/contactBook/subMenu.vue";
import {getOrgData} from "@/api/user";
export default {
  name: 'addressUserMod',
  components: {subMenu},
  props: ['groupList'],
  data () {
    let validatePhone = (rule, value, callback)=>{
@@ -124,6 +136,13 @@
      wrapperCol: { span: 14 },
      areaId: null,
      orgName: '',
      areaVal: [],
      orgData: [],
      fieldNames:{
        label: 'name',
        value: 'id',
        children: 'children'
      },
      form: {
        id: null,
        name: '',
@@ -214,19 +233,26 @@
        key:'id',
        value: 'id'
      },
      currentKey: [],
      openKeys: [],
    }
  },
  created() {
    const t = this
    t.getDistrictInfo()
    // t.getDistrictInfo()
    t.getStructure()
  },
  methods:{
    openDialog(type,data,areaId,orgName,orgId){
    openDialog(type,data,areaId,orgName,orgId) {
      const t = this
      t.changeArea(areaId)
      t.createRules()
      t.areaId = Number(areaId)
      t.orgName = orgName
      if(type == 'add'){
        t.title = '新增责任人'
        t.isView = false
@@ -268,6 +294,10 @@
        }
      }
      t.visible = true
    },
    onChange(value) {
      const t = this
    },
    isValidKey(key, object){
      return key in object;
@@ -360,8 +390,36 @@
      });
    },
    async getStructure(){
      const t = this
      const res = await getStructure()
      if(res.data.code == 100){
        t.areaData = t.filterBranches(res.data.data,['自治区直辖县级行政区划'])
        // const firstItem = this.firstIdWithOrgStructures(res.data.data[0])
        // if(firstItem){
        //   t.openKeys =  [firstItem.id +'-'+  firstItem.name]
        //   t.currentId = firstItem.id
        //   t.currentKey = [firstItem.orgStructures[0].id +'-'+  firstItem.orgStructures[0].orgName]
        // }else{
        //   t.$message.warning('暂无可操作的单位,请先进入“组织架构维护页面”新建相应的本级单位')
        // }
      }else{
        t.$message.warning(res.data.msg)
      }
    },
    filterBranches(branches, targetNames) {
      return branches.filter(branch => {
        if (targetNames.includes(branch.name)) {
          return false; // 过滤掉当前分支
        }
        if (branch.children && branch.children.length > 0) {
          branch.children = this.filterBranches(branch.children, targetNames);
        }
        return true; // 保留当前分支
      });
    },
    async getDistrictInfo(){
      let res = await getDistrictInfo()
      let res = await getStructure()
      if(res.data.code == 100){
        this.areaData = res.data.data
      } else {
@@ -387,6 +445,20 @@
    handleCancel(e) {
      const t = this
      t.visible = false;
    },
    changeArea(val){
      const t = this
      t.form.districtId = val;
      t.form.districtCode = t.findCodeById(t.areaData,val)
      t.form.orgStructureId = null;
      getOrgData(val).then(res => {
        if(res.data.code === 100) {
          console.log("res",res)
          t.orgData = res.data.data
        }else {
          t.$message.warning(res.data.msg)
        }
      })
    }
  }
}