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/procure/purchaseOrder/edit.vue |  213 +++++++++++++++++++++++++++++------------------------
 1 files changed, 117 insertions(+), 96 deletions(-)

diff --git a/admin-web/src/views/stock/procure/purchaseOrder/edit.vue b/admin-web/src/views/stock/procure/purchaseOrder/edit.vue
index 121b417..9ed3d61 100644
--- a/admin-web/src/views/stock/procure/purchaseOrder/edit.vue
+++ b/admin-web/src/views/stock/procure/purchaseOrder/edit.vue
@@ -65,14 +65,10 @@
               <el-form-item
                 label="鐗╁搧鍚嶇О"
                 :prop="`procureGoods[${goodsIndex}].baseGoodsTemplateId`"
-                :rules="{
-                  required: true,
-                  message: '璇烽�夋嫨',
-                  trigger: 'change',
-                }"
+                :rules="rules.baseGoodsTemplateId"
               >
                 <el-select
-                  v-model="goodsItem.baseGoodsTemplateId"
+                 v-model="goodsItem.baseGoodsTemplateId"
                   placeholder="璇峰厛鎷╃墿鍝佸垎绫�"
                   filterable
                   :disabled="!goodsItem.baseCategoryId"
@@ -137,12 +133,26 @@
             </el-table-column>
             <el-table-column prop="price" label="鍗曚环锛堝厓锛�" align="center">
               <template slot-scope="scope">
-                <el-input type="number" v-model="scope.row.price"></el-input>
+                <el-form-item
+                  label-width="0"
+                  style="margin-bottom: 0"
+                  :prop="`procureGoods[${goodsIndex}].models[${scope.$index}].price`"
+                  :rules="rules.price"
+                >
+                  <el-input type="number" v-model.number="scope.row.price"></el-input>
+                </el-form-item>
               </template>
             </el-table-column>
             <el-table-column prop="counts" label="閲囪喘鏁伴噺" align="center">
               <template slot-scope="scope">
-                <el-input type="number" v-model="scope.row.counts"></el-input>
+                <el-form-item
+                  label-width="0"
+                  style="margin-bottom: 0"
+                  :prop="`procureGoods[${goodsIndex}].models[${scope.$index}].counts`"
+                  :rules="rules.counts"
+                >
+                  <el-input v-model.number="scope.row.counts"></el-input>
+                </el-form-item>
               </template>
             </el-table-column>
           </el-table>
@@ -170,8 +180,8 @@
       </div>
     </el-form>
     <div slot="footer" align="center" class="dialog-footer">
-      <my-button name="鍙栨秷" site="form" @click="close"/>
-      <my-button name="淇濆瓨" site="form" @click="handleSubmit"/>
+      <my-button name="鍙栨秷" site="form" @click="close" />
+      <my-button name="淇濆瓨" site="form" @click="handleSubmit" />
     </div>
   </win-md>
 </template>
@@ -188,36 +198,76 @@
 import MyButton from '@/components/myButton/myButton';
 import winMd from '@/components/win/win-md';
 import upload from '@/components/upload/index';
