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
<!--
 * @Descripttion: 新报工查看投入
 * @version:
 * @Author: zt_lc
 * @Date: 2022-06-10 09:24:05
 * @LastEditors: zt_lc
 * @LastEditTime: 2022-06-10 10:30:42
-->
 
<template>
  <el-dialog
    title="投料查看"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <div class="work-report-product-in-header">
      <div></div>
      <div>
        <el-button
          class="in-btn"
          type="primary"
          @click="openProductInDialog()"
          v-if="canEdit"
          >投入</el-button
        >
      </div>
    </div>
    <el-table
      ref="productInTable"
      :data="productInputList"
      height="320px"
      :header-cell-style="productInTableHeaderCellStyle"
      :row-class-name="productInTableRowClassName"
      class="tracking-table"
    >
      <el-table-column label="报工单号" prop="productNo" align="center">
      </el-table-column>
      <el-table-column
        label="SN号"
        prop="partBatchNo"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="零件编号"
        prop="partNo"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="零件名称"
        prop="partName"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="IFS批次号"
        prop="ifsBatchNo"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="投入数量"
        prop="inputQuantity"
        align="center"
        width="100"
      >
        <template scope="scope">
          <el-input
            size="small"
            v-model="scope.row.inputQuantity"
            placeholder="投入数量"
            :disabled="!canEdit"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        label="可用数量"
        prop="availableStockQuantity"
        align="center"
      >
      </el-table-column>
      <el-table-column label="单位" prop="unit" align="center">
      </el-table-column>
      <el-table-column align="center" width="120px" fixed="right">
        <template slot-scope="scope">
          <el-tooltip
            effect="dark"
            content="全投"
            placement="top-start"
            v-if="canEdit"
          >
            <el-button
              type="text"
              size="small"
              @click="allIn(scope.$index, scope.row)"
              >全投</el-button
            >
          </el-tooltip>
          <el-tooltip
            effect="dark"
            content="保存"
            placement="top-start"
            v-if="canEdit"
          >
            <el-button
              type="text"
              size="small"
              @click="addOrUpdateProductIn(scope.row)"
              >保存</el-button
            >
          </el-tooltip>
          <el-tooltip
            effect="dark"
            content="删除"
            placement="top-start"
            v-if="canEdit"
          >
            <el-button
              type="text"
              size="small"
              class="red-but"
              @click="delProductIn(scope.$index, scope.row)"
              >删除</el-button
            >
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
 
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
    </span>
    <productInDialog
      :currshowlist.sync="showProductInDialog"
      :workstationId="workstationId"
      @handleSelectionChange="selectWorkstationFeed"
    />
  </el-dialog>
</template>
 
