Commit 07565417e5af0bf9130ea375ef7dfc478e41443f

Authored by yvan.ni
1 parent 0d400342

购物车 汇总商品的时候,再啦一下

Showing 1 changed file with 57 additions and 59 deletions
pages/cart/cart/cart.js
@@ -2611,7 +2611,7 @@ Page({ @@ -2611,7 +2611,7 @@ Page({
2611 } 2611 }
2612 for (let j = 0; j < this.data.requestData.length;j++){ 2612 for (let j = 0; j < this.data.requestData.length;j++){
2613 if(j!=pitem){ 2613 if(j!=pitem){
2614 - var goods=this.data.requestData[j]; 2614 + var goods=this.data.requestData[j].goods;
2615 for (let k = 0; k <goods.length ; k++) { 2615 for (let k = 0; k <goods.length ; k++) {
2616 var m_item=goods[k]; 2616 var m_item=goods[k];
2617 if(m_item.goods_id==goods_id && m_item.is_gift==0){ 2617 if(m_item.goods_id==goods_id && m_item.is_gift==0){
@@ -2734,7 +2734,7 @@ Page({ @@ -2734,7 +2734,7 @@ Page({
2734 if (res_d.data.code == 0 && res_d.data.data) { 2734 if (res_d.data.code == 0 && res_d.data.data) {
2735 2735
2736 var cbuy=limit; 2736 var cbuy=limit;
2737 - if (t.goods_num > store_count && !is_showing) { 2737 + if (t.goods_num+other_gd_num > store_count && !is_showing) {
2738 wx.showToast({ 2738 wx.showToast({
2739 title: '购买数量超出商品库存', 2739 title: '购买数量超出商品库存',
2740 icon: 'none', 2740 icon: 'none',
@@ -2742,7 +2742,7 @@ Page({ @@ -2742,7 +2742,7 @@ Page({
2742 is_showing=1; 2742 is_showing=1;
2743 } 2743 }
2744 //一直都要给一个最小值,和库存比较 2744 //一直都要给一个最小值,和库存比较
2745 - if(cbuy>store_count) cbuy=store_count; 2745 + if(cbuy>store_count-other_gd_num) cbuy=store_count-other_gd_num;
2746 2746
2747 var false_data = res_d.data.data; 2747 var false_data = res_d.data.data;
2748 //--判断库存-- 2748 //--判断库存--
@@ -2789,7 +2789,7 @@ Page({ @@ -2789,7 +2789,7 @@ Page({
2789 e.update_cart(t, pitem, item); 2789 e.update_cart(t, pitem, item);
2790 2790
2791 } else { 2791 } else {
2792 - e.normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds); //普通商品的调用和计算 2792 + e.normal_check(t, item, pitem,store_count,limit,other_gd_num,goodsinfo, wareIds); //普通商品的调用和计算
2793 } 2793 }
2794 break; 2794 break;
2795 case 2: 2795 case 2:
@@ -2799,7 +2799,7 @@ Page({ @@ -2799,7 +2799,7 @@ Page({
2799 if (res.data.code == 0 && res.data.data) { 2799 if (res.data.code == 0 && res.data.data) {
2800 2800
2801 var cbuy=limit; 2801 var cbuy=limit;
2802 - if (t.goods_num > store_count && !is_showing) { 2802 + if (t.goods_num > store_count-other_gd_num && !is_showing) {
2803 wx.showToast({ 2803 wx.showToast({
2804 title: '购买数量超出商品库存', 2804 title: '购买数量超出商品库存',
2805 icon: 'none', 2805 icon: 'none',
@@ -2807,7 +2807,7 @@ Page({ @@ -2807,7 +2807,7 @@ Page({
2807 is_showing=1; 2807 is_showing=1;
2808 } 2808 }
2809 //一直都要给一个最小值,和库存比较 2809 //一直都要给一个最小值,和库存比较
2810 - if(cbuy>store_count) cbuy=store_count; 2810 + if(cbuy>store_count) cbuy=store_count-other_gd_num;
2811 2811
2812 var gr_data = res.data.data; 2812 var gr_data = res.data.data;
2813 //--判断库存-- 2813 //--判断库存--
@@ -2853,11 +2853,11 @@ Page({ @@ -2853,11 +2853,11 @@ Page({
2853 e.update_cart(t, pitem, item); 2853 e.update_cart(t, pitem, item);
2854 2854
2855 } else { 2855 } else {
2856 - e.normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds); //普通商品的调用和计算 2856 + e.normal_check(t, item, pitem,store_count,limit,other_gd_num,goodsinfo, wareIds); //普通商品的调用和计算
2857 } 2857 }
2858 break; 2858 break;
2859 default: 2859 default:
2860 - e.normal_check(t, item, pitem,store_count,limit, goodsinfo, wareIds); //普通商品的调用和计算 2860 + e.normal_check(t, item, pitem,store_count,limit,other_gd_num,goodsinfo, wareIds); //普通商品的调用和计算
2861 break 2861 break
2862 } 2862 }
2863 } 2863 }
@@ -2865,7 +2865,7 @@ Page({ @@ -2865,7 +2865,7 @@ Page({
2865 }, 2865 },
2866 2866
2867 //-- 这个函数在计算的时候,要包含限购的那一部分 -- 2867 //-- 这个函数在计算的时候,要包含限购的那一部分 --
2868 - async normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds){ 2868 + async normal_check(t, item, pitem,store_count,limit,other_gd_num,goodsinfo, wareIds){
2869 2869
2870 var cx_arr=await getApp().get_has_cx_act(goodsinfo.goods_id); 2870 var cx_arr=await getApp().get_has_cx_act(goodsinfo.goods_id);
2871 2871
@@ -2873,6 +2873,8 @@ Page({ @@ -2873,6 +2873,8 @@ Page({
2873 // getApp().my_warnning('购买数量超出商品库存', 0, th); 2873 // getApp().my_warnning('购买数量超出商品库存', 0, th);
2874 var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; 2874 var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num";
2875 2875
  2876 +
  2877 + var cQty=store_count;
2876 //--- 看一下是不是线下库存 --- 2878 //--- 看一下是不是线下库存 ---
2877 if (th.data.sales_rules >= 2 && !goodsinfo.whsle_id) { 2879 if (th.data.sales_rules >= 2 && !goodsinfo.whsle_id) {
2878 2880
@@ -2881,63 +2883,63 @@ Page({ @@ -2881,63 +2883,63 @@ Page({
2881 await th.check_down_line_next(t, pitem, item, erpwareid, function (res) { 2883 await th.check_down_line_next(t, pitem, item, erpwareid, function (res) {
2882 ob = res; 2884 ob = res;
2883 }); 2885 });
  2886 + cQty=ob.CanOutQty;
  2887 + }
2884 2888
2885 2889
2886 - } else { 2890 + var is_showing=0;
  2891 + var cbuy=limit;
  2892 + if (t.goods_num > limit) {
  2893 + wx.showToast({
  2894 + title: '购买数量超出商品限购',
  2895 + icon: 'none',
  2896 + });
  2897 + is_showing=1;
  2898 + }
2887 2899
2888 - var is_showing=0;  
2889 - var cbuy=limit;  
2890 - if (t.goods_num > limit) {  
2891 - wx.showToast({  
2892 - title: '购买数量超出商品限购',  
2893 - icon: 'none',  
2894 - });  
2895 - is_showing=1; 2900 + if (t.goods_num > cQty-other_gd_num) {
  2901 + if(!is_showing){
  2902 + wx.showToast({
  2903 + title: '购买数量超出商品库存',
  2904 + icon: 'none',
  2905 + });
  2906 + is_showing=1;
2896 } 2907 }
  2908 + }
  2909 + if(cbuy>cQty-other_gd_num) cbuy=cQty-other_gd_num;
2897 2910
2898 - if (t.goods_num > store_count) {  
2899 - if(!is_showing){  
2900 - wx.showToast({  
2901 - title: '购买数量超出商品库存',  
2902 - icon: 'none',  
2903 - });  
2904 - is_showing=1;  
2905 - }  
2906 - }  
2907 - if(cbuy>store_count) cbuy=store_count; 2911 + if(t.goods_num>cbuy) t.goods_num=cbuy;
2908 2912
2909 - if(t.goods_num>cbuy) t.goods_num=cbuy; 2913 + if([0,3,5,7,10].indexOf(goodsinfo.prom_type)>-1){
  2914 + var mo_num=getApp().get_limit_qty(goodsinfo,cx_arr.length);
  2915 + var steep=getApp().get_limit_qty(goodsinfo,cx_arr.length,1);
2910 2916
2911 - if([0,3,5,7,10].indexOf(goodsinfo.prom_type)>-1){  
2912 - var mo_num=getApp().get_limit_qty(goodsinfo,cx_arr.length);  
2913 - var steep=getApp().get_limit_qty(goodsinfo,cx_arr.length,1); 2917 + if(mo_num>1 && t.goods_num<mo_num){
  2918 + if(!is_showing) {
  2919 + wx.showToast({
  2920 + title: '购买数量小于商品的起订量',
  2921 + icon: 'none',
  2922 + });
  2923 + }
  2924 + t.goods_num=mo_num;
  2925 + }
2914 2926
2915 - if(mo_num>1 && t.goods_num<mo_num){ 2927 + if(steep>1 && t.goods_num>mo_num && (t.goods_num-mo_num)%steep!=0){
2916 if(!is_showing) { 2928 if(!is_showing) {
2917 - wx.showToast({  
2918 - title: '购买数量小于商品的起订量',  
2919 - icon: 'none',  
2920 - }); 2929 + wx.showToast({
  2930 + title: '购买数量必须是起订量的倍数',
  2931 + icon: 'none',
  2932 + });
2921 } 2933 }
2922 - t.goods_num=mo_num;  
2923 - } 2934 + if(t.goods_num<mo_num) t.goods_num=mo_num;
  2935 + else{
  2936 + t.goods_num=mo_num+parseInt((t.goods_num-mo_num)/steep+'')*steep
  2937 + }
  2938 + }
  2939 + }
2924 2940
2925 - if(steep>1 && t.goods_num>mo_num && (t.goods_num-mo_num)%steep!=0){  
2926 - if(!is_showing) {  
2927 - wx.showToast({  
2928 - title: '购买数量必须是起订量的倍数',  
2929 - icon: 'none',  
2930 - });  
2931 - }  
2932 - if(t.goods_num<mo_num) t.goods_num=mo_num;  
2933 - else{  
2934 - t.goods_num=mo_num+parseInt((t.goods_num-mo_num)/steep+'')*steep  
2935 - }  
2936 - }  
2937 - } 2941 + th.update_cart(t, pitem, item);
2938 2942
2939 - th.update_cart(t, pitem, item);  
2940 - }  
2941 }, 2943 },
2942 2944
2943 //----------------------更新购物数量,加减,调用接口--------------------- 2945 //----------------------更新购物数量,加减,调用接口---------------------
@@ -3076,18 +3078,14 @@ Page({ @@ -3076,18 +3078,14 @@ Page({
3076 await th.doCheckAll(); 3078 await th.doCheckAll();
3077 await th.update_cart_ser(t, pitem, item); 3079 await th.update_cart_ser(t, pitem, item);
3078 return false; 3080 return false;
3079 - };  
3080 - 3081 + }
3081 } 3082 }
3082 3083
3083 -  
3084 } 3084 }
3085 3085
3086 3086
3087 await e.doCheckAll(); 3087 await e.doCheckAll();
3088 await e.update_cart_ser(t, pitem, item); 3088 await e.update_cart_ser(t, pitem, item);
3089 -  
3090 -  
3091 }, 3089 },
3092 3090
3093 3091