Browse Source

feat:组合商品库存添加

snow 1 year ago
parent
commit
c4362b024a

+ 6 - 6
src/views/purchaseIn/wsmInOrder/detail.vue

@@ -120,24 +120,24 @@
   </div>
 </template>
 <script>
-import resToken from "@/mixins/resToken";
 import asyncRequest from "@/apis/service/purchaseIn/purchaseOrder";
-import wsmIn from "./components/wsm-in";
 import ShowDataTableColumns from "./components/ShowDataTableColumns";
 import { cg_order_type_options } from "@/assets/js/statusList";
-import { mapGetters } from "vuex";
 import { statusOptions } from "./columns"; //表格列参数
+import resToken from "@/mixins/resToken";
+import wsmIn from "./components/wsm-in";
+import { mapGetters } from "vuex";
+
 export default {
   name: "wsmInOrderDetail",
   mixins: [resToken],
-  components: {
-    wsmIn
-  },
+  components: { wsmIn },
   computed: {
     ...mapGetters(["isSupertube", "userInfo"]),
     canInStock() {
       const { contactor } = this.sitem || {};
       const { id } = this.userInfo || {};
+      console.log(contactor, id);
       if (!contactor || !id) return false;
       return String(contactor) === String(id);
     },

+ 2 - 2
src/views/sellOut/combinedAdd/columns.js

@@ -132,8 +132,8 @@ const detailColumns = [
     span:8
   },
   {
-    label:'仓库类型',
-    prop:'wsm_type',
+    label:'添加库存数',
+    prop:'stock_num',
     span:8
   },
   {

+ 137 - 102
src/views/sellOut/combinedAdd/components/baseForm.vue

@@ -1,5 +1,12 @@
 <template>
-  <el-form ref="ruleForm" v-loading="loading.full" label-width="90px" size="mini" :model="ruleForm" :rules="rules">
+  <el-form
+    ref="ruleForm"
+    v-loading="loading.full"
+    label-width="90px"
+    size="mini"
+    :model="ruleForm"
+    :rules="rules"
+  >
     <el-form-item v-loading="loading.product" label="组合商品" prop="spuCode">
       <el-input v-if="!productinfo" placeholder="选择组合商品" @focus="pVisible = true" />
 
@@ -29,15 +36,15 @@
 
           <template slot="cat_info">
             {{
-              productinfo.cat_info
-                ? productinfo.cat_info.map(({ name }) => name).join("_")
-                : "--"
+            productinfo.cat_info
+            ? productinfo.cat_info.map(({ name }) => name).join("_")
+            : "--"
             }}
           </template>
 
           <template slot="is_combind">
             {{
-              String(productinfo.is_combind) === '1' ? '组合商品' : '非组合商品'
+            String(productinfo.is_combind) === '1' ? '组合商品' : '非组合商品'
             }}
           </template>
 
@@ -49,7 +56,7 @@
               class="fl"
               :src="productinfo.good_thumb_img"
               alt
-            >
+            />
             <span>{{ productinfo.good_name }}</span>
             <span v-for="(si, i) in productinfo.speclist" :key="si.spec_id + i">
               <span v-if="i !== 0">-</span>
@@ -70,11 +77,11 @@
           <template slot="noble">
             <span v-if="productinfo.noble_metal">
               {{ productinfo.noble_weight ? productinfo.noble_weight : "0" }}g-{{
-                productinfo.noble_name
+              productinfo.noble_name
               }}-{{ productinfo.gold_price ? productinfo.gold_price : "0" }}元/g-{{
-                productinfo.is_gold_price + "" === "0" ? "不" : ""
+              productinfo.is_gold_price + "" === "0" ? "不" : ""
               }}启用实时金价-{{ productinfo.is_diff + "" === "1" ? "有" : "无" }}工差-{{
-                productinfo.config
+              productinfo.config
               }}-{{ productinfo.other_config }}
             </span>
           </template>
@@ -88,12 +95,12 @@
           <template slot="noble_weight">{{ productinfo.noble_weight }}g</template>
           <template slot="is_gold_price">
             {{
-              String(productinfo.is_gold_price) === "1" ? "是" : "否"
+            String(productinfo.is_gold_price) === "1" ? "是" : "否"
             }}
           </template>
           <template slot="is_diff">
             {{
-              String(productinfo.is_diff) === "1" ? "有公差" : "无工差"
+            String(productinfo.is_diff) === "1" ? "有公差" : "无工差"
             }}
           </template>
 
@@ -173,20 +180,17 @@
         <el-table-column label="子商品成本编号" prop="childCode" min-width="160px" />
         <el-table-column label="子商品名称" prop="child_name" min-width="180px" show-overflow-tooltip />
         <el-table-column label="组合比例" prop="child_num" />
+        <el-table-column label="本次添加库存数">
+          <template
+            slot-scope="{ row }"
+          >{{ ((row.child_num || 0) * ( ruleForm.stock_num || 0)) || 0}}</template>
+        </el-table-column>
+
         <el-table-column label="锁定库存总数">
-          <template slot-scope="{ row }">
-            {{ row.usable_stock || 0 }}
-          </template>
+          <template slot-scope="{ row }">{{ row.stock || 0 }}</template>
         </el-table-column>
         <el-table-column label="锁定库存可用库存数">
-          <template slot-scope="{ row }">
-            {{ row.usable_stock || 0 }}
-          </template>
-        </el-table-column>
-        <el-table-column label="未锁定库存数" prop="usable_stock">
-          <template slot-scope="{ row }">
-            {{ row.usable_stock || 0 }}
-          </template>
+          <template slot-scope="{ row }">{{ row.usable_stock || 0 }}</template>
         </el-table-column>
       </el-table>
     </el-form-item>
@@ -203,33 +207,33 @@
 </template>
 
 <script>
-import StockModal from './stockModal.vue'
-import ProductModal from './productModal.vue'
-import asyncRequest from '@/apis/service/sellOut/combindAdd'
-import { stockColumns, productColumns } from './columnsForm'
-import privateField from '@/mixins/privateField'
-import { add_sum, isnumber } from '@/utils/validate'
+import StockModal from "./stockModal.vue";
+import ProductModal from "./productModal.vue";
+import asyncRequest from "@/apis/service/sellOut/combindAdd";
+import { stockColumns, productColumns } from "./columnsForm";
+import privateField from "@/mixins/privateField";
+import { add_sum, isnumber } from "@/utils/validate";
 
 const validateNum = (rule, value, callback) => {
-  if (value === '') {
-    callback(new Error('添加库存数不能为空!'))
+  if (value === "") {
+    callback(new Error("添加库存数不能为空!"));
   } else {
-    const num = parseInt(value + '')
-    console.log(num)
+    const num = parseInt(value + "");
+    console.log(num);
     if (!isnumber(value)) {
-      callback(new Error('添加库存数必须是整数!'))
+      callback(new Error("添加库存数必须是整数!"));
     } else if (num === NaN) {
-      callback(new Error('添加库存数必须是整数!'))
+      callback(new Error("添加库存数必须是整数!"));
     } else if (num === 0) {
-      callback(new Error('添加库存数不能为零!'))
+      callback(new Error("添加库存数不能为零!"));
     } else {
-      callback()
+      callback();
     }
   }
-}
+};
 
 export default {
-  name: 'BaseForm',
+  name: "BaseForm",
   components: { StockModal, ProductModal },
   mixins: [privateField],
   data() {
@@ -246,124 +250,155 @@ export default {
         full: false
       },
       ruleForm: {
-        spuCode: '',
-        wsm_code: '',
+        spuCode: "",
+        wsm_code: "",
         stock_num: 0,
         usable_stock: 0
       },
       options6: [
-        { id: '1', name: '全国' },
-        { id: '2', name: '全国除偏远' }
+        { id: "1", name: "全国" },
+        { id: "2", name: "全国除偏远" }
       ],
       options3: [
-        { id: '0', name: '无销售权限' },
-        { id: '1', name: '有销售权限' }
+        { id: "0", name: "无销售权限" },
+        { id: "1", name: "有销售权限" }
       ],
       rules: {
-        spuCode: [{ required: true, trigger: 'change', message: '请选择组合商品' }],
-        wsm_code: [{ required: true, trigger: 'change', message: '请选择所在仓库' }],
-        stock_num: [{ required: true, trigger: 'change', validator: validateNum }]
+        spuCode: [
+          { required: true, trigger: "change", message: "请选择组合商品" }
+        ],
+        wsm_code: [
+          { required: true, trigger: "change", message: "请选择所在仓库" }
+        ],
+        stock_num: [
+          { required: true, trigger: "change", validator: validateNum }
+        ]
       }
-    }
+    };
   },
   methods: {
     async submit() {
       try {
-        await this.$refs.ruleForm.validate()
-        const { usable_stock: _, ...params } = this.ruleForm
-        this.loading.full = true
+        await this.$refs.ruleForm.validate();
+        const { usable_stock, ...params } = this.ruleForm;
+
+        // const total = this.productinfo.combind_list.reduce(
+        //   (prev, { child_num }) => add_sum(prev, child_num * params.stock_num),
+        //   0
+        // );
+
+        // if (total > usable_stock) {
+        //   this.$message.warning("添加库存数不能超过可用库存数");
+        //   return;
+        // }
+
+        // (row.child_num || 0) * ( ruleForm.stock_num || 0
+        for (let item of this.productinfo.combind_list) {
+          const { child_num, usable_stock, child_name } = item;
+          if (child_num * params.stock_num > usable_stock) {
+            this.$message.warning(
+              `子商品   ${child_name}   添加库存数不能超过可用库存数`
+            );
+            return;
+          }
+        }
+
+        this.loading.full = true;
         const { code, message } = await asyncRequest.add({
           ...params,
-          flag: '1'
-        })
-        this.loading.full = false
+          flag: "1"
+        });
+        this.loading.full = false;
         if (Number(code) === 0) {
-          this.$router.push('/sellOut/combinedAdd')
-          return
+          this.$router.push("/sellOut/combinedAdd");
+          return;
         } else if (code === 1004) {
-          this.$message.warning(message)
+          this.$message.warning(message);
         }
       } catch (e) {
-        console.log(e)
+        console.log(e);
       }
     },
     number_change(e, key) {
-      this.ruleForm[key] = e
+      this.ruleForm[key] = e;
       this.$nextTick(() => {
-        this.$refs.ruleForm && this.$refs.ruleForm.validateField(key)
-      })
+        this.$refs.ruleForm && this.$refs.ruleForm.validateField(key);
+      });
     },
     resetStock() {
-      this.stockinfo = null
-      this.ruleForm.wsm_code = ''
+      this.stockinfo = null;
+      this.ruleForm.wsm_code = "";
     },
     resetProduct() {
-      this.productinfo = null
-      this.ruleForm.spuCode = ''
+      this.productinfo = null;
+      this.ruleForm.spuCode = "";
     },
     async handleStockSelected(evt) {
-      const { id } = evt
-      this.loading.stock = true
-      const { code, data } = await asyncRequest.stockinfo({ id })
-      if (code !== 0) return
-      const { addr_code, addrs_code } = data
+      const { id } = evt;
+      this.loading.stock = true;
+      const { code, data } = await asyncRequest.stockinfo({ id });
+      if (code !== 0) return;
+      const { addr_code, addrs_code } = data;
 
-      const { city_code: sourceCodeL2, area_code: sourceCodeL3 } = addr_code
-      const { city_code: targetCodeL2, area_code: targetCodeL3 } = addrs_code
+      const { city_code: sourceCodeL2, area_code: sourceCodeL3 } = addr_code;
+      const { city_code: targetCodeL2, area_code: targetCodeL3 } = addrs_code;
 
       const { code: _co1, data: _d1 } = await asyncRequest.addrquery({
         code: sourceCodeL2,
         level: 3
-      })
+      });
 
       const { code: _co2, data: _d2 } = await asyncRequest.addrquery({
         code: targetCodeL2,
         level: 3
-      })
+      });
 
