jinlin
2024-11-19 195bb5267a6ece13363303e177fee7d1fa3941aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
<template>
  <div>
    <el-row :gutter="5">
      <el-col :span="4">
        <div class="fa-card-a" style="margin-right: 5px;height: calc(100vh - 123px)">
          <product-model-tree ref="modelTree" @on-selected="onProductSelected" @on-default="onDefault" showXdy="false" :isShow="false"/>
        </div>
      </el-col>
      <el-col :span="20">
        <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"
                           v-slot="{ table }"
                           :paging='false'
          >
            <el-form :inline="true" :model="dataForm" @keyup.enter.native="table.query()">
              <el-form-item>
                <zt-dict v-model="dataForm.basicJoinCompute" dict="is_or_not" placeholder="是否参与计算" clearable></zt-dict>
              </el-form-item>
              <el-form-item>
                <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>
              </el-form-item>
              <el-form-item>
                <zt-dict v-model="dataForm.repairDistribType" dict="RepairDistribType" placeholder="请选择维修分布类型"
                         clearable></zt-dict>
              </el-form-item>
              <el-form-item>
                <el-input v-model="dataForm.name" placeholder="请输入名称" clearable></el-input>
              </el-form-item>
              <el-form-item>
                <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-tabs v-model="activeName" @tab-click="handleClick">
              <el-tab-pane label="基本可靠性" name="first">
                <el-table v-loading="table.dataLoading" :data="table.dataList" height="100px"
                          v-adaptive="{bottomOffset:30}"
                          :header-cell-style="{'text-align':'center'}"
                          class="paramsDataTable"
                          @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" width="120"/>
                  <el-table-column v-if="dataForm.productType==='3'||dataForm.productType==='4'"
                                   prop="reliabDistribType"
                                   label="可靠性分布类型" :key="27"
                                   align="center">
                    <template v-slot="{ row }">
                      <el-select v-if="row.isEdit" v-model="row.reliabDistribType"
                                 placeholder="请选择">
                        <el-option v-for="item in reliabDistribType"
                                   :key="item.value"
                                   :label="item.label"
                                   :value="item.value">
                        </el-option>
                      </el-select>
                      <zt-dict-tag v-else dict="ReliabDistribType" :value="row.reliabDistribType" :typeS="typeS"
                                   :typeI="typeI" :typeD="typeD" :typeColor="typeColor" :size="size" :effect="effect"
                                   :hit="hit"/>
                    </template>
                  </el-table-column>
                  <el-table-column v-if="dataForm.productType==='2'" :key="3" prop="baseOperatRatio" label="基本可靠性运行比"
                                   align="right">
                    <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.productType==='1'||dataForm.productType==='2'" :key="4"
                                   prop="actualRunTime"
                                   label="实际运行时间" align="right">
                    <template slot-scope="scope">
                      <el-input v-if="scope.row.isEdit" v-model="scope.row.actualRunTime"></el-input>
                      <span v-else v-text="scope.row.actualRunTime"></span>
                    </template>
                  </el-table-column>
                  <el-table-column v-if="dataForm.productType==='3'||dataForm.productType==='4'" :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" align="center">
                      <template v-slot="{ row }">
                        <el-select v-if="row.isEdit" v-model="row.basicJoinCompute"
                                   placeholder="参加计算">
                          <el-option v-for="item in isOrNot"
                                     :key="item.value"
                                     :label="item.label"
                                     :value="item.value">
                          </el-option>
                        </el-select>
                        <zt-dict-tag v-else dict="is_or_not" :value="row.basicJoinCompute" :typeS="typeS" :typeI="typeI"
                                     :typeD="typeD"
                                     :typeColor="typeColor" :size="size" :effect="effect" :hit="hit"/>
                      </template>
                    </el-table-column>
                    <el-table-column prop="basicMtbfRegulate" :key="7" label="MTBF" align="right" width="110">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.basicMtbfRegulate"></el-input>
                        <span v-else>{{scope.row.basicMtbfRegulate | keepNumber}}</span>
                      </template>
                    </el-table-column>
                    <!--<el-table-column prop="basicMtbfAccept" :key="8" label="可接受的MTBF" width="100">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.basicMtbfAccept"></el-input>
                        <span v-else v-text="scope.row.basicMtbfAccept"></span>
                      </template>
                    </el-table-column>-->
                    <el-table-column prop="basicMtbfRegulSuccRate" :key="9" label="成功率" align="right">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.basicMtbfRegulSuccRate"></el-input>
                        <span v-else v-text="scope.row.basicMtbfRegulSuccRate"></span>
                      </template>
                    </el-table-column>
                    <!-- <el-table-column prop="basicMtbfAcceptSuccRate" :key="10" label="MTBF可接受成功率" width="120">
                       <template slot-scope="scope">
                         <el-input v-if="scope.row.isEdit" v-model="scope.row.basicMtbfAcceptSuccRate"></el-input>
                         <span v-else v-text="scope.row.basicMtbfAcceptSuccRate"></span>
                       </template>
                     </el-table-column>-->
                    <el-table-column prop="basicUnitNum" label="单元数量" :key="11" width="100" align="center">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.basicUnitNum"></el-input>
                        <span v-else v-text="scope.row.basicUnitNum"></span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="basicRunsNum" label="运行次数" :key="12" width="100" align="center">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.basicRunsNum"></el-input>
                        <span v-else v-text="scope.row.basicRunsNum"></span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="basicMtbfOperatingRatio" :key="13" label="运行比" align="right">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.basicMtbfOperatingRatio"></el-input>
                        <span v-else v-text="scope.row.basicMtbfOperatingRatio"></span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="basicSingleRunTime" :key="14" label="运行时间" align="right" width="100">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.basicSingleRunTime"></el-input>
                        <span v-else v-text="scope.row.basicSingleRunTime"></span>
                      </template>
                    </el-table-column>
                  </el-table-column>
                  <el-table-column fixed="right" align="center" label="操作" width="100">
                    <template slot-scope="scope">
                      <zt-table-button size="small" type="primary" @click="edit(scope.row)">修改
                      </zt-table-button>
                      <zt-table-button v-if="scope.row.isCanel" size="small" type="primary" @click="canel(scope.row)">取消
                      </zt-table-button>
                    </template>
                  </el-table-column>
                </el-table>
              </el-tab-pane>
 
 
              <el-tab-pane label="任务可靠性" name="second" v-if="dataForm.productType==='3'||dataForm.productType==='4'">
                <el-table v-loading="table.dataLoading" :data="table.dataList" height="100px"
                          v-adaptive="{bottomOffset:30}"
                          class="paramsDataTable"
                          @selection-change="table.selectionChangeHandle"
                          :header-cell-style="{'text-align':'center'}">
                  <el-table-column type="selection" :key="1" width="40" align="center"/>
                  <el-table-column prop="name" :key="2" label="名称" fixed="left" width="120"/>
 
                  <el-table-column v-if="dataForm.productType==='3'||dataForm.productType==='4'" :key="15"
                                   label="任务可靠性计算">
                    <el-table-column prop="taskMtbcfRegulate" :key="16" label="MTBCF" width="110" align="right">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.taskMtbcfRegulate"></el-input>
                        <span v-else>{{scope.row.taskMtbcfRegulate | keepNumber}}</span>
                      </template>
                    </el-table-column>
                    <!--<el-table-column prop="taskMtbcfAccept" :key="17" label="可接受的MTBCF" width="100">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.taskMtbcfAccept"></el-input>
                        <span v-else v-text="scope.row.taskMtbcfAccept"></span>
                      </template>
                    </el-table-column>-->
                    <el-table-column prop="taskMtbcfRegulSuccRate" :key="18" label="成功率" align="right">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.taskMtbcfRegulSuccRate"></el-input>
                        <span v-else v-text="scope.row.taskMtbcfRegulSuccRate"></span>
                      </template>
                    </el-table-column>
                    <!-- <el-table-column prop="taskMtbcfAcceptSuccRate" :key="19" label="MTBCF可接受成功率" width="100">
                       <template slot-scope="scope">
                         <el-input v-if="scope.row.isEdit" v-model="scope.row.taskMtbcfAcceptSuccRate"></el-input>
                         <span v-else v-text="scope.row.taskMtbcfAcceptSuccRate"></span>
                       </template>
                     </el-table-column>-->
                    <el-table-column prop="taskMtbcfOperatingRatio" :key="20" label="运行比" align="right">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.taskMtbcfOperatingRatio"></el-input>
                        <span v-else v-text="scope.row.taskMtbcfOperatingRatio"></span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="taskMtbcfOtherParams2" :key="21" label="其他参数2" align="right">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.taskMtbcfOtherParams2"></el-input>
                        <span v-else v-text="scope.row.taskMtbcfOtherParams2"></span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="taskMtbcfOtherParams3" :key="30" label="其他参数3" align="right">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.taskMtbcfOtherParams3"></el-input>
                        <span v-else v-text="scope.row.taskMtbcfOtherParams3"></span>
                      </template>
                    </el-table-column>
                  </el-table-column>
                  <el-table-column v-if="dataForm.productType==='3'||dataForm.productType==='4'" :key="22" label="维修分布"
                                   align="center">
                    <!--                <zt-table-column-dict prop="repairable" :keys="23" label="可维修" dict="is_or_not"/>-->
                    <el-table-column prop="repairable" label="可维修" :key="23" width="80" align="center">
                      <template v-slot="{ row }">
                        <el-select v-if="row.isEdit" v-model="row.repairable"
                                   placeholder="请选择">
                          <el-option v-for="item in isOrNot"
                                     :key="item.value"
                                     :label="item.label"
                                     :value="item.value">
                          </el-option>
                        </el-select>
                        <zt-dict-tag v-else dict="is_or_not" :value="row.repairable" :typeS="typeS" :typeI="typeI"
                                     :typeD="typeD"
                                     :typeColor="typeColor" :size="size" :effect="effect" :hit="hit"/>
                      </template>
                    </el-table-column>
                    <!--                <zt-table-column-dict prop="repairDistribType" :keys="24" label="维修分布类型" width="140" dict="RepairDistribType"/>-->
                    <el-table-column prop="repairDistribType" label="维修分布类型" :key="24" width="130" align="center">
                      <template v-slot="{ row }">
                        <el-select v-if="row.isEdit" v-model="row.repairDistribType"
                                   placeholder="请选择">
                          <el-option v-for="item in repairDistribType"
                                     :key="item.value"
                                     :label="item.label"
                                     :value="item.value">
                          </el-option>
                        </el-select>
                        <zt-dict-tag v-else dict="RepairDistribType" :value="row.repairDistribType" :typeS="typeS"
                                     :typeI="typeI"
                                     :typeD="typeD" :typeColor="typeColor" :size="size" :effect="effect" :hit="hit"/>
                      </template>
                    </el-table-column>
                    <el-table-column prop="repairMttcr" label="MTTCR" :key="25" width="100" align="right">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.repairMttcr"></el-input>
                        <span v-else>{{scope.row.repairMttcr | keepNumber}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="repairMttcrOtherParams2" :key="26" label="其他参数2" align="right">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.repairMttcrOtherParams2"></el-input>
                        <span v-else v-text="scope.row.repairMttcrOtherParams2"></span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="repairMttcrOtherParams3" :key="27" label="其他参数3" align="right">
                      <template slot-scope="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.repairMttcrOtherParams3"></el-input>
                        <span v-else v-text="scope.row.repairMttcrOtherParams3"></span>
                      </template>
                    </el-table-column>
                  </el-table-column>
                  <el-table-column fixed="right" align="center" label="操作" width="100">
                    <template slot-scope="scope">
                      <zt-table-button size="small" type="primary" @click="edit(scope.row)">修改
                      </zt-table-button>
                      <zt-table-button v-if="scope.row.isCanel" size="small" type="primary" @click="canel(scope.row)">取消
                      </zt-table-button>
                    </template>
                  </el-table-column>
 
                </el-table>
              </el-tab-pane>
            </el-tabs>
            <!-- 弹窗, 新增 / 修改 -->
            <select-ty-model @refreshDataList="table.query" ref="SelectTyModel"/>
          </zt-table-wraper>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
 
<script>
  import ProductModelTree from "./ProductModelTree";
  import SelectTyModel from "./SelectTyModel";
 
  export default {
    data() {
      return {
        activeName: 'first',
        pageCode: '',
        key: '',
        typeS: '',
        typeI: '',
        typeW: '',
        typeD: '',
        typeColor: {},
        size: '',
        effect: '',
        hit: false,
        dataForm: {
          id: '',
          pid: '',
          srcId: '',
          name: '',
          dataThreeList: null,
          productType: '1',
          basicJoinCompute: '',
          repairable: '',
          repairDistribType: '',
          reliabDistribType: ''
        },
        isOrNot: [{
          value: 0,
          label: '否'
        },{
          value: 1,
          label: '是'
        }],
        repairDistribType: [{
          value: 1,
          label: '指数分布'
        },
          {
            value: 2,
            label: '威布尔分布'
          },
        ],
        reliabDistribType: [
          {
            value: 1,
            label: '指数分布'
          },
          {
            value: 2,
            label: '威布尔分布'
          },
          {
            value: 3,
            label: '二项分布'
          }
        ],
        // editingCell:null,
        dataList: [],
        originalTableData: [],
        originalData: null, // 记录修改前的数据
      }
    },
    filters: {
      keepNumber(value) { //过滤器保留4为小数
        const numM = Number(value).toFixed(5);
        if (numM === "NaN") {
          return "0.0000";
        }
        const realVal = numM.substring(0, numM.length - 1);
        return realVal;
      },
    },
    // 在组件中定义 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: {
      ProductModelTree,
      SelectTyModel
    },
    mounted() {
      this.$refs.modelTree.getProductList()
    },
    methods: {
      add() {
        this.$refs.SelectTyModel.$refs.dialog.init(null, {
          type: this.dataForm.productType + 1,
          id: this.dataForm.srcId,
          pageCode: 'expect'
        })
        console.log(this.dataForm.srcId, 'add')
      },
      //批量保存
      async handleSaveRows() {
        this.dataForm.dataThreeList = this.$refs.tableObj.dataList
        console.log(this.dataForm, 'this.dataForm this.dataForm')
        let res = await this.$http.post('/basicInfo/ParamData/save', this.dataForm)
        if (res.success) {
          console.log(res.data)
          await this.$tip.success()
          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) {
        row.isCanel = true
        row.isEdit = true
        row.isRemove = false
        this.originalData = {...row}
      },
      canel(row) {
        // 如果原始数据为空,则记录原始数据
        if (!this.originalData) {
          this.originalData = {...row}
        }
        // 将当前数据恢复为原始数据
        Object.assign(row, this.originalData)
        console.log(this.originalData, 'console.log(this.originalData)')
        // 恢复成功后,将 originalData 设为 null
        this.originalData = null
        row.isEdit = false
        row.isCanel = false
      },
      // handleCellClick(row, column) {
      //   this.editingCell = {row, column}
      //   this.$nextTick(() => {
      //     if(this.$refs.editInput){
      //       this.$refs.editInput.focus()
      //     }
      //   })
      //   console.log(this.editingCell, 'this.editingCell')
      // },
      onProductSelected(data) {
        this.dataForm.srcId = data.id
        this.dataForm.productType = data.productType
        this.activeName = 'first'
        console.log(data, 'onProductSelected(data)')
        this.$nextTick(() => {
          this.$refs.tableObj.query()
        })
      },
      onDefault(defaultId) {
        this.dataForm.srcId = defaultId
        this.dataForm.productType = '1'
        this.activeName = 'first'
        this.$nextTick(() => {
          this.$refs.tableObj.query()
        })
      },
      dataLoaded(data) {
        this.dataList = data
        for (let dataList of data) {
          this.$set(dataList, 'isEdit', false)
          this.$set(dataList, 'isCanel', false)
          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>
<style>
  .paramsDataTable.el-table thead.is-group th {
    background: #edf6ff;
  }
</style>