-import { getUploadUrl,getDownUrl} from '@/utils/base';
-
-import SettingIplatform from '../../../../../public/static/config';
+import { getUploadUrl, getDownUrl } from '@/utils/base';
+import { findParentIds } from '@/utils/index';
+import { mapGetters } from 'vuex';
 
 export default {
   components: { MyButton, winMd, upload },
   props: {
     setting: {
       type: Object,
-      default: () => {
-      }
-    }
+      default: () => {},
+    },
   },
   data() {
+    // 鑷畾涔夋牎楠�
+    // 鐗╁搧閲嶅鏍¢獙
+    var checkGoodsTemplateId = (rule, value, callback) => {
+      if (!value) {
+        return callback(new Error('璇烽�夋嫨'));
+      }
+      let temp = this.formData.procureGoods.filter((v) => v.baseGoodsTemplateId == value);
+      if (!temp || temp.length!=1) {
+        return callback(new Error('宸查�夎繃姝ょ墿鍝�'));
+      }
+      callback();
+    };
+    // 閲戦鏍¢獙
+    var checkPrice = (rule, value, callback) => {
+      if (!value) {
+        return callback(new Error('璇疯緭鍏�'));
+      }
+      if (value == 0) {
+        this.$message.warning('鏁板瓧鍊间笉鑳戒负0');
+        return callback(new Error('鏁板瓧鍊间笉鑳戒负0'));
+      }
+      callback();
+    };
+    // 鏁伴噺鏍¢獙
+    var checkCounts = (rule, value, callback) => {
+      console.log(value)
+      if (!value) {
+        return callback(new Error('璇疯緭鍏�'));
+      }
+      if (!Number.isInteger(value)) {
+        this.$message.warning('璇疯緭鍏ユ暟瀛楀��');
+        return callback(new Error('璇疯緭鍏ユ暟瀛楀��'));
+      }
+      if (value == 0) {
+        this.$message.warning('鏁板瓧鍊间笉鑳戒负0');
+        return callback(new Error('鏁板瓧鍊间笉鑳戒负0'));
+      }
+      callback();
+    };
     return {
-      visible: false,
       loading: false,
-      buyTypeOptions:[{
-        label:'闆嗛噰',
-        value: '1'
-      },{
-        label:'鑷噰',
-        value: '2'
-      }],
-      fileList:[],
+      buyTypeOptions: [
+        {
+          label: '闆嗛噰',
+          value: '1',
+        },
+        {
+          label: '鑷噰',
+          value: '2',
+        },
+      ],
+      fileList: [],
       warehouses: [], // 鍏ュ簱浠撳簱鍒楄〃
       categoryOptions: [], // 鐗╁搧鍒嗙被鍒楄〃
       modelList: [], //鍨嬪彿鍒楄〃
       formData: {
-        procureDoc:'',
+        procureDoc: '',
         warehouseId: '', // 鍏ュ簱浠撳簱id
         procureTime: '', // 閲囪喘鏃堕棿
         buyType: '2', // 閲囪喘鏂瑰紡锛�1锛氶泦閲囷紱2=鑷噰锛�
@@ -237,9 +287,8 @@
       },
       modelsItem: {
         baseGoodsModelsId: '', // 瑙勬牸鍨嬪彿缂栧彿
-        price: 0, // 鍗曚环(閲囪喘闇�瑕侊紝璋冩嫧涓嶉渶瑕�)
-        counts: 0, // 鎿嶄綔鏁伴噺
-        supplier: '', // 渚涘簲鍟�
+        price: null, // 鍗曚环(閲囪喘闇�瑕侊紝璋冩嫧涓嶉渶瑕�)
+        counts: null, // 鎿嶄綔鏁伴噺
         unit: null, //鍗曚綅
       },
       rules: {
@@ -249,8 +298,10 @@
 
         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' }],
+        price: [{ validator: checkPrice, trigger: 'blur' }],
+        counts: [{ validator: checkCounts, trigger: 'blur' }],
       },
 
       uploadSettings: {
@@ -266,45 +317,51 @@
       },
     };
   },