-      this.loading.stock = false
+      this.loading.stock = false;
 
       if (_co1 === 0) {
-        const d1 = _d1.find(item => item.code === sourceCodeL3)
-        const { area: _a1, city: _c1, province: _p1 } = (d1 || {}).info || {}
-        data.source = [_p1, _c1, _a1].map(({ name }) => name).join('')
+        const d1 = _d1.find(item => item.code === sourceCodeL3);
+        const { area: _a1, city: _c1, province: _p1 } = (d1 || {}).info || {};
+        data.source = [_p1, _c1, _a1].map(({ name }) => name).join("");
       }
 
       if (_co2 === 0) {
-        const d2 = _d2.find(item => item.code === targetCodeL3)
-        const { area: _a2, city: _c2, province: _p2 } = (d2 || {}).info || {}
-        data.target = [_p2, _c2, _a2].map(({ name }) => name).join('')
+        const d2 = _d2.find(item => item.code === targetCodeL3);
+        const { area: _a2, city: _c2, province: _p2 } = (d2 || {}).info || {};
+        data.target = [_p2, _c2, _a2].map(({ name }) => name).join("");
       }
 
-      this.stockinfo = data
-      this.ruleForm.wsm_code = data.wsm_code
+      this.stockinfo = data;
+      this.ruleForm.wsm_code = data.wsm_code;
     },
