From 94de1745b4b69eeeb1ac8c5d3508ce87258afc25 Mon Sep 17 00:00:00 2001
From: haoyahui <2032914783@qq.com>
Date: 星期四, 16 十一月 2023 09:22:06 +0800
Subject: [PATCH] 库存管理

---
 admin-web/src/views/stock/accessStock/outbound/edit.vue |   89 +++++++++++++++++++-------------------------
 1 files changed, 38 insertions(+), 51 deletions(-)

diff --git a/admin-web/src/views/stock/accessStock/outbound/edit.vue b/admin-web/src/views/stock/accessStock/outbound/edit.vue
index fce80a0..064fcf2 100644
--- a/admin-web/src/views/stock/accessStock/outbound/edit.vue
+++ b/admin-web/src/views/stock/accessStock/outbound/edit.vue
@@ -56,11 +56,7 @@
               <el-form-item
                 label="鐗╁搧鍚嶇О"
                 :prop="`goods[${goodsIndex}].baseGoodsTemplateId`"
-                :rules="{
-                  required: true,
-                  message: '璇烽�夋嫨',
-                  trigger: 'change',
-                }"
+                :rules="rules.baseGoodsTemplateId"
               >
                 <el-select
                   v-model="goodsItem.baseGoodsTemplateId"
@@ -128,11 +124,18 @@
             </el-table-column>
             <el-table-column prop="counts" label="鍑哄簱鏁伴噺" align="center">
               <template slot-scope="scope">
+                <el-form-item
+                  label-width="0"
+                  style="margin-bottom: 0"
+                  :prop="`goods[${goodsIndex}].models[${scope.$index}].counts`"
+                  :rules="rules.counts"
+                >
                 <el-input
                   type="number"
                   v-model="scope.row.counts"
                   @change="countsChange($event, goodsIndex,scope.$index)"
                 ></el-input>
+                </el-form-item>
               </template>
             </el-table-column>
           </el-table>
@@ -180,8 +183,7 @@
 import winMd from '@/components/win/win-md';
 import upload from '@/components/upload/index';
 import { getUploadUrl } from '@/utils/base';
-
-import SettingIplatform from '../../../../../public/static/config';
+import {mapGetters} from 'vuex'
 
 export default {
   components: { MyButton, winMd, upload },
@@ -192,6 +194,18 @@
     },
   },
   data() {
+    // 鑷畾涔夋牎楠�
+    // 鐗╁搧閲嶅鏍¢獙
+    var checkGoodsTemplateId = (rule, value, callback) => {
+      if (!value) {
+        return callback(new Error('璇烽�夋嫨'));
+      }
+      let temp = this.formData.goods.filter((v) => v.baseGoodsTemplateId == value);
+      if (!temp || temp.length!=1) {
+        return callback(new Error('宸查�夎繃姝ょ墿鍝�'));
+      }
+      callback();
+    };
     return {
       loading: false,
       warehouseOptions: [], // 鍑哄簱浠撳簱鍒楄〃
@@ -216,7 +230,7 @@
       modelsItem: {
         baseGoodsModelsId: '', // 瑙勬牸鍨嬪彿缂栧彿
         worehouseCount: 0,
-        counts: 0, // 鎿嶄綔鏁伴噺
+        counts: null, // 鎿嶄綔鏁伴噺
         unit: null, //鍗曚綅
       },
       rules: {
@@ -224,10 +238,10 @@
         dealTime: [{ required: true, message: '璇烽�夋嫨', trigger: 'change' }],
         buyType: [{ required: true, message: '璇烽�夋嫨', trigger: 'change' }],
 
-        procureDoc: [{ required: true, message: '璇蜂笂浼�', trigger: 'change' }],
         baseCategoryIds: [{ required: true, message: '璇烽�夋嫨', trigger: 'change' }],
-        baseGoodsTemplateId: [{ required: true, message: '璇烽�夋嫨', trigger: 'change' }],
+        baseGoodsTemplateId: [{ validator: checkGoodsTemplateId, trigger: ['blur', 'change'] }],
         modelsIds: [{ required: true, message: '璇烽�夋嫨', trigger: 'change' }],
+        counts: [{ required: true, message: '璇疯緭鍏�', trigger: 'change' }],
       },
 
       uploadSettings: {
@@ -243,6 +257,9 @@
       },
     };
   },
+  computed:{
+    ...mapGetters(['userInfo'])
+  },
   created() {
     this.init();
   },
@@ -254,14 +271,16 @@
       // 鑾峰彇鐗╁搧鍒嗙被鍒楄〃
       const treeRes = await getTree();
       this.categoryOptions = this.removeEmptyChildren(treeRes);
