333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
<template>
  <div ref="container" class="page-list-container">
    <!--数据Table-->
    <yrt-data-list :ref="dataListRef" :editor-ref="editorRef" :data-options="dataOptions" :fields.sync="dataListOptions.fields" :buttons="dataListOptions.buttons" :button-click="buttonClick" :data-list-selections.sync="dataListSelections" :auth-nodes="authNodes" :on-delete-before="onDeleteBefore" :on-stop-before="onStopBefore">
      <template slot="common-column-slot" slot-scope="{row, col}">
        <template v-if="col.prop=='statusText'">
          <state-flow :load-options="stateLoadOptions" :where="{order_Id: row[dataOptions.idField]}">
            <template slot="content">
              <el-tag :color="setStatusBgColor(row[col.prop])" :style="setStatusColor(row[col.prop])">
                {{ row[col.prop] }}
              </el-tag>
            </template>
          </state-flow>
        </template>
        <!--审核字段-->
        <template v-else-if="col.prop=='auditing'">
          <template>
            <el-tag v-if="row[col.prop]==0" color="#ffff33" style="color:black;border:0">
              {{ $refs[dataListRef].translateText(col.prop, row[col.prop], col.dropdown_Id) }}
            </el-tag>
            <el-tag v-else-if="row[col.prop]==1" color="#ff0033" style="color:white;border:0">
              {{ $refs[dataListRef].translateText(col.prop, row[col.prop], col.dropdown_Id) }}
            </el-tag>
            <el-tag v-else-if="row[col.prop]==2" color="#33cc33" style="color:black;border:0;color:#fff;">
              {{ $refs[dataListRef].translateText(col.prop, row[col.prop], col.dropdown_Id) }}
            </el-tag>
            <span v-else>
              {{ row[col.prop] }}
            </span>
          </template>
        </template>
        <!--连接字段-->
        <template v-else-if="col.prop==dataOptions.linkColumn">
          <el-link type="primary" @click.native="()=>{linkEditor(row[dataOptions.idField]);}">{{ row[col.prop] }}</el-link>
        </template>
        <template v-else-if="col.dropdown_Id>0">
          {{ $refs[dataListRef].translateText(col.prop, row[col.prop], col.dropdown_Id) }}
        </template>
        <template v-else>
          <template v-if="['date', 'datetime'].indexOf(col.dataType)>=0 && col.formatter">
            {{ common.formatDate(row[col.prop], col.formatter) }}
          </template>
          <template v-else-if="['byte', 'int32', 'int64', 'decimal', 'double'].indexOf(col.dataType)>=0 && col.formatter">
            {{ common.formatNumber(row[col.prop], col.formatter) }}
          </template>
          <template v-else>
            {{ row[col.prop] }}
          </template>
        </template>
      </template>
    </yrt-data-list>
 
    <!--数据编辑器Editor-->
    <yrt-editor :ref="editorRef" :data-list-ref="dataListRef" :fields="editorOptions.fields" :config="editorOptions.config" :data-options="dataOptions" :action.sync="editorOptions.action" :top.sync="editorOptions.top" :visible.sync="editorOptions.config.visible" :detail-button-click="detailButtonClick" :use-detail-slot="[ 'images']" :auth-nodes="authNodes" :btn-read-only="btnReadOnly" :default-value="defaultValue" :edit-button-click="editButtonClick" :before-close="beforeClose" :on-stop-before="onStopBefore" :on-save-before="onSaveBefore" :use-label-slot="useLabelSlot" @on-edit-load-after="onEditLoadAfter" @on-detail-change="onDetailChange" @on-add-load-after="onEditLoadAfter" @on-row-change="onRowChange" @on-item-click="(ref, val, itemData, field, formData)=>{onChange(ref, val, field, formData, itemData)}" @on-change="onChange" @on-load-dropdown-after="onLoadDropdownAfter">
      <!--自定义标签插槽-->
      <template slot="label-feeItem_Ids">
        一次性收费项
        <a href="javascript:;" style="color:blue;" @click="showFeeTtemPopup()">修改</a>
      </template>
      <!--自定义按钮插槽-->
      <!-- <template slot="footer-button-region" slot-scope="{ formData, details }"> -->
      <!--打印条码按钮-->
      <!-- <el-button :disabled="btnReadOnly.printBarcode" type="success" icon="el-icon-yrt-print" @click.native="printBarcode(formData, details)">打印条码</el-button> -->
      <!--打印中条码按钮-->
      <!-- <el-button :disabled="btnReadOnly.printBarcode" type="success" icon="el-icon-yrt-print" @click.native="printBarcode(formData, details, 'middleBarcode')">打印中条码</el-button> -->
      <!--打印大条码按钮-->
      <!-- <el-button :disabled="btnReadOnly.printBarcode" type="success" icon="el-icon-yrt-print" @click.native="printBarcode(formData, details, 'bigBarcode')">打印大条码</el-button> -->
      <!-- </template> -->
      <template slot="detail-column-slot" slot-scope="{ row, col, formData }">
        <template v-if="col.prop === 'images'">
          <el-image :src="row.images" :fit="fit" style="width: 140px; height: 100px"></el-image>
        </template>
      </template>
    </yrt-editor>
 
    <!--物料选择器-->
    <yrt-selector ref="selector-dialog" :config="selectorConfig" :visible.sync="selectorConfig.visible" @on-selected="onSelected"></yrt-selector>
    <!--物料库存选择器-->
    <yrt-selector ref="selector-position-dialog" :config="selectorPositionConfig" :visible.sync="selectorPositionConfig.visible" :url="selectorPositionConfig.url" @on-selected="onPositionSelected"></yrt-selector>
    <!--打印条码弹出页面-->
    <order-barcode ref="barcode-dialog" :visible.sync="barcodeVisible"></order-barcode>
    <!--明细转移页面-->
    <detail-transfer ref="detailtransfer-dialog" :visible.sync="detailtransferVisible"></detail-transfer>
    <!--批量拆分-->
    <batch-transfer ref="batchtransfer-dialog" :visible.sync="batchtransferVisible"></batch-transfer>
    <!--批量更改折扣率页面-->
    <batch-update ref="batchupdate-dialog" :visible.sync="batchupdateVisible"></batch-update>
    <!--批量拆分导入-->
    <batch-import ref="batchimport-dialog" :visible.sync="batchimportVisible"></batch-import>
    <!--明细拆分单据-->
    <order-detail-split ref="detailsplitDialog" :visible.sync="detailsplitimportVisible"></order-detail-split>
    <!-- 一键确认入库 -->
    <quick-enter-dialog ref="checkEnterDialog" :visible.sync="checkEnterVisible"></quick-enter-dialog>
    <!-- 一次性收费项 -->
    <order-one-charge ref="feeTtemPopupDialog" :visible.sync="isFeeTtemPopupVisible"></order-one-charge>
    <!--明细导入-->
    <import-dialog :visible.sync="orderImportConfig.isShowDialog" :import-config="orderImportConfig" :before-import-submit="beforeImportSubmit" @on-close="onCloseOrderDetail">
    </import-dialog>
  </div>
