Browse Source

添加字段和计算方式

yuhongqi 1 tháng trước cách đây
mục cha
commit
7e0fac1adc

+ 98 - 0
src/views/store/components/productOrder.vue

@@ -235,6 +235,11 @@
             <p>¥{{JSON.parse(scope.row.jsonInfo).price.toFixed(2)}}</p>
           </template>
         </el-table-column>
+        <el-table-column label="出库价" width="240" align="center">
+          <template slot-scope="scope">
+            <p>¥{{getOutboundPrice(scope.$index, scope.row).toFixed(2)}}</p>
+          </template>
+        </el-table-column>
         <el-table-column label="规格" width="240" align="center">
           <template slot-scope="scope">
             {{JSON.parse(scope.row.jsonInfo).sku}}
@@ -304,6 +309,22 @@
                 ¥{{order.serviceFee}}
               </span>
           </el-descriptions-item>
+          <el-descriptions-item label="折扣率"  >
+              <span v-if="order!=null && productTotal > 0">
+                {{((order.payPrice / productTotal) * 100).toFixed(2)}}%
+              </span>
+              <span v-else-if="order!=null">
+                0.00%
+              </span>
+          </el-descriptions-item>
+          <el-descriptions-item label="产品合计"  >
+              <span v-if="order!=null && items!=null && items.length > 0">
+                ¥{{productTotal.toFixed(2)}}
+              </span>
+              <span v-else-if="order!=null">
+                ¥0.00
+              </span>
+          </el-descriptions-item>
 
       </el-descriptions>
 
@@ -638,6 +659,29 @@ export default {
       this.scheduleOptions = response.data;
     });
   },
+  computed: {
+    /**
+     * 计算产品合计:每个产品单价*数量之和
+     */
+    productTotal() {
+      if (!this.items || this.items.length === 0) {
+        return 0;
+      }
+      let total = 0;
+      for (let i = 0; i < this.items.length; i++) {
+        const item = this.items[i];
+        try {
+          const jsonInfo = JSON.parse(item.jsonInfo);
+          const price = parseFloat(jsonInfo.price) || 0;
+          const num = parseFloat(item.num) || 0;
+          total += price * num;
+        } catch (e) {
+          console.warn('解析商品信息失败', e);
+        }
+      }
+      return total;
+    }
+  },
   watch: {
     'editDyForm.deliverSn': {
       handler(newValue) {
@@ -904,6 +948,60 @@ export default {
         this.editDyForm.deliverName=null;
       }
     },
+    /**
+     * 计算出库价
+     * @param index 商品索引
+     * @param row 商品行数据
+     * @returns {number} 出库价
+     */
+    getOutboundPrice(index, row) {
+      if (!this.order || !this.items || this.items.length === 0) {
+        return 0;
+      }
+      
+      const jsonInfo = JSON.parse(row.jsonInfo);
+      const price = parseFloat(jsonInfo.price) || 0;
+      const num = parseFloat(row.num) || 0;
+      
+      // 计算折扣率:应付金额 / 产品合计
+      const payPrice = parseFloat(this.order.payPrice) || 0;
+      
+      if (this.productTotal <= 0) {
+        return 0;
+      }
+      
+      const discountRate = payPrice / this.productTotal;
+      
+      // 如果只有一个商品,直接按折扣率计算
+      if (this.items.length === 1) {
+        return price * discountRate;
+      }
+      
+      // 多个商品的情况
+      // 判断是否是最后一个商品
+      const isLastItem = index === this.items.length - 1;
+      
+      if (isLastItem) {
+        // 最后一个商品:出库价 = (应付金额 - 之前所有产品出库价*数量的合计) / 数量
+        let previousTotal = 0;
+        for (let i = 0; i < index; i++) {
+          const prevRow = this.items[i];
+          const prevJsonInfo = JSON.parse(prevRow.jsonInfo);
+          const prevPrice = parseFloat(prevJsonInfo.price) || 0;
+          const prevNum = parseFloat(prevRow.num) || 0;
+          const prevOutboundPrice = prevPrice * discountRate;
+          previousTotal += prevOutboundPrice * prevNum;
+        }
+        
+        if (num > 0) {
+          return (payPrice - previousTotal) / num;
+        }
+        return 0;
+      } else {
+        // 前n-1个商品:出库价 = 单价 * 折扣率
+        return price * discountRate;
+      }
+    },
     getOrder(orderId){
         this.orderId=orderId;
         this.certificates = null;

+ 63 - 4
src/views/store/storeProduct/index.vue

@@ -224,7 +224,18 @@
               <el-input v-model="form.unitName" placeholder="请输入单位名" />
             </el-form-item>
           </el-col>
-
+        </el-row>
+        <el-row>
+          <el-col :span="12">
+            <el-form-item label="税收分类码" prop="taxClassificationCode">
+              <el-input v-model="form.taxClassificationCode" placeholder="请输入税收分类码" />
+            </el-form-item>
+          </el-col>
+          <el-col :span="12">
+            <el-form-item label="商品发票名称" prop="invoiceName">
+              <el-input v-model="form.invoiceName" placeholder="请输入商品发票名称" />
+            </el-form-item>
+          </el-col>
         </el-row>
         <el-row>
           <el-col :span="24">
@@ -318,11 +329,27 @@
                         <div v-else-if="scope.column.property == 'action'" align="center" >
                           <a @click="delAttrTable(scope.$index)" align="center">删除</a>
                         </div>
+                        <div v-else-if="scope.column.property == 'taxRate'" align="center">
+                          <el-input 
+                            v-model="scope.row.taxRate" 
+                            placeholder="请输入税率"
+                            @input="handleTaxRateInput($event, scope.row)"
+                          />
+                        </div>
                         <div v-else align="center">
                           <el-input  v-model="scope.row[scope.column.property]" align="center" />
                         </div>
                       </template>
                     </el-table-column>
+                    <el-table-column prop="taxRate" label="税率" align="center" width="150">
+                      <template slot-scope="scope">
+                        <el-input 
+                          v-model="scope.row.taxRate" 
+                          placeholder="请输入税率"
+                          @input="handleTaxRateInput($event, scope.row)"
+                        />
+                      </template>
+                    </el-table-column>
                   </el-table>
 
                 </el-form-item>
@@ -404,6 +431,15 @@
                     <el-input type="text" v-model="scope.row.brokerageThree"/>
                   </template>
                 </el-table-column>
+                <el-table-column prop="taxRate" label="税率" align="center">
+                  <template slot-scope="scope">
+                    <el-input 
+                      v-model="scope.row.taxRate" 
+                      placeholder="请输入税率"
+                      @input="handleTaxRateInput($event, scope.row)"
+                    />
+                  </template>
+                </el-table-column>
               </el-table>
             </el-form-item>
           </el-col>
@@ -1008,7 +1044,9 @@ export default {
         prescribeName: null,
         isDisplay:"1",
         warehouseCode: null,
-        warehouseId: null
+        warehouseId: null,
+        taxClassificationCode: null,
+        invoiceName: null
       };
       this.resetForm("form");
       this.oneFormValidate = [
@@ -1025,7 +1063,8 @@ export default {
           integral: 0,
           brokerage:0,
           brokerageTwo:0,
-          warehouseCode:null
+          warehouseCode:null,
+          taxRate: null
         }
       ]
       this.attrs=[];
@@ -1104,7 +1143,8 @@ export default {
               volume: 0,
               integral: 0,
               brokerage:0,
-              brokerageTwo:0
+              brokerageTwo:0,
+              taxRate: null
             }
           ]
         }
@@ -1210,6 +1250,25 @@ export default {
         }).then(response => {
           this.download(response.msg);
         }).catch(function() {});
