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
<template>
  <el-dialog
    width="70%"
    top="5vh"
    title="扫码投料"
    :visible.sync="innerVisible"
    append-to-body
    @close="$emit('update:currshowlist', false)"
    :show="currshowlist"
    class="scan-feed-dialog"
  >
    <div class="app-container">
      <div class="avue-crud">
        <div style="display:flex;margin-bottom:10px;">
          <div style="line-height:32px;">
            <span style="font-weight:bold;">扫码:</span>
          </div>
          <div>
            <el-input
              size="small"
              ref="sn_seach_input"
              v-model="scanContent"
              v-focus
              @keyup.enter.native="queryFeedStock"
            ></el-input>
          </div>
          <div
            v-show="batchNo != null"
            style="line-height:32px;margin-left:10px;color:#076ecd;"
          >
            <span>sn号:{{ batchNo }}</span>
          </div>
          <!-- <div
            v-show="ifsBatchNo != null"
            style="line-height:32px;margin-left:10px;color:#006eff;"
          >
            <span>ifs批次号:{{ ifsBatchNo }}</span>
          </div> -->
        </div>
        <el-table
          :key="tableKey"
          :data="scanFeedList"
          border
          style="width: 100%;"
          height="500px"
        >
          <el-table-column type="index" width="50" align="center" label="序号">
          </el-table-column>
          <el-table-column
            prop="partNo"
            header-align="center"
            align="center"
            label="零件编号"
          >
          </el-table-column>
          <el-table-column
            prop="partName"
            header-align="center"
            align="center"
            label="零件"
          >
          </el-table-column>
          <el-table-column
            prop="partBatchNo"
            header-align="center"
            align="center"
            label="零件批号"
          >
          </el-table-column>
          <el-table-column
            prop="specs"
            header-align="center"
            align="center"
            label="规格型号"
          >
          </el-table-column>
          <el-table-column
            prop="availableStockQuantity"
            header-align="center"
            align="center"
            label="可用数量"
          >
          </el-table-column>
          <el-table-column
            prop="suppliedQuantity"
            header-align="center"
            align="center"
            label="投入数量"
          >
            <template scope="scope">
              <el-input
                size="small"
                v-model="scope.row.suppliedQuantity"
                placeholder="请输入数量"
                clearable
              ></el-input>
              <!--<span v-if="!scope.row.suppliedQuantityFlag">{{scope.row.suppliedQuantity}}</span>-->
            </template>
          </el-table-column>
          <el-table-column
            prop="unit"
            header-align="center"
            align="center"
            label="单位"
          >
          </el-table-column>
          <el-table-column label="操作" align="center" width="80px">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                style="color:red;"
                @click="delFeed(scope.$index)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="innerVisible = false">取 消</el-button>
      <el-button type="primary" :disabled="isSubmit" v-thinclick="`saveFeed`"
        >投 料</el-button
      >
    </div>
  </el-dialog>