-    async getArea(prop = 'delivery_place') {
-      const chunks = this.productinfo[prop].split(',')
-      let { data: province } = await asyncRequest.province()
+    async getArea(prop = "delivery_place") {
+      const chunks = this.productinfo[prop].split(",");
+      let { data: province } = await asyncRequest.province();
       province = province.find(
         ({ province_code }) => province_code === chunks[0]
-      )
-      let { data: city } = await asyncRequest.city({ code: chunks[0] })
-      city = city.find(({ city_code }) => city_code === chunks[1])
-      let { data: area } = await asyncRequest.area({ code: chunks[1] })
-      area = area.find(({ area_code }) => area_code === chunks[2]) || {}
-      return [province, city, area].map(({ name }) => name).join('')
+      );
+      let { data: city } = await asyncRequest.city({ code: chunks[0] });
+      city = city.find(({ city_code }) => city_code === chunks[1]);
+      let { data: area } = await asyncRequest.area({ code: chunks[1] });
+      area = area.find(({ area_code }) => area_code === chunks[2]) || {};
+      return [province, city, area].map(({ name }) => name).join("");
     },
     async handleProductSelected(spuCode) {
-      this.loading.product = true
-      const { code, data } = await asyncRequest.productinfo({ spuCode })
-      if (code !== 0) return
+      this.loading.product = true;
+      const { code, data } = await asyncRequest.productinfo({ spuCode });
+      if (code !== 0) return;
       this.productinfo = data;
 
       (data.combind_list || []).forEach(item => {
-        this.ruleForm.usable_stock = add_sum(this.ruleForm.usable_stock || 0, item.usable_stock || 0)
-      })
-      this.ruleForm.spuCode = spuCode
-      this.delivery_place = await this.getArea('delivery_place')
-      this.origin_place = await this.getArea('origin_place')
-      this.loading.product = false
+        this.ruleForm.usable_stock = add_sum(
+          this.ruleForm.usable_stock || 0,
+          item.usable_stock || 0
+        );
+      });
+      this.ruleForm.spuCode = spuCode;
+      this.delivery_place = await this.getArea("delivery_place");
+      this.origin_place = await this.getArea("origin_place");
+      this.loading.product = false;
     }
   }
