fuliqi
2024-11-29 7adbf0551f6a6b307e66cdd6537ab45fc5a2bf11
src/views/projectEngineering/projectLibrary/component/BasicInfo.vue
@@ -107,7 +107,7 @@
              placeholder="请选择"
              style="width: 100%"
              collapse-tags
              @change="changeDepartment">
            >
              <el-option
                v-for="item in approvalList"
                :key="item.id"
@@ -139,7 +139,6 @@
              placeholder="请选择"
              style="width: 100%"
              collapse-tags
              @change="changePutUnder"
            >
              <el-option v-for="item in dict.type.sys_centralized_management" :key="item.value" :label="item.label"
                         :value="item.value"/>
@@ -316,7 +315,11 @@
    disabled: {
      type: Boolean,
      default: false
    }
    },
    isShow: {
      type: Boolean,
      required: true,
    },
  },
  data() {
    return {
@@ -360,8 +363,10 @@
        year: '',
        yearInvestAmount: '',
        competentDepartmentList: [],
        managementCentralizationList: []
        managementCentralizationList: [],
      },
      subclass: '',
      largeCategory: '',
      approvalList: [],
      setTime: '',
      planStartTime: '',
@@ -373,8 +378,6 @@
      hasMore: true,
      selectOptions: [],
      accept: ['pdf', 'docx', 'xlsx', 'jpg', 'jpeg'],
      largeCategory: '',
      subclass: '',
      mapCreateInfo: {},
      demoFormRef: null,
      rules: {
@@ -392,28 +395,32 @@
  },
  mounted() {
    this.projectForm.id = this.$route.query.projectId;
    const projectForm = Cookies.get("projectForm");
    const projectForm = localStorage.getItem("projectForm");
    //初始化主管部门下拉框
    this.getApprovalList();
    if (projectForm) {
      this.projectForm = JSON.parse(projectForm);
      this.$emit('updateIsShow', true);
    } else {
      //初始化主管部门下拉框
      this.getApprovalList();
      this.projectForm.id = this.$route.query.projectId;
      // 在组件创建时获取项目信息,如果 projectId 存在
      if (this.projectForm.id) {
        this.getProjectInfo(this.projectForm.id);
      } else {
        this.getProjectCodeApi();
        this.$emit('updateIsShow', true);
      }
      // this.handleLoadMore(1);
    }
  },
  beforeDestroy() {
    Cookies.set("projectForm", JSON.stringify(this.projectForm));
    localStorage.setItem("projectForm", JSON.stringify(this.projectForm));
  },
  methods: {
    getProjectInfo(id) {
      getProject(id).then(res => {
        this.projectForm = res.data;
        this.$emit('updateIsShow', true);
      });
    },
    getApprovalList() {
@@ -424,7 +431,7 @@
    submit() {
      this.$refs["projectForm"].validate(valid => {
        if (valid) {
          if (this.projectForm.id != null) {
          if (this.projectForm.id) {
            updateProject(this.projectForm).then(response => {
              this.$modal.msgSuccess("修改成功");
              //跳转到下个组件
@@ -446,22 +453,23 @@
        this.projectForm.projectCode = res.data;
      });
    },
    changeDepartment(val) {
      if (!val.length) {
        this.largeCategory = '';
        return;
      }
      const labels = this.approvalList.filter(item => val.includes(item.id)).map(item => item.value);
      this.largeCategory = labels.join(',');
    },
    changePutUnder(val) {
      if (!val.length) {
        this.subclass = '';
        return;
      }
      const labels = this.dict.type.sys_centralized_management.filter(item => val.includes(item.value)).map(item => item.label);
      this.subclass = labels.join(',');
    },
    // changeDepartment(val) {
    //   console.log("触发事件" + val + this.approvalList)
    //   if (!val.length) {
    //     this.largeCategory = '';
    //     return;
    //   }
    //   const labels = this.approvalList.filter(item => val.includes(item.id)).map(item => item.value);
    //   this.largeCategory = labels.join(',');
    // },
    // changePutUnder(val) {
    //   if (!val.length) {
    //     this.subclass = '';
    //     return;
    //   }
    //   const labels = this.dict.type.sys_centralized_management.filter(item => val.includes(item.value)).map(item => item.label);
    //   this.subclass = labels.join(',');
    // },
    async loadDataList(newPage) {
      try {
        this.loading = true;
@@ -506,22 +514,25 @@
  },
  watch: {
    'projectForm.managementCentralizationList'(val) {
      if (val) {
        const labels = this.dict.type.sys_centralized_management
          .filter(item => val.includes(item.value))
          .map(item => item.label);
        this.subclass = labels.join(',');
      }
    },
    'projectForm.competentDepartmentList'(val) {
      if (val) {
        const labels = this.approvalList
          .filter(item => val.includes(item.id))
          .map(item => item.value);
        this.largeCategory = labels.join(',');
      }
    },
    'projectForm': {
      handler(newVal, oldVal) {
        setTimeout(() => {
          if (newVal.managementCentralizationList) {
            const labels = this.dict.type.sys_centralized_management
              .filter(item => newVal.managementCentralizationList.includes(item.value))
              .map(item => item.label);
            this.subclass = labels.join(',');
          }
          if (newVal.competentDepartmentList) {
            const labels = this.approvalList
              .filter(item => newVal.competentDepartmentList.includes(item.id))
              .map(item => item.value);
            this.largeCategory = labels.join(',');
          }
        }, 1000);
      },
      deep: true
    }
  }
};
</script>