Houjie
2025-06-13 0036adeb95ec933d6b504bf9ae965d029875c76b
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
505
506
507
508
509
510
511
512
513
514
515
516
<template>
  <a-modal :title="title" :width="1500" :height="1500" :visible="visible" :maskClosable="false" @ok="handleOk"
           cancelText="关闭"
           @cancel="handleCancel" :confirmLoading="confirmLoading">
 
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="盘点单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderCode">
              <a-input :disabled="true" v-model="model.orderCode" placeholder="系统自动生成"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="盘点类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approvalStatus">
              <j-dict-select-tag dictCode="stocktakingType" placeholder="请选择盘点类型" v-model="model.stocktakingType"
                                 :disabled="disableSubmit"></j-dict-select-tag>
            </a-form-model-item>
          </a-col>
 
 
          <a-col :span="12">
            <a-form-model-item label="盘点名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stocktakingName">
              <a-input v-model="model.stocktakingName" placeholder="请输入盘点名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="审核人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reviewer">
              <j-select-user-by-dep :disabled="disableSubmit" v-model="model.reviewer" :store="'username'"
                                    :text="'realname'" :multi="false" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="盘点时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inventoryTime">
              <j-date placeholder="请选择盘点时间" date-format="YYYY-MM-DD HH:mm:ss" v-model="model.inventoryTime"
                      style="width: 100%" />
            </a-form-model-item>
          </a-col>
 
          <a-col :span="12">
            <a-form-model-item v-show="addShow" label="经手人" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="handler">
              <j-dict-select-tag dictCode="sys_user,realname,id" placeholder="请选择经手人" v-model="model.handler"
                                 :disabled="disableSubmit" />
            </a-form-model-item>
          </a-col>
 
          <a-col :span="12">
            <a-form-model-item v-show="addShow" label="审核状态" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="approvalStatus">
              <j-dict-select-tag dictCode="approval_status" placeholder="请选择审核状态" v-model="model.approvalStatus"
                                 :disabled="true"></j-dict-select-tag>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item v-show="addShow" label="审核意见" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="approvalOpinion">
              <a-input v-model="model.approvalOpinion" placeholder="请输入审核意见" type="textarea"
                       :disabled="model.approvalStatus==1"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item  v-show="addShow" label="审核时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inventoryTime">
              <j-date placeholder="请选择审核时间" date-format="YYYY-MM-DD HH:mm:ss" v-model="model.approvalDate"
                      style="width: 100%" />
            </a-form-model-item>
          </a-col>
 
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注" type="textarea"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
    <a-button type="primary" :style="{ marginRight: '8px', marginBottom: '8px' }" :loading="confirmLoading"
              :disabled="disableSubmit" @click="selectTools()">工具明细
    </a-button>
    <a-table ref="table" bordered size="middle" rowKey="id" :columns="columns" :dataSource="dataSource"
             :scroll="{x:true}">
      <template v-for="col in columns" :slot="col.dataIndex" slot-scope="text, record, index">
        <a-input-number :disabled="disableSubmit" :value="text" v-if="col.dataIndex == 'practicalQuantity'" :min="0"
                        :max="99999"
                        @change="(e) => handleChange(e, record.key, col, index)" style="width: 100%;" />
        <a-input-number :value="text" v-if="col.dataIndex == 'differenceValue'" :min="0" :max="99999"
                        :disabled="true" @change="(e) => handleChange(e, record.key, col, index)"
                        style="width: 100%;" />
        <j-dict-select-tag :value="text" v-if="col.dataIndex == 'surplusDeficit'"
                           dictCode="surplusDeficit"
                           :disabled="true"
                           style="width: 100%;"
                           @change="(e) => handleChange(e, record.key, col, index)" />
        <!--        <j-dict-select-tag :value="text" v-if="col.dataIndex == 'classifyId'"-->
        <!--                           dictCode="tms_tools_classify,type_name,id"-->
        <!--                           style="width: 100%;"-->
        <!--                           :disabled="true"-->
        <!--                           @change="(e) => handleChange(e, record.key, col, index)" />-->
        <j-date
          :value="text"
          v-if="col.dataIndex == 'stocktakingDate'"
          placeholder="选择盘库时间"
          @change="(e) => handleChange(e, record.key, col, index)"
          style="width: 100%;"
        />
 
        <a-textarea
          v-if="col.dataIndex == 'remark'"
          :disabled="disableSubmit"
          style="margin: -5px 0"
          :value="text"
          @change="(e) => handleChange(e.target.value, record.key, col, index)"
        />
 
      </template>
 
      <span slot="action" slot-scope="text, record, index">
        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(text, record, index)">
          <a :disabled="disableSubmit">删除</a>
        </a-popconfirm>
      </span>
    </a-table>
    <template slot="footer">
      <a-button :style="{ marginRight: '8px' }" @click="handleCancel()">
        关闭
      </a-button>
 
      <a-button @click="handleOk()" :disabled="disableSubmit" type="primary" :loading="confirmLoading">确定</a-button>
    </template>
    <tool-selector-modal ref="toolsModalForm"></tool-selector-modal>
  </a-modal>
 