</template>
<script>
import { addFeed, getStock, getTodoStock } from '@/api/product/personboard'
export default {
  props: {
    currshowlist: {
      type: Boolean,
      default: false
    },
    isOk: {
      type: Boolean,
      default: true
    },
    paramObject: {
      type: Object,
      default: () => {
        return {}
      }
    },
    workstationId: {
      type: Number
    },
    operationTaskId: {
      type: Number
    },
    materialList: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data() {
    return {
      innerVisible: false,
      tableKey: 0,
      isSubmit: false,
      scanContent: null,
      batchNo: null,
      ifsBatchNo: null,
      scanFeedList: []
    }
  },
  directives: {
    focus: {
      inserted: function(el, option) {
        var defClass = 'el-input'
        var defTag = 'input'
        var value = option.value || true
        if (typeof value === 'boolean')
          value = { cls: defClass, tag: defTag, foc: value }
        else
          value = {
            cls: value.cls || defClass,
            tag: value.tag || defTag,
            foc: value.foc || false
          }
        // if (el.classList.contains(value.cls) && value.foc)
        el.getElementsByTagName(value.tag)[0].focus()
      }
    }
  },
  methods: {
    saveFeed() {
      this.isSubmit = true
      // 调用投料接口,然后刷新线边仓、投料列表
      var feeds = []
      var feed
      for (var i = 0; i < this.scanFeedList.length; i++) {
        if (!this.scanFeedList[i].suppliedQuantity) {
          this.isSubmit = false
          this.$message.error('第' + (i + 1) + '投入数量不能为空')
          return
        }
        if (!this.checkDecimal(this.scanFeedList[i].suppliedQuantity)) {
          this.isSubmit = false
          this.$message.error(
            '第' + (i + 1) + '数据格式有误,数据大于0且最多保留6位小数'
          )
          return
        }
        feed = {
          workstationId: this.workstationId,
          stockId: this.scanFeedList[i].id,
          joinStockOrderId: null,
          suppliedQuantity: this.scanFeedList[i].suppliedQuantity,
          partId: this.scanFeedList[i].partId,
          partBatchNo: this.scanFeedList[i].partBatchNo,
          systemNo: this.scanFeedList[i].systemNo,
          partName: this.scanFeedList[i].partName,
          unit: this.scanFeedList[i].unit ? this.scanFeedList[i].unit : ''
        }
        feeds.push(feed)
      }
      const feedIn = {
        feeds: feeds,
        feedingFrom: 'stocker',
        operationTaskId: this.operationTaskId
      }
      if (feeds.length > 0) {
        addFeed(feedIn)
          .then((response) => {
            var data = response.data
            if (data.code === 0) {
              this.$message.success('投料成功')
            } else {
              this.$message.error('投料失败')
            }
            // 刷新线边仓、投料列表
            this.$emit('refreshFeedList')
            this.isSubmit = false
            this.innerVisible = false
          })
          .catch(() => {
            this.isSubmit = false
          })
      } else {
        this.isSubmit = false
      }
    },
    // 大于0且最多保留6位小数
    checkDecimal(value) {
      const reg = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,6})?$/
      return reg.test(value)
    },
    // 查询线边仓物料库存
    queryFeedStock() {
      if (this.workstationId && this.workstationId != null) {
        // 根据扫入的字符串信息,判断扫的是条形码,还是二维码
        if (this.scanContent != null) {
          let scanParamObject
          if (this.scanContent.indexOf('lot_batch_no') != -1) {
            // 二维码
            const scanContentJson = JSON.parse(
              this.scanContent.replace(/\n/g, '').replace(/\s*/g, '')
            )
            const partNo = scanContentJson.part_no
            this.ifsBatchNo = scanContentJson.lot_batch_no
            scanParamObject = {
              partNo: partNo,
              ifsBatchNo: this.ifsBatchNo
            }
          } else {
            // 条形码
            this.batchNo = this.scanContent
            scanParamObject = {
              partBatchNo: this.batchNo
            }
          }
          const query = Object.assign(
            { current: 0, size: 50 },
            { workstationId: this.workstationId },
            this.paramObject,
            scanParamObject
          )
          if (!this.isOk) {
            // 待处理
            getTodoStock(query)
              .then((response) => {
                this.dealStoreResponse(response)
              })
              .catch(() => {})
          } else {
            // 合格
            getStock(query)
              .then((response) => {
                this.dealStoreResponse(response)
              })
              .catch(() => {})
          }
        } else {
          this.$message.error('请扫码')
        }
      }
    },
    dealStoreResponse(response) {
      const data = response.data
      if (data.code === 0) {
        const newScanFeedList = data.data.records
        if (newScanFeedList != null && newScanFeedList.length > 0) {
          const _this = this
          // 校验newScanFeedList中的批次号是否已经扫入过
          let flag = true
          for (let i = 0; i < newScanFeedList.length; i++) {
            const exist = _this.scanFeedList.find(
              (el) => el.partBatchNo == newScanFeedList[i].partBatchNo
            )
            if (exist) {
              flag = false
            }
          }
          if (flag) {
            newScanFeedList.forEach(function(item) {
              const material = _this.materialList.find((el) => {
                return el.partNo == item.partNo
              })
              /* if (material) {
                if (material.quantityRequired > item.availableStockQuantity) {
                  _this.$set(
                    item,
                    'suppliedQuantity',
                    item.availableStockQuantity
                  )
                } else {
                  _this.$set(
                    item,
                    'suppliedQuantity',
                    material.quantityRequired
                  )
                }
              } else {
                _this.$set(
                  item,
                  'suppliedQuantity',
                  item.availableStockQuantity
                )
              } */
              _this.$set(item, 'suppliedQuantity', item.availableStockQuantity)
              _this.scanFeedList.push(item)
            })
          } else {
            this.$message.error('零件批次已存在')
          }
        }
        this.scanContent = null
      } else {
        this.$message.error('获取线边仓物料信息失败')
      }
    },
    delFeed(index) {
      this.scanFeedList.splice(index, 1)
    }
  },
  watch: {
    currshowlist() {
      this.innerVisible = this.currshowlist
      this.scanFeedList = []
      this.batchNo = null
      this.ifsBatchNo = null
      if (this.currshowlist) {
        this.$nextTick(() => {
          this.$refs.sn_seach_input.focus()
          // 根据工单,查询工单对应的产出批次
        })
      }
    }
  },
  mounted() {}
}
</script>
<style scoped>
.scan-feed-dialog >>> .el-dialog__body {
  padding: 0px 20px 30px 20px;
}
</style>