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
 
<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" :data-list-selections.sync="dataListSelections" :auth-nodes="authNodes">
      <template slot="common-column-slot" slot-scope="{row, col}">
        <template v-if="col.prop=='statusText'">
          <template>
            <el-tag v-if="row[col.prop]=='确认出库'" color="#00fa9a" style="color:white;border:0">
              {{ row[col.prop] }}
            </el-tag>
            <el-tag v-else-if="row[col.prop]=='终止'" color="#ff0066" style="color:white;border:0">
              {{ row[col.prop] }}
            </el-tag>
            <el-tag v-else color="#ffff99" style="color:#888;">
              {{ row[col.prop] }}
            </el-tag>
          </template>
        </template>
        <!--审核字段-->
        <template v-else-if="col.prop=='auditing'">
          <template>
            <el-tag v-if="row[col.prop]==0" color="#ffff33" style="color:black;border:0">
              {{ dataList.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">
              {{ dataList.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;">
              {{ dataList.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 == 'sortingStatus'">
          <template>
            <el-tag v-if="row[col.prop] == 1" color="#ffff33" style="color:black;border:0">
              {{ dataList.translateText( col.prop, row[col.prop], col.dropdown_Id ) }}
            </el-tag>
            <el-tag v-else-if="row[col.prop] == 2" color="#00ff99" style="color:black;border:0">
              {{ dataList.translateText( col.prop, row[col.prop], col.dropdown_Id ) }}
            </el-tag>
            <el-tag v-else-if="row[col.prop] == 3" color="#ff0000" style="color:black;border:0;color:#fff;">
              {{ dataList.translateText( col.prop, row[col.prop], col.dropdown_Id ) }}
            </el-tag>
            <el-tag v-else-if="row[col.prop] == 5" color="#6699FF" style="color:black;border:0;color:#fff;">
              {{ dataList.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>
          <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" v-bind="editorOptions" :data-options="dataOptions" :action.sync="editorOptions.action" :top.sync="editorOptions.top" :visible.sync="editorOptions.config.visible" :detail-button-click="detailButtonClick" :auth-nodes="authNodes" :edit-button-click="editButtonClick" :on-save-before="onSaveBefore" :btn-read-only="btnReadOnly" @on-add-load-after="onEditLoadAfter" @on-edit-load-after="onEditLoadAfter" @on-detail-change="onDetailChange" @on-row-change="onRowChange">
      <!--自定义按钮插槽-->
      <template slot="footer-button-region" slot-scope="{ formData }">
        <el-button :disabled="btnReadOnly.sorting" type="success" icon="el-icon-yrt-shuaxin" @click.native="multiBatchSort(formData)">分拣</el-button>
        <!--自定义审核按钮-->
        <el-button :disabled="btnReadOnly.confirm" type="success" icon="el-icon-yrt-qiyong" @click.native="onConfirm(formData)">审核</el-button>
      </template>
    </yrt-editor>
 
    <!--明细选择器-->
    <yrt-selector ref="selector-position-dialog" :config="selectorPositionConfig" :visible.sync="selectorPositionConfig.visible" :url="selectorPositionConfig.url" :set-search-default="setSearchDefault" :get-custom-where="getCustomWhere" @on-selected="onPositionSelected">
      <template slot="search-form-item">
        <el-select v-model="operationType" splaceholder="账面库存量" class="w-150">
          <el-option label="库存大于0" value=">0">
          </el-option>
          <el-option label="库存大于等于0" value=">=0">
          </el-option>
          <el-option label="库存等于0" value="=0">
          </el-option>
          <el-option label="全部" value="">
          </el-option>
        </el-select>
      </template>
    </yrt-selector>
  </div>
</template>
<script>
import baseLayout from "@/components/common/base-layout.vue";
import yrtSelector from "@/components/common/yrtSelector.vue";
 
export default {
  name: "storage-borrow-outer",
  components: {
    yrtSelector
    // outerImport
  },
  mixins: [baseLayout],
  data() {
    return {
      selectorConfig: {
        title: "物料选择器",
        width: "1000px",
        visible: false,
        // 配置路由
        router: "/selector/s-product-selector",
        // 编辑规则验证
        rules: {
          positionType: [{ required: true, message: "请选择货位类型", trigger: "blur" }]
        }
      },
      selectorPositionConfig: {
        title: "物料库存选择器",
        width: "1000px",
        visible: false,
        // 配置路由
        router: "/selector/x-product-selector",
        url: "/api/common/GroupDataList"
      }
    };
  },
  // 自定义初始化数据
  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;
              }
            });
          });
      });
    }
  },
  methods: {
    // 明细按钮点击事件
    detailButtonClick(authNode) {
      switch (authNode) {
        case "detailAdd":
          // 明细添加
          this.openPositionSelected();
          return true;
      }
    },
    // 打开库存选择器
    openPositionSelected() {
      var editorRef = this.editor;
      if (!editorRef.formData.consignorName) {
        this.$message({
          message: "请选择货主!",
          type: "warning"
        });
        return;
      } else if (!editorRef.formData.storageName) {
        this.$message({
          message: "请选择仓库!",
          type: "warning"
        });
        return;
      }
      const selector = this.$refs["selector-position-dialog"];
      selector.setSearchValue("consignor_Id", [editorRef.formData.consignor_Id]);
      selector.setSearchValue("storage_Id", [editorRef.formData.storage_Id]);
      if (editorRef.formData.positionType) {
        selector.setSearchValue("positionType", [editorRef.formData.positionType]);
      }
      selector.setReadOnly("storage_Id", true); // 设为只读
      selector.setReadOnly("consignor_Id", true); // 设为只读
      selector.loadData();
      this.selectorPositionConfig.visible = true;
    },
    // 编辑按钮点击事件
    editButtonClick(authNode) {
      switch (authNode) {
        case "auditing":
          // 审核
          this.auditing();
          return false;
        case "open":
          this.open();
          return false;
        case "stop":
          this.stop();
          return false;
      }
    },
    open() {
      var the = this;
      var formData = the.editor.formData;
      if (formData.statusText !== "终止") {
        the.$message({
          type: "error",
          message: "只有终止的调拨单才能开启!"
        });
        return false;
      }
      the
        .$confirm("确定要进行开启操作吗, 是否继续?", "开启操作", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
        .then(() => {
          the._open();
        })
        .catch(() => {
          the.$message({
            type: "info",
            message: "已取消开启"
          });
        });
    },
    _open() {
      var the = this;
      var formData = the.editor.formData;
      var idField = the.dataOptions.idField;
      var idValue = formData[the.dataOptions.idField];
      var tableName = the.dataOptions.tableView;
 
      const ref = the.dataList;
      var url = "/api/storage/allocateApply/open";
      the.initLoading = true;
      var params = {
        idField: idField,
        idValue: idValue,
        tableName: tableName
      };
      the.common.ajax(
        url,
        params,
        res => {
          if (res.result) {
            the.$message.success(res.msg);
            ref.loadData();
            this.editor.reload();
          } else {
            the.$message({
              showClose: true,
              duration: 6000,
              message: res.msg,
              type: "error"
            });
          }
          the.initLoading = false;
        },
        true
      );
    },
    stop() {
      var the = this;
      var formData = the.editor.formData;
      if (formData.statusText !== "新建" || formData.sortingStatus !== 2) {
        the.$message({
          type: "error",
          message: "只有申请单状态为新建,分拣状态为已分配才能终止!"
        });
        return false;
      }
      this.$confirm("确定要进行终止操作吗, 是否继续?", "终止操作", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this._stop();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消终止"
          });
        });
    },
    // 在内部定义 加function 无法刷新编辑页面
    _stop() {
      var the = this;
      var formData = the.editor.formData;
      var idField = the.dataOptions.idField;
      var idValue = formData[the.dataOptions.idField];
      var tableName = the.dataOptions.tableView;
      const ref = the.dataList;
      var url = "/api/storage/allocateApply/stop";
      the.initLoading = true;
      var params = {
        idField: idField,
        idValue: idValue,
        tableName: tableName
      };
      the.common.ajax(
        url,
        params,
        res => {
          if (res.result) {
            the.$message.success(res.msg);
            ref.loadData();
            this.editor.reload();
          } else {
            the.$message({
              showClose: true,
              duration: 6000,
              message: res.msg,
              type: "error"
            });
          }
          the.initLoading = false;
        },
        true
      );
    },
    // 将选择器选择中的数据填充到明细表中
    onPositionSelected(rows) {
      rows.forEach(item => {
        item.weight = 0;
        if (item.productStorage !== 0 && item.totalWeight) {
          item.weight = Math.Round(item.totalWeight / item.productStorage, 2);
          item.totalWeight = 0;
          item.quantity = item.usingStorage;
        }
      });
      this.editor.addDetailDataRow(rows);
      this.selectorPositionConfig.visible = false;
    },
    // 分拣
    multiBatchSort(formData) {
      this.$confirm("请点击“开始分拣”按钮进行出库单分拣,判断库存是否满足出库?", "分拣", {
        confirmButtonText: "开始分拣",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        if (!formData.borrowOuter_Id) {
          this.$message({
            message: "当前数据没有保存!",
            type: "warning"
          });
          return;
        }
        const the = this;
        this.isAuditing = true;
        if (formData.statusText !== "新建") {
          this.$message({
            message: "只有新建状态才允许审核操作!",
            type: "warning"
          });
          return;
        }
        const url = "/api/storage/borrowOuter/startSorting";
        const borrowOuter_Id = formData.borrowOuter_Id;
        const params = {
          borrowOuter_Id: borrowOuter_Id
        };
        var callback = res => {
          the.common.showMsg(res);
          if (res.msg) {
            this.dataList.reload();
            this.editorOptions.config.visible = false;
          }
        };
        this.common.ajax(url, params, callback, true);
      });
    },
    // 开始审核
    onConfirm(formData) {
      this.$confirm("请点击“确认审核”按钮进行审核?", "确认审核", {
        confirmButtonText: "确认审核",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        if (!formData.borrowOuter_Id) {
          this.$message({
            message: "当前数据没有保存!",
            type: "warning"
          });
          return;
        }
        const the = this;
        this.isAuditing = true;
        if (formData.sortingStatus !== 2) {
          this.$message({
            message: "只有分拣成功状态允许确认审核操作!",
            type: "warning"
          });
          return;
        }
        const url = "/api/storage/borrowOuter/onConfirm";
        const borrowOuter_Id = formData.borrowOuter_Id;
        const params = {
          borrowOuter_Id: borrowOuter_Id
        };
        var callback = res => {
          the.common.showMsg(res);
          if (res.msg) {
            this.dataList.reload();
            this.editorOptions.config.visible = false;
          }
        };
        this.common.ajax(url, params, callback, true);
      });
    },
    // 主表数据改变
    onChange(ref, val, field, formData) {
      switch (field.options.prop) {
        case "storageName":
          this.$refs["selector-position-dialog"].setSearchValue("storageName", formData.storageName);
          this.$refs["selector-position-dialog"].loadData();
          break;
        case "consignorName":
          this.$refs["selector-position-dialog"].setSearchValue("consignorName", formData.consignorName);
          this.$refs["selector-position-dialog"].loadData();
          break;
      }
    },
    // 保存前事件
    onSaveBefore(formData) {
      return this.setTotal();
    },
    setTotal() {
      let hasQty = true;
      var formData = this.editor.formData;
      var detailRows = formData["Storage_BorrowOuterList"].rows;
      detailRows.forEach(item => {
        if (!item.outerQuantity) {
          hasQty = false;
        }
      });
      if (!hasQty) {
        this.$message({
          message: "借出数量不能空!",
          type: "warning"
        });
        return false;
      }
    },
    // 对选择器默认值操作
    setSearchDefault(searchData) {},
 
    // 表格下拉框字段改变事件
    onRowChange(ref, val, field) {
      // 货主和仓库改变
      if (["consignorName", "storageName"].indexOf(field.options.prop) >= 0) {
        window.setTimeout(() => {
          this.getDefaultItems();
        }, 200);
      }
    }
  }
};
</script>