| <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"> | 
|   | 
|     </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" :btn-read-only="btnReadOnly" :default-value="defaultValue" :edit-button-click="editButtonClick" :on-save-before="onSaveBefore" @on-edit-load-after="onEditLoadAfter" @on-add-load-after="onEditLoadAfter" @on-detail-change="onDetailChange"> | 
|     </yrt-editor> | 
|   | 
|     <el-dialog v-dialogDrag :visible.sync="dialogBatchAdd" width="40%" title="调整库存"> | 
|       <el-alert :closable="false" title="一行对应一条记录,每行数据用逗号、tab符或空格分隔,格式为:货位,物料编号,盘点数量 也可以从excel复制过来" type="success" class="alert-msg"> | 
|       </el-alert> | 
|       <el-input v-model="txtData" :autosize="{ minRows: 2, maxRows: 4}" type="textarea" placeholder="请输入内容"> | 
|       </el-input> | 
|       <div slot="footer" class="dialog-footer"> | 
|         <el-button @click="dialogBatchAdd=false">取 消</el-button> | 
|         <el-button type="primary" @click="batchAdd">确 定</el-button> | 
|       </div> | 
|     </el-dialog> | 
|   | 
|     <!--明细选择器--> | 
|     <!-- <yrt-selector ref="selector-dialog" :config="selectorConfig" :visible.sync="selectorConfig.visible" :set-search-default="setSearchDefault" @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"> | 
|       <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> | 
|   | 
|     <!-- 批量导入 --> | 
|     <import-dialog :visible.sync="importConfig.isShowDialog" :import-config="importConfig" @on-close="onClose"></import-dialog> | 
|   </div> | 
| </template> | 
|   | 
| <script> | 
| import baseLayout from "@/components/common/base-layout.vue"; | 
| import yrtSelector from "@/components/common/yrtSelector.vue"; | 
| import ImportDialog from "@/components/common/components/import-common-dialog"; | 
|   | 
| export default { | 
|   name: "storage-operation-storage-adjust", | 
|   components: { yrtSelector, ImportDialog }, | 
|   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" | 
|       }, | 
|       // 表单默认值,新建时用 | 
|       defaultValue: { | 
|         statusID: 1, | 
|         statusText: "新建", | 
|         auditing: 0 | 
|       }, | 
|       dialogBatchAdd: false, | 
|       txtData: null, // 要添加的数据 | 
|       operationType: null, | 
|   | 
|       // 导入对话框参数 | 
|       importConfig: { | 
|         // 显示导入对话框 | 
|         isShowDialog: false, | 
|         title: "明细批量导入", | 
|         // 导入地址 | 
|         url: "/api/storage/storageAdjust/importExcel", | 
|         // 模板地址 | 
|         templateUrl: "https://auod-beijing.oss-cn-beijing.aliyuncs.com/node-wms/template/库存调整明细导入模板.xlsx", | 
|         // 自定义后端参数 | 
|         params: {} | 
|       } | 
|     }; | 
|   }, | 
|   activated() { | 
|     // SaaS模块权限 | 
|     this.common.hasSaaSAuth("库存调整", this.$refs.container); | 
|   }, | 
|   | 
|   methods: { | 
|     // 列表页面按钮点击事件 | 
|     buttonClick(authNode) {}, | 
|     // 明细按钮点击事件 | 
|     detailButtonClick(authNode) { | 
|       switch (authNode) { | 
|         case "add": | 
|           // 明细添加 | 
|           this.selectorConfig.visible = true; | 
|   | 
|           return true; | 
|         case "detailAddPisition": | 
|           this.openPositionSelected(); | 
|           return true; | 
|         case "batchAdd": | 
|           this.dialogBatchAdd = true; | 
|           return true; | 
|         case "exportList": | 
|           this.exportList(); | 
|           return true; | 
|         case "importList": | 
|           this.importConfig.isShowDialog = true; | 
|           return true; | 
|       } | 
|     }, | 
|     // 编辑按钮点击事件 | 
|     editButtonClick(authNode) { | 
|       switch (authNode) { | 
|         case "auditing": | 
|           // 审核 | 
|           this.auditing(); | 
|           return false; | 
|       } | 
|     }, | 
|     // 批量添加新库存物料 | 
|     batchAdd() { | 
|       const ref = this.dataList; | 
|       var editorRef = this.editor; | 
|       if (!editorRef.formData.adjust_Id) { | 
|         this.$message.error("请先保存后再添加"); | 
|         return; | 
|       } | 
|       var url = "api/storage/storageAdjust/batchAdd"; | 
|       var params = { | 
|         openNodeApi: true, | 
|         data: this.txtData, | 
|         adjust_Id: editorRef.formData.adjust_Id | 
|       }; | 
|       this.common.ajax(url, params, res => { | 
|         if (res.result) { | 
|           this.common.showMsg(res); | 
|           ref.loadData(); | 
|         } else { | 
|           this.$message({ | 
|             message: res.msg, | 
|             type: "error" | 
|           }); | 
|         } | 
|       }); | 
|     }, | 
|     // 查询条件改变 | 
|     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; | 
|     }, | 
|     // 打开库存选择器 | 
|     openPositionSelected() { | 
|       var editorRef = this.editor; | 
|       if (!editorRef.formData.consignorName) { | 
|         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; | 
|     }, | 
|     // 将选择器选择中的数据填充到明细表中 | 
|     onSelected(rows) { | 
|       this.editor.addDetailDataRow(rows); | 
|       this.selectorConfig.visible = false; | 
|     }, | 
|     // 将选择器选择中的数据填充到明细表中 | 
|     onPositionSelected(rows) { | 
|       rows.forEach(element => { | 
|         element.Quantity = element.productStorage; | 
|       }); | 
|       this.editor.addDetailDataRow(rows); | 
|       this.selectorPositionConfig.visible = false; | 
|     }, | 
|     auditing() { | 
|       var the = this; | 
|       this.$confirm("审核后将无法进行修改, 是否继续?", "审核操作", { | 
|         confirmButtonText: "确定", | 
|         cancelButtonText: "取消", | 
|         type: "warning" | 
|       }) | 
|         .then(() => { | 
|           _auditing(); | 
|         }) | 
|         .catch(() => { | 
|           this.$message({ | 
|             type: "info", | 
|             message: "取消审核" | 
|           }); | 
|         }); | 
|       function _auditing() { | 
|         var formData = the.editor.formData; | 
|         var dBServer = "Sys"; | 
|         var idField = the.dataOptions.idField; | 
|         var idValue = formData[the.dataOptions.idField]; | 
|         var tableName = the.dataOptions.tableView; | 
|   | 
|         const ref = the.dataList; | 
|         var url = "/api/storage/storageAdjust/auditing"; | 
|         the.initLoading = true; | 
|         var params = { | 
|           dBServer: dBServer, | 
|           idField: idField, | 
|           idValue: idValue, | 
|           tableName: tableName, | 
|           auditing: 2 | 
|         }; | 
|         the.common.ajax( | 
|           url, | 
|           params, | 
|           res => { | 
|             the.common.showMsg(res); | 
|             if (res.result) { | 
|               ref.loadData(); | 
|             } | 
|             the.initLoading = false; | 
|             the.editorOptions.config.visible = false; | 
|           }, | 
|           true | 
|         ); | 
|       } | 
|     }, | 
|     // 数据加载后 | 
|     onEditLoadAfter(formData) { | 
|       // 将主键ID复制给导入明细框 | 
|       this.importConfig.params.adjust_Id = formData.adjust_Id; | 
|   | 
|       var auditing = formData.auditing; | 
|       if (auditing === 2) { | 
|         // 审核成功 | 
|         this.btnReadOnly.save = true; | 
|         this.btnReadOnly.stop = true; | 
|         this.btnReadOnly.open = false; | 
|         this.btnReadOnly.auditing = true; | 
|         this.editorOptions.config.disabled = true; // 整个对话框不可编辑 | 
|       } else { | 
|         this.btnReadOnly.save = false; | 
|         this.btnReadOnly.stop = false; | 
|         this.btnReadOnly.open = false; | 
|         this.btnReadOnly.auditing = false; | 
|         this.editorOptions.config.disabled = false; // 整个对话框可编辑 | 
|       } | 
|     }, | 
|     // 主表数据改变 | 
|     onChange(ref, val, field, formData) { | 
|       switch (field.options.prop) { | 
|         case "providerShortName": | 
|           this.$refs["selector-dialog"].setSearchValue("provider_Id", [val]); | 
|           this.$refs["selector-dialog"].loadData(); | 
|           break; | 
|         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; | 
|       } | 
|     }, | 
|     // 明细数据改变时触发 | 
|     onDetailChange(ref, val, row, field) { | 
|       this.setTotal(ref, val, row, field); | 
|     }, | 
|     // 保存前事件 | 
|     onSaveBefore() { | 
|       this.setTotal(); | 
|     }, | 
|     // 明细求和 | 
|     setTotal(ref, val, row, field) { | 
|       // 合计数量求和 | 
|       let totalProductStorage = 0; // 合计账面库存量 | 
|       let totalPurchaseMoney = 0.0; // 合计账面成本额 | 
|       let totalCheckQuantity = 0; // 合计盘点数量 | 
|   | 
|       let totalProfitQuantity = 0; // 合计盘盈数量 | 
|       let totalProfitMoney = 0.0; // 合计盘盈金额 | 
|   | 
|       let totalLossQuantity = 0; // 合计盘亏数量 | 
|       let totalLossMoney = 0.0; // 合计盘亏金额 | 
|       var formData = this.editor.formData; | 
|       var detailRows = formData["Storage_AdjustList"].rows; | 
|       detailRows.forEach(item => { | 
|         totalProductStorage += item.productStorage || 0; | 
|         totalPurchaseMoney += item.purchaseMoney || 0; | 
|         totalCheckQuantity += item.checkQuantity || 0; | 
|         if (field) { | 
|           if (field.prop === "checkQuantity" || field.prop === "weight") { | 
|             // 库存重量  =  盘点数量 * 单位重量 | 
|             item.totalWeight = (item.productStorage || 0) * (item.weight || 0); | 
|           } else if (field && field.prop === "totalWeight") { | 
|             // 单位重量:weight=  库存重量:totalWeight/ 盘点数量:checkQuantity | 
|             if (item.checkQuantity) { | 
|               item.weight = (item.totalWeight || 0) / (item.checkQuantity || 0); | 
|             } else { | 
|               item.weight = 0; | 
|             } | 
|           } | 
|         } | 
|         // 盘盈重量=盘盈数量*单位重量 | 
|         item.profitWeight = (item.profitQuantity || 0) * item.weight; | 
|         if (item.checkQuantity > item.productStorage) { | 
|           var profitQuantity = (item.checkQuantity || 0) - item.productStorage; | 
|           var ProfitMoney = profitQuantity * item.purchasePrice; | 
|           item.profitQuantity = profitQuantity; | 
|           item.ProfitMoney = ProfitMoney; | 
|   | 
|           item.lossQuantity = 0; | 
|           item.lossMoney = 0; | 
|   | 
|           totalProfitQuantity += profitQuantity; | 
|           totalProfitMoney += ProfitMoney; | 
|         } else if (item.checkQuantity < item.productStorage) { | 
|           var lossQuantity = item.productStorage - item.checkQuantity; | 
|           var lossMoney = lossQuantity * item.purchasePrice; | 
|   | 
|           item.profitQuantity = 0; | 
|           item.ProfitMoney = 0; | 
|   | 
|           item.lossQuantity = lossQuantity; | 
|           item.lossMoney = lossMoney; | 
|   | 
|           totalLossQuantity += lossQuantity; | 
|           totalLossMoney += lossMoney; | 
|         } else { | 
|           item.profitQuantity = 0; | 
|           item.ProfitMoney = 0; | 
|           item.lossQuantity = 0; | 
|           item.lossMoney = 0; | 
|         } | 
|       }); | 
|       this.editor.changeValue("totalProductStorage", totalProductStorage); | 
|       this.editor.changeValue("totalPurchaseMoney", totalPurchaseMoney); | 
|       this.editor.changeValue("totalCheckQuantity", totalCheckQuantity); | 
|       this.editor.changeValue("totalProfitQuantity", totalProfitQuantity); | 
|       this.editor.changeValue("totalProfitMoney", totalProfitMoney); | 
|       this.editor.changeValue("totalLossQuantity", totalLossQuantity); | 
|       this.editor.changeValue("totalLossMoney", totalLossMoney); | 
|     }, | 
|     // 对选择器默认值操作 | 
|     setSearchDefault(searchData) {}, | 
|     // 明细导出 | 
|     exportList() { | 
|       const ids = []; | 
|       var formData = this.editor.formData; | 
|       var detailRows = formData["Storage_AdjustList"].rows; | 
|       detailRows.map((item, index, array) => { | 
|         ids.push(item.adjustList_Id); | 
|       }); | 
|       var url = "/api/storage/storageAdjust/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); | 
|     }, | 
|     // 上传附件Url | 
|     upLoadUrl: function() { | 
|       var domain = this.common.domain; | 
|       // return domain + "/api/TMS_WayBillOther/UploadImport";+ | 
|   | 
|       return domain + "/api/common/uploadSingleFile"; | 
|     }, | 
|     // 导入窗口关闭事件 | 
|     onClose() { | 
|       // 关闭导入窗口时,刷新编辑器 | 
|       this.editor.reload(); | 
|     } | 
|   } | 
| }; | 
| </script> |