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
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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
<template>
  <el-dialog
    top="10vh"
    width="80%"
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-tabs v-model="activeName" type="card">
      <el-tab-pane label="待发货明细" name="待发货明细">
        <div style="float: left; margin-right: 20px">
          <el-button
            type="primary"
            v-show="dataForm.status !== '02completed'"
            @click="openStockDialog()"
            >新增</el-button
          >
          <el-button
            type="primary"
            v-show="dataForm.status !== '02completed'"
            @click="deleteOrderStock()"
            >删除</el-button
          >
        </div>
        <el-table
          ref="stockTable"
          :data="escortDetailList"
          @selection-change="selectionEscortDetail"
          height="500px"
          :header-cell-style="{ color: '#999' }"
          :row-style="{ height: '26px' }"
          :cell-style="{ padding: '0' }"
        >
          <el-table-column type="selection" width="55"></el-table-column>
 
          <el-table-column
            label="零件批号"
            prop="partBatchNo"
            align="center"
            show-overflow-tooltip
            min-width="120px"
          >
            <template slot="header">
              <div style="line-height: 14px;">零件批号</div>
              <div class="th" @click.stop>
                <el-input
                  type="text"
                  v-model="queryParam.partBatchNo"
                  @keyup.enter.native="handleEscortDetailList"
                  clearable
                  @clear="handleEscortDetailList"
                  size="mini"
                ></el-input>
              </div>
            </template>
            <template slot-scope="scope">
              <span>{{ scope.row.partBatchNo }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="零件编号"
            prop="partNo"
            align="center"
            show-overflow-tooltip
            min-width="120px"
          >
            <template slot="header">
              <div style="line-height: 14px;">零件编号</div>
              <div class="th" @click.stop>
                <el-input
                  type="text"
                  v-model="queryParam.partNo"
                  @keyup.enter.native="handleEscortDetailList"
                  clearable
                  @clear="handleEscortDetailList"
                  size="mini"
                ></el-input>
              </div>
            </template>
            <template slot-scope="scope">
              <span>{{ scope.row.partNo }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="零件名称"
            prop="partName"
            align="center"
            show-overflow-tooltip
            min-width="120px"
          >
            <template slot="header">
              <div style="line-height: 14px;">零件名称</div>
              <div class="th" @click.stop>
                <el-input
                  type="text"
                  v-model="queryParam.partName"
                  @keyup.enter.native="handleEscortDetailList"
                  clearable
                  @clear="handleEscortDetailList"
                  size="mini"
                ></el-input>
              </div>
            </template>
            <template slot-scope="scope">
              <span>{{ scope.row.partName }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="本次发货数量"
            prop="deliveryQty"
            align="center"
            show-overflow-tooltip
            min-width="120px"
          >
            <template slot="header">
              <div style="line-height: 14px;">本次发货数量</div>
              <div class="th" @click.stop>
                <el-input
                  type="text"
                  v-model="queryParam.deliveryQty"
                  @keyup.enter.native="handleEscortDetailList"
                  clearable
                  @clear="handleEscortDetailList"
                  size="mini"
                ></el-input>
              </div>
            </template>
            <template slot-scope="scope">
              <span>{{ scope.row.deliveryQty }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="押运单" name="押运单">
        <div>
          <el-button
            type="primary"
            v-show="dataForm.status !== '02completed'"
            @click="openCustomOrderDialog()"
            >新增</el-button
          >
          <el-button
            type="primary"
            v-show="dataForm.status !== '02completed'"
            @click="cleanForm()"
            >清空</el-button
          >
        </div>
        <el-form
          :model="dataForm"
          :rules="dataRule"
          ref="dataForm"
          label-width="100px"
          class="l-mes"
        >
          <el-row>
            <el-col :span="8">
              <el-form-item label="押运单号" prop="escortNo">
                <el-input v-model="dataForm.escortNo" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="订单编号" prop="orderNo">
                <el-input v-model="dataForm.orderNo"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="要求到货日期" prop="requestDate">
                <el-date-picker
                  style="width: 100%"
                  v-model="dataForm.requestDate"
                  type="date"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="客户订单号" prop="customerOrderNo">
                <el-input v-model="dataForm.customerOrderNo"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="工程名称" prop="entityName">
                <el-input v-model="dataForm.entityName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="客户名称" prop="customerName">
                <el-input v-model="dataForm.customerName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="交货地址" prop="address">
                <el-input v-model="dataForm.address"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="联系人" prop="receiver">
                <el-input v-model="dataForm.receiver"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="联系电话" prop="phone">
                <el-input v-model="dataForm.phone"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="发货日期" prop="deliveryDate">
                <el-date-picker
                  style="width: 100%"
                  v-model="dataForm.deliveryDate"
                  type="date"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="承运商" prop="carrier">
                <el-input v-model="dataForm.carrier"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="业务员" prop="salesman">
                <el-input v-model="dataForm.salesman"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="dataForm.remark"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </el-tabs>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button
        type="primary"
        v-show="dataForm.status !== '02completed'"
        @click="dataFormSubmit()"
        >确定</el-button
      >
    </span>
 
    <!-- 库存信息选择弹框 -->
    <StockMulti
      :currshowlist.sync="relateVisible"
      @handleSelectionChange="selectStock"
      :multiSelect="multiSelect"
      :paramObj="paramObj"
      :paramSelArr="paramSelArr"
      :paramSelCol="paramSelCol"
    />
    <!--客户订单-->
    <customerorder
      :currshowlist.sync="showCustomerorder"
      @handleSelectionChange="selectCustomerorder"
    ></customerorder>
  </el-dialog>
</template>
 
<script>
import {
  getEscort,
  addEscort,
  putEscort,
  fetchListEscortDetailAll,
  getEscortInfoByOrder,
  delEscort,
  delEscortDetails
} from '@/api/warehouse/escort'
import { fetchList as fetchLocationList } from '@/api/warehouse/location'
import Customerorder from '@/views/common/customerorder.vue'
import StockMulti from '@/views/common/stock-multi.vue'
 
export default {
  data() {
    return {
      clickDateArr: [],
      visible: false,
      multiSelect: true,
      activeName: '押运单',
      dataForm: {
        id: 0,
        escortNo: '',
        requestDate: '',
        orderNo: '',
        customerOrderNo: '',
        entityName: '',
        customerName: '',
        address: '',
        receiver: '',
        phone: '',
        deliveryDate: '',
        carrier: '',
        salesman: '',
        remark: '',
        customerOrderId: null
      },
      dataRule: {
        remark: [{ required: true, message: '备注不能为空', trigger: 'blur' }]
      },
 
      queryParam: {},
      escortDetailList: [], // 发货明细
      selectEscortDetailList: [],
 
      paramObj: { locationId: null },
      paramSelArr: [],
      paramSelCol: 'id',
      relateVisible: false,
      showCustomerorder: false
    }
  },
  components: {
    StockMulti,
    Customerorder
  },
  methods: {
    init(id) {
      this.getDefaultLocation()
      this.dataForm.id = id || 0
      this.activeName = '押运单'
      this.visible = true
      this.$nextTick(() => {
        this.$refs.dataForm.resetFields()
        this.clear()
        if (this.dataForm.id) {
          getEscort(this.dataForm.id).then((response) => {
            this.dataForm = response.data.data
            this.moment = this.dataForm.createTime
          })
        } else {
          this.dataForm.escortAutoId = ''
        }
        this.getEscortDetailList()
      })
    },
    // 获取默认的待发货库位
    getDefaultLocation() {
      fetchLocationList(
        Object.assign(
          {
            current: 1,
            size: 20
          },
          { locType: '9' }
        )
      ).then((res) => {
        if (res.data.code === 0) {
          const toBeShippeds = res.data.data.records
          if ((toBeShippeds != null) & (toBeShippeds.length > 0)) {
            const toBeShipped = toBeShippeds[0]
            this.paramObj.locationId = toBeShipped.id
          }
        }
      })
    },
    clear() {
      this.dataForm.status = ''
    },
    // 表单提交
    dataFormSubmit() {
      var canClickFlag = true
      this.clickDateArr.push(new Date().getTime())
      if (this.clickDateArr.length > 1) {
        if (
          this.clickDateArr[this.clickDateArr.length - 1] -
            this.clickDateArr[this.clickDateArr.length - 2] <
          2000
        ) {
          // 小于2秒则认为重复提交
          canClickFlag = false
        }
      }
      if (!canClickFlag) {
        return
      }
 
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          if (this.dataForm.id) {
            putEscort(
              Object.assign({}, this.dataForm, {
                escortDetailList: this.escortDetailList
              })
            )
              .then((data) => {
                this.$message.success('押运单修改成功')
                this.$emit('refreshDataList')
                this.visible = false
              })
              .catch((error) => {
                console.log(error)
              })
          } else {
            addEscort(
              Object.assign({}, this.dataForm, {
                status: '01draft',
                escortDetailList: this.escortDetailList
              })
            )
              .then((data) => {
                this.$message.success('押运单新增成功')
                this.$emit('refreshDataList')
                this.visible = false
              })
              .catch((error) => {
                console.log(error)
              })
          }
        }
      })
    },
    // 打开库存信息
    openStockDialog() {
      // 筛选出当前发货的库存
      this.paramSelArr = []
      if (this.escortDetailList && this.escortDetailList.length > 0) {
        this.escortDetailList.forEach((e) => {
          this.paramSelArr.push(e.stockId)
        })
      }
      this.relateVisible = true
    },
    // 选择库存
    selectStock(stockList) {
      if (stockList && stockList.length > 0) {
        // 添加发货明细
        stockList.forEach((item) => {
          this.escortDetailList.push(
            Object.assign({
              id: null,
              stockId: item.id,
              partBatchNo: item.partBatchNo,
              partNo: item.partNo,
              partName: item.partName,
              deliveryQty: item.availableStockQuantity
            })
          )
        })
      }
    },
    // 选择订单预留
    selectOrderStock(orderStockList) {
      if (orderStockList && orderStockList.length > 0) {
        const newCustomerOrderIdList = []
        // 添加发货明细
        orderStockList.forEach((item) => {
          const exist = this.escortDetailList.find(
            (detail) => detail.customerOrderId === item.customerOrderId
          )
          if (!exist) {
            newCustomerOrderIdList.push(item.customerOrderId)
          }
          this.escortDetailList.push(
            Object.assign({
              stockOrderId: item.id,
              customerOrderId: item.customerOrderId,
              customerOrderNo: item.customerOrderNo,
              customerName: item.customerName,
              partBatchNo: item.partBatchNo,
              partNo: item.partNo,
              partName: item.partName,
              reservedQuantity: item.reservedQuantity,
              deliveredQuantity: item.deliveryQuantity,
              deliveryQty: item.undeliveredQuantity
            })
          )
        })
        // 如果是新增的,自动填充押运单主表信息
        if (
          !this.dataForm.id &&
          newCustomerOrderIdList &&
          newCustomerOrderIdList.length > 0
        ) {
          getEscortInfoByOrder(newCustomerOrderIdList).then((response) => {
            if (response.data.code === 0) {
              const escortInfoList = response.data.data
              if (escortInfoList && escortInfoList.length > 0) {
                escortInfoList.forEach((escortInfo) => {
                  if (escortInfo.orderNo) {
                    this.dataForm.orderNo =
                      (this.dataForm.orderNo
                        ? this.dataForm.orderNo + ','
                        : '') + escortInfo.orderNo
                  }
                  if (!this.dataForm.requestDate) {
                    this.dataForm.requestDate = escortInfo.requestDate
                  }
                  if (escortInfo.customerOrderNo) {
                    this.dataForm.customerOrderNo =
                      (this.dataForm.customerOrderNo
                        ? this.dataForm.customerOrderNo + ','
                        : '') + escortInfo.customerOrderNo
                  }
                  if (escortInfo.entityName) {
                    this.dataForm.entityName =
                      (this.dataForm.entityName
                        ? this.dataForm.entityName + ','
                        : '') + escortInfo.entityName
                  }
                  if (escortInfo.customerName) {
                    this.dataForm.customerName =
                      (this.dataForm.customerName
                        ? this.dataForm.customerName + ','
                        : '') + escortInfo.customerName
                  }
                  if (escortInfo.address) {
                    this.dataForm.address =
                      (this.dataForm.address
                        ? this.dataForm.address + ','
                        : '') + escortInfo.address
                  }
                  if (escortInfo.receiver) {
                    this.dataForm.receiver =
                      (this.dataForm.receiver
                        ? this.dataForm.receiver + ','
                        : '') + escortInfo.receiver
                  }
                  if (escortInfo.phone) {
                    this.dataForm.phone =
                      (this.dataForm.phone ? this.dataForm.phone + ',' : '') +
                      escortInfo.phone
                  }
                  if (escortInfo.salesman) {
                    this.dataForm.salesman =
                      (this.dataForm.salesman
                        ? this.dataForm.salesman + ','
                        : '') + escortInfo.salesman
                  }
                })
              }
            }
          })
        }
      }
    },
    // 删除待发货明细
    deleteOrderStock() {
      if (
        this.selectEscortDetailList &&
        this.selectEscortDetailList.length > 0
      ) {
        const escortDetailIds = []
        this.selectEscortDetailList.forEach((obj) => {
          if (obj.id != null) {
            escortDetailIds.push(obj.id)
          }
        })
        if (escortDetailIds.length > 0) {
          delEscortDetails(escortDetailIds).then((response) => {
            if (response.data.code === 0) {
              this.selectEscortDetailList.forEach((obj) => {
                const index = this.escortDetailList.findIndex(
                  (item) => item.stockId === obj.stockId
                )
                if (index !== -1) {
                  this.escortDetailList.splice(index, 1)
                }
              })
              this.$message.warning('删除明细成功')
            } else {
              this.$message.warning('删除明细失败')
            }
          })
        } else {
          this.selectEscortDetailList.forEach((obj) => {
            const index = this.escortDetailList.findIndex(
              (item) => item.stockId === obj.stockId
            )
            if (index !== -1) {
              this.escortDetailList.splice(index, 1)
            }
          })
          this.$message.warning('删除明细成功')
        }
      } else {
        this.$message.warning('请选择待发货明细')
      }
    },
 
    // 查询待发货明细
    handleEscortDetailList() {
      this.getEscortDetailList()
    },
    getEscortDetailList() {
      this.escortDetailList = []
      if (this.dataForm.id) {
        const query = Object.assign(
          { escortId: this.dataForm.id },
          this.queryParam
        )
        fetchListEscortDetailAll(query).then((response) => {
          if (response.data.code === 0) {
            this.escortDetailList = response.data.data
          } else {
            this.$message.error('获取待发货明细失败')
          }
        })
      }
    },
    // 选择待发货明细
    selectionEscortDetail(val) {
      this.selectEscortDetailList = val
    },
    // 打开客户订单对话框
    openCustomOrderDialog() {
      this.showCustomerorder = true
    },
    // 选中客户订单之后,回调重置押运单客户信息
    selectCustomerorder(param) {
      if (param && param.length > 0) {
        const customerOrder = param[0]
        const newCustomerOrderIdList = [customerOrder.id]
        this.dataForm.customerOrderId = customerOrder.id
        this.dataForm.orderNo = customerOrder.customerNo
        this.dataForm.customerOrderNo = customerOrder.customerOrderNo
        this.dataForm.customerName = customerOrder.customerName
        getEscortInfoByOrder(newCustomerOrderIdList).then((response) => {
          if (response.data.code === 0) {
            const escortInfoList = response.data.data
            if (escortInfoList && escortInfoList.length > 0) {
              const escortInfo = escortInfoList[0]
 
              if (!this.dataForm.requestDate) {
                this.dataForm.requestDate = escortInfo.requestDate
              }
              if (escortInfo.entityName) {
                this.dataForm.entityName = escortInfo.entityName
              }
              if (escortInfo.address) {
                this.dataForm.address = escortInfo.address
              }
              if (escortInfo.receiver) {
                this.dataForm.receiver = escortInfo.receiver
              }
              if (escortInfo.phone) {
                this.dataForm.phone = escortInfo.phone
              }
              if (escortInfo.salesman) {
                this.dataForm.salesman = escortInfo.salesman
              }
            }
          }
        })
      }
    },
    initDataForm() {
      this.dataForm.id = 0
      this.dataForm.escortNo = ''
      this.dataForm.requestDate = ''
      this.dataForm.orderNo = ''
      this.dataForm.customerOrderNo = ''
      this.dataForm.entityName = ''
      this.dataForm.customerName = ''
      this.dataForm.address = ''
      this.dataForm.receiver = ''
      this.dataForm.phone = ''
      this.dataForm.deliveryDate = ''
      this.dataForm.carrier = ''
      this.dataForm.salesman = ''
      this.dataForm.remark = ''
      this.dataForm.customerOrderId = null
    },
    // 清空
    cleanForm() {
      if (this.escortDetailList != null && this.escortDetailList.length > 0) {
        this.$message.warning('请先删除待发货明细')
      } else {
        if (this.dataForm.id) {
          // 存在押运单id,需调用后端接口删除
          delEscort(this.dataForm.id).then((response) => {
            if (response.data.code === 0) {
              this.initDataForm()
              this.$message.success('清空成功')
              this.$emit('refreshDataList')
            } else {
              this.$message.error('清空失败')
            }
          })
        } else {
          // 不存在押运单id,押运单数据初始化
          this.initDataForm()
        }
      }
    }
  }
}
</script>