zouyu
2023-11-13 5381292617ad40f2fc7a9266ceb964a672d25a5a
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
<template>
  <el-dialog
    width="90%"
    :title="isEditCommit ? '质检表单' : '布局预览'"
    top="5vh"
    :visible.sync="innerVisible"
    append-to-body
    @close="$emit('update:currshowlist', false)"
    :show="currshowlist"
    class="preview-layout-dialog"
  >
    <div>
      <el-row
        :gutter="5"
        v-for="(rowItem, i) in layOutJson"
        :key="rowItem.uniqueId"
      >
        <div
          :ref="'body_row_' + rowItem.uniqueId"
          :style="'min-height:' + rowItem.minHeight + 'px'"
        >
          <el-col
            :span="colItem.span"
            v-for="(colItem, k) in rowItem.cols"
            :key="colItem.uniqueId"
          >
            <div
              style="background:#ecf5ff;"
              :class="[colItem.isSelect ? 'selected-item' : '']"
            >
              <div v-if="colItem.type === 'item'" style="position:relative;">
                <div>
                  <div class="preview-col-title">
                    <div
                      style="cursor: move;width:calc(100% - 18px)"
                      :title="colItem.label"
                      :id="colItem.uniqueId"
                    >
                      {{ colItem.label }}
                    </div>
                    <div
                      v-if="colItem.isQualified == null"
                      style="width:18px;text-align:center;line-height:18px;background:#fff;color:#fff;border:1px solid #dcdfe6;cursor: pointer;"
                      @click.stop="judgeItem(colItem)"
                    ></div>
                    <div
                      v-else-if="colItem.isQualified"
                      style="width:18px;text-align:center;line-height:18px;background:#67c23a;color:#fff;cursor: pointer;"
                      @click.stop="judgeItem(colItem)"
                    >
                      ✓
                    </div>
                    <div
                      v-else
                      style="width:18px;text-align:center;line-height:18px;background:#f56c6c;color:#fff;cursor: pointer;"
                      @click.stop="judgeItem(colItem)"
                    >
                      ✕
                    </div>
                  </div>
                  <div
                    class="preview-col-remark"
                    :title="colItem.referenceValue"
                  >
                    {{ colItem.referenceValue }}
                  </div>
                  <div>
                    <el-input
                      class="preview-item-input"
                      v-model="colItem.itemValue"
                      :ref="`item_input`"
                      @keyup.enter.native="focusInput(colItem.uniqueId)"
                    ></el-input>
                  </div>
                </div>
              </div>
              <div v-else style="position:relative;">
                <div>
                  <div class="preview-group-title">
                    <div
                      style="cursor: move;line-height:30px;font-weight:bold;text-align:center;"
                      :id="colItem.uniqueId"
                    >
                      {{ colItem.label }}
                    </div>
                  </div>
                  <div class="preview-group-item">
                    <el-row
                      :gutter="5"
                      v-for="(child, j) in colItem.children"
                      :key="child.uniqueId"
                    >
                      <div class="preview-test-item-row-div">
                        <el-col
                          :span="childCol.span"
                          v-for="(childCol, m) in child.cols"
                          :key="childCol.uniqueId"
                        >
                          <div style="position:relative;">
                            <div
                              style="background:#f4f6fc;"
                              :class="[
                                childCol.isSelect ? 'selected-item' : ''
                              ]"
                            >
                              <div class="preview-col-title">
                                <div
                                  style="cursor: move;width:calc(100% - 18px)"
                                  :title="childCol.label"
                                  :id="childCol.uniqueId"
                                >
                                  {{ childCol.label }}
                                </div>
                                <div
                                  v-if="childCol.isQualified == null"
                                  style="width:18px;text-align:center;line-height:18px;background:#fff;color:#fff;border:1px solid #dcdfe6;cursor: pointer;"
                                  @click.stop="judgeItem(childCol)"
                                ></div>
                                <div
                                  v-else-if="childCol.isQualified"
                                  style="width:18px;text-align:center;line-height:18px;background:#67c23a;color:#fff;cursor: pointer;"
                                  @click.stop="judgeItem(childCol)"
                                >
                                  ✓
                                </div>
                                <div
                                  v-else
                                  style="width:18px;text-align:center;line-height:18px;background:#f56c6c;color:#fff;cursor: pointer;"
                                  @click.stop="judgeItem(childCol)"
                                >
                                  ✕
                                </div>
                              </div>
                              <div>
                                <el-input
                                  class="item-input"
                                  v-model="childCol.itemValue"
                                  :ref="`item_input`"
                                  @keyup.enter.native="
                                    focusInput(childCol.uniqueId)
                                  "
                                ></el-input>
                              </div>
                            </div>
                          </div>
                        </el-col>
                      </div>
                    </el-row>
                  </div>
                </div>
              </div>
            </div>
          </el-col>
        </div>
      </el-row>
      <div v-if="isEditCommit" style="text-align:right;">
        <el-button @click="innerVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveForm">保 存</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<style>
