From 20913c80c3f5fc8e533cb92b90e6f20bcd68e032 Mon Sep 17 00:00:00 2001
From: 石广澎 <shiguangpeng@163.com>
Date: 星期三, 29 十一月 2023 17:49:32 +0800
Subject: [PATCH] feat: 1、优化导入 2、部门物品台账查询对接

---
 admin-web/src/views/stock/procure/purchaseOrder/edit.vue |  311 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 173 insertions(+), 138 deletions(-)

diff --git a/admin-web/src/views/stock/procure/purchaseOrder/edit.vue b/admin-web/src/views/stock/procure/purchaseOrder/edit.vue
index 93e1c42..bca8123 100644
--- a/admin-web/src/views/stock/procure/purchaseOrder/edit.vue
+++ b/admin-web/src/views/stock/procure/purchaseOrder/edit.vue
@@ -1,15 +1,5 @@
 <template>
-  <el-dialog
-    :title="`${type == 'create' ? '鏂板' : '缂栬緫'}${title}`"
-    width="60%"
-    :modal="true"
-    :visible.sync="visible"
-    :top="'15vh'"
-    :close-on-click-modal="false"
-    :append-to-body="true"
-    :destroy-on-close="true"
-    @close="close"
-  >
+  <win-md class="stock-edit" :title="`${setting.title}閲囪喘鍏ュ簱`" @close="close" :width="'800px'" :loading="loading">
     <el-form class="form" ref="ruleForm" :model="formData" :rules="rules" label-width="120px">
       <div class="main-w">
         <el-row :gutter="24" class="headerHeight">
@@ -35,9 +25,18 @@
           </el-col>
         </el-row>
         <el-row :gutter="24" class="headerHeight">
+          <el-col :span="12">
+            <el-form-item label="閲囪喘绫诲瀷" prop="buyType">
+              <el-select v-model="formData.buyType" placeholder="璇烽�夋嫨" style="width: 100%">
+                <el-option v-for="item in buyTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
+              </el-select>
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row :gutter="24" class="headerHeight">
           <el-col :span="24">
             <el-form-item label="閲囪喘鍏ュ簱鎵嬬画" prop="procureDoc">
-              <upload :settings="uploadSettings" @on-change="uploadChange"></upload>
+              <upload ref="uploadRef" :values="fileList" :settings="uploadSettings" @on-change="uploadChange"></upload>
             </el-form-item>
           </el-col>
         </el-row>
@@ -66,11 +65,7 @@
               <el-form-item
                 label="鐗╁搧鍚嶇О"
                 :prop="`procureGoods[${goodsIndex}].baseGoodsTemplateId`"
-                :rules="{
-                  required: true,
-                  message: '璇烽�夋嫨',
-                  trigger: 'change',
-                }"
+                :rules="rules.baseGoodsTemplateId"
               >
                 <el-select
                   v-model="goodsItem.baseGoodsTemplateId"
@@ -136,14 +131,32 @@
                 {{ scope.row.unit }}
               </template>
             </el-table-column>
