storeBelieveInLight hace 1 año
padre
commit
3e01ce8f2b
Se han modificado 3 ficheros con 419 adiciones y 46 borrados
  1. 315 42
      shop/productManagementModule/addProduct.vue
  2. 4 4
      shop/productManagementModule/index.vue
  3. 100 0
      utils/acc.js

+ 315 - 42
shop/productManagementModule/addProduct.vue

@@ -153,7 +153,7 @@
153 153
           </view>
154 154
         </view>
155 155
       </view>
156
-      <view
156
+      <!-- <view
157 157
         class="form-box mr-t"
158 158
         v-for="(item, index) in attrValue"
159 159
         :key="index"
@@ -190,6 +190,123 @@
190 190
             </view>
191 191
           </template>
192 192
         </view>
193
+      </view> -->
194
+      <view class="form-box mr-t">
195
+        <!-- 分润比例 extension_one-->
196
+        <view class="form-item-box" v-if="formData.extension_type == 1">
197
+          <view class="form-box-txt" :class="['mustBox']">分润比例(%)</view>
198
+          <!-- <input
199
+            type="digit"
200
+            v-model="attrValueForm.extension_one"
201
+            :adjust-position="false"
202
+            placeholder="请输入分润比例"
203
+            class="placeholder-class"
204
+            @input="changeInputHandleExtensionOne"
205
+          /> -->
206
+          <uni-easyinput
207
+            type="digit"
208
+            v-model="attrValueForm.extension_one"
209
+            :adjust-position="false"
210
+            placeholder="请输入分润比例"
211
+            class="placeholder-class"
212
+            @input="changeInputHandleExtensionOne"
213
+            :clearable="false"
214
+          ></uni-easyinput>
215
+          <view class="view-unit-input">%</view>
216
+        </view>
217
+        <!-- 商品成本价 cost-->
218
+        <view class="form-item-box">
219
+          <view class="form-box-txt" :class="['mustBox']">商品成本价</view>
220
+
221
+          <uni-easyinput
222
+            type="digit"
223
+            v-model="attrValueForm.cost"
224
+            :adjust-position="false"
225
+            placeholder="请输入商品成本价"
226
+            class="placeholder-class"
227
+            :clearable="false"
228
+            @input="changeInputHandleCost"
229
+          ></uni-easyinput>
230
+        </view>
231
+        <!-- 商品售价 price-->
232
+        <view class="form-item-box">
233
+          <view class="form-box-txt" :class="['mustBox']">商品售价</view>
234
+          <view class="form-box--arae">
235
+            <view class="price-box">
236
+              <view class="flex-price">{{ priceDefault }}</view>
237
+              <view class="price-box_tips" v-if="formData.extension_type == 1"
238
+                >商品成本价×分润比例</view
239
+              >
240
+            </view>
241
+          </view>
242
+        </view>
243
+        <!-- 商品原价 ot_price-->
244
+        <view class="form-item-box">
245
+          <view class="form-box-txt" :class="['mustBox']">商品原价</view>
246
+
247
+          <uni-easyinput
248
+            type="digit"
249
+            v-model="attrValueForm.ot_price"
250
+            :adjust-position="false"
251
+            placeholder="请输入商品原价"
252
+            class="placeholder-class"
253
+            :clearable="false"
254
+            @input="changeInputHandleOTPrice"
255
+          ></uni-easyinput>
256
+          <!--          
257
+          <input
258
+            type="digit"
259
+            v-model="attrValueForm.ot_price"
260
+            :adjust-position="false"
261
+            placeholder="请输入商品原价"
262
+            class="placeholder-class"
263
+            @input="changeInputHandleOTPrice"
264
+          /> -->
265
+        </view>
266
+        <!-- 商品库存 -->
267
+        <view class="form-item-box">
268
+          <view class="form-box-txt" :class="['mustBox']">商品库存</view>
269
+          <input
270
+            type="number"
271
+            v-model="attrValueForm.stock"
272
+            :adjust-position="false"
273
+            placeholder="请输入商品库存"
274
+            class="placeholder-class"
275
+          />
276
+        </view>
277
+        <!-- 商品编号 -->
278
+        <view class="form-item-box">
279
+          <view class="form-box-txt" :class="['']">商品编号</view>
280
+          <input
281
+            type="text"
282
+            v-model="attrValueForm.bar_code"
283
+            :adjust-position="false"
284
+            placeholder="请输入商品编号"
285
+            class="placeholder-class"
286
+          />
287
+        </view>
288
+        <!-- 重量(KG) -->
289
+        <view class="form-item-box">
290
+          <view class="form-box-txt" :class="['']">重量(KG)</view>
291
+          <input
292
+            type="text"
293
+            v-model="attrValueForm.weight"
294
+            :adjust-position="false"
295
+            placeholder="请输入商重量(KG)"
296
+            class="placeholder-class"
297
+          />
298
+        </view>
299
+        <!-- 商品体积(m³) -->
300
+        <view class="form-item-box">
301
+          <view class="form-box-txt" :class="['']">商品体积(m³)</view>
302
+          <input
303
+            type="text"
304
+            v-model="attrValueForm.volume"
305
+            :adjust-position="false"
306
+            placeholder="请输入商品体积(m³)"
307
+            class="placeholder-class"
308
+          />
309
+        </view>
193 310
       </view>