<script>
import {
  queryProductMainDetail,
  deleteProductInputById,
  updateProductInput,
  saveProductInput
} from '@/api/product/personboard'
import productInDialog from './productInDialog.vue'
export default {
  components: {
    productInDialog
  },
  data() {
    return {
      queryId: '',
      visible: false,
      productInputList: [],
      showProductInDialog: false,
      workstationId: null,
      productMainId: null,
      productNo: null,
      canEdit: true
    }
  },
  methods: {
    init(id, workstationId, productMainId, productNo, state, shiftState) {
      this.queryId = id
      this.queryProductMainDetail(id)
      this.visible = true
      this.workstationId = workstationId
      this.productMainId = productMainId
      this.productNo = productNo
      if (
        state != null &&
        state != '' &&
        state == '01draft' &&
        !(
          shiftState != null &&
          shiftState != '' &&
          shiftState == '03changeshift'
        )
      ) {
        this.canEdit = true
      } else {
        this.canEdit = false
      }
    },
    productInTableHeaderCellStyle({ row, column, rowIndex, columnIndex }) {
      let headerStyle = 'background:#599ef4;color:#fff;'
      if (columnIndex === 0) {
        headerStyle += 'border-radius: 6px 0px 0px 0px;'
      } else if (columnIndex === 9) {
        headerStyle += 'border-radius: 0px 6px 0px 0px;'
      }
      return headerStyle
    },
    productInTableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'stripe-row'
      } else {
        return ''
      }
    },
    // 根据报工主表id获取投入、产出明细
    queryProductMainDetail(id) {
      return new Promise((resolve, reject) => {
        this.productInputList = []
        queryProductMainDetail(id)
          .then((response) => {
            var code = response.data.code
            if (code == 0) {
              var productMainInfo = response.data.data
              const productInputs = productMainInfo.productInputList
              if (productInputs != null && productInputs.length > 0) {
                productInputs.forEach((item) => {
                  if (item.availableStockQuantity == null) {
                    item.availableStockQuantity = 0
                  }
                })
              }
              this.productInputList = productInputs
              resolve()
            } else {
              this.$message.error('获取投入产出明细失败')
              reject()
            }
          })
          .catch((error) => {
            reject()
          })
      })
    },
    // 弹出投料列表,供报工投入使用
    openProductInDialog() {
      if (this.productMainId != null && this.productMainId != '') {
        this.showProductInDialog = true
      } else {
        this.$message.warning('请先选择报告或者先填写产出!')
      }
    },
    // 选中需要的投料
    selectWorkstationFeed(val) {
      if (val != null && val.length > 0) {
        for (var i = 0; i < val.length; i++) {
          this.addProductIn(val[i])
        }
      }
      this.showProductInDialog = false
    },
    // 页面新增投入
    addProductIn(inPartInfo) {
      var productInput = {}
      productInput.id = null
      productInput.stockId = inPartInfo.id
      productInput.inputQuantity = null
      productInput.productMainId = this.productMainId
      productInput.productNo = this.productNo
      productInput.partNo = inPartInfo.partNo
      productInput.partName = inPartInfo.partName
      productInput.partDescription = null
      productInput.unit = inPartInfo.unit
      productInput.partBatchNo = inPartInfo.partBatchNo
      productInput.ifsBatchNo = inPartInfo.ifsBatchNo
      productInput.availableStockQuantity = inPartInfo.availableStockQuantity
      this.productInputList.push(productInput)
    },
    // 新增或更新投入信息,若存在id则更新、不存在则新增
    addOrUpdateProductIn(currRow) {
      if (currRow.inputQuantity != null && currRow.inputQuantity.trim != '') {
        if (currRow.id != null) {
          // 修改
          const productIn = {}
          productIn.id = currRow.id
          productIn.inputQuantity = currRow.inputQuantity
          updateProductInput(productIn)
            .then((response) => {
              var data = response.data
              if (data.code == 0) {
                this.$message.success('更新投入成功')
                // 刷新投料信息
                this.$emit('refreshFeedsForDel')
              } else {
                this.$message.error('更新投入失败')
              }
            })
            .catch((error) => {})
        } else {
          // 新增
          const productIn = {}
          productIn.stockId = currRow.stockId
          productIn.productMainId = currRow.productMainId
          productIn.inputQuantity = currRow.inputQuantity
          saveProductInput(productIn)
            .then((response) => {
              var data = response.data
              if (data.code == 0) {
                this.$message.success('添加投入成功')
                this.queryProductMainDetail(this.queryId)
                // currRow.id = data.data
                // 刷新投料信息
                this.$emit('refreshFeedsForDel')
              } else {
                this.$message.error('添加投入失败')
              }
            })
            .catch((error) => {})
        }
      } else {
        this.$message.error('投入不能为空')
      }
    },
    // 删除投入信息,若存在投入id,则需调用后台删除并删除前端投入,若不存在,则只需删除前端投入
    delProductIn(index, currRow) {
      if (currRow.id != null) {
        // 则需调用后台删除并删除前端投入
        deleteProductInputById(currRow.id)
          .then((response) => {
            var data = response.data
            if (data.code == 0) {
              this.productInputList.splice(index, 1)
              this.$message.success('删除投入成功')
              // 刷新投料信息
              this.$emit('refreshFeedsForDel')
            } else {
              this.$message.error('删除投入失败')
            }
          })
          .catch((error) => {})
      } else {
        // 删除前端投入
        this.productInputList.splice(index, 1)
        this.$message.success('删除投入成功')
      }
    },
    // 全投
    allIn(index, currRow) {
      if (currRow.inputQuantity != null && currRow.inputQuantity != '') {
        currRow.inputQuantity =
          currRow.inputQuantity + currRow.availableStockQuantity
        currRow.inputQuantity = Number(currRow.inputQuantity.toFixed(6))
        currRow.availableStockQuantity = 0
      } else {
        currRow.inputQuantity = currRow.availableStockQuantity
        currRow.availableStockQuantity = 0
      }
    }
  }
}
</script>
 
<style lang="scss" scoped>
.work-report-product-in-header {
  margin-top: 10px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.red-but.is-disabled {
  color: #fab6b6;
}
 
.red-but {
  color: red;
}
</style>