xiangpei
2025-06-05 1fa6ac40e2ce16e1174cec9ca538d45eeb660fdc
src/views/projectEngineering/projectLibrary/component/InvestInfo.vue
@@ -164,7 +164,6 @@
</template>
<script>
import Cookies from "js-cookie";
import {
  addProjectInvestmentInfo,
  editProjectInvestmentInfo,
@@ -179,28 +178,28 @@
      type: Boolean,
      default: false,
      required: true
    }
    },
  },
  data() {
    return {
      projectForm: {},
      investmentForm: {
        id: '',
        beCrossRegion: '',
        constructionLocation: '',
        detailedAddress: '',
        beCompensationProject: '',
        compensationReason: '',
        plannedStartDate: '',
        expectedCompletionDate: '',
        nationalIndustryClassification: '',
        industryClassification: '',
        projectNature: '',
        projectAttribute: '',
        useEarth: '',
        contentScale: '',
        code: '',
        projectId: '',
        // id: '',
        // beCrossRegion: '',
        // constructionLocation: '',
        // detailedAddress: '',
        // beCompensationProject: '',
        // compensationReason: '',
        // plannedStartDate: '',
        // expectedCompletionDate: '',
        // nationalIndustryClassification: '',
        // industryClassification: '',
        // projectNature: '',
        // projectAttribute: '',
        // useEarth: '',
        // contentScale: '',
        // code: '',
        // projectId: '',
      },
      plannedStartDate: '',
      expectedCompletionDate: '',
@@ -212,36 +211,46 @@
      sys_administrative_divisions: []
    };
  },
  created() {
    this.investmentForm.projectId = this.$route.query.projectId
  mounted() {
    // 从Cookies中获取缓存数据
    const investmentForm = Cookies.get("investmentForm");
    const projectForm = Cookies.get("projectForm");
    const investmentForm = localStorage.getItem("investmentForm");
    const projectForm = localStorage.getItem("projectForm");
    // 尝试解析JSON数据
    const parsedInvestmentForm = investmentForm ? JSON.parse(investmentForm) : null;
    const parsedProjectForm = projectForm ? JSON.parse(projectForm) : null;
    // 设置investment和projectForm对象
    if(parsedInvestmentForm) this.investmentForm = parsedInvestmentForm;
    if(parsedProjectForm) this.projectForm = parsedProjectForm;
    // 如果路由存在id且没有缓存,视为编辑或查看,调用api
    if (this.investmentForm.projectId && !investmentForm) {
      this.getInvestment();
    if(parsedInvestmentForm) {
      this.investmentForm = parsedInvestmentForm;
    }
    this.investmentForm.constructionLocation = this.projectForm.area;
    this.investmentForm.detailedAddress = this.projectForm.projectAddress;
    this.investmentForm.plannedStartDate = this.projectForm.planStartTime;
    this.investmentForm.expectedCompletionDate = this.projectForm.planCompleteTime;
    if(parsedProjectForm) {
      this.projectForm = parsedProjectForm;
    }
    // 如果路由存在id且没有缓存,视为编辑或查看,调用api
    if (this.$route.query.projectId && !investmentForm) {
      this.getInvestment();
    }else {
      this.investmentForm.constructionLocation = this.projectForm.area;
      this.investmentForm.detailedAddress = this.projectForm.projectAddress;
      this.investmentForm.plannedStartDate = this.projectForm.planStartTime;
      this.investmentForm.expectedCompletionDate = this.projectForm.planCompleteTime;
    }
    this.investmentForm.projectId = this.projectForm.id;
  },
  beforeDestroy() {
    Cookies.set("investmentForm", JSON.stringify(this.investmentForm));
    if(Object.keys(this.investmentForm).length !==0) localStorage.setItem("investmentForm", JSON.stringify(this.investmentForm));
  },
  methods: {
    getInvestment() {
      getProjectInvestmentInfoById(this.investmentForm.projectId ).then(res => {
      getProjectInvestmentInfoById(this.$route.query.projectId).then(res => {
        this.investmentForm = res.data;
          this.$nextTick(() => {
            this.investmentForm.constructionLocation = this.projectForm.area;
            this.investmentForm.detailedAddress = this.projectForm.projectAddress;
            this.investmentForm.plannedStartDate = this.projectForm.planStartTime;
            this.investmentForm.expectedCompletionDate = this.projectForm.planCompleteTime;
          })
      });
    },
    submit() {
@@ -249,7 +258,7 @@
        this.$message.error("请先保存投资管理基本信息")
      } else {
        this.investmentForm.projectId = this.projectForm.id;
        if (this.investmentForm.id != null) {
        if (this.investmentForm.id) {
          editProjectInvestmentInfo(this.investmentForm).then(response => {
            this.$modal.msgSuccess("修改成功");
            //跳转到下个组件
@@ -265,6 +274,14 @@
        }
      }
    },
  },
  watch: {
    investmentForm: {
      deep: true,
      handler(newVal) {
        this.$emit('investInfoForm', newVal)
      }
    }
  }
};