194 311
       <!-- 商品简介 -->
195 312
       <view class="business-box pb15">
@@ -251,6 +368,7 @@ import {
251 368
   getMerchantProfitApi,
252 369
 } from "@/commit/product.js";
253 370
 import { getBaseInfo } from "@/commit/user.js";
371
+import { accMul, accDiv, accAdd, accSub } from "@/utils/acc.js";
254 372
 export default {
255 373
   components: {
256 374
     headersVue,
@@ -331,7 +449,17 @@ export default {
331 449
         gong_market_price: "",
332 450
         plate_mer_profit: "",
333 451
         extension_two: null,
452
+        image: "", //商品图片
453
+        extension_one: this.base_commission, //分润比例(%)
454
+        cost: "", //成本价
455
+        price: "", //商品售价
456
+        ot_price: "", //商品原价
457
+        stock: "", //商品库存
458
+        bar_code: "", //商品编号
459
+        weight: "", //重量(KG)
460
+        volume: "", //商品体积(m³)
334 461
       },
462
+      costInputValue: "",
335 463
     };
336 464
   },
337 465
   async onLoad() {
@@ -422,6 +550,7 @@ export default {
422 550
       getMerchantProfitApi()
423 551
         .then((res) => {
424 552
           this.base_commission = res.data.message;
553
+          this.attrValueForm.extension_one = this.base_commission;
425 554
         })
426 555
         .catch((err) => {
427 556
           console.log(err);
@@ -502,27 +631,56 @@ export default {
502 631
         });
503 632
         return;
504 633
       }
505
-      const dataList = (this.attrValue[0] && this.attrValue[0].modules) || [];
506
-      const dataNew = dataList.map((item, index) => {
507
-        return {
508
-          tips: dataList[index].title,
509
-          props: dataList[index].props,
510
-          isEmpty:
511
-            dataList[index].ismust &&
512
-            (dataList[index].value == "" ||
513
-              dataList[index].value == undefined ||
514
-              dataList[index].value == null),
515
-          value: dataList[index].value || "",
516
-        };
517
-      });
518
-      const data = dataNew.some((item) => item.isEmpty);
519
-      if (data) {
634
+      if (
635
+        this.attrValueForm.extension_one == "" ||
636
+        this.attrValueForm.extension_one == null
637
+      ) {
638
+        uni.showToast({
639
+          title: "请填写分润比例",
640
+          icon: "none",
641
+        });
642
+        return;
643
+      }
644
+      if (this.attrValueForm.cost == "" || this.attrValueForm.cost == null) {
645
+        uni.showToast({
646
+          title: "请填写商品成本价",
647
+          icon: "none",
648
+        });
649
+        return;
650
+      }
651
+      if (this.attrValueForm.price == "" || this.attrValueForm.price == null) {
652
+        uni.showToast({
653
+          title: "请填写商品售价",
654
+          icon: "none",
655
+        });
656
+        return;
657
+      }
658
+      if (
659
+        this.attrValueForm.ot_price == "" ||
660
+        this.attrValueForm.ot_price == null ||
661
+        this.attrValueForm.ot_price == 0
662
+      ) {
520 663
         uni.showToast({
521
-          title: "请填写完所有必填项",
664
+          title: "请填写商品原价",
522 665
           icon: "none",
523 666
         });
524 667
         return;
525 668
       }
669
+      if (this.attrValueForm.stock == "" || this.attrValueForm.stock == null) {
670
+        uni.showToast({
671
+          title: "请填写商品库存",
672
+          icon: "none",
673
+        });
674
+        return;
675
+      }
676
+      if(this.attrValueForm.extension_one <5 || this.attrValueForm.extension_one > 100 || this.attrValueForm.extension_one == ""){
677
+        uni.showToast({
678
+          title: "请填写正确的分润比例",
679
+          icon: "none", 
680
+        })
681
+        return;
682
+      }
683
+       
526 684
       if (this.formData.store_info == "") {
527 685
         uni.showToast({
528 686
           title: "请填写商品简介",
@@ -530,23 +688,14 @@ export default {
530 688
         });
531 689
         return;
532 690
       }
533
-      let attrValueData = dataNew.map((item, index) => {
534
-        let parmas = {};
535
-        if ([item.props] == "image") {
536
-          Object.assign(parmas, { image: this.formData.image });
537
-        } else {
538
-          Object.assign(parmas, { [item.props]: item.value });
539
-        }
540
-        return parmas;
541
-      });
542
-      // 使用 reduce 方法合并数组中的对象
543
-      const mergedObject = attrValueData.reduce((acc, current) => {
544
-        return { ...acc, ...current };
545
-      }, {});
691
+      this.attrValueForm.image =  this.formData.image 
692
+
693
+
546 694
 
547 695
       // 转换为包含合并后对象的数组
548
-      const result = [{ mergedObject, ...this.attrValueForm }];
696
+      const result = [{  ...this.attrValueForm }];
549 697
       const newParams = { ...this.formData, attrValue: result };
698
+      console.log(newParams, "newParams");
550 699
       uni.showLoading({
551 700
         title: "数据提交中...",
552 701
       });
@@ -591,16 +740,8 @@ export default {
591 740
     },
592 741
     /**分润设置选择 */
593 742
     changeFengrun(val) {
594
-      this.formData.extension_type = val;
595
-      const _this = this;
596
-      this.attrValue[0].modules.forEach((item) => {
597
-        if (item.props === "extension_one") {
598
-          _this.$set(item, "value", _this.base_commission);
599
-        } else {
600
-          _this.$set(item, "value", item.value);
601
-        }
602
-      });
603
-      this.priceDefault = "0.00"
743
+      console.log(val, "分润设置选择");
744
+      this.attrValueForm.extension_one = this.base_commission;
604 745
     },
605 746
     changeInputHandle(ev, its, item, idx) {
606 747
       if (its.props == "cost" || its.props == "extension_one") {
@@ -623,6 +764,129 @@ export default {
623 764
       }
624 765
       console.log(this.attrValueForm, "attrValueForm", its);
625 766
     },
767
+    /**分润比例输入框 */
768
+    changeInputHandleExtensionOne(e) {
769
+      let value = e;
770
+      if (value < 5) {
771
+        uni.showToast({
772
+          title: "分润比例不能小于5%",
773
+          icon: "none",
774
+        });
775
+        this.$nextTick(()=>{
776
+        this.attrValueForm.extension_one = '5';
777
+        })
778
+      }
779
+      if (value > 100) {
780
+        uni.showToast({
781
+          title: "分润比例不能大于100%",
782
+          icon: "none",
783
+        });
784
+        this.$nextTick(()=>{
785
+        this.attrValueForm.extension_one = this.base_commission;
786
+        })
787
+
788
+      }
789
+
790
+      let data = {
791
+        extension_one: this.attrValueForm.extension_one,
792
+        cost: this.attrValueForm.cost,
793
+      };
794
+      this.getCalcAfterPrice(data);
795
+    },
796
+    getCalcAfterPrice(data) {
797
+      let bili = accMul(data.extension_one, 100); //比例
798
+      console.log(bili, "比例");
799
+      let gong_mer_profit = accMul(data.cost, bili); //利润
800
+      console.log(gong_mer_profit, "利润");
801
+      let gong_market_price = accAdd(data.cost, gong_mer_profit); //加入利润后的价格
802
+      let plate_mer_profit = gong_mer_profit;
803
+      console.log(gong_market_price, "加入利润后的价格", plate_mer_profit);
804
+      this.attrValueForm.price = gong_market_price;
805
+      this.priceDefault = gong_market_price;
806
+      this.attrValueForm.gong_mer_profit = gong_mer_profit;
807
+      this.attrValueForm.gong_market_price = gong_market_price;
808
+      this.attrValueForm.plate_mer_profit = plate_mer_profit;
809
+      console.log(this.attrValueForm, "计算的内容:");
810
+    },
811
+    /**
812
+     * 商品成本价
813
+     */
814
+    changeInputHandleCost(e) {
815
+      console.log("商品成本价", e);
816
+      let value = e;
817
+      const _this = this;
818
+      if (value == "" || value == null || value == undefined || value == "0") {
819
+        uni.showToast({
820
+          title: "请输入正确的金额",
821
+          icon: "none",
822
+        });
823
+      }
824
+
825
+      const formatted = this.limitPriceFormat(value);
826
+      _this.attrValueForm.cost = formatted;
827
+      let data = {
828
+        extension_one: this.attrValueForm.extension_one,
829
+        cost: this.attrValueForm.cost || "0",
830
+      };
831
+      this.getCalcAfterPrice(data);
832
+    },
833
+    /**
834
+     * 商品原价
835
+     */
836
+    changeInputHandleOTPrice(e) {
837
+      let value = e;
838
+      const _this = this;
839
+      if (value == "" || value == null || value == undefined || value == "0") {
840
+        uni.showToast({
841
+          title: "请输入正确的金额",
842
+          icon: "none",
843
+        });
844
+      }
845
+
846
+      const formatted = this.limitPriceFormat(value);
847
+        this.$nextTick(()=>{
848
+        _this.attrValueForm.ot_price = formatted;
849
+        })
850
+     
851
+    },
852
+
853
+    limitPriceFormat(value) {
854
+      // 移除不符合金额格式的字符
855
+      value = value.replace(/[^\d.]/g, "");
856
+
857
+      // 处理多个连续的 0 开头的情况
858
+      while (
859
+        value.startsWith("0") &&
860
+        value.length > 1 &&
861
+        !value.startsWith("0.")
862
+      ) {
863
+        value = value.slice(1);
864
+      }
865
+
866
+      // 处理多个小数点的情况
867
+      const parts = value.split(".");
868
+      if (parts.length > 2) {
869
+        value = parts[0] + "." + parts.slice(1).join("");
870
+      }
871
+
872
+      // 处理小数点后超过两位的情况
873
+      const decimalIndex = value.indexOf(".");
874
+      if (decimalIndex !== -1) {
875
+        value = value.slice(0, decimalIndex + 3);
876
+      }
877
+
878
+      // 若结果为纯 0 字符串,只保留一个 0
879
+      if (/^0+\.?0*$/.test(value)) {
880
+        value = "0";
881
+      }
882
+
883
+      return value;
884
+    },
885
+    isValidAmount(input) {
886
+      // 正则表达式,用于匹配金额格式
887
+      const regex = /^\d+(\.\d{1,2})?$/;
888
+      return regex.test(input);
889
+    },
626 890
   },
627 891
   computed: {
628 892
     shangpingleixing() {
@@ -979,12 +1243,21 @@ page {
979 1243
   font-size: 30rpx;
980 1244
   color: #333333;
981 1245
   text-align: right;
982
-  padding: 0rpx 0rpx 0rpx 15rpx;
1246
+  padding: 0rpx 5rpx 0rpx 15rpx;
983 1247
   outline: none;
984 1248
   border: none;
985 1249
   background: none;
986 1250
   /deep/.uni-input-placeholder {
987 1251
     color: #999;
1252
+    font-size: 28rpx;
1253
+  }
1254
+  /deep/.uni-easyinput__content {
1255
+    outline: none;
1256
+    border: none;
1257
+    background: none;
1258
+  }
1259
+  /deep/.uni-input-input {
1260
+    font-size: 28rpx;
988 1261
   }
989 1262
 }
990 1263
 .mr-t {

+ 4 - 4
shop/productManagementModule/index.vue

@@ -10,12 +10,12 @@
10 10
         :cardData="dataBuss"
11 11
         @custom-handle-click="businessHandleClick"
12 12
       ></listCardInfo>
13
-      <listCardInfo
13
+      <!-- <listCardInfo
14 14
         headerTitle="供应链"
15 15
         class="mb-t1"
16 16
         :cardData="onlineData"
17 17
         @custom-handle-click="onGongyingliang"
18
-      ></listCardInfo>
18
+      ></listCardInfo> -->
19 19
       <!-- <listCardInfo headerTitle="商品分类" class="mb-t1" :fullSreen="true" fullSreenTitle="商品分类列表" ></listCardInfo> -->
20 20
       <!-- <listCardInfo headerTitle="商品规格" class="mb-t1" :fullSreen="true" fullSreenTitle="商品规格列表"></listCardInfo> -->
21 21
       <listCardInfo
@@ -25,11 +25,11 @@
25 25
         fullSreenTitle="商品评价列表"
26 26
         @custom-handle-click="onHandlePingJia"
27 27
       ></listCardInfo>
28
-      <listCardInfo
28
+      <!-- <listCardInfo
29 29
        headerTitle="在线选品"
30 30
        class="mb-t1" 
31 31
       :fullSreen="true"
32
-        fullSreenTitle="在线选品列表"  @custom-handle-click="onHandleXuanPin"></listCardInfo>
32
+        fullSreenTitle="在线选品列表"  @custom-handle-click="onHandleXuanPin"></listCardInfo> -->
33 33
     </view>
34 34
   </view>
35 35
 </template>

+ 100 - 0
utils/acc.js

@@ -0,0 +1,100 @@
1
+/**
2
+ * 数学运算
3
+ */
4
+
5
+/**
6
+ * 两个浮点数求和
7
+ * @author lsy
8
+ * @param num1
9
+ * @param num2
10
+ * @return {number}
11
+ */
12
+export function accAdd(num1, num2) {
13
+  // eslint-disable-next-line one-var
14
+  let r1 = 0, r2 = 0
15
+  try {
16
+    r1 = (num1.toString().split('.')[1] || []).length
17
+  } catch (e) {
18
+    return num1 + num2
19
+  }
20
+  try {
21
+    r2 = (num2.toString().split('.')[1] || []).length
22
+  } catch (e) {
23
+    return num1 + num2
24
+  }
25
+  const m = Math.pow(10, Math.max(r1, r2))
26
+  return Math.round(accMul(num1, m) + accMul(num2, m)) / m
27
+}
28
+
29
+/**
30
+ * 两个浮点数相减
31
+ * @author lsy
32
+ * @param num1
33
+ * @param num2
34
+ * @return {number}
35
+ */
36
+export function accSub(num1, num2) {
37
+  let r1, r2
38
+  try {
39
+    r1 = (num1.toString().split('.')[1] || []).length
40
+  } catch (e) {
41
+    return num1 - num2
42
+  }
43
+  try {
44
+    r2 = (num2.toString().split('.')[1] || []).length
45
+  } catch (e) {
46
+    return num1 - num2
47
+  }
48
+  const m = Math.pow(10, Math.max(r1, r2))
49
+  return Math.round(accMul(num1, m) - accMul(num2, m)) / m
50
+}
51
+
52
+/**
53
+ * 两个浮点数相乘
54
+ * @author lsy
55
+ * @param num1
56
+ * @param num2
57
+ * @return {number}
58
+ */
59
+export function accMul(num1, num2) {
60
+  let m = 0
61
+  const s1 = num1.toString()
62
+  const s2 = num2.toString()
63
+  try {
64
+    m += (s1.split('.')[1] || []).length
65
+  } catch (e) {
66
+    return num1 * num2
67
+  }
68
+  try {
69
+    m += (s2.split('.')[1] || []).length
70
+  } catch (e) {
71
+    return num1 * num2
72
+  }
73
+  return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m)
74
+}
75
+
76
+/**
77
+ * 两个浮点数相除
78
+ * @author lsy
79
+ * @param num1
80
+ * @param num2
81
+ * @return {number}
82
+ */
83
+export function accDiv(num1, num2) {
84
+  let m = 0
85
+  const s1 = num1.toString()
86
+  const s2 = num2.toString()
87
+  try {
88
+    m += (s1.split('.')[1] || []).length
89
+  } catch (e) {
90
+    return num1 / num2
91
+  }
92
+  try {
93
+    m += (s2.split('.')[1] || []).length
94
+  } catch (e) {
95
+    return num1 / num2
96
+  }
97
+  const n1 = accMul(num1, Math.pow(10, m))
98
+  const n2 = accMul(num2, Math.pow(10, m))
99
+  return Number(n1) / Number(n2)
100
+}