-      this.formData.goods.push(JSON.parse(JSON.stringify(this.goodsItem)));
     },
 
     // 鑾峰彇鍑哄簱浠撳簱鍒楄〃
     getWarehouseList() {
-      selectTenantWarehouse()
+      selectTenantWarehouse({agencyId:this.userInfo.tenantId})
         .then((res) => {
-          this.warehouseOptions = res;
+          this.warehouseOptions = res
+          if(res.length) {
+            this.formData.goods.push(JSON.parse(JSON.stringify(this.goodsItem)));
+          }
           if (this.warehouseOptions.length && !this.formData.warehouseId) {
             // 榛樿閫変腑绗竴涓粨搴�
             this.formData.warehouseId = this.warehouseOptions[0].id;
@@ -337,7 +356,7 @@
       this.getgoodsTemplate(e[e.length - 1], index);
     },
 
-    // 鐗╁搧鍚嶇О鍒楄〃
+    // 鐗╁搧鍚嶇О鍒楄〃閫夋嫨
     goodsTemplateChange(e, index) {
       this.formData.goods[index].modelsOptions = [];
       this.formData.goods[index].modelsIds = [];
@@ -390,9 +409,13 @@
     countsChange(e, goodsIndex,index) {
       const curItem = this.formData.goods[goodsIndex].models[index]
       const worehouseCount = curItem.worehouseCount
+      if (e == 0) {
+        this.$message.warning('鏁伴涓嶈兘涓�0');
+        curItem.counts = null
+      }
       if (e > worehouseCount) {
         this.$message.warning('鏁伴瓒呰繃鐜版湁搴撳瓨');
-        curItem.counts = worehouseCount
+        curItem.counts = worehouseCount > 0 ? worehouseCount : null
       }
     },
 
@@ -424,42 +447,6 @@
         goods: [],
       };
       this.$emit('close');
-    },
-
-    // 閫氳繃瀛愰泦id鏌ュ埌鎵�浠ョ浉鍏崇埗绾d骞惰繑鍥炴暟缁�
-    findParentIds(dataSource, nodeId) {
-      const parentIds = []; // 鐢ㄤ簬瀛樺偍鎵�鏈夌埗鑺傜偣ID鐨勬暟缁�
-
-      // 瀹氫箟涓�涓�掑綊鍑芥暟锛岀敤浜庨亶鍘嗘暣妫垫爲骞舵煡鎵惧瓙鑺傜偣鐨勬墍鏈夌埗鑺傜偣
-      function traverse(node, nodeId) {
-        if (node.id === nodeId) {
-          // 濡傛灉褰撳墠鑺傜偣鐨処D绛変簬瀛愯妭鐐圭殑ID锛屽垯琛ㄧず宸茬粡鎵惧埌浜嗗瓙鑺傜偣锛屽彲浠ュ紑濮嬪悜涓婃煡鎵剧埗鑺傜偣
-          return true; // 杩斿洖true琛ㄧず宸茬粡鎵惧埌浜嗗瓙鑺傜偣
-        }
-
-        if (node.children) {
-          // 濡傛灉褰撳墠鑺傜偣鏈夊瓙鑺傜偣锛屽垯缁х画閬嶅巻瀛愯妭鐐�
-          for (const childNode of node.children) {
-            if (traverse(childNode, nodeId)) {
-              // 濡傛灉鍦ㄥ瓙鑺傜偣涓壘鍒颁簡瀛愯妭鐐圭殑鐖惰妭鐐癸紝鍒欏皢褰撳墠鑺傜偣鐨処D娣诲姞鍒扮埗鑺傜偣ID鏁扮粍涓紝骞惰繑鍥瀟rue琛ㄧず宸茬粡鎵惧埌浜嗗瓙鑺傜偣
-              parentIds.push(node.id);
-              return true;
-            }
-          }
-        }
-
-        return false; // 濡傛灉褰撳墠鑺傜偣涓嶆槸瀛愯妭鐐圭殑鐖惰妭鐐癸紝鍒欒繑鍥瀎alse
-      }
-
-      // 浠庢牴鑺傜偣寮�濮嬮亶鍘嗘暣妫垫爲锛屽苟璋冪敤閫掑綊鍑芥暟鏌ユ壘瀛愯妭鐐圭殑鎵�鏈夌埗鑺傜偣
-      for (const node of dataSource) {
-        if (traverse(node, nodeId)) {
-          // 濡傛灉鍦ㄥ綋鍓嶈妭鐐圭殑瀛愭爲涓壘鍒颁簡瀛愯妭鐐圭殑鐖惰妭鐐癸紝鍒欑洿鎺ラ��鍑哄惊鐜�
-          break;
-        }
-      }
-
-      return parentIds; // 杩斿洖鎵�鏈夌埗鑺傜偣ID鐨勬暟缁�
     },
   },
 };

--
Gitblit v1.9.1