</template>
 
<script>
import baseLayout from "@/components/common/base-layout.vue";
import yrtSelector from "@/components/common/yrtSelector.vue";
import orderBarcode from "./components/order-barcode.vue";
import detailTransfer from "./components/detail-transfer.vue";
import batchUpdate from "./components/batch-update.vue";
import batchTransfer from "./components/batch-transfer.vue";
import batchImport from "./components/batch-import.vue";
import stateFlow from "@/components/common/components/stateflow.vue";
import quickEnterDialog from "./components/quick-enter-dialog.vue";
import ImportDialog from "@/components/common/components/import-common-dialog";
import orderDetailSplit from "./components/order-detail-split.vue";
import orderOneCharge from "./components/order-one-charge.vue";
 
import orderMixinButton from "./components/order-mixin-button.vue";
import orderMixinStatus from "./components/order-mixin-status.vue";
var moment = require("moment");
 
export default {
  name: "inbound-purchase-order-wx",
  components: {
    yrtSelector,
    orderBarcode,
    detailTransfer,
    batchUpdate,
    batchTransfer,
    batchImport,
    stateFlow,
    quickEnterDialog,
    ImportDialog,
    orderDetailSplit,
    orderOneCharge
  },
  mixins: [baseLayout, orderMixinButton, orderMixinStatus],
  // 自定义处理权限函数
  doAuth(the) {
    // 判断当前版本是否拥有导入权限
    var authList = [
      { name: "预到货单批量导入", auth: "allImport" },
      { name: "打印预到货单", auth: "print" }
      // { name: "确认在途中", auth: "inTransit" }
    ];
    const names = authList.map(item => {
      return item.name;
    });
    the.common.isSaaSAuth(names, res => {
      res = the.common.objectToCase(res);
      authList.forEach(node => {
        let hasAuth = res.result;
        if (hasAuth) {
          hasAuth = res.data.some(item => {
            return item.moduleName === node.name;
          });
        }
        the.authNodes[node.auth] = hasAuth;
      });
    });
  },
  data() {
    return {
      fileList: [],
      // 条码对话框是否显示
      barcodeVisible: false,
      // 表单默认值,新建时用
      defaultValue: {
        statusID: 1,
        statusText: "新建"
      },
      // 配置参数
      config: {
        // 预到货单明细自动生成批次号
        in_autoGenerateBatchCode: false,
        // 预到货单明细自动生成唯一码
        in_autoSingleSignCode: false
      },
      orderImportConfig: {
        // 显示导入对话框
        isShowDialog: false,
        title: "入库单批量导入",
        // 导入地址
        url: "api/inbound/order/importExcel",
        // 模板地址
        templateUrl: "https://auod-beijing.oss-cn-beijing.aliyuncs.com/node-wms/template/预到货单明细导入模板.xlsx"
        // templateUrl: this.common.templateDomain + "/node-wms/template/预到货单明细导入模板.xlsx"
      },
      // 明细拆分是否显示
      detailsplitimportVisible: false,
      // 一次性收费项弹框
      isFeeTtemPopupVisible: false
    };
  },
  mounted() {
    this.getConfig();
  },
  // 自定义初始化数据
  init(the) {
    var userInfo = the.common.getUserInfo();
    // 设置经手人不是超级管理员,不允许编辑
    if (!userInfo.isAdministrator) {
      the.editorOptions.fields.forEach(cols => {
        cols.columns &&
          cols.columns.forEach(col => {
            col.fields.forEach(item => {
              if (item.options.prop === "UserTrueName") {
                item.options.disabled = true;
              }
            });
          });
      });
    }
  },
  activated() {
    // SaaS模块权限
    this.common.hasSaaSAuth("预到货单", this.$refs.container);
  },
  methods: {
    onChange(ref, val, field, formData) {
      debugger;
      if (field.options.prop === "plateCode") {
        // this.editor.changeValue("plateType", val);
        const plateCode = this.editor.formData["plateCode"];
        const url = "/api/basicInfo/base/plate/getList";
        const params = {
          name: plateCode
        };
        const _ref = this.dataList;
        const callback = res => {
          this.common.showMsg(res);
          if (res.result) {
            this.editor.changeValue("plateType", res.data[0].plateType);
            this.editor.changeValue("plateType_Id", res.data[0].plateType_Id);
            this.editor.changeValue("storageCode", res.data[0].storageCode);
            this.editor.changeValue("storageName", res.data[0].storageName);
            this.loadProductDropDown();
          } else {
            this.editor.changeValue("plateType", null);
          }
        };
        this.common.ajax(url, params, callback, _ref);
      }
    },
    // 下拉框加载完毕后
    onLoadDropdownAfter(formData) {
      // 在新间时获取工厂名称第一条数据
      const consignorDropdownList = this.editor.getDropdownData(797);
      if (consignorDropdownList && consignorDropdownList.length) {
        // 只有新建时,默认值
        if (!formData.order_Id) {
          const firstItem = consignorDropdownList[0];
          this.defaultValue.consignor_Id = firstItem.consignor_Id;
          this.defaultValue.consignorCode = firstItem.consignorCode;
          this.defaultValue.consignorName = firstItem.consignorName;
          formData.consignor_Id = firstItem.consignor_Id;
          formData.consignorCode = firstItem.consignorCode;
          formData.consignorName = firstItem.consignorName;
        }
      }
    },
    // 加载明细商品下拉框
    loadProductDropDown() {
      debugger;
      var plateType = this.masterData.plateType;
      var plateType_Id = this.masterData.plateType_Id;
      const url = "/api/basicInfo/base/productInfo/getListByPlateType";
      const params = {
        plateType_Id: plateType_Id,
        plateType: plateType
      };
      var callback = res => {
        if (res.result) {
          this.editor.setDropdownData(34, res.data);
        }
      };
      this.common.ajax(url, params, callback, true);
    },
    // 将选择器选择中的数据填充到明细表中
    onPositionSelected(rows) {
      rows.forEach(item => {
        if (!item.originPlace) {
          if (this.detailRows.length) {
            item.originPlace = this.detailRows[this.detailRows.length - 1].originPlace;
          }
        }
      });
      this.editor.addDetailDataRow(rows);
      this.selectorPositionConfig.visible = false;
    },
    // 将选择器选择中的数据填充到明细表中
    onSelected(rows) {
      // 设置默认值
      const lastRow = this.detailRows[this.detailRows.length - 1];
      let originPlace = lastRow ? lastRow.originPlace : "";
      rows.forEach(row => {
        row.originPlace = row.originPlace;
 
        if (originPlace && !row.originPlace) {
          row.originPlace = originPlace;
        }
        if (row.originPlace) {
          originPlace = row.originPlace;
        }
      });
      this.editor.addDetailDataRow(rows);
      this.selectorConfig.visible = false;
    },
    // 获得配置参数
    getConfig() {
      var keys = Object.keys(this.config).join(",");
      var url = "/api/sys/param/getConfig";
      var params = {
        openNodeApi: true,
        keys: keys
      };
      var callback = res => {
        this.common.showMsg(res);
        this.valueList = res.data;
        // 获得参数值列表,将数字转换为对象
        res.data.forEach(item => {
          var value03 = item.value03;
          if (this.common.isNumber(item.value03)) {
            value03 = parseInt(item.value03);
          }
          this.$set(this.config, item.value02, !!value03);
        });
      };
      this.common.ajax(url, params, callback, this.$refs.container);
    },
    // 上传前事件
    beforeUpload() {},
    // 数据加载后
    onEditLoadAfter(formData) {
      var statusID = formData.statusID;
      if (statusID === 1) {
        // 新建
        this.btnReadOnly.auditing = false;
        this.btnReadOnly.stop = false;
        this.btnReadOnly.open = true;
        this.btnReadOnly.save = false;
        this.btnReadOnly.inTransit = false;
        this.editorOptions.config.disabled = false; // 整个对话框可编辑
      } else if (statusID === 2) {
        // 审核成功
        this.btnReadOnly.auditing = true;
        this.btnReadOnly.stop = false;
        this.btnReadOnly.open = true;
        this.btnReadOnly.save = true;
        this.btnReadOnly.inTransit = false;
        this.editorOptions.config.disabled = true; // 整个对话框可编辑
      } else if (statusID === 4) {
        // 4-在途中
        this.btnReadOnly.auditing = true;
        this.btnReadOnly.stop = false;
        this.btnReadOnly.open = true;
        this.btnReadOnly.save = true;
        this.btnReadOnly.inTransit = true;
        this.editorOptions.config.disabled = true; // 整个对话框可编辑
      } else if (statusID === 8) {
        // 8-完全交货
        this.btnReadOnly.auditing = true;
        this.btnReadOnly.stop = true;
        this.btnReadOnly.open = true;
        this.btnReadOnly.save = true;
        this.btnReadOnly.inTransit = true;
        this.editorOptions.config.disabled = true; // 整个对话框可编辑
      } else if (statusID === 14) {
        // 已合并
        this.btnReadOnly.auditing = true;
        this.btnReadOnly.stop = true;
        this.btnReadOnly.open = true;
        this.btnReadOnly.save = true;
        this.btnReadOnly.inTransit = true;
        this.editorOptions.config.disabled = true; // 整个对话框可编辑
      } else if (statusID === 9) {
        // 9-终止
        this.btnReadOnly.auditing = true;
        this.btnReadOnly.stop = true;
        this.btnReadOnly.open = false;
        this.btnReadOnly.save = true;
        this.btnReadOnly.inTransit = true;
        this.editorOptions.config.disabled = true; // 整个对话框可编辑
      } else {
        // 3-部分交货,9-终止
        this.btnReadOnly.auditing = true;
        this.btnReadOnly.stop = true;
        this.btnReadOnly.open = true;
        this.btnReadOnly.save = true;
        this.btnReadOnly.inTransit = true;
        this.editorOptions.config.disabled = true; // 整个对话框可编辑
      }
 
      if (formData && formData.order_Id) {
        let totalQuantity = 0;
        let totalMoney = 0;
        let totalRateMoney = 0;
        var detailRows = formData["Purchase_OrderList"].rows;
        detailRows.forEach(item => {
          totalQuantity += item.quantity;
          totalMoney += item.purchaseMoney;
          totalRateMoney += item.taxAmount;
        });
        this.editor.changeValue("totalQuantity", totalQuantity);
        this.editor.changeValue("totalMoney", totalMoney);
        this.editor.changeValue("totalRateMoney", totalRateMoney);
      }
    },
    // 明细字段改变
    onDetailChange(ref, val, row, field) {
      this.setTotal(ref, val, row, field);
      if (!row.quantity || !row.unitConvert) {
        row.bigUnitRounding = 0;
      } else {
        row.bigQty = Math.Round(row.quantity / row.unitConvert, 4);
        row.bigUnitRounding = Math.ceil(row.quantity / row.unitConvert, 4);
      }
      if (row.produceDate) {
        row.effectivedate = moment(row.produceDate)
          .add(row.shelfLifeDay || 0, "days")
          .format("YYYY-MM-DD");
      }
    },
    // 求和
    setTotal(ref, val, row, field) {
      var detailRows = this.detailRows;
      // 合计数量求和
      let totalQuantity = 0;
      let totalMoney = 0.0;
      let totalRateMoney = 0.0;
      let totalWeight = 0.0;
      detailRows.forEach(item => {
        if (item.productName) {
          var now = moment().format("YYYY-MM-DD");
          const url = "/api/basicInfo/base/productInfo/getByIds";
          const params = {
            id: item.product_Id
          };
          var callback = res => {
            if (res.result) {
              // this.editor.setDropdownData(34, res.data);
              this.dataTable = res.data;
              item.weight = this.dataTable.weight;
              item.ratePrice = this.dataTable.ratePrice;
              item.images = this.dataTable.images;
              if (!item.produceDate) {
                item.produceDate = now;
              }
            }
          };
          this.common.ajax(url, params, callback, true);
        }
 
        // var now = moment().format("YYYY-MM-DD");
        // if (item.produceDate) {
        //   item.produceDate = now;
        // }
        const urls = "/api/tms/userSys/quotation/getBatchNumber";
        const param = {
          code: item.productCode,
          time: item.produceDate
        };
        var callbacks = res => {
          if (res.result) {
            // this.editor.setDropdownData(34, res.data);
            this.getBatchNumber = res.data;
            item.batchNumber = this.getBatchNumber.batchNumber;
          }
        };
        this.common.ajax(urls, param, callbacks, true);
 
        // item.ratePrice = Math.Round((item.purchasePrice || 0) * (1 + (item.rate || 0)), 2);
        // 明细不含税金额 = 数量 * 不含税单价;
        item.purchaseMoney = Math.Round((item.quantity || 0) * (item.ratePrice || 0), 2);
        // 含税金额 = 数量 * 含税单价;
        item.taxAmount = Math.Round((item.quantity || 0) * (item.ratePrice || 0), 2);
        item.rateMoney = item.taxAmount;
        // 行小计重量
        if (field) {
          // weight 单位毛重  /   totalWeight 小计毛重 quantity 数量
          if (field.prop === "quantity" || field.prop === "weight") {
            // 小计  =  数量 * 单位毛重
            this.$set(item, "totalWeight", Math.Round((item.quantity || 0) * (item.weight || 0), 4));
          } else if (field && field.prop === "totalWeight") {
            // 修改合计重量,计算出单位重量
            if (item.quantity) {
              this.$set(item, "weight", Math.Round((item.totalWeight || 0) / (item.quantity || 0), 4));
            } else {
              item.weight = 0;
            }
          }
        }
        item.unitPackage = Math.ceil(item.unitPackage);
        if (field) {
          if (field.prop === "quantity") {
            // 总数量同步于数量
            item.totalPackageQty = item.quantity;
          }
          if (field.prop === "totalPackageQty") {
            this.$set(item, "totalPackageQty", item.totalPackageQty);
          }
          if (field.prop === "paiQty") {
            item.paiQty = Math.ceil(item.paiQty);
          } else {
            item.paiQty = item.unitPackage ? Math.ceil(item.totalPackageQty / item.unitPackage) : 0;
          }
        }
        // item.totalPackageQty = item.quantity;
        // 建议拍数 = 总件数 / 打包配置
        // item.paiQty = item.unitPackage ? Math.ceil(item.totalPackageQty || 0 / item.unitPackage || 0) : 0;
 
        totalQuantity += item.quantity || 0;
        totalMoney += item.purchaseMoney || 0;
        totalRateMoney += item.taxAmount || 0;
        totalWeight += item.totalWeight || 0;
        // debugger;
        if (item.unitPackageType === "按数量") {
          item.totalPackageQty = item.quantity;
        } else if (item.unitPackageType === "按毛重") {
          item.totalPackageQty = item.totalWeight;
        } else if (item.unitPackageType === "按大单位数量") {
          item.totalPackageQty = item.bigUnitRounding;
        }
      });
      this.editor.changeValue("totalQuantity", totalQuantity);
      this.editor.changeValue("totalMoney", Math.Round(totalMoney, 2));
      this.editor.changeValue("totalRateMoney", Math.Round(totalRateMoney, 2));
      this.editor.changeValue("totalWeight", Math.Round(totalWeight, 4));
      // this.editor.changeValue("totalWeight", totalWeight);
      // this.editor.changeValue("weight", Math.Round(weight, 2));
    },
    // 保存前事件
    onSaveBefore() {
      this.setTotal();
 
      // 生成数据
      this.detailRows.forEach((row, index) => {
        const currentDate = moment(new Date());
        if (this.config.in_autoGenerateBatchCode && !row.batchNumber) {
          row.batchNumber = currentDate.format("YYYYMMDD") + "-" + (index + 1);
          row.__ischange__ = true;
        }
        if (this.config.in_autoSingleSignCode && !row.singleSignCode) {
          row.singleSignCode = this.common.getGUID();
          row.__ischange__ = true;
        }
      });
 
      let hasQty = true;
      var formData = this.editor.formData;
      var detailRows = formData["Purchase_OrderList"].rows;
      detailRows.forEach(item => {
        if (item.quantity <= 0 && !item.quantity) {
          hasQty = false;
        }
      });
      if (!hasQty) {
        this.$message({
          message: "下线数量必须大于0!",
          type: "warning"
        });
        return false;
      }
    },
    // 删除前事件
    onDeleteBefore(rows) {
      let statusText = true;
      rows.forEach(rowData => {
        statusText = rowData.statusText;
        if (statusText !== "新建") {
          statusText = false;
        }
      });
      if (statusText === false) {
        this.$message.error("仅可删除新建预到货单!");
        return false;
      }
      return true;
    },
    // 终止前事件
    onStopBefore(rows) {
      const statusList = ["新建", "审核成功", "在途中"];
      for (const row of rows) {
        const statusText = row.statusText;
 
        if (statusList.indexOf(statusText) < 0) {
          this.$message.error(`只有["新建", "审核成功", "在途中"]状态时才可以做终止动作!`);
          return false;
        }
        return true;
      }
    },
    // 关闭窗口前钩子函数, return true关闭窗口
    beforeClose() {
      const detailList = this.editor.formData["Purchase_OrderList"].rows.filter(item => {
        return !item.orderList_Id;
      });
      if (this.editor.formData.statusText === "新建" && detailList.length) {
        this.$confirm("数据未保存,是否关闭?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            this.editor.config.visible = false;
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
            this.editor.config.visible = true;
          });
      } else {
        this.editor.config.visible = false;
      }
    },
    // 表格下拉框字段改变事件
    onRowChange(ref, val, field) {
      // 货主和仓库改变
      if (["consignorName", "storageName"].indexOf(field.options.prop) >= 0) {
        window.setTimeout(() => {
          this.getDefaultItems();
        }, 200);
      }
    },
    // 获取一次性收费项默认值
    getDefaultItems() {
      const formData = this.editor.formData;
      if (formData.feeItem_Ids && this.editorOptions.config.action !== "add") return; // 已经有值了不在设置默认值
 
      const url = "/api/finance/baseOneCharge/getDefaultItems";
      const params = {
        associatedTasks: "入库单",
        consignor_Id: formData.consignor_Id,
        storage_Id: formData.storage_Id
      };
      this.common.ajax(url, params, res => {
        this.common.showMsg(res);
        if (res.result) {
          this.$set(formData, "feeItem_Ids", res.data);
        }
      });
    },
    // 预到货明细批量导入前事件
    beforeImportSubmit() {
      const order_Id = this.editor.formData["order_Id"];
      // 自定义参数
      this.orderImportConfig.params = {
        order_Id: order_Id
      };
    },
    // 明细导入窗口关闭时事件
    onCloseOrderDetail() {
      this.editor.reload();
    }
  }
};
</script>