-            <el-table-column prop="price" label="鍗曚环锛堝厓锛�" align="center">
+            <el-table-column prop="priceYuan" 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}].priceYuan`"
+                  :rules="rules.priceYuan"
+                >
+                  <el-input
+                    type="number"
+                    v-model.number="scope.row.priceYuan"
+                    @change="priceChange($event, goodsIndex, scope.$index)"
+                  ></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>
@@ -171,51 +184,99 @@
       </div>
     </el-form>
     <div slot="footer" align="center" class="dialog-footer">
-      <el-button name="纭畾" site="form" type="primary" @click="handleSubmit">纭畾</el-button>
-      <el-button name="鍙栨秷" site="form" @click="close">鍙栨秷</el-button>
+      <my-button name="鍙栨秷" site="form" @click="close" />
+      <my-button name="淇濆瓨" site="form" @click="handleSubmit" />
     </div>
-  </el-dialog>
+  </win-md>
 </template>
 <script>
 import {
+  goodsModel,
   goodsTemplate,
   procureAdd,
+  procureDetail,
   procureEdit,
   selectTenantWarehouse,
-  goodsModel,
-  procureDetail,
 } from '@/api/stock/procure/purchaseOrder';
-import { getTree } from '@/api/foudation/classification';
+import {getTree} from '@/api/foudation/classification';
 import MyButton from '@/components/myButton/myButton';
 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 {getUploadUrl} from '@/utils/base';
+import {findParentIds} from '@/utils/index';
+import {mapGetters} from 'vuex';
 
 export default {
   components: { MyButton, winMd, upload },
   props: {
-    title: {
-      type: String,
-      default: '閲囪喘鍏ュ簱',
+    setting: {
+      type: Object,
+      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) => {
+      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 {
-      type: 'create',
-      visible: false,
-      loading: false,
+      loading: true,
+      buyTypeOptions: [
+        {
+          label: '闆嗛噰',
+          value: '1',
+        },
+        {
+          label: '鑷噰',
+          value: '2',
+        },
+      ],
+      fileList: [],
       warehouses: [], // 鍏ュ簱浠撳簱鍒楄〃
       categoryOptions: [], // 鐗╁搧鍒嗙被鍒楄〃
       modelList: [], //鍨嬪彿鍒楄〃
       formData: {
+        procureDoc: '',
         warehouseId: '', // 鍏ュ簱浠撳簱id
         procureTime: '', // 閲囪喘鏃堕棿
+        buyType: '2', // 閲囪喘鏂瑰紡锛�1锛氶泦閲囷紱2=鑷噰锛�
         procureGoods: [],
       },
       goodsItem: {
-        whFormProcureId: '', // 閲囪喘鍗旾D
         baseCategoryIds: '', // 鍒嗙被缂栧彿鏁扮粍
         baseCategoryId: '', // 鍒嗙被缂栧彿
         baseGoodsTemplateId: '', // 鐗╁搧妯$増缂栧彿
@@ -229,69 +290,85 @@
       },
       modelsItem: {
         baseGoodsModelsId: '', // 瑙勬牸鍨嬪彿缂栧彿
-        price: 0, // 鍗曚环(閲囪喘闇�瑕侊紝璋冩嫧涓嶉渶瑕�)
-        counts: 0, // 鎿嶄綔鏁伴噺
-        supplier: '', // 渚涘簲鍟�
+        priceYuan: null, // 鍗曚环(鍏�)
+        price: null, // 鍗曚环(鍒� 閲囪喘闇�瑕侊紝璋冩嫧涓嶉渶瑕�)
+        counts: null, // 鎿嶄綔鏁伴噺
         unit: null, //鍗曚綅
       },
       rules: {
         warehouseId: [{ required: true, message: '璇烽�夋嫨', trigger: 'change' }],
         procureTime: [{ required: true, message: '璇烽�夋嫨', trigger: 'change' }],
+        buyType: [{ required: true, message: '璇烽�夋嫨', trigger: 'change' }],
 
-        // procureDoc: [{ 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' }],
+        priceYuan: [{ validator: checkPrice, trigger: 'blur' }],
+        counts: [{ validator: checkCounts, trigger: 'blur' }],
       },
 
       uploadSettings: {
         title: '涓婁紶',
         max: 20, // 鏈�澶уぇ灏忥紝鍗曚綅M
-        num: 2, // 鏀寔涓婁紶鍥剧墖涓暟
-        accept: '.jpg,.png', // 闄愬埗鏍煎紡
+        num: 10, // 鏀寔涓婁紶鍥剧墖涓暟
         tip: '', // 鎻愮ず 榛樿锛歚鍙兘涓婁紶${this.defaultSettings.num}涓�${this.defaultSettings.accept}鏂囦欢锛屼笖涓嶈秴杩�${this.defaultSettings.max}kb`
         uploadUrl: getUploadUrl(), // 涓婁紶璺緞
         multiple: true, // 鏄惁鏀寔鎵归噺涓婁紶
         disabled: false, // 鏄惁绂佺敤
-        type: 'text', // text/picture
+        type: 'picture', // text/picture
       },
     };
   },
-  created() {},
+  computed: {
+    ...mapGetters(['userInfo']),
+  },
+  created() {
+    this.init();
+  },
   methods: {
-    async open(id) {
+    async init() {
       this.getWarehouseList();
+      this.getgoodsTemplate();
       this.getgoodsModel();
       // 鑾峰彇鐗╁搧鍒嗙被鍒楄〃
       const treeRes = await getTree();
       this.categoryOptions = this.removeEmptyChildren(treeRes);
-      if (id) {
-        this.type = 'edit';
-        const detail = await procureDetail({ id });
-        console.log('procureDetail', detail);
+      if (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);
+        }
+        this.$set(this.formData, 'buyType', this.formData.buyType.toString());
         this.formData.procureTime = this.formData.procureTime.toString();
         this.formData.procureGoods.map((item, index) => {
           // 鏍规嵁瀛愰泦ID鎷兼帴鐗╁搧鍒嗙被鍒楄〃
-          let pIds = this.findParentIds(this.categoryOptions, item.baseCategoryId);
-          pIds = pIds.reverse();
-          item.baseCategoryIds = [...pIds, item.baseCategoryId];
-          item.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);
+          item.models.forEach((child, childIndex) => {
+            this.$set(this.formData.procureGoods[index].models[childIndex], 'priceYuan', child.price / 100);
+          });
+          return item;
         });
-      } else {
-        this.type = 'create';
-        this.formData.procureGoods.push(JSON.parse(JSON.stringify(this.goodsItem)));
       }
-      this.visible = true;
+      this.loading = false;
     },
 
     // 鑾峰彇鍏ュ簱浠撳簱鍒楄〃
     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;