+  computed: {
+    ...mapGetters(['userInfo']),
+  },
   created() {
-    this.init()
+    this.init();
   },
   methods: {
     async init() {
       this.getWarehouseList();
-      this.getgoodsTemplate()
+      this.getgoodsTemplate();
       this.getgoodsModel();
       // 鑾峰彇鐗╁搧鍒嗙被鍒楄〃
       const treeRes = await getTree();
       this.categoryOptions = this.removeEmptyChildren(treeRes);
       if (this.setting.id) {
-        const detail = await procureDetail({ id:this.setting.id });
+        const detail = await procureDetail({ id: this.setting.id });
         this.formData = Object.assign(this.formData, detail);
-        if(this.formData.procureDoc) {
-          this.fileList = JSON.parse(this.formData.procureDoc)
+        if (this.formData.procureDoc) {
+          this.fileList = JSON.parse(this.formData.procureDoc);
         }
-        this.$set(this.formData,'buyType',this.formData.buyType.toString())
+        this.$set(this.formData, 'buyType', this.formData.buyType.toString());
         this.formData.procureTime = this.formData.procureTime.toString();
         this.formData.procureGoods.map((item, index) => {
           // 鏍规嵁瀛愰泦ID鎷兼帴鐗╁搧鍒嗙被鍒楄〃
-          item.baseCategoryIds = this.findParentIds(this.categoryOptions, item.baseCategoryId);
-          this.$set(this.formData.procureGoods[index],'modelsIds',item.models.map((v) => v.baseGoodsModelsId))
+          item.baseCategoryIds = findParentIds(this.categoryOptions, item.baseCategoryId);
+          this.$set(
+            this.formData.procureGoods[index],
+            'modelsIds',
+            item.models.map((v) => v.baseGoodsModelsId),
+          );
           this.getgoodsTemplate(item.baseCategoryId, index);
           this.getgoodsModel(item.baseGoodsTemplateId, index);
-          return item
+          return item;
         });
-        console.log('this.formData.procureGoods',this.formData.procureGoods)
-      } else {
-        this.formData.procureGoods.push(JSON.parse(JSON.stringify(this.goodsItem)));
       }
-      this.visible = true;
     },
 
     // 鑾峰彇鍏ュ簱浠撳簱鍒楄〃
     getWarehouseList() {
-      selectTenantWarehouse()
+      selectTenantWarehouse({ agencyId: this.userInfo.tenantId })
         .then((res) => {
           this.warehouses = res;
+          if (!this.setting.id && res.length) {
+            this.formData.procureGoods.push(JSON.parse(JSON.stringify(this.goodsItem)));
+          }
           if (this.warehouses.length && !this.formData.warehouseId) {
             // 榛樿閫変腑绗竴涓粨搴�
             this.formData.warehouseId = this.warehouses[0].id;
@@ -331,7 +388,7 @@
       goodsTemplate({ categoryId: id || '' }).then((res) => {
         if (index || index == 0) {
           this.$set(this.formData.procureGoods[index], 'goodsOptions', res);
-        }else {
+        } else {
           this.goodsTemplatelAll = res;
         }
       });
@@ -368,12 +425,12 @@
 
     // 鐗╁搧鍒嗙被閫夋嫨
     categoryChange(e, index) {
-      this.formData.procureGoods[index].goodsOptions = []
-      this.formData.procureGoods[index].baseGoodsTemplateId = ''
-      this.formData.procureGoods[index].goodsTemplateName = ''
-      this.formData.procureGoods[index].modelsOptions = []
-      this.formData.procureGoods[index].modelsIds = []
-      this.formData.procureGoods[index].models = []
+      this.formData.procureGoods[index].goodsOptions = [];
+      this.formData.procureGoods[index].baseGoodsTemplateId = '';
+      this.formData.procureGoods[index].goodsTemplateName = '';
+      this.formData.procureGoods[index].modelsOptions = [];
+      this.formData.procureGoods[index].modelsIds = [];
+      this.formData.procureGoods[index].models = [];
 
       this.formData.procureGoods[index].baseCategoryId = e[e.length - 1];
       // 鏍规嵁閫変腑鍒嗙被璇锋眰鐗╁搧鍚嶇О鍒楄〃
@@ -382,11 +439,11 @@
 
     // 鐗╁搧鍚嶇О鍒楄〃
     goodsTemplateChange(e, index) {
-      this.formData.procureGoods[index].modelsOptions = []
-      this.formData.procureGoods[index].modelsIds = []
-      this.formData.procureGoods[index].models = []
+      this.formData.procureGoods[index].modelsOptions = [];
+      this.formData.procureGoods[index].modelsIds = [];
+      this.formData.procureGoods[index].models = [];
 
-      this.formData.procureGoods[index].goodsTemplateName = this.getGoodsTemplateName(e)
+      this.formData.procureGoods[index].goodsTemplateName = this.getGoodsTemplateName(e);
       // 鏍规嵁閫変腑鐗╁搧鍚嶇Оid鑾峰彇瑙勬牸鍨嬪彿鍒楄〃
       this.getgoodsModel(e, index);
     },
@@ -413,8 +470,8 @@
 
     // 涓婁紶
     uploadChange() {
-      let arr = this.$refs.uploadRef.fileList
-      this.formData.procureDoc = JSON.stringify(arr)
+      let arr = this.$refs.uploadRef.fileList;
+      this.formData.procureDoc = JSON.stringify(arr);
     },
 
     // 鐐瑰嚮鏂板鐗╁搧
@@ -462,48 +519,12 @@
     },
 
     close() {
-      this.formData ={
+      this.formData = {
         warehouseId: '', // 鍏ュ簱浠撳簱id
         procureTime: '', // 閲囪喘鏃堕棿
         procureGoods: [],
-      }
-      this.$emit('close')
-    },
-
-    // 閫氳繃瀛愰泦id鏌ュ埌鎵�浠ョ浉鍏崇埗绾d骞惰繑鍥炴暟缁�
-    findParentIds(dataSource, nodeId) {
-      const parentIds = [nodeId]; // 鐢ㄤ簬瀛樺偍鎵�鏈夌埗鑺傜偣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.unshift(node.id);
-              return true;
-            }
-          }
-        }
-
-        return false; // 濡傛灉褰撳墠鑺傜偣涓嶆槸瀛愯妭鐐圭殑鐖惰妭鐐癸紝鍒欒繑鍥瀎alse
-      }
-
-      // 浠庢牴鑺傜偣寮�濮嬮亶鍘嗘暣妫垫爲锛屽苟璋冪敤閫掑綊鍑芥暟鏌ユ壘瀛愯妭鐐圭殑鎵�鏈夌埗鑺傜偣
-      for (const node of dataSource) {
-        if (traverse(node, nodeId)) {
-          // 濡傛灉鍦ㄥ綋鍓嶈妭鐐圭殑瀛愭爲涓壘鍒颁簡瀛愯妭鐐圭殑鐖惰妭鐐癸紝鍒欑洿鎺ラ��鍑哄惊鐜�
-          break;
-        }
-      }
-
-      return parentIds; // 杩斿洖鎵�鏈夌埗鑺傜偣ID鐨勬暟缁�
+      };
+      this.$emit('close');
     },
   },
 };

--
Gitblit v1.9.1