Fixiaobai
2023-10-13 e8308ddac0ba4a1f406e8f63d7e6b6f2541cb770
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
<template>
  <div style="height: 100%">
    <div class="page-header">
      <div class="header-left">
        <a @click="$router.go(-1)"><i class="icon-btn-back"></i></a>
        <h2>编辑-检测计划</h2>
      </div>
      <div class="btn-group header-right">
        <el-button title="保存" :disabled="isSubmit" v-thinclick="`save`"
          >保存</el-button
        >
      </div>
    </div>
    <div class="page-main">
      <div class="testplan-basic">
        <el-form
          :inline="true"
          :model="dataForm"
          :rules="dataRule"
          ref="dataForm"
          label-width="120px"
          class="l-mes"
        >
          <el-row>
            <el-col :span="24">
              <el-form-item label="计划编号" prop="testPlanNo">
                <el-input
                  v-model="dataForm.testPlanNo"
                  placeholder="计划编号"
                  disabled
                >
                </el-input>
              </el-form-item>
              <el-form-item label="计划名称" prop="testPlanName">
                <el-input
                  v-model="dataForm.testPlanName"
                  placeholder="计划名称"
                >
                </el-input>
              </el-form-item>
              <el-form-item label="开始执行时间" prop="startExecutionTime">
                <el-date-picker
                  v-model="dataForm.startExecutionTime"
                  type="datetime"
                  placeholder="开始执行时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item label="结束执行时间" prop="endExecutionTime">
                <el-date-picker
                  v-model="dataForm.endExecutionTime"
                  type="datetime"
                  placeholder="结束执行时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item label="品类" prop="category">
                <el-select v-model="dataForm.category" placeholder="品类">
                  <el-option
                    v-for="item in materialCategoryTypeOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
              <el-form-item label="循环周期" prop="cyclePeriod">
                <el-input v-model="dataForm.cyclePeriod" placeholder="循环周期">
                </el-input>
              </el-form-item>
              <el-form-item class="cycle-unit" label="" prop="cycleUnit">
                <el-select v-model="dataForm.cycleUnit" placeholder="单位">
                  <el-option
                    v-for="item in testplanCycleUnitOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
 
              <el-form-item label="备注" prop="remark">
                <el-input
                  type="textarea"
                  :autosize="{ minRows: 1, maxRows: 3 }"
                  v-model="dataForm.remark"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="testplan-detail">
        <el-card class="testplan-card" shadow="never" style="">
          <div slot="header" class="clearfix">
            <div>
              <span>关联检测标准</span>
            </div>
          </div>
          <div>
            <div style=" margin-left: 20px">
              <el-button
                type="text"
                size="medium"
                class="blue-but"
                @click="addNode()"
                >添加
              </el-button>
            </div>
            <div style="display:flex;justify-content:space-between">
              <div style="width:35%;">
                <el-table
                  :data="testStandardData"
                  border
                  style="width: 100%"
                  @row-click="clickTestStandard"
                  highlight-current-row
                  height="665px"
                >
                  <el-table-column
                    type="index"
                    label="序号"
                    align="center"
                    width="50"
                  >
                  </el-table-column>
                  <el-table-column
                    prop="standardNo"
                    label="标准编号"
                    align="center"
                    show-overflow-tooltip
                  >
                  </el-table-column>
                  <el-table-column
                    prop="standardName"
                    label="标准名称"
                    align="center"
                    show-overflow-tooltip
                  >
                  </el-table-column>
                  <el-table-column
                    prop="inspectionType"
                    label="检测类型"
                    align="center"
                  >
                  </el-table-column>
                  <el-table-column
                    label="操作"
                    align="center"
                    width="60px"
                    fixed="right"
                  >
                    <template slot-scope="scope">
                      <el-button
                        type="text"
                        size="small"
                        class="red-but"
                        @click.stop="delStandard(scope.row)"
                        >删除</el-button
                      >
                    </template>
                  </el-table-column>
                </el-table>
              </div>
              <div style="width:64%;">
                <el-table
                  :data="testStandardParamData"
                  border
                  style="width: 100%"
                  height="665px"
                >
                  <el-table-column
                    type="index"
                    label="序号"
                    align="center"
                    width="50"
                  >
                  </el-table-column>
                  <el-table-column prop="code" label="参数编号" align="center">
                  </el-table-column>
                  <el-table-column
                    prop="parameterItem"
                    label="参数项"
                    align="center"
                    show-overflow-tooltip
                  >
                  </el-table-column>
                  <el-table-column
                    prop="referenceValue"
                    label="要求范围"
                    align="center"
                    show-overflow-tooltip
                  >
                  </el-table-column>
                  <el-table-column
                    prop="paramType"
                    label="检测类型"
                    align="center"
                  >
                  </el-table-column>
                  <el-table-column
                    prop="parameterFormat"
                    label="参数格式"
                    align="center"
                  >
                  </el-table-column>
                  <el-table-column prop="unit" label="单位" align="center">
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </div>
        </el-card>
      </div>
    </div>
    <testStandardDialog
      :currshowlist.sync="showTestStandard"
      @listenToSelectTestStandardEvent="selectTestStandard"
    />
  </div>