@@ -318,6 +395,8 @@
       goodsTemplate({ categoryId: id || '' }).then((res) => {
         if (index || index == 0) {
           this.$set(this.formData.procureGoods[index], 'goodsOptions', res);
+        } else {
+          this.goodsTemplatelAll = res;
         }
       });
     },
@@ -333,6 +412,15 @@
       });
     },
 
+    // 鏍规嵁鐗╁搧鍚嶇Оid鑾峰彇鍚嶅瓧
+    getGoodsTemplateName(id) {
+      let item = this.goodsTemplatelAll.find((v) => v.id == id);
+      if (item) {
+        return item.goodsName;
+      }
+      return;
+    },
+
     // 鏍规嵁瑙勬牸鍨嬪彿id鑾峰彇鍚嶅瓧
     getGoodsModelsName(id) {
       let item = this.goodsModelAll.find((v) => v.id == id);
@@ -344,8 +432,12 @@
 
     // 鐗╁搧鍒嗙被閫夋嫨
     categoryChange(e, index) {
-      this.formData.procureGoods[index].goodsOptions = []
-      this.formData.procureGoods[index].baseCategoryId = ''
+      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];
       // 鏍规嵁閫変腑鍒嗙被璇锋眰鐗╁搧鍚嶇О鍒楄〃
@@ -354,10 +446,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);
       // 鏍规嵁閫変腑鐗╁搧鍚嶇Оid鑾峰彇瑙勬牸鍨嬪彿鍒楄〃
       this.getgoodsModel(e, index);
     },
@@ -382,9 +475,15 @@
       this.formData.procureGoods[index].models.splice(delIndex, 1);
     },
 
+    // 浠锋牸input鐩戝惉 杞负鍒�
+    priceChange(e, goodsIndex, index) {
+      this.formData.procureGoods[goodsIndex].models[index].price = e * 100;
+    },
+
     // 涓婁紶
-    uploadChange(e) {
-      console.log('uploadChange', e);
+    uploadChange() {
+      let arr = this.$refs.uploadRef.fileList;
+      this.formData.procureDoc = JSON.stringify(arr);
     },
 
     // 鐐瑰嚮鏂板鐗╁搧
@@ -401,8 +500,8 @@
     handleSubmit() {
       this.$refs['ruleForm'].validate((valid) => {
         if (valid) {
-          console.log('this.formData', this.formData);
-          if (this.type == 'create') {
+          this.loading = true;
+          if (!this.setting.id) {
             procureAdd(this.formData)
               .then((res) => {
                 this.$message.success('淇濆瓨鎴愬姛锛�');
@@ -410,7 +509,7 @@
                 this.$emit('search');
               })
               .catch((err) => {
-                console.log('create err', err);
+                this.loading = false;
                 this.$message.error('淇濆瓨澶辫触');
               });
           } else {
@@ -421,7 +520,7 @@
                 this.$emit('search');
               })
               .catch((err) => {
-                console.log('edit err', err);
+                this.loading = false;
                 this.$message.error('淇濆瓨澶辫触');
               });
           }
@@ -432,80 +531,16 @@
     },
 
     close() {
-      this.formData ={
+      this.formData = {
         warehouseId: '', // 鍏ュ簱浠撳簱id
         procureTime: '', // 閲囪喘鏃堕棿
         procureGoods: [],
-      }
-      this.visible = false;
-    },
-
-    // 閫氳繃瀛愰泦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鐨勬暟缁�
+      };
+      this.$emit('close');
     },
   },
 };
 </script>
 <style scoped lang="scss">
-.main-w {
-  width: 88%;
-}
-.goods-card {
-  position: relative;
-  background: #f6f6f6;
-  padding: 20px;
-  box-sizing: border-box;
-  border-radius: 4px;
-  background-color: #f9f9f9;
-  margin-top: 20px;
-  &:nth-of-type(1) {
-    margin-top: 0;
-  }
-}
-.btn-group {
-  width: 140px;
-  position: absolute;
-  right: -160px;
-  bottom: 0px;
-  .el-button {
-    margin-bottom: 10px;
-    margin-left: 0;
-    display: block;
-    &:last-child {
-      margin-bottom: 0;
-    }
-  }
-}
+@import url(../../index.scss);
 </style>

--
Gitblit v1.9.1