zouyu
2023-11-17 d8ac6057eaad648687699e25a575f3b7b8c1b102
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
<template>
  <el-dialog
    width="40%"
    title="投料"
    :visible.sync="innerVisible"
    append-to-body
    @close="$emit('update:currshowlist', false)"
    :show="currshowlist"
  >
    <div class="app-container">
      <div class="avue-crud">
        <el-table
          v-loading="listLoading"
          :key="tableKey"
          :data="dataList"
          border
          style="width: 100%;"
          @cell-dblclick="dblhandleCurrentChange"
        >
          <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="suppliedQuantity"
            header-align="center"
            align="center"
            label="投入数量"
          >
            <template scope="scope">
              <el-input
                size="small"
                v-model="scope.row.suppliedQuantity"
                placeholder="请输入数量"
                @blur="inputblur"
                v-focus
                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>
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="innerVisible = false">取 消</el-button>
      <el-button
        type="primary"
        :disabled="isSubmit"
        v-thinclick="`saveReserveFeed`"
        >投 料</el-button
      >
    </div>
  </el-dialog>
</template>
<script>
import { addFeed } from '@/api/product/personboard'
import { fetchList } from '@/api/warehouse/joinstockorder'
export default {
  props: {
    currshowlist: {
      type: Boolean,
      default: false
    },
    dataList: {
      type: Array
    },
    isErp: {
      type: Boolean,
      default: false
    },
    workstationId: {
      type: Number
    },
    operationTaskId: {
      type: Number
    },
    partInfo: {}
  },
  data() {
    return {
      innerVisible: false,
      listLoading: false,
      tableKey: 0,
      isSubmit: false
    }
  },
  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: {
    dblhandleCurrentChange(row, column, cell, event) {
      switch (column.label) {
        case '投入数量':
          this.$set(row, 'suppliedQuantityFlag', true)
          break
      }
    },
    inputblur(row, event, column, cell) {
      const _that = this
      const tableD = _that.dataList
      tableD.forEach(function(item) {
        _that.$set(item, 'suppliedQuantityFlag', false)
      })
    },
    async saveReserveFeed() {
      this.isSubmit = true
      // 调用投料接口,然后刷新线边仓、投料列表、预留物料
      const feeds = []
      let feed
      for (let i = 0; i < this.dataList.length; i++) {
        if (!this.dataList[i].suppliedQuantity) {
          this.isSubmit = false
          this.$message.error('第' + (i + 1) + '投入数量不能为空')
          return
        }
        if (!this.checkDecimal(this.dataList[i].suppliedQuantity)) {
          this.isSubmit = false
          this.$message.error(
            '第' + (i + 1) + '数据格式有误,数据大于0且最多保留6位小数'
          )
          return
        }
        feed = {
          workstationId: this.workstationId,
          stockId: this.dataList[i].stockId,
          joinStockOrderId: this.dataList[i].id,
          suppliedQuantity: this.dataList[i].suppliedQuantity,
          partId: this.dataList[i].partId,
          partBatchNo: this.dataList[i].partBatchNo,
          systemNo: this.dataList[i].systemNo,
          partName: this.dataList[i].partName,
          partNo: this.dataList[i].partNo
        }
        feeds.push(feed)
      }
      const feedIn = {
        feeds: feeds,
        feedingFrom: this.isErp ? 'stocker' : 'joinStocker',
        operationTaskId: this.operationTaskId,
        source: this.isErp ? 'erp' : undefined
      }
      if (feeds.length > 0) {
        if (this.isErp) {
          // ERP 投料校验是否在预留中包含
          var query = Object.assign(
            { current: 1, size: 999, operationTaskId: this.operationTaskId },
            this.partInfo
          )
          const response = await fetchList(query)
          if (response.data.code === 0) {
            for (let i = 0; i < feeds.length; i++) {
              const f = feeds[i]
              for (let j = 0; j < response.data.data.records.length; j++) {
                const item = response.data.data.records[j]
                if (
                  f.partBatchNo === item.partBatchNo &&
                  f.partNo === item.partNo
                ) {
                  this.$message.error('预留配盘中存在数据:' + f.partNo)
                  this.isSubmit = false
                  return
                }
              }
            }
          } else {
            this.$message.error('校验零件是否有预留发生异常')
            this.isSubmit = false
            return
          }
        }
        addFeed(feedIn)
          .then((response) => {
            const 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)
    }
  },
  watch: {
    currshowlist() {
      this.innerVisible = this.currshowlist
    }
  },
  mounted() {}
}
</script>