schangxiang@126.com
2025-09-19 9be9c3784b2881a3fa25e93ae2033dc2803c0ed0
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
<template>
  <div 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" :on-delete-before="onDeleteBefore" :data-list-selections.sync="dataListSelections" :auth-nodes="authNodes">
      <template slot="action-column-slot" slot-scope="{row, col}">
        <template>
          <!-- <el-button type="text" size="mini" @click="editData(row.wayBill_Id)">轨迹</el-button> -->
          <state-flow :load-options="stateflowLoadOptions" :where="{clientDesc:{operator:'not', value:null}, wayBillCode:row.wayBillCode}">
            <template slot="content">
              <el-button type="text" size="mini">轨迹</el-button>
            </template>
          </state-flow>
 
          <waybill-history :load-options="stateLoadOptions" :where="{wayBill_Id: row[dataOptions.idField]}">
            <template slot="content">
              <el-button type="text" size="mini">运单记录</el-button>
            </template>
          </waybill-history>
        </template>
      </template>
 
      <template slot="button-tool2-slot">
        <el-dropdown>
          <el-button type="primary">
            运单打印
            <i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item v-for="(item, index) in printTemplateList" :key="index" class="w-200" @click.native="detailPrint(item)">{{ item.templateName }}</el-dropdown-item>
            <el-dropdown-item v-if="printTemplateList.length === 0" disabled>暂时没有模板</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </template>
    </yrt-data-list>
 
    <!--数据编辑器Editor-->
    <yrt-editor :ref="editorRef" :data-list-ref="dataListRef" v-bind="editorOptions" :data-options="dataOptions" :action.sync="editorOptions.action" :visible.sync="editorOptions.config.visible" :detail-button-click="detailButtonClick" :auth-nodes="authNodes" @on-change="onChange" @on-add-load-after="onEditLoadAfter" @on-edit-load-after="onEditLoadAfter" @on-detail-change="onDetailChange"></yrt-editor>
 
    <!--明细选择器-->
    <yrt-selector ref="selector-dialog" :config="selectorConfig" :visible.sync="selectorConfig.visible" @on-selected="onSelected"></yrt-selector>
  </div>
