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
 
<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" :action-field="actionField" :on-delete-before="onDeleteBefore" :data-list-selections.sync="dataListSelections" :auth-nodes="authNodes">
    </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" :btn-read-only="btnReadOnly" :auth-nodes="authNodes" :do-data-parser="doDataParser" :on-save-before="onSaveBefore" @on-detail-change="onDetailChange" @on-add-load-after="onEditLoadAfter" @on-edit-load-after="onEditLoadAfter">
      <!--自定义按钮插槽-->
      <template slot="footer-button-region" slot-scope="{ formData, details }">
        <!--打印条码按钮-->
        <el-button :disabled="btnReadOnly.subimtCheckBill" type="success" icon="el-icon-yrt-pan" @click.native="subimtCheckBill(formData, details)">提交</el-button>
        <el-button :disabled="btnReadOnly.createProfitLoss" type="success" icon="el-icon-yrt-pan" @click.native="createProfitLoss(formData, details)">生成盈亏单</el-button>
      </template>
    </yrt-editor>
    <el-dialog :visible.sync="dialogLandingTime">
      <el-form>
        <el-upload ref="upload" :on-preview="handlePreview" :on-remove="handleRemove" :on-success="handleSuccess" :file-list="fileList" :auto-upload="true" :action="upLoadUrl()" :limit="1" class="upload-bill">
          <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
          <el-button style="margin-left: 10px;" size="small" type="success" @click="submitImport()">开始导入</el-button>
          <el-button style="margin-left: 10px;" size="small" type="primary" plain>
            <a :href="common.ossDomain+'/node-wms/template/盘点单明细导入模板.xlsx'" style="color:while;font-size:12px;">下载模板</a>
          </el-button>
          <div slot="tip" class="el-upload__tip">只能上传扩展名为.xlsx的excel文件</div>
        </el-upload>
      </el-form>
      <div class="margin-10" v-html="importMsg">{{ importMsg }}</div>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="EditlogLandingTimesave">确 定</el-button> -->
      </div>
    </el-dialog>
    <!--明细选择器-->
    <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" :set-search-default="setSearchDefault" :get-custom-where="getCustomWhere" @on-selected="onPositionSelected" @on-page-size-change="onPageSizeChange">
      <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-check-check",
  components: {
    yrtSelector
  },
  mixins: [baseLayout],
  data() {
    return {
      selectorConfig: {
        title: "物料选择器",
        width: "1000px",
        visible: false,
        // 配置路由
        router: "/selector/s-product-selector"
      },
      selectorPositionConfig: {
        title: "物料库存选择器",
        width: "1000px",
        visible: false,
        // 配置路由
        router: "/selector/x-product-selector",
        url: "/api/common/GroupDataList"
      },
      actionField: {},
      // 表单默认值,新建时用
      defaultValue: {
        statusID: 1,
        statusText: "新建",
        isBlind: 0
      },
      // 库存值操作符
      operationType: null,
      // 弹出导入框
      dialogLandingTime: false,
      fileList: [],
      // 导入消息
      importMsg: null
    };
  },
  activated() {
    // SaaS模块权限
    this.common.hasSaaSAuth("库存盘点", this.$refs.container);
  },
  mounted() {
    this.editor.$refs["import-dialog"].isShowTemplateButton = false;
  },
  methods: {
    // 明细按钮点击事件
    detailButtonClick(authNode) {
      switch (authNode) {
        case "add":
          // 明细添加
          this.selectorConfig.visible = true;
          return true;
        case "detailAddPisition":
          this.openPositionSelected();
          return true;
        case "exportList":
          this.exportList();
          return true;
        case "importList":
          this.importList();
          return true;
      }
    }, // 列表页面按钮点击事件
    buttonClick() {},
    // 将选择器选择中的数据填充到明细表中
    onSelected(rows) {
      this.editor.addDetailDataRow(rows);
      this.selectorConfig.visible = false;
    },
    // 删除前事件
    onDeleteBefore(rows) {
      // var rows = this.editor.formData[subTableView].rows;
      let status = true;
      rows.forEach(rowData => {
        if (rowData.statusText !== "新建") {
          status = false;
        }
      });
      if (!status) {
        this.$message.error("仅可删除新建的盘点单!");
        return false;
      }
      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;
      }
      this.$refs["selector-position-dialog"].setSearchValue("consignor_Id", [editorRef.formData.consignor_Id]);
      this.$refs["selector-position-dialog"].setSearchValue("storage_Id", [editorRef.formData.storage_Id]);
      this.$refs["selector-position-dialog"].loadData();
      this.selectorPositionConfig.visible = true;
    },
    // 将选择器选择中的数据填充到明细表中
    onPositionSelected(rows) {
      rows.forEach(element => {
        element.quantity = element.productStorage;
      });
 
      this.editor.addDetailDataRow(rows);
      this.selectorPositionConfig.visible = false;
    },
    // 提交
    subimtCheckBill(formData, details) {
      this.$confirm("提示:确实要提交当前盘点吗", "确认提交", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          var formData = this.editor.formData;
          if (formData.statusText !== "新建") {
            this.$message({
              type: "info",
              message: "只有新建状态的单子才能提交!"
            });
            return;
          }
          const url = "/api/storage/check/submit";
          const check_Id = formData.check_Id;
          const parmas = {
            check_Id: check_Id
          };
          var callback = res => {
            this.common.showMsg(res);
            if (res.result) {
              this.dataList.loadData();
              this.editor.reload();
            }
          };
          this.common.ajax(url, parmas, callback, this.dataList);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 生成盈亏单
    createProfitLoss(formData, details) {
      this.$confirm("提示:确定要生成盈亏单吗!", "确认", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          var formData = this.editor.formData;
          if (formData.statusText !== "已提交") {
            this.$message({
              type: "info",
              message: "只有已提交状态的单子才能生成!"
            });
            return;
          }
          const url = "/api/storage/check/createYKD";
          const check_Id = formData.check_Id;
          const ref = this.dataList;
          const parmas = {
            check_Id: check_Id
          };
          var callback = res => {
            this.common.showMsg(res);
            if (res.result) {
              this.editorOptions.config.visible = false;
              ref.loadData();
            }
          };
          this.common.ajax(url, parmas, callback, ref);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 主表数据改变
    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;
      }
    },
    // 对选择器默认值操作
    setSearchDefault(searchData) {},
    // 查询条件改变
    getCustomWhere(val) {
      var where = {};
      if (this.operationType === ">0") {
        where.productStorage = {
          operator: ">",
          value: 0
        };
      } else if (this.operationType === ">=0") {
        where.productStorage = {
          operator: ">=",
          value: 0
        };
      } else if (this.operationType === "=0") {
        where.productStorage = {
          operator: "=",
          value: 0
        };
      }
      return where;
    },
    // 保存前事件
    onSaveBefore(formData) {
      // 合计数量求和
      let totalCheckQuantity = 0;
      // 合计账面库存量
      let totalProductStorage = 0;
      // 合计账面库存重量
      let totalWeight = 0.0;
      // 合计账面成本额
      let totalPurchaseMoney = 0.0;
      // 合计盘盈数量
      let totalProfitQuantity = 0.0;
      // 合计盘盈金额
      let totalProfitMoney = 0.0;
      // 合计盘亏数量
      let totalLossQuantity = 0.0;
      // 合计盘亏金额
      let totalLossMoney = 0.0;
      var detailRows = formData["Storage_CheckList"].rows;
      detailRows.forEach(item => {
        totalCheckQuantity += item.checkQuantity || 0;
        totalProductStorage += item.productStorage || 0;
        totalWeight += item.totalWeight || 0;
        totalPurchaseMoney += item.purchaseMoney || 0;
        totalProfitQuantity += item.profitQuantity || 0;
        totalProfitMoney += item.profitMoney || 0;
        totalLossQuantity += item.lossQuantity || 0;
        totalLossMoney += item.lossMoney || 0;
      });
      this.editor.changeValue("totalCheckQuantity", totalCheckQuantity);
      this.editor.changeValue("totalPurchaseMoney", totalPurchaseMoney);
      this.editor.changeValue("totalProductStorage", totalProductStorage);
      this.editor.changeValue("totalWeight", totalWeight);
      this.editor.changeValue("totalProfitQuantity", totalProfitQuantity);
      this.editor.changeValue("totalProfitMoney", totalProfitMoney);
      this.editor.changeValue("totalLossQuantity", totalLossQuantity);
      this.editor.changeValue("totalLossMoney", totalLossMoney);
    },
    onDetailChange(ref, val, row, field) {
      // 合计盘点数量
      let totalCheckQuantity = 0.0;
      // 合计盘点重量
      let totalWeight = 0.0;
      var profitQuantity = row.checkQuantity - row.productStorage;
      if (profitQuantity >= 0) {
        // 盘盈
        row.profitQuantity = profitQuantity;
        row.lossQuantity = 0;
        const profitMoney = Math.Round(profitQuantity * row.purchasePrice, 2);
        row.profitMoney = profitMoney;
        row.lossMoney = 0;
      } else {
        // 盘亏
        row.profitQuantity = 0;
        row.lossQuantity = 0 - profitQuantity;
        const profitMoney = Math.Round(profitQuantity * row.purchasePrice, 2);
        row.profitMoney = 0;
        row.lossMoney = 0 - profitMoney;
      }
      var formData = this.editor.formData;
      var detailRows = formData["Storage_CheckList"].rows;
      detailRows.forEach(item => {
        totalCheckQuantity += item.checkQuantity;
        totalWeight += item.totalWeight;
        // 盘盈重量=盘盈数量*单位重量
        item.profitWeight = Math.Round(item.profitQuantity * item.weight, 4);
      });
      this.editor.changeValue("totalCheckQuantity", totalCheckQuantity);
      this.editor.changeValue("totalWeight", Math.Round(totalWeight, 4));
    },
    // 数据加载后
    onEditLoadAfter(formData) {
      var statusText = formData.statusText;
      if (statusText === "新建") {
        this.$set(this.btnReadOnly, "subimtCheckBill", false);
        this.$set(this.btnReadOnly, "createProfitLoss", true);
        this.editorOptions.config.disabled = false; // 整个对话框可编辑
      } else if (statusText === "已提交") {
        this.$set(this.btnReadOnly, "subimtCheckBill", true);
        this.$set(this.btnReadOnly, "createProfitLoss", false);
        this.editorOptions.config.disabled = true;
      } else if (statusText === "已生成盈亏单") {
        this.$set(this.btnReadOnly, "subimtCheckBill", true);
        this.$set(this.btnReadOnly, "createProfitLoss", true);
        this.editorOptions.config.disabled = true;
      }
    },
    // 选择器页面大小改变
    onPageSizeChange(pageSize) {
      // 找到明细表配置
      var details = this.editorOptions.fields.filter(item => item.type === "detail-grid");
      details[0].options.pageSize = pageSize;
    },
    // 处理数据
    doDataParser(rawData) {
      rawData.Storage_CheckList.rows.forEach((row, index) => {
        if (row.checkQuantity === null) {
          delete row.checkQuantity;
        }
      });
    },
    // 明细导出
    exportList() {
      const ids = [];
      var formData = this.editor.formData;
      var detailRows = formData["Storage_CheckList"].rows;
      detailRows.map((item, index, array) => {
        ids.push(item.checkList_Id);
      });
      var url = "/api/storage/check/exportList";
      const params = {
        ids: ids.join(",")
      };
      var callback = res => {
        this.common.showMsg(res);
        if (res.result) {
          const url = this.common.domain + "/api/common/download?url=" + res.data.url;
          window.open(url);
        }
      };
      this.common.ajax(url, params, callback, true);
    },
    // 明细导入
    importList() {
      this.dialogLandingTime = true;
    },
    // 点击文件时的钩子
    handlePreview(file) {},
    handleRemove(file, fileList) {
      this.fullFileRote = null;
    },
    // 上传附件Url
    upLoadUrl: function() {
      var domain = this.common.domain;
      // return domain + "/api/TMS_WayBillOther/UploadImport";
      return domain + "/api/common/uploadSingleFile";
    },
    // 上传成功后
    handleSuccess(res, file) {
      this.common.showMsg("上传成功!");
      this.fullFileRote = res.data.url;
    },
    // 导入
    submitImport() {
      var the = this;
      var formData = the.editor.formData;
      var idValue = formData[the.dataOptions.idField];
      this.importMsg = null;
      if (!this.fullFileRote) {
        this.$message.error("请上传文件!");
        return;
      }
      const url = "api/storage/check/importExel";
      const ref = this.dataList;
      const params = {
        url: this.fullFileRote,
        check_Id: idValue
        // StorageName: StorageName
      };
      var callback = res => {
        if (res.result) {
          this.fullFileRote = null;
          this.fileList = [];
          this.importMsg = res.msg;
          ref.loadData();
        } else {
          this.importMsg = "<font color='red'>" + res.msg + "</font>";
        }
      };
      this.common.ajax(url, params, callback, true);
    }
  }
};
</script>