+    },
+    /** 处理税率输入过滤 */
+    handleTaxRateInput(value, row) {
+      // 只保留数字和小数点
+      let filteredValue = value.replace(/[^\d.]/g, '');
+      // 确保只有一个小数点
+      const parts = filteredValue.split('.');
+      if (parts.length > 2) {
+        filteredValue = parts[0] + '.' + parts.slice(1).join('');
+      }
+      // 限制小数点后最多2位
+      if (parts.length === 2 && parts[1].length > 2) {
+        filteredValue = parts[0] + '.' + parts[1].substring(0, 2);
+      }
+      // 限制最大值100
+      if (filteredValue && parseFloat(filteredValue) > 100) {
+        filteredValue = '100';
+      }
+      row.taxRate = filteredValue;
     }
   }
 };

+ 13 - 0
src/views/store/storeProductGroup/index.vue

@@ -237,6 +237,19 @@ export default {
           return;
         }
       }
+      
+      // 如果已有商品,校验仓库代码是否一致
+      if (this.products.length > 0) {
+        const firstWarehouseCode = this.products[0].prodWareHouseCode;
+        const currentWarehouseCode = row.prodWareHouseCode;
+        
+        // 检查仓库代码是否一致
+        if (firstWarehouseCode !== currentWarehouseCode) {
+          this.$message.error(`只能添加仓库代码一致的商品:${firstWarehouseCode || '未知'}`);
+          return;
+        }
+      }
+      
       this.products.push(row);
     },
     handleAddProduct(){

+ 13 - 19
src/views/store/storeProductPackage/index.vue

@@ -505,32 +505,26 @@ export default {
           return;
         }
       }
+      
+      // 如果已有商品,校验仓库代码是否一致
+      if (this.products.length > 0) {
+        const firstWarehouseCode = this.products[0].prodWareHouseCode;
+        const currentWarehouseCode = row.prodWareHouseCode;
+        
+        // 检查仓库代码是否一致
+        if (firstWarehouseCode !== currentWarehouseCode) {
+          this.$message.error(`只能添加仓库代码一致的商品:${firstWarehouseCode || '未知'}`);
+          return;
+        }
+      }
+      
       row.count=1;
       row.money=row.count*row.price;
-      let testProduct = [...this.products,row]
-      if (!this.checkProductsWarehouseCode(testProduct)) {
-        this.$message.error("商品仓库代码不一致,且不能为空");
-        return;
-      }
       this.products.push(row);
       this.compute();
 
       this.$message.success('添加成功!')
     },
-    checkProductsWarehouseCode(products) {
-      const warehouseCodeSet = new Set(products.map(row => row.prodWareHouseCode));
-      // 2. 检查 Set 大小是否为 1
-      if (warehouseCodeSet.size !== 1) {
-        return false;
-      }
-      // 3. 获取 Set 中的唯一元素(因为 Set 大小为 1,所以可以直接获取)
-      const [singleWarehouseCode] = warehouseCodeSet;
-      // 4. 检查唯一元素是否为空
-      if (singleWarehouseCode === null || singleWarehouseCode === undefined || singleWarehouseCode === '') {
-        return false; // 元素为空
-      }
-      return true; // 所有条件都满足
-    },
     handleAddProduct(){
       this.product.open=true;
       // setTimeout(() => {