</template>
<script>
import baseLayout from "@/components/common/base-layout.vue";
import waybillHistory from "./components/waybillhistory.vue";
import yrtSelector from "@/components/common/yrtSelector.vue";
import stateFlow from "./components/stateflow.vue";
export default {
  name: "user-way-bill",
  components: {
    waybillHistory,
    yrtSelector,
    stateFlow
  },
  mixins: [baseLayout],
  // 自定义JSON路由地址
  custoJsonmRoute: "/user/way/bill",
  data() {
    return {
      // 选择器配置参数
      selectorConfig: {
        title: "物料选择器",
        width: "1000px",
        visible: false,
        // 配置路由
        router: "/selector/s-product-selector"
      },
      // 运单记录加载参数
      stateLoadOptions: {
        folder: "express/tms",
        projectName: "Interface.Express",
        tableView: "TMS_WayBill",
        idField: "wayBill_Id",
        sortName: { wayBill_Id: "DESC" },
        pageIndex: 1,
        pageSize: 100,
        menu_Id: -1
      },
      // 状态流加载参数
      stateflowLoadOptions: {
        folder: "express/tms",
        projectName: "Interface.Express",
        tableView: "TMS_WayBillTracking",
        idField: "wayBillTracking_Id",
        sortName: { wayBillTracking_Id: "DESC" },
        pageIndex: 1,
        pageSize: 100,
        menu_Id: -1
      },
      // 客户端权限点需要在这里增加,否则无法显示按钮
      authNodes: {
        add: true,
        delete: true,
        export: true,
        save: true,
        batchAuditing: true,
        returnGoods: true,
        batchOpen: true,
        batchStop: true
      },
      // 打印模板列表
      printTemplateList: []
    };
  },
  mounted() {
    var addListString = localStorage.getItem("addList");
    if (addListString) {
      var the = this;
      var addList = JSON.parse(addListString);
      window.setTimeout(function() {
        the.dataList.addSearchFields(addList);
        the.dataList.loadData();
      }, 1000);
      localStorage.removeItem("addList");
    }
    this.getPrintTemplate();
  },
  methods: {
    // 编辑框弹出
    // editData(id) {
    //   var ref = this.editor;
    //   ref.editData(id);
    // },
    // 列表页面按钮点击事件
    buttonClick(authNode) {
      switch (authNode) {
        case "batchAuditing":
          // 批量提交
          this.batchAuditing();
          return true;
        case "returnGoods":
          // 批量退货
          this.returnGoods();
          break;
        case "batchOpen":
          // 批量开启
          this.multiBatchOpen();
          return true;
        case "batchStop":
          // 批量终止
          this.multiBatchStop();
          return true;
      }
    },
    // 明细按钮点击事件
    detailButtonClick(authNode) {
      switch (authNode) {
        case "add":
          // 明细添加
          this.detailAdd();
          return true;
      }
    },
    // 批量提交操作
    batchAuditing() {
      const the = this;
      this.$confirm("确定要批量进行提交操作吗?", "批量提交", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          // 获得已选中的ID
          var isOrderStatus = true; // 可操作状态
          const selectIDs = the.dataListSelections.map((item, index, Array) => {
            if (item.orderStatus !== "新建") {
              isOrderStatus = false;
            }
            return item.wayBill_Id;
          });
          if (!selectIDs.length) {
            this.$message({
              message: "至少选中一行!",
              type: "warning"
            });
            return;
          }
          if (isOrderStatus === false) {
            this.$message({
              message: "所选单据存在不可操作提交状态!",
              type: "warning"
            });
            return;
          }
          const url = "/api/tms/waybill/batchAuditing";
          const params = {
            ids: selectIDs
          };
          const ref = this.dataList;
          var callback = res => {
            this.common.showMsg(res);
            if (res.result) {
              ref.loadData();
            }
          };
          this.common.ajax(url, params, callback, ref);
        })
        .catch(() => {
          the.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 批量退货操作
    returnGoods() {
      const the = this;
      this.$confirm("确定要批量进行退货操作吗?", "批量退货", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          // 获得已选中的ID
          var isOrderType = ""; // 运单类型=仓配,=直邮
          var isOrderStatus = ""; // 可操作状态
          const selectIDs = the.dataListSelections.map((item, index, Array) => {
            isOrderType = item.orderType;
            isOrderStatus = item.orderStatus;
            return item.wayBill_Id;
          });
          if (selectIDs === "") {
            this.$message({
              message: "至少选中一行!",
              type: "warning"
            });
            return;
          }
          if (isOrderType === "仓配") {
            if (isOrderStatus === "审核成功" || isOrderStatus === "已提交") {
              this.updateOrderStatus(selectIDs);
            } else {
              this.$message({
                message: "提交的数据订单状态不符合仓配退货条件!",
                type: "warning"
              });
              return;
            }
          } else if (isOrderType === "直邮") {
            if (isOrderStatus === "新建" || isOrderStatus === "已提交" || isOrderStatus === "面单已录入" || isOrderStatus === "审核成功") {
              this.updateOrderStatus(selectIDs);
            } else {
              this.$message({
                message: "提交的数据订单状态不符合直邮退货条件!",
                type: "warning"
              });
              return;
            }
          }
        })
        .catch(() => {
          the.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 修改满足条件数据的退货状态
    updateOrderStatus(selectIDs) {
      const url = "/api/tms/wayBill/billReturnGoods";
      const params = {
        ids: selectIDs,
        abnormalReason: "客户端操作退货"
      };
      const ref = this.dataList;
      var callback = res => {
        this.common.showMsg(res);
        if (res.result) {
          ref.loadData();
        }
      };
      this.common.ajax(url, params, callback, ref);
    },
    // 获得运单打印模板
    getPrintTemplate() {
      const url = "/api/sys/printTemplate/getTemplateList";
      const params = {
        templateName: "客户端运单面单"
      };
      this.common.ajax(url, params, res => {
        this.common.showMsg(res);
        if (res.result) {
          this.printTemplateList = res.data;
        }
      });
    },
    // 打印运单
    detailPrint(templateInfo) {
      var ids = [];
      this.dataListSelections.forEach(item => {
        ids.push(item[this.dataOptions.idField]);
      });
      if (!ids.length) {
        this.$message.error("至少选择一项!");
        return;
      }
      this.printRecord(ids);
      window.open(`/user.html#/print/base/${templateInfo.menu_Id}/${ids}`);
    },
    printRecord(ids) {
      var url = "/api/tms/userSys/bill/changePrintStatus";
      var params = {
        wayBill_Ids: ids
      };
      this.common.ajax(url, params, res => {});
    },
    // 删除前事件
    onDeleteBefore(row) {
      let StatusText = true;
      this.dataListSelections.forEach(rowData => {
        StatusText = rowData.orderStatus;
        if (StatusText !== "新建") {
          StatusText = false;
        }
      });
      if (StatusText === false) {
        this.$message.error("仅可删除新建运单!");
        return false;
      }
      return true;
    },
    // 将选择器选择中的数据填充到明细表中
    onSelected(rows) {
      this.editor.addDetailDataRow(rows);
      this.selectorConfig.visible = false;
      setTimeout(() => {
        this.editorOptions.config.disabled = false; // 整个对话框可编辑
      }, 800);
    },
    // 明细添加
    detailAdd() {
      this.selectorConfig.visible = true;
      this.$refs["selector-dialog"].setSearchValue("provider_Id", []);
      this.$refs["selector-dialog"].loadData();
    },
    // 批量开启操作
    multiBatchOpen() {
      const the = this;
      this.$confirm("确定要批量进行开启操作吗?", "批量开启", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          // 获得已选中的ID
          var isOrderStatus = true;
          const selectIDs = the.dataListSelections.map((item, index, Array) => {
            if (item.orderStatus !== "终止") {
              isOrderStatus = false;
            }
            return item.wayBill_Id;
          });
          if (!selectIDs.length) {
            this.$message({
              message: "至少选中一行!",
              type: "warning"
            });
            return;
          }
          if (isOrderStatus !== true) {
            this.$message({
              message: "只有终止的运单才可以开启!",
              type: "warning"
            });
            return;
          }
          const url = "/api/tms/waybill/multiBatchOpen";
          const params = {
            ids: selectIDs
          };
          const ref = the.dataList;
          var callback = res => {
            the.common.showMsg(res);
            if (res.result) {
              ref.loadData();
            }
          };
          the.common.ajax(url, params, callback, ref);
        })
        .catch(() => {
          the.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 批量终止操作
    multiBatchStop() {
      const the = this;
      this.$confirm("确定要批量进行终止操作吗?", "批量终止", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          // 获得已选中的ID
          var isOrderStatus = true;
          var isCollectStatus = true;
          const selectIDs = the.dataListSelections.map((item, index, Array) => {
            if (item.orderStatus !== "新建" && item.orderStatus !== "已提交") {
              isOrderStatus = false;
            }
            if (item.CollectStatus === "已揽收") {
              isCollectStatus = false;
            }
            return item.wayBill_Id;
          });
          if (selectIDs === "") {
            this.$message({
              message: "至少选中一行!",
              type: "warning"
            });
            return;
          }
          if (isOrderStatus !== true) {
            this.$message({
              message: "只有新建或已提交的运单才可以终止!",
              type: "warning"
            });
            return;
          }
          if (isCollectStatus === false) {
            this.$message({
              message: "已揽收的运单不允许操作终止!",
              type: "warning"
            });
            return;
          }
          const url = "/api/tms/waybill/multiBatchStop";
          const params = {
            ids: selectIDs
          };
          const ref = the.dataList;
          var callback = res => {
            the.common.showMsg(res);
            if (res.result) {
              ref.loadData();
            }
          };
          the.common.ajax(url, params, callback, ref);
        })
        .catch(() => {
          the.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 级联改变数据
    onChange(ref, val, field, formData) {
      // 所有状态都可以编辑
      // this.editorOptions.config.disabled = false;
 
      var editor = this.editor;
      if (field.options.prop === "portName") {
        var url = "/api/tms/wayBill/getGoodsRegion";
        var parsms = {
          portName: formData.portName
        };
        this.common.ajax(url, parsms, res => {
          if (res.result) {
            editor.formData.planDropOffPort = res.data.RegionName; // 落口名称
          }
        });
      }
    },
    // 数据加载后事件
    onEditLoadAfter(formData) {
      if (formData.orderStatus === "终止") {
        // 不可以编辑
        this.editorOptions.config.disabled = true; // 整个对话框不可编辑
      } else {
        this.editorOptions.config.disabled = false; // 整个对话框可编辑
      }
    },
    // 明细字段改变
    onDetailChange(ref, val, row, field) {
      // 合计数量求和
      let totalQuantityOrder = 0;
      let grandTotal = 0.0;
 
      var formData = this.editor.formData;
      var detailRows = formData["TMS_WayBillList"].rows;
      detailRows.forEach(item => {
        if (item.quantityOrder !== null || item.salePrice !== null) {
          // 行金额
          item.rowTotal = Math.Round(item.quantityOrder * item.salePrice, 2);
        }
 
        // totalQuantityOrder += item.Quantity;
        totalQuantityOrder += item.quantityOrder;
        grandTotal += item.rowTotal;
      });
 
      this.editor.changeValue("totalQuantityOrder", parseInt(totalQuantityOrder));
      this.editor.changeValue("grandTotal", Math.Round(grandTotal, 2));
    }
  }
};
</script>