</template>
<script>
import {
  addObj,
  putObj,
  getObj,
  addStandard,
  getDtoById,
  delStandard
} from '@/api/quality/testplan'
import { remote } from '@/api/admin/dict'
import testStandardDialog from '@/views/common/teststandardradio'
import { getTestStandardParams } from '@/api/quality/teststandard'
import { validatePositiveInteger } from '@/util/validate'
export default {
  components: { testStandardDialog },
  data() {
    return {
      dataForm: {
        id: null,
        testPlanNo: null,
        testPlanName: null,
        state: null,
        startExecutionTime: null,
        endExecutionTime: null,
        cyclePeriod: null,
        cycleUnit: null,
        category: null,
        remark: null
      },
      nodeList: [],
      dataRule: {
        testPlanName: [
          { required: true, message: '计划名称不能为空', trigger: 'blur' }
        ],
        startExecutionTime: [
          { required: true, message: '开始执行时间不能为空', trigger: 'blur' }
        ],
        endExecutionTime: [
          { required: true, message: '结束执行时间不能为空', trigger: 'blur' }
        ],
        cyclePeriod: [
          { required: true, message: '循环周期不能为空', trigger: 'blur' },
          { validator: validatePositiveInteger, trigger: 'blur' }
        ],
        category: [{ required: true, message: '品类不能为空', trigger: 'blur' }]
      },
      isSubmit: false,
      testplanCycleUnitOptions: [],
      materialCategoryTypeOptions: [],
      testStandardData: [],
      testStandardParamData: [],
      showTestStandard: false
    }
  },
  computed: {
    editable: function() {
      if (!this.dataForm.id) {
        return true
      }
      return false
    }
  },
  mounted() {
    window.addEventListener(
      'hashchange',
      () => {
        const currentPath = window.location.hash.slice(1)
        if (this.$route.path !== currentPath) {
          this.$router.push(currentPath)
        }
      },
      false
    )
  },
  created() {
    const formId = this.$route.params.id
    this.init(formId)
    this.getTestplanCycleUnitOptions()
    this.getMaterialCategoryTypeOptions()
  },
  methods: {
    // 查询检测计划单位字典
    getTestplanCycleUnitOptions() {
      remote('testplan_cycle_unit').then((response) => {
        if (response.data.code === 0) {
          this.testplanCycleUnitOptions = response.data.data
        } else {
          this.testplanCycleUnitOptions = []
        }
      })
    },
    // 查询品类字典
    getMaterialCategoryTypeOptions() {
      remote('material_category_type').then((response) => {
        if (response.data.code === 0) {
          this.materialCategoryTypeOptions = response.data.data
        } else {
          this.materialCategoryTypeOptions = []
        }
      })
    },
    init(id) {
      this.dataForm.id = id || 0
      this.$nextTick(() => {
        const formId = this.dataForm.id
        this.initAllData()
        if (formId) {
          this.getTestPlanInfo(formId)
        }
      })
    },
    getTestPlanInfo(formId) {
      getDtoById(formId).then((response) => {
        const resCode = response.data.code
        const resData = response.data.data
        this.testStandardData = []
        this.testStandardParamData = []
        if (resCode === 0) {
          this.dataForm.id = resData.id
          this.dataForm.testPlanNo = resData.testPlanNo
          this.dataForm.testPlanName = resData.testPlanName
          this.dataForm.state = resData.state
          this.dataForm.startExecutionTime = resData.startExecutionTime
          this.dataForm.endExecutionTime = resData.endExecutionTime
          this.dataForm.cyclePeriod = resData.cyclePeriod
          this.dataForm.cycleUnit = resData.cycleUnit
          this.dataForm.category = resData.category
          this.dataForm.remark = resData.remark
          this.testStandardData = resData.reliabilityTestPlanStandardList
        }
      })
    },
    initAllData() {
      this.dataForm.id = null
      this.dataForm.testPlanNo = null
      this.dataForm.testPlanName = null
      this.dataForm.state = null
      this.dataForm.startExecutionTime = null
      this.dataForm.endExecutionTime = null
      this.dataForm.cyclePeriod = null
      this.dataForm.cycleUnit = null
      this.dataForm.category = null
      this.dataForm.remark = null
      this.nodeList = []
    },
    save() {
      this.isSubmit = true
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          if (this.dataForm.id) {
            putObj(this.dataForm).then((response) => {
              var data = response.data
              if (data.code === 0) {
                this.$message.success('保存成功')
              } else {
                this.$message.error('保存失败')
              }
              this.isSubmit = false
            })
          } else {
            if (this.dataForm.cycleUnit != null) {
              addObj(this.dataForm).then((response) => {
                var data = response.data
                if (data.code === 0) {
                  this.dataForm.id = data.data
                  this.$message.success('保存成功')
                } else {
                  this.$message.error('保存失败')
                }
                this.isSubmit = false
              })
            } else {
              this.$message.error('请选择循环周期单位')
            }
          }
        } else {
          this.isSubmit = false
        }
      })
    },
    addNode() {
      if (this.dataForm.id != null && this.dataForm.id) {
        this.showTestStandard = true
      } else {
        this.$message.warning('请先保存检测计划信息')
      }
    },
    selectTestStandard(param) {
      if (param) {
        const planAndStandard = []
        planAndStandard.push({
          standardId: param.id,
          testPlanId: this.dataForm.id
        })
        this.testStandardData = []
        this.testStandardParamData = []
        addStandard(planAndStandard).then((res) => {
          if (res.data.code === 0) {
            const resData = res.data.data
            this.testStandardData = resData
            this.$message.success('关联检测标准成功')
          }
        })
      }
    },
    // 检测标准的回调
    clickTestStandard(row) {
      this.getTestStandardParamData(row.standardId)
    },
    // 获取关联的检测标准参数信息
    getTestStandardParamData(testStandardId) {
      getTestStandardParams(
        Object.assign({
          testStandardId: testStandardId
        })
      ).then((response) => {
        this.testStandardParamData = response.data.data
      })
    },
    // 删除子表
    delStandard(row) {
      console.log(row)
      delStandard(row.id).then((res) => {
        if (res.data.code === 0) {
          this.getTestPlanInfo(this.dataForm.id)
          this.$message.success('删除检测标准成功')
        }
      })
    }
  }
}
</script>
<style>
.testplan-basic {
  background-color: #fff;
  height: 100px;
  display: flex;
  padding: 20px 30px;
  border: 1px solid #ddd;
}
.testplan-detail {
  overflow: hidden;
  width: 100%;
  height: 760px;
  padding: 10px 20px;
  display: flex;
  border: 1px solid #ddd;
  background-color: #fff;
  margin-top: 10px;
}
.testplan-detail .el-card__header {
  padding: 0px 20px;
}
.testplan-card {
  width: 100%;
  border: 0px;
}
.testplan-card .el-card__header {
  border-bottom: 0px;
}
.testplan-card .el-card__body {
  padding-top: 0px;
}
.blue-but.is-disabled {
  color: #aacfff;
}
 
.blue-but {
  color: #006eff;
}
.red-but.is-disabled {
  color: #fab6b6;
}
 
.red-but {
  color: red;
}
.cycle-unit {
  width: 40px;
}
</style>