</template>
 
<script>
import { getAction, postAction, requestPut } from '@/api/manage'
import JMultiSelectTag from '@/components/dict/JMultiSelectTag'
import Tooltip from 'ant-design-vue/es/tooltip'
import ToolSelectorModal from '@views/tms/stocktakingBound/modules/ToolSelectorModal.vue'
 
export default {
  name: 'ToolsStocktakingBoundModal',
  components: {
    ToolSelectorModal,
    JMultiSelectTag,
    Tooltip
  },
  data() {
 
    return {
      addShow: true,
      model: {},
      formDisabled: false,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0
      },
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          },
          width: 50
        },
        {
          title: '刀具编号',
          dataIndex: 'toolId',
          align: 'center',
          width: 180
        },
 
        {
          title: '工具类型',
          dataIndex: 'applicationType_dictText',
          align: 'center',
          width: 150
        },
        {
          title: '账面库存',
          width: 150,
          dataIndex: 'bookQuantity',
          align: 'center'
 
        },
        {
          title: '可用数量',
          width: 150,
          dataIndex: 'availableQuantity',
          align: 'center'
 
        },
        {
          title: '实盘数量',
          dataIndex: 'practicalQuantity',
          align: 'center',
          width: 150,
          scopedSlots: { customRender: 'practicalQuantity' }
        },
        {
          title: '差异值',
          dataIndex: 'differenceValue',
          align: 'center',
          width: 150,
          scopedSlots: { customRender: 'differenceValue' }
        },
 
        {
          title: '盘亏盘盈',
          width: 150,
          dataIndex: 'surplusDeficit',
          align: 'center',
          scopedSlots: { customRender: 'surplusDeficit' }
        },
 
        {
          title: '盘库时间',
          width: 150,
          dataIndex: 'stocktakingDate',
          align: 'center',
          scopedSlots: { customRender: 'stocktakingDate' }
        },
        {
          title: '备注',
          width: 150,
          dataIndex: 'remark',
          align: 'center',
          scopedSlots: { customRender: 'remark' }
        },
        {
          title: '中文名称',
          dataIndex: 'chineseName',
          width: 150,
          align: 'center'
        },
 
        {
          title: '型号/图号',
          dataIndex: 'toolModel',
          width: 150,
          align: 'center'
        },
 
        {
          title: '刀具材料',
          width: 150,
          dataIndex: 'toolMaterial',
          align: 'center'
        },
        {
          title: '零件材料',
          width: 150,
          dataIndex: 'partMaterial',
          align: 'center'
        },
        {
          title: '厂家',
          width: 150,
          dataIndex: 'supplierId',
          align: 'center'
 
        },
        {
          title: '存储位置',
          width: 150,
          dataIndex: 'goodsShelvesId',
          align: 'center'
 
        },
 
 
        {
          title: '操作',
          width: 150,
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
          align: 'center'
        }
      ],
      title: '操作',
      visible: false,
      disableSubmit: false,
      codeDisable: true,
 
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {
        orderCode: [
          { required: true, message: '请输入盘点单号!' }
        ],
        handler: [
          { required: true, message: '请输入经手人!' }
        ],
        stocktakingName: [
          { required: true, message: '请输入盘点名称!' }
        ],
        approvalStatus: [
          { required: true, message: '请输入审核状态!' }
        ],
        inventoryTime: [
          { required: true, message: '请输入盘点时间!' }
        ]
      },
      url: {
        add: '/tms/toolsStocktakingBound/add',
        edit: '/tms/toolsStocktakingBound/edit',
        queryDetailList: '/tms/toolsStocktakingBound/listToolsStocktakingBoundControllerDetailsByMainId'
 
      },
      dataSource: []
    }
  },
 
  mounted() {
    this.$bus.$on('selectionRows', (data) => {
      for (let i = 0; i < data.length; i++) {
        this.dataSource.push({
          toolId: data[i].toolId,
          toolCode: data[i].toolCode,
          classifyId: data[i].classifyId,
          applicationType_dictText: data[i].applicationType_dictText,
          chineseName: data[i].chineseName,
          availableQuantity:data[i].availableCount,
          toolModel: data[i].toolModel,
          material: data[i].material,
          toolMaterial: data[i].toolMaterial,
          partMaterial: data[i].partMaterial,
          bookQuantity: data[i].totalCount,
          supplierId: data[i].supplierId,
          goodsShelvesId: data[i].positionCode
        })
      }
    })
  },
 
  methods: {
    selectTools: function() {
      let ids = []
      for (let i = 0; i < this.dataSource.length; i++) {
        ids.push(this.dataSource[i].partId)
      }
      this.$refs.toolsModalForm.showModals(ids)
      this.$refs.toolsModalForm.title = '选择工具信息'
      this.$refs.toolsModalForm.disableSubmit = false
    },
    add() {
      this.addShow = false
      this.edit()
    },
 
    edit(record) {
      console.log(record)
      console.log(this.auditFlag)
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      getAction(this.url.queryDetailList, {
        stocktakingBoundId: record.id,
        pageNo: 1,
        pageSize: 99999
      }).then((res) => {
        if (res.success) {
          console.log(res.result.records)
          this.dataSource = res.result.records
        } else {
          this.dataSource = null
        }
      })
    },
 
 
 
    close() {
      this.$emit('close')
      this.visible = false
    },
 
    handleCancel() {
      this.model = {}
      this.dataSource = []
      this.close()
    },
 
    handleOk() {
      const that = this
      let data = that.dataSource
      for (let i = 0; i < data.length; i++) {
        if (data[i].practicalQuantity == undefined || data[i].practicalQuantity == null || data[i].practicalQuantity == '') {
          that.$message.warning('请输入第' + (i + 1) + '行的实盘数量数据!')
          return false
        }
      }
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let formData = Object.assign(this.model, values)
          if (that.dataSource.length === 0) {
            that.$message.warning('请选择工具!')
            that.confirmLoading = false
            return
          }
          formData.toolsStocktakingBoundDetailList = that.dataSource
          // formData.status = '0';
          let obj
          if (!this.model.id) {
            obj = postAction(this.url.add, formData)
          } else {
            obj = requestPut(this.url.edit, formData, { id: this.model.id })
          }
          obj.then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
              that.close()
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        }
      })
    },
 
    handleDelete(text, record, index) {
      this.dataSource.splice(index, 1)
    },
 
    handleChange(value, key, column, index) {
      let that = this
      const temp = [...that.dataSource]
      const target = temp.filter(item => key === item.key)[index]
      if (target) {
        // if (column.dataIndex == 'practicalQuantity') {
        //   target[column.dataIndex] = value
        // }
        if (column.dataIndex === 'practicalQuantity') {
          target[column.dataIndex] = value
 
          // 计算差异值
          target.differenceValue = value - target.availableQuantity
 
          // 根据差异值判断盘亏盘盈
          if (target.differenceValue > 0) {
            target.surplusDeficit = 1
          } else if (target.differenceValue < 0) {
            target.surplusDeficit = 2
          } else {
            target.surplusDeficit = 0
          }
        }
        if (column.dataIndex == 'differenceValue') {
          target[column.dataIndex] = value
        }
        if (column.dataIndex == 'classifyId') {
          target[column.dataIndex] = value
        }
        if (column.dataIndex == 'surplusDeficit') {
          target[column.dataIndex] = value  // 假设 value 是字符串格式的日期
        }
        if (column.dataIndex == 'stocktakingDate') {
          target[column.dataIndex] = value  // 假设 value 是字符串格式的日期
        }
        if (column.dataIndex === 'remark') {
          // 注意这里使用的是 e.target.value
          target[column.dataIndex] = value
        }
 
        that.dataSource = temp
      }
    }
  }
 
}
</script>
 
<style lang="less" scoped>
.frozenRowClass {
  color: #c9c9c9;
}
 
.fontweight {
  font-weight: bold;
}
 
.ant-btn {
  padding: 0 10px;
  margin-left: 3px;
}
 
.ant-form-item-control {
  line-height: 0px;
}
 
/** 主表单行间距 */
.ant-form .ant-form-item {
  margin-bottom: 10px;
}
 
/** Tab页面行间距 */
.ant-tabs-content .ant-form-item {
  margin-bottom: 0px;
}
</style>