wente
2024-06-06 f6cdad43a14ca0fc362b6b8846f7fb8e362043f0
web/src/views/modules/basicInfo/ParamData.vue
@@ -1,13 +1,13 @@
<template>
  <div>
    <el-row :gutter="20">
    <el-row :gutter="5">
      <el-col :span="5">
        <div class="fa-card-a">
          <product-model-tree @on-selected="onProductSelected"/>
        <div class="fa-card-a" style="margin-right: 5px;height: calc(100vh - 123px)">
          <product-model-tree @on-selected="onProductSelected" showXdy="false"/>
        </div>
      </el-col>
      <el-col :span="19">
        <div class="mod-basicInfo-paramData}">
        <div class="mod-basicInfo-paramData fa-card-a" style="margin-left: 5px;">
          <zt-table-wraper ref="tableObj" defaultNotQuery="true" query-url="/basicInfo/ParamData/page"
                           delete-url="/basicInfo/ParamData/"
                           @dataLoaded="dataLoaded"
@@ -21,31 +21,33 @@
                <zt-dict v-model="dataForm.repairable" dict="is_or_not" placeholder="是否可维修" clearable></zt-dict>
              </el-form-item>
              <el-form-item>
                <zt-dict v-model="dataForm.reliabDistribType" dict="ReliabDistribType" placeholder="请选择可靠性分布类型" clearable></zt-dict>
                <zt-dict v-model="dataForm.reliabDistribType" dict="ReliabDistribType" placeholder="请选择可靠性分布类型"
                         clearable></zt-dict>
              </el-form-item>
              <el-form-item>
                <zt-dict v-model="dataForm.repairDistribType" dict="RepairDistribType"  placeholder="请选择维修分布类型" clearable></zt-dict>
                <zt-dict v-model="dataForm.repairDistribType" dict="RepairDistribType" placeholder="请选择维修分布类型"
                         clearable></zt-dict>
              </el-form-item>
              <el-form-item>
                <zt-button type="warning" @click="handleSaveRows">保存</zt-button>
                <zt-button type="query" @click="table.query()"/>
                <zt-button type="add" v-if="dataForm.nodeType==='2'" @click="add()"/>
                <zt-button type="delete" @click="table.deleteHandle()"/>
                <zt-button v-if="dataForm.srcId" type="warning" @click="handleSaveRows">保存</zt-button>
                <zt-button v-if="dataForm.srcId" type="query" @click="table.query()"/>
                <zt-button type="add" v-if="dataForm.productType==='3'" @click="add()"/>
                <zt-button v-if="dataForm.srcId" type="delete" @click="table.deleteHandle()"/>
              </el-form-item>
            </el-form>
            <el-table v-loading="table.dataLoading" :data="table.dataList" height="100px" v-adaptive="{bottomOffset:70}"
            <el-table v-loading="table.dataLoading" :data="table.dataList" height="100px" v-adaptive="{bottomOffset:30}"
                      class="paramsDataTable"
                      border @selection-change="table.selectionChangeHandle">
                      @selection-change="table.selectionChangeHandle">
              <el-table-column type="selection" :key="1" width="40" align="center"/>
              <el-table-column prop="name" :key="2" label="名称" fixed="left"/>
              <el-table-column v-if="dataForm.nodeType==='4'" :key="3" prop="baseOperatRatio" label="基本可靠性运行比">
              <el-table-column prop="name" :key="2" label="名称" fixed="left" width="140"/>
              <el-table-column v-if="dataForm.productType==='4'" :key="3" prop="baseOperatRatio" label="基本可靠性运行比">
                <template slot-scope="scope">
                  <el-input v-if="scope.row.isEdit" v-model="scope.row.baseOperatRatio"></el-input>
                  <span v-else v-text="scope.row.baseOperatRatio"></span>
                </template>
              </el-table-column>
              <el-table-column v-if="dataForm.nodeType==='5'||dataForm.nodeType==='4'" :key="4" prop="actualRunTime"
              <el-table-column v-if="dataForm.productType==='5'||dataForm.productType==='4'" :key="4"
                               prop="actualRunTime"
                               label="实际运行时间">
                <!--                <template slot-scope="scope">
                                    <span v-if="editingCell && editingCell.row === scope.row && editingCell.column.property === scope.column.property">
@@ -58,7 +60,7 @@
                  <span v-else v-text="scope.row.actualRunTime"></span>
                </template>
              </el-table-column>
              <el-table-column v-if="dataForm.nodeType==='2'" :key="5" label="基本可靠性计算">
              <el-table-column v-if="dataForm.productType==='3'||dataForm.productType==='2'" :key="5" label="基本可靠性计算">
                <!--                <zt-table-column-dict prop="joinCompute" :keys="6" label="参加计算" width="100" dict="is_or_not"/>-->
                <el-table-column prop="basicJoinCompute" label="参加计算" :key="6" width="100">
                  <template v-slot="{ row }">