.preview-col-title {
  display: flex;
  justify-content: space-between;
  height: 18px;
  text-align: center;
}
.preview-col-title div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview-col-remark {
  border-top: 1px solid #ccc;
  height: 16px;
  font-size: 12px;
  text-align: center;
}
.preview-item-input input {
  height: 28px;
}
.preview-group-title {
  height: 30px;
}
.preview-group-item {
  border: 1px dashed #ccc;
}
.preview-test-item-row-div {
  min-height: 60px;
}
</style>
<script>
import { putReportSampleItem } from '@/api/quality/report'
export default {
  props: {
    currshowlist: {
      type: Boolean,
      default: false
    },
    layOutJson: {
      type: Array,
      default: () => {
        return []
      },
      required: true
    },
    isEditCommit: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      innerVisible: false
    }
  },
  methods: {
    // 保存质检表单数据
    saveForm() {
      const saveParams = []
      let saveParam
      let layOut
      let firstCols
      let firstCol
      let childs
      let child
      let cols
      let col
      for (let i = 0; i < this.layOutJson.length; i++) {
        layOut = this.layOutJson[i]
        firstCols = layOut.cols
        if (firstCols.length > 0) {
          // 判断是是否为分组
          firstCol = firstCols[0]
          if (firstCol.type === 'item') {
            // 普通列
            for (let j = 0; j < firstCols.length; j++) {
              firstCol = firstCols[j]
              saveParam = {
                id: firstCol.id,
                itemValue: firstCol.itemValue,
                isQualified: firstCol.isQualified
              }
              saveParams.push(saveParam)
            }
          } else {
            // 分组列
            childs = firstCol.children
            if (childs.length > 0) {
              for (let j = 0; j < childs.length; j++) {
                child = childs[j]
                if (child.cols.length > 0) {
                  cols = child.cols
                  for (let k = 0; k < cols.length; k++) {
                    col = cols[k]
                    saveParam = {
                      id: col.id,
                      itemValue: col.itemValue,
                      isQualified: col.isQualified
                    }
                    saveParams.push(saveParam)
                  }
                }
              }
            }
          }
        }
      }
      if (saveParams.length > 0) {
        putReportSampleItem(saveParams).then((response) => {
          this.$message.success('样品检测参数保存成功')
          this.$emit('refreshParams')
          this.innerVisible = false
        })
      }
    },
    // 判断项检测结果
    judgeItem(item) {
      if (item.isQualified == null || !item.isQualified) {
        item.isQualified = true
      } else {
        item.isQualified = false
      }
    },
    // 聚焦
    focusInput(uniqueId) {
      // 只有在应用页面才支持enter换聚焦,预览页面不支持
      if (this.isEditCommit) {
        const itemIndex = this.getItemIndex(uniqueId)
        const nextEl = this.$refs.item_input[itemIndex + 1]
        if (nextEl) {
          nextEl.focus()
        }
      }
    },
    // 返回项的index
    getItemIndex(uniqueId) {
      let itemIndex = 0
      let layOut
      let firstCols
      let firstCol
      let childs
      let child
      let cols
      let col
      for (let i = 0; i < this.layOutJson.length; i++) {
        layOut = this.layOutJson[i]
        firstCols = layOut.cols
        if (firstCols.length > 0) {
          // 判断是是否为分组
          firstCol = firstCols[0]
          if (firstCol.type === 'item') {
            // 普通列
            let breakFlag = false
            for (let j = 0; j < firstCols.length; j++) {
              firstCol = firstCols[j]
              if (firstCol.uniqueId === uniqueId) {
                breakFlag = true
                break
              } else {
                itemIndex++
              }
            }
            if (breakFlag) {
              break
            }
          } else {
            // 分组列
            childs = firstCol.children
            if (childs.length > 0) {
              let flag = false
              for (let j = 0; j < childs.length; j++) {
                child = childs[j]
                if (child.cols.length > 0) {
                  cols = child.cols
                  let breakFlag = false
                  for (let k = 0; k < cols.length; k++) {
                    col = cols[k]
                    if (col.uniqueId === uniqueId) {
                      breakFlag = true
                      break
                    } else {
                      itemIndex++
                    }
                  }
                  if (breakFlag) {
                    flag = true
                    break
                  }
                }
              }
              if (flag) {
                break
              }
            }
          }
        }
      }
      return itemIndex
    },
    // 关闭dialog时触发
    closeDialog() {
      if (this.isEditCommit) {
        this.$confirm('此操作将关闭该页面, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            this.currshowlist = false
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
      } else {
        this.currshowlist = false
      }
    }
  },
  watch: {
    currshowlist() {
      this.innerVisible = this.currshowlist
      if (this.currshowlist) {
        this.$nextTick(() => {
          this.$refs.item_input[0].focus()
          // this.getData()
        })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.preview-layout-dialog >>> .el-dialog__header {
  padding: 10px 20px 10px;
}
.preview-layout-dialog >>> .el-dialog__header .el-dialog__headerbtn {
  top: 10px;
}
.preview-layout-dialog >>> .el-dialog__body {
  padding: 5px 15px;
}
 
.preview-layout-dialog >>> .el-dialog__footer {
  padding: 5px 20px 10px;
}
 
.preview-layout-dialog >>> .el-dialog__body .avue-crud__pagination {
  margin-top: 0px;
  margin-bottom: 5px;
}
</style>