-}
+};
 </script>

+ 39 - 9
src/views/sellOut/combinedAdd/detail.vue

@@ -17,6 +17,12 @@
                       :type="sitem.status == '1' ? 'warning' : ''"
                     >{{(statusOptions.find((item) => item.id == String(sitem.status)) || {}).label || '--'}}</el-tag>
                   </template>
+
+                  <template #wsmtype>
+                    <el-tag
+                      size="mini"
+                    >{{(wsm_options.find(({value}) => value === sitem.wsm_type) || {}).label || '--'}}</el-tag>
+                  </template>
                 </show-data-table>
               </el-collapse-item>
 
@@ -30,14 +36,17 @@
                     show-overflow-tooltip
                   />
                   <el-table-column label="组合比例" prop="child_num" />
+                  <el-table-column label="本次添加库存数">
+                    <template
+                      slot-scope="{ row }"
+                    >{{ ((row.child_num || 0) * ( sitem.stock_num || 0)) || 0}}</template>
+                  </el-table-column>
+
                   <el-table-column label="锁定库存总数">
-                    <template slot-scope="{ row }">{{ row.usable_stock || 0 }}</template>
+                    <template slot-scope="scope">{{ scope.row.stock || 0 }}</template>
                   </el-table-column>
                   <el-table-column label="锁定库存可用库存数">
-                    <template slot-scope="{ row }">{{ row.usable_stock || 0 }}</template>
-                  </el-table-column>
-                  <el-table-column label="未锁定库存数" prop="usable_stock">
-                    <template slot-scope="{ row }">{{ row.usable_stock || 0 }}</template>
+                    <template slot-scope="scope">{{ scope.row.usable_stock || 0 }}</template>
                   </el-table-column>
                 </el-table>
               </el-collapse-item>
@@ -63,14 +72,13 @@
   </div>
 </template>
 <script>
-import mixinPage from "@/mixins/elPaginationHandle";
-import resToken from "@/mixins/resToken";
 import asyncRequest from "@/apis/service/sellOut/combinedAdd";
-import { showColumns, detailColumns } from "./columns";
 import { xs_order_type_options } from "@/assets/js/statusList";
+import { showColumns, detailColumns } from "./columns";
 import WaitApproval from "./components/waitApproval";
-
+import mixinPage from "@/mixins/elPaginationHandle";
 import BaseForm from "./components/baseForm";
+import resToken from "@/mixins/resToken";
 import { mapGetters } from "vuex";
 export default {
   name: "combinedAddDetail",
@@ -116,6 +124,28 @@ export default {
           label: "竞价订单不减工差"
         }
       ],
+      wsm_options: [
+        // {
+        //   value: "1",
+        //   label: "系统仓",
+        // },
+        //   {
+        //   value: "2",
+        //   label: "虚拟仓",
+        // },
+        //     {
+        //   value: "3",
+        //   label: "自建仓",
+        // },
+        {
+          value: "5",
+          label: "销售仓"
+        },
+        {
+          value: "4",
+          label: "次品仓"
+        }
+      ],
       is_act_options: [
         {
           value: "1",