@@ -125,7 +127,7 @@
                </el-table-column>
              </el-table-column>
              <el-table-column v-if="dataForm.nodeType==='2'" :key="15" label="任务可靠性计算">
              <el-table-column v-if="dataForm.productType==='3'||dataForm.productType==='2'" :key="15" label="任务可靠性计算">
                <el-table-column prop="taskMtbcfRegulate" :key="16" label="规定MTBCF" width="120">
                  <template slot-scope="scope">
                    <el-input v-if="scope.row.isEdit" v-model="scope.row.taskMtbcfRegulate"></el-input>
@@ -164,7 +166,7 @@
                </el-table-column>
              </el-table-column>
              <el-table-column v-if="dataForm.nodeType==='2'" :key="22" label="维修分布">
              <el-table-column v-if="dataForm.productType==='3'||dataForm.productType==='2'" :key="22" label="维修分布">
                <!--                <zt-table-column-dict prop="repairable" :keys="23" label="可维修" dict="is_or_not"/>-->
                <el-table-column prop="repairable" label="可维修" :key="23">
                  <template v-slot="{ row }">
@@ -211,9 +213,10 @@
                </el-table-column>
              </el-table-column>
              <!--  <zt-table-column-dict v-if="dataForm.nodeType==='2'" :key="27" prop="reliabDistribType" label="可靠性分布类型"
              <!--  <zt-table-column-dict v-if="dataForm.productType==='3'" :key="27" prop="reliabDistribType" label="可靠性分布类型"
                                      width="160"/>-->
              <el-table-column v-if="dataForm.nodeType==='2'" prop="reliabDistribType" label="可靠性分布类型" :key="27"
              <el-table-column v-if="dataForm.productType==='3'||dataForm.productType==='2'" prop="reliabDistribType"
                               label="可靠性分布类型" :key="27"
                               width="160">
                <template v-slot="{ row }">
                  <el-select v-if="row.isEdit" v-model="row.reliabDistribType"
@@ -229,7 +232,8 @@
                               :hit="hit"/>
                </template>
              </el-table-column>
              <el-table-column v-if="dataForm.nodeType==='2'" :key="28" prop="runTime" label="运行时间" width="100">
              <el-table-column v-if="dataForm.productType==='3'||dataForm.productType==='2'" :key="28" prop="runTime"
                               label="运行时间" width="100">
                <template slot-scope="scope">
                  <el-input v-if="scope.row.isEdit" v-model="scope.row.runTime"></el-input>
                  <span v-else v-text="scope.row.runTime"></span>
@@ -278,11 +282,11 @@
          srcId: '',
          name: '',
          dataThreeList: null,
          nodeType: '5',
          basicJoinCompute:'',
          repairable:'',
          repairDistribType:'',
          reliabDistribType:''
          productType: '5',
          basicJoinCompute: '',
          repairable: '',
          repairDistribType: '',
          reliabDistribType: ''
        },
        isOrNot: [{
          value: 1,
@@ -312,7 +316,26 @@
        ],
        // editingCell:null,
        dataList: [],
        originalTableData: [],
        originalData: null, // 记录修改前的数据
      }
    },
    // 在组件中定义 beforeRouteLeave 导航守卫
    beforeRouteLeave(to, from, next) {
      console.log(this.$store.state.contentTabs, 'this.$store.state.contentTabsActiveName')
      if (this.hasUnsavedChanges()) { // 检查是否有未保存的变更
        this.$confirm('您有未保存的更改,请先保存。是否继续离开?', '提示', {
          confirmButtonText: '保存',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.handleSaveRows(); // 保存数据
          next();
        }).catch(() => {
          next(false); // 取消路由离开
        });
      } else {
        next();
      }
    },
    components: {
@@ -327,7 +350,7 @@
    methods: {
      add() {
        this.$refs.SelectTyModel.$refs.dialog.init(null, {
          type: this.dataForm.nodeType - 1,
          type: this.dataForm.productType - 1,
          id: this.dataForm.srcId,
          pageCode: this.pageCode
        })
@@ -344,6 +367,8 @@
          this.originalData = null
          this.dataForm.dataThreeList = null
          this.$refs.tableObj.query()
          this.originalTableData = JSON.parse(JSON.stringify(this.dataList)); // 更新初始数据为当前数据
          console.log(this.originalTableData, 'this.originalTableData 当前表格json数据')
        }
      },
      edit(row) {
@@ -376,11 +401,11 @@
      // },
      onProductSelected(data) {
        this.dataForm.srcId = data.id
        if (data.productType === '3') {
          this.dataForm.nodeType = '2'
        }
        this.dataForm.productType = data.productType
        console.log(data, 'onProductSelected(data)')
        this.$refs.tableObj.query()
        this.$nextTick(() => {
          this.$refs.tableObj.query()
        })
      },
      dataLoaded(data) {
        this.dataList = data
@@ -390,7 +415,13 @@
          this.$set(dataList, 'isRemove', false)
          console.log(dataList, 'dataList')
        }
      }
        this.originalTableData = JSON.parse(JSON.stringify(this.dataList))
        console.log(this.originalTableData, 'this.originalTableData 初始表格json数据')
      },
      hasUnsavedChanges() {
        // 检查当前表格数据与初始数据是否相同
        return JSON.stringify(this.dataList) !== JSON.stringify(this.originalTableData);
      },
    }
  }
</script>