xiangpei
2024-11-28 cf2faab021222e1e345e8098da38f2c24ea8b504
src/views/projectEngineering/projectLibrary/projectDetails.vue
@@ -18,6 +18,7 @@
      :is="componentName"
      ref="childRef"
      :disabled="disabled"
      @toNext="changeTable"
      class="full-width custom-height"
    />
    <div v-if="!disabled" class="button-container">
@@ -35,14 +36,14 @@
import LegalPerson from '@/views/projectEngineering/projectLibrary/component/legalPerson';
import PolicyInfo from '@/views/projectEngineering/projectLibrary/component/PolicyInfo';
import DocumentsInfo from '@/views/projectEngineering/projectLibrary/component/DocumentsInfo';
import { addProject, getProject, updateProject, getProjectCode } from '@/api/projectInfo';
export default {
  name: 'ProjectDetails',
  data() {
    return {
      currentTab: '项目管理基础信息',
      id: this.$route.query.id || '',
      disabled: false,
      projectForm:{},
      componentName: BasicInfo,
      TABS_DATA: [
        {
@@ -52,11 +53,11 @@
        },
        {
          label: '投资管理基础信息',
          value: '任务下发',
          value: '投资管理基础信息',
          componentName: InvestInfo
        },
        {
          label: ' 项目投资及资金来源',
          label: '项目投资及资金来源',
          value: '项目投资及资金来源',
          componentName: InvestmentFunds
        },
@@ -83,117 +84,19 @@
    handleClick(tabTarget) {
      this.componentName = this.TABS_DATA[tabTarget.index].componentName;
    },
    submit() {
      if (!this.projectForm.projectName) {
        this.$message.error('请输入项目名称');
        return;
      }
      if (this.projectForm.contact) {
        const phoneRegex = /^1[3-9]\d{9}$/;
        if (!phoneRegex.test(this.projectForm.contact)) {
          this.$message.error('请输入正确的手机号码');
          return;
        }
      }
      if (this.$refs.childRef) {
        this.$refs.childRef.$refs.demoFormRef.validate((valid) => {
          if (valid) {
            const payload = {
              projectInfoInsertDTO: this.projectForm,
              projectInvestmentInfo: this.investment,
              projectInvestmentFunding: this.investmentFunds,
              projectUnitRegistrationInfo: this.legalPerson,
              investmentProjectPolicyComplianceDTO: this.investmentProjectPolicyComplianceDTO,
              fileIdList: this.fileIdList
            };
            if (this.id) {
              updateProject(payload).then(res => {
                if (res.code === 200) {
                  this.$message.success(res.msg);
                  this.$router.push({ path: '/projectEngineering/project/projectLibrary' });
                } else {
                  this.$message.error(res.msg);
                }
              });
            } else {
              addProject(payload).then(res => {
                if (res.code === 200) {
                  this.$message.success(res.msg);
                  this.$router.push({ path: '/projectEngineering/project/projectLibrary' });
                } else {
                  this.$message.error(res.msg);
                }
              });
            }
          }
        });
      }
    changeTable(index) {
      this.componentName = this.TABS_DATA[index].componentName;
      this.currentTab = this.TABS_DATA[index].value;
    },
    getProjectInfo(id) {
      getProject(id, 0).then(res => {
        if (res.data) {
          this.investment = res.data.projectInvestmentInfo || {};
          this.investmentFunds = res.data.projectInvestmentFunding || {};
          this.legalPerson = res.data.projectUnitRegistrationInfo || {};
          this.investmentProjectPolicyComplianceDTO = res.data.investmentProjectPolicyComplianceDTO || {};
          if (res.data.investmentProjectPolicyComplianceDTO && res.data.investmentProjectPolicyComplianceDTO.sysOssVos.length > 0) {
            this.fileList = res.data.investmentProjectPolicyComplianceDTO.sysOssVos.map(item => ({
              fileId: item.ossId,
              name: item.originalName,
              url: item.url
            }));
          } else {
            this.fileList = [];
          }
          if (res.data.fileIdList) {
            this.fileIdList = res.data.fileIdList;
            this.documentsInfoList = res.data.sysOssVos.map(item => ({
              fileId: item.ossId,
              name: item.originalName,
              url: item.url
            }));
          }
          this.projectForm = res.data.projectInfoInsertDTO || {};
          this.projectList = res.data.projectInfoInsertDTO.sysOssVos.map(item => ({
            fileId: item.ossId,
            name: item.originalName,
            url: item.url
          }));
        }
      });
    submit() {
      this.$refs.childRef.submit();
    },
    reset() {
      if (this.id) {
        this.getProjectInfo(this.id);
      } else {
        this.getProjectCodeApi();
        this.resetPlanLibrary();
        this.fileList = [];
        this.fileIdList = [];
        this.projectList = [];
        this.documentsInfoList = [];
      }
    },
    cancel() {
      this.$router.push({ path: '/projectEngineering/project/reserveProjects', query: { projectCategory: '1' } });
      localStorage.removeItem('fileIdList');
    },
    getProjectCodeApi() {
      getProjectCode().then(res => {
        if (res.code === 200) {
          this.projectForm.projectCode = res.msg;
        }
      });
      this.$refs.childRef.reset();
    },
  },
  created() {
    // 在组件创建时获取项目信息,如果 id 存在
    if (this.id) {
      this.getProjectInfo(this.id);
    } else {
      this.getProjectCodeApi();
    }
    console.log("sss")
  },
};