fuliqi
2025-02-11 e57e645d24a89adb3391be16f6948b292183fa04
src/views/projectEngineering/projectLibrary/component/InvestInfo.vue
@@ -11,7 +11,7 @@
              style="width: 100%"
            >
              <el-option v-for="item in dict.type.sys_cross_domain" :key="item.value" :label="item.label"
                         :value="item.value"/>
                         :value="parseInt(item.value)"/>
            </el-select>
          </el-form-item>
        </el-col>
@@ -46,7 +46,7 @@
              style="width: 100%"
            >
              <el-option v-for="item in dict.type.sys_whether_project" :key="item.value" :label="item.label"
                         :value="item.value"/>
                         :value="parseInt(item.value)"/>
            </el-select>
          </el-form-item>
        </el-col>
@@ -137,7 +137,7 @@
              style="width: 100%"
            >
              <el-option v-for="item in dict.type.sys_whether_project" :key="item.value" :label="item.label"
                         :value="item.value"/>
                         :value="parseInt(item.value)"/>
            </el-select>
          </el-form-item>
        </el-col>
@@ -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: '',
@@ -214,33 +213,44 @@
  },
  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对象
    this.investmentForm = parsedInvestmentForm || {};
    this.projectForm = parsedProjectForm || {};
    // 如果projectForm存在id且没有缓存,则调用api
    if (this.projectForm.id && !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.id).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() {
@@ -248,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("修改成功");
            //跳转到下个组件
@@ -264,6 +274,14 @@
        }
      }
    },
  },
  watch: {
    investmentForm: {
      deep: true,
      handler(newVal) {
        this.$emit('investInfoForm', newVal)
      }
    }
  }
};