Commit cde5f2d2c202bf4aec45fc2bc207ae9eb614b59e

Authored by 前端开发-罗建龙
1 parent 886dff49

预存使用场景增加1、积分购 2、秒杀 3、预售

packageC/pages/presell/cart/cart2_pre.js
... ... @@ -5,939 +5,1177 @@ var regeneratorRuntime = require('../../../../utils/runtime.js');
5 5 var util_pay = require("../../../../utils/pay.js");
6 6  
7 7 Page({
8   - data: {
9   - url: t.globalData.setting.url,
10   - resourceUrl: t.globalData.setting.resourceUrl,
11   - imgUrl: t.globalData.setting.imghost,
12   - goods: null,
13   - order: null,
14   - orderPrices: null,
15   - coupons: null,
16   - coupon: null,
17   - invoiceToggle: !0,
18   - payWithUserMoney: !0,
19   - payWithPoints: !0,
20   - maxWord: 0,
21   - enterAddressPage: !1,
22   - firstEnter: !0,
23   - //页面获取的参数
24   - param: null,
25   - postdata: null,
26   - //提交订单的格式
27   - formData: {
28   - order_amount: 0,//支付金额
29   - total_amount: 0,//总价
30   - all_price: 0,//商品卖的总价
31   - pay_points: 0,//使用积分
32   - user_money: 0,//使用余额
33   - couponCode: "",//使用优惠券(多单就用逗号隔开)
34   - shipping_price: 0,//物流费用
35   - },
36   -
37   - /*----------------立即购买---------------------*/
38   - is_b_now: 0, //0是购物车结算 1立即购买
39   - bn_goods: null, //立即购买时候的调用商品
40   - bn_use_money: 0,//是否使用余额
41   - bn_exp_type: 1, //0是物流 1自提
42   - bn_pick: 0, //选择的门店
43   - bn_pickname: "", //选择的门店名称
44   - bn_t_exp_t: 0, //判断商品和门店一起决定的物流自提的方式0 都可以 1自提 2物流
45   - /*------------------------*/
46   - user_addr: null,//物流
47   - userinfo: null, //获取会员
48   - /*----------物流选择--------*/
49   - wu_arr: null,
50   - index: 0,
51   -
52   - //判断页面是返回回来的还是 首次进入的
53   - isclose: 1,
54   - is_express: 0,//选择物流的控制器
55   - yuer: 0,
56   - agree_no_ref: 0
57   - },
58   - onLoad: function (t) {
59   - wx.setNavigationBarTitle({
60   - title: "填写订单",
61   - });
62   - var th = this; this.setData({ is_b_now: 1 });
63   - th.data.postdata = getApp().get_b_now();
64   - th.data.param = t;
65   -
66   - },
67   - onUnload: function () { this.setData({ isclose: 1 }) },
68   -
69   - //------获取会员信息-----先获取用户信息,在进行下一步---
70   - get_info: function (func) {
71   - var user_id = t.globalData.user_id;
72   - app.auth.get_u(func);
73   - },
74   -
75   - //-------------------获取物流---------------
76   - get_wuliu(func) {
77   - var th = this;
78   - app.getwuliu(function (e) {
79   - if (th.data.is_default_logistics) {
80   - //如果第一个不是开启默认,说明要让用户自己选
81   - if (!e[0].is_default) {
82   - th.setData({ is_default_logistics: 0 });
83   - }
84   - }
85   - th.setData({ wu_arr: e })
86   - typeof func == "function" && func();
87   - })
  8 + data: {
  9 + url: t.globalData.setting.url,
  10 + resourceUrl: t.globalData.setting.resourceUrl,
  11 + imgUrl: t.globalData.setting.imghost,
  12 + goods: null,
  13 + order: null,
  14 + orderPrices: null,
  15 + coupons: null,
  16 + coupon: null,
  17 + invoiceToggle: !0,
  18 + payWithUserMoney: !0,
  19 + payWithPoints: !0,
  20 + maxWord: 0,
  21 + enterAddressPage: !1,
  22 + firstEnter: !0,
  23 + //页面获取的参数
  24 + param: null,
  25 + postdata: null,
  26 + //提交订单的格式
  27 + formData: {
  28 + order_amount: 0,//支付金额
  29 + total_amount: 0,//总价
  30 + all_price: 0,//商品卖的总价
  31 + pay_points: 0,//使用积分
  32 + user_money: 0,//使用余额
  33 + couponCode: "",//使用优惠券(多单就用逗号隔开)
  34 + shipping_price: 0,//物流费用
88 35 },
89 36  
90   - //------获取会员收货地址-----
91   - getuser_addr: function (func) {
92   - if (app.globalData.baddr != null) {
93   - var user_addr = app.globalData.baddr;
94   - app.globalData.baddr = null;
95   - func(user_addr);
96   - } else {
97   - a.get("/api/weshop/useraddress/page", {
98   - data: { user_id: app.globalData.user_id, store_id: os.stoid, pageSize: 600 },
99   - success: function (su) {
100   -
101   - var user_addr = su.data.data.pageData;
102   - var item = null;
103   - var def_item = null;
104   - for (var i = 0; i < user_addr.length; i++) {
105   - if (user_addr[i]['is_default'] == 1) { def_item = user_addr[i]; }
106   - if (user_addr[i]['is_pickup'] == 1) { item = user_addr[i]; }
107   - }
108   - if (item == null) item = def_item;
109   - if (item == null) item = user_addr[0];
110   - if (item == undefined) item = null;
111   - func(item);
112   - }
113   - });
  37 + /*----------------立即购买---------------------*/
  38 + is_b_now: 0, //0是购物车结算 1立即购买
  39 + bn_goods: null, //立即购买时候的调用商品
  40 + bn_use_money: 0,//是否使用余额
  41 + bn_exp_type: 1, //0是物流 1自提
  42 + bn_pick: 0, //选择的门店
  43 + bn_pickname: "", //选择的门店名称
  44 + bn_t_exp_t: 0, //判断商品和门店一起决定的物流自提的方式0 都可以 1自提 2物流
  45 + /*------------------------*/
  46 + user_addr: null,//物流
  47 + userinfo: null, //获取会员
  48 + /*----------物流选择--------*/
  49 + wu_arr: null,
  50 + index: 0,
  51 + udata: null,//用户预存值,数据
  52 + //判断页面是返回回来的还是 首次进入的
  53 + isclose: 1,
  54 + is_express: 0,//选择物流的控制器
  55 + yuer: 0,
  56 + agree_no_ref: 0
  57 + },
  58 + onLoad: function (t) {
  59 + wx.setNavigationBarTitle({
  60 + title: "填写订单",
  61 + });
  62 + var th = this; this.setData({ is_b_now: 1 });
  63 + th.data.postdata = getApp().get_b_now();
  64 + th.data.param = t;
  65 +
  66 + },
  67 + onUnload: function () { this.setData({ isclose: 1 }) },
  68 +
  69 + //------获取会员信息-----先获取用户信息,在进行下一步---
  70 + get_info: function (func) {
  71 + var user_id = t.globalData.user_id;
  72 + app.auth.get_u(func);
  73 + },
  74 +
  75 + //-------------------获取物流---------------
  76 + get_wuliu(func) {
  77 + var th = this;
  78 + app.getwuliu(function (e) {
  79 + if (th.data.is_default_logistics) {
  80 + //如果第一个不是开启默认,说明要让用户自己选
  81 + if (!e[0].is_default) {
  82 + th.setData({ is_default_logistics: 0 });
114 83 }
115   - },
116   - //----------------展示页面,是再获取用户信息之后--------------
117   - show_page: function () {
118   - var th = this;
119   - var user = getApp().globalData.userInfo;
120   - getApp().request.get("/api/weshop/users/get/" + os.stoid + "/" + user.user_id, {
121   - data: { r: Math.random() },
122   - success: function (e) {
123   -
124   - getApp().globalData.userInfo = e.data.data;
125   - th.setData({ userinfo: e.data.data });
126   - //获取立即购买的商品信息
127   - th.get_buy_goods();
128   -
129   - //获取提现金额
130   - getApp().request.get("/api/weshop/withdrawals/summoney", {
131   - data: { user_id: app.globalData.user_id, store_id: os.stoid, status: 0 },
132   - success: function (su) {
133   - if (su.data.code == 0) {
134   - var yuer = parseFloat(th.data.userinfo.user_money -
135   - (th.data.userinfo.frozen_money > 0 ? th.data.userinfo.frozen_money : 0) - su.data.data.summoney).toFixed(2);
136   - if (yuer < 0) yuer = 0;
137   - th.setData({ txmon: su.data.data.summoney, yuer: yuer });
138   - }
139   - }
140   - });
  84 + }
  85 + th.setData({ wu_arr: e })
  86 + typeof func == "function" && func();
  87 + })
  88 + },
  89 +
  90 + //------获取会员收货地址-----
  91 + getuser_addr: function (func) {
  92 + if (app.globalData.baddr != null) {
  93 + var user_addr = app.globalData.baddr;
  94 + app.globalData.baddr = null;
  95 + func(user_addr);
  96 + } else {
  97 + a.get("/api/weshop/useraddress/page", {
  98 + data: { user_id: app.globalData.user_id, store_id: os.stoid, pageSize: 600 },
  99 + success: function (su) {
  100 +
  101 + var user_addr = su.data.data.pageData;
  102 + var item = null;
  103 + var def_item = null;
  104 + for (var i = 0; i < user_addr.length; i++) {
  105 + if (user_addr[i]['is_default'] == 1) { def_item = user_addr[i]; }
  106 + if (user_addr[i]['is_pickup'] == 1) { item = user_addr[i]; }
  107 + }
  108 + if (item == null) item = def_item;
  109 + if (item == null) item = user_addr[0];
  110 + if (item == undefined) item = null;
  111 + func(item);
  112 + }
  113 + });
  114 + }
  115 + },
  116 + //----------------展示页面,是再获取用户信息之后--------------
  117 + show_page: async function () {
  118 + var th = this;
  119 + //获取用户预存款
  120 + await th.getAdvancesum()
  121 + var user = getApp().globalData.userInfo;
  122 + getApp().request.get("/api/weshop/users/get/" + os.stoid + "/" + user.user_id, {
  123 + data: { r: Math.random() },
  124 + success: function (e) {
  125 +
  126 + getApp().globalData.userInfo = e.data.data;
  127 + th.setData({ userinfo: e.data.data });
  128 + //获取立即购买的商品信息
  129 + th.get_buy_goods();
  130 +
  131 + //获取提现金额
  132 + getApp().request.get("/api/weshop/withdrawals/summoney", {
  133 + data: { user_id: app.globalData.user_id, store_id: os.stoid, status: 0 },
  134 + success: function (su) {
  135 + if (su.data.code == 0) {
  136 + var yuer = parseFloat(th.data.userinfo.user_money -
  137 + (th.data.userinfo.frozen_money > 0 ? th.data.userinfo.frozen_money : 0) - su.data.data.summoney).toFixed(2);
  138 + if (yuer < 0) yuer = 0;
  139 + th.setData({ txmon: su.data.data.summoney, yuer: yuer });
141 140 }
  141 + }
142 142 });
143   - },
144   -
145   - //-----获取立即购买的商品信息----
146   - get_buy_goods: async function () {
147   - var th = this, a = getApp().request;
148   - //定义变量
149   - var gg = th.data.postdata, act = null, prelist = null;
150   - var url = "/api/weshop/marketing/marketingPresellForm/get/" + os.stoid + "/" + gg.prom_id;
151   - await getApp().request.promiseGet(url, {}).then(res => {
152   - if (res.data.code == 0) {
153   - act = res.data.data;
154   - }
155   - })
156   - if (!act) {
157   - wx.showToast({ title: "未找到活动", icon: 'none', duration: 3000 });
158   - return false;
159   - }
160   - if (act.is_end == 1) {
161   - wx.showToast({ title: '活动已经结束', icon: 'none', duration: 3000 });
162   - return false;
163   - }
164   - if (ut.gettimestamp() > act.end_time) {
165   - wx.showToast({ title: "活动定金支付时间已过期", icon: 'none', duration: 3000 });
166   - return false;
167   - }
  143 + }
  144 + });
  145 + },
  146 +
  147 + //-----获取立即购买的商品信息----
  148 + get_buy_goods: async function () {
  149 + var th = this, a = getApp().request;
  150 + //定义变量
  151 + var gg = th.data.postdata, act = null, prelist = null;
  152 + var url = "/api/weshop/marketing/marketingPresellForm/get/" + os.stoid + "/" + gg.prom_id;
  153 + await getApp().request.promiseGet(url, {}).then(res => {
  154 + if (res.data.code == 0) {
  155 + act = res.data.data;
  156 + }
  157 + })
  158 + if (!act) {
  159 + wx.showToast({ title: "未找到活动", icon: 'none', duration: 3000 });
  160 + return false;
  161 + }
  162 + if (act.is_end == 1) {
  163 + wx.showToast({ title: '活动已经结束', icon: 'none', duration: 3000 });
  164 + return false;
  165 + }
  166 + if (ut.gettimestamp() > act.end_time) {
  167 + wx.showToast({ title: "活动定金支付时间已过期", icon: 'none', duration: 3000 });
  168 + return false;
  169 + }
168 170  
169   - var url = "/api/weshop/marketing/marketingPresellList/get/" + os.stoid + "/" + gg.presell_list_id;
170   - await getApp().request.promiseGet(url, {}).then(res => {
171   - if (res.data.code == 0) {
172   - prelist = res.data.data;
173   - }
174   - })
175   - if (!prelist) {
176   - wx.showToast({ title: "未找到商品", icon: 'none', duration: 3000 });
177   - return false;
178   - }
179   - //-- 调用商品 --
180   - a.get("/api/weshop/goods/get/" + os.stoid + "/" + gg.goods_id, {
181   - success: function (t) {
182   - var gd = t.data.data;
183   - if (!gd) return false;
  171 + var url = "/api/weshop/marketing/marketingPresellList/get/" + os.stoid + "/" + gg.presell_list_id;
  172 + await getApp().request.promiseGet(url, {}).then(res => {
  173 + if (res.data.code == 0) {
  174 + prelist = res.data.data;
  175 + }
  176 + })
  177 + if (!prelist) {
  178 + wx.showToast({ title: "未找到商品", icon: 'none', duration: 3000 });
  179 + return false;
  180 + }
  181 + //-- 调用商品 --
  182 + a.get("/api/weshop/goods/get/" + os.stoid + "/" + gg.goods_id, {
  183 + success: function (t) {
  184 + var gd = t.data.data;
  185 + if (!gd) return false;
184 186  
185   - t.data.data.original_img = os.imghost + t.data.data.original_img;
186   - t.data.data['buynum'] = gg.goods_num;
  187 + t.data.data.original_img = os.imghost + t.data.data.original_img;
  188 + t.data.data['buynum'] = gg.goods_num;
187 189  
188   - var distr_t = 0, et = 0;
  190 + var distr_t = 0, et = 0;
189 191  
190   - if(t.data.data.is_minishop==1 && getApp().is_sp_hao()){
  192 + if (t.data.data.is_minishop == 1 && getApp().is_sp_hao()) {
191 193  
192   - if(t.data.data.distr_type==1 || gg.pick_dis==1) {
193   - wx.showToast({
194   - title: "视频号仅支持物流",
195   - icon: 'none',
196   - duration: 2000
197   - })
  194 + if (t.data.data.distr_type == 1 || gg.pick_dis == 1) {
  195 + wx.showToast({
  196 + title: "视频号仅支持物流",
  197 + icon: 'none',
  198 + duration: 2000
  199 + })
198 200  
199   - setTimeout(function(){
200   - wx.navigateBack({delta: 1})
201   - },1000)
  201 + setTimeout(function () {
  202 + wx.navigateBack({ delta: 1 })
  203 + }, 1000)
202 204  
203   - return false
204   - }
  205 + return false
  206 + }
205 207  
206   - t.data.data.distr_type=2;
207   - th.setData({show_same_city:0})
  208 + t.data.data.distr_type = 2;
  209 + th.setData({ show_same_city: 0 })
208 210  
209   - }
  211 + }
210 212  
211 213  
212   - if (t.data.data.distr_type == 0) {
213   - distr_t = gg.pick_dis;
214   - } else {
215   - distr_t = t.data.data.distr_type;
216   - }
  214 + if (t.data.data.distr_type == 0) {
  215 + distr_t = gg.pick_dis;
  216 + } else {
  217 + distr_t = t.data.data.distr_type;
  218 + }
217 219  
218   - if (act.presell_type == 1) {
219   - switch (distr_t) {
220   - case 0:
221   - et = 1;
222   - //-- 系统后台有设置要默认的 --
223   - if (th.data.json_d.pickupway && th.data.json_d.pickupway == 1) et = 0;
224   - break;
225   - case 1:
226   - et = 1;
227   - break;
228   - case 2:
229   - et = 0;
230   - break;
231   - }
232   - } else {
233   - et = 1; //要付定金的时候
234   - }
  220 + if (act.presell_type == 1) {
  221 + switch (distr_t) {
  222 + case 0:
  223 + et = 1;
  224 + //-- 系统后台有设置要默认的 --
  225 + if (th.data.json_d.pickupway && th.data.json_d.pickupway == 1) et = 0;
  226 + break;
  227 + case 1:
  228 + et = 1;
  229 + break;
  230 + case 2:
  231 + et = 0;
  232 + break;
  233 + }
  234 + } else {
  235 + et = 1; //要付定金的时候
  236 + }
235 237  
236   - t.data.data.shop_price = prelist.presell_money;
237   - th.setData({
238   - bn_goods: t.data.data, bn_pickname: gg.pick_name, prelist: prelist, act: act,
239   - bn_pick: gg.pick_id, bn_t_exp_t: distr_t, bn_exp_type: et
240   - });
241   - //计算价格
242   - th.calculatePrice2();
243   - }
  238 + t.data.data.shop_price = prelist.presell_money;
  239 + th.setData({
  240 + bn_goods: t.data.data, bn_pickname: gg.pick_name, prelist: prelist, act: act,
  241 + bn_pick: gg.pick_id, bn_t_exp_t: distr_t, bn_exp_type: et
244 242 });
245   - },
246   -
247   - //----------子页返回父页触发----------
248   - onShow: function () {
249   - var th = this;
250   - if (th.data.isclose == 0) {
251   - wx.navigateTo({
252   - url: "/pages/index/index/index"
253   - })
254   - } else {
255   - this.getuser_addr(function (ie) {
256   - //更换地址回来要重新调用计算价钱的接口
257   - th.setData({ user_addr: ie });
258   - if (!th.data.user_addr || th.data.user_addr.address_id != ie.address_id) {
259   - th.setData({ add_back: 1 });
260   - if (th.data.bn_goods) th.calculatePrice2();
261   - }
262   - })
263   - //--更新默认地址--,看一下是不是跳到地址页面
264   - if (!getApp().globalData.is_cart_old) {
265   - this.update_code();
266   - } else {
267   - getApp().globalData.is_cart_old = 0;
268   - }
  243 + //计算价格
  244 + th.calculatePrice2();
  245 + }
  246 + });
  247 + },
  248 +
  249 + //----------子页返回父页触发----------
  250 + onShow: function () {
  251 + var th = this;
  252 + if (th.data.isclose == 0) {
  253 + wx.navigateTo({
  254 + url: "/pages/index/index/index"
  255 + })
  256 + } else {
  257 + this.getuser_addr(function (ie) {
  258 + //更换地址回来要重新调用计算价钱的接口
  259 + th.setData({ user_addr: ie });
  260 + if (!th.data.user_addr || th.data.user_addr.address_id != ie.address_id) {
  261 + th.setData({ add_back: 1 });
  262 + if (th.data.bn_goods) th.calculatePrice2();
269 263 }
  264 + })
  265 + //--更新默认地址--,看一下是不是跳到地址页面
  266 + if (!getApp().globalData.is_cart_old) {
  267 + this.update_code();
  268 + } else {
  269 + getApp().globalData.is_cart_old = 0;
  270 + }
  271 + }
270 272  
271   - //先获取是否有关闭使用优惠券
272   - getApp().getConfig2(function (ee) {
273   - var json_d = JSON.parse(ee.switch_list);
274   - th.data.json_d = json_d;
275   - th.data.ispt_goods = json_d.ispt_goods; //是不是平摊到单品的控制参数赋值
276   - var is_default_logistics = json_d.is_default_logistics;
277   -
278   - th.setData({ is_close_quan: json_d.is_close_quan, sales_rules: ee.sales_rules, rank_switch: json_d.rank_switch, is_default_logistics: is_default_logistics });
279   -
280   - var rank_switch = json_d.rank_switch;
281   - var max_price = -1;
282   - var show_card = null;
283   - var name = "";
284   - //如果有开等级卡的时候,
285   - //因为都是调接口,要返回在计算
286   - if (rank_switch == 2) {
287   - //-- 获取所有的等级卡, --
288   - getApp().request.promiseGet("/api/weshop/plus/vip/mem/bership/list?storeId=" + os.stoid,
289   - {}).then(res => {
290   - if (res.data.code == 0) {
291   - var plusCard = res.data.data;
292   - //-- 循环判断,拿到最贵的那张卡 --
293   - for (var ih in plusCard) {
294   - if (plusCard[ih].IsStopBuy == true) { continue; }
295   - if (max_price < 0) {
296   - max_price = plusCard[ih].CardFee;
297   - name = 'card' + plusCard[ih]['CorrPrice'];
298   - show_card = plusCard[ih];
299   - } else {
300   - if (max_price < plusCard[ih].CardFee) {
301   - max_price = plusCard[ih].CardFee;
302   - name = 'card' + plusCard[ih]['CorrPrice'];
303   - show_card = plusCard[ih];
304   - }
305   - }
306   - }
307   -
308   - if (show_card) {
309   - name = name.toLowerCase();
310   - th.setData({ card_name: name, show_card: show_card })
311   - }
312   - }
313   - //-----先获取物流,再获取用户信息,再展示页面-----
314   - th.get_wuliu(th.get_info(th.show_page));
315   - })
316   - } else {
317   - //-----先获取物流,再获取用户信息,再展示页面-----
318   - th.get_wuliu(th.get_info(th.show_page));
319   - }
320   - }, 1)
  273 + //先获取是否有关闭使用优惠券
  274 + getApp().getConfig2(function (ee) {
  275 + var json_d = JSON.parse(ee.switch_list);
  276 + th.data.json_d = json_d;
  277 + th.data.ispt_goods = json_d.ispt_goods; //是不是平摊到单品的控制参数赋值
  278 + var is_default_logistics = json_d.is_default_logistics;
  279 +
  280 + th.setData({ is_close_quan: json_d.is_close_quan, sales_rules: ee.sales_rules, rank_switch: json_d.rank_switch, is_default_logistics: is_default_logistics });
  281 +
  282 + var rank_switch = json_d.rank_switch;
  283 + var max_price = -1;
  284 + var show_card = null;
  285 + var name = "";
  286 + //如果有开等级卡的时候,
  287 + //因为都是调接口,要返回在计算
  288 + if (rank_switch == 2) {
  289 + //-- 获取所有的等级卡, --
  290 + getApp().request.promiseGet("/api/weshop/plus/vip/mem/bership/list?storeId=" + os.stoid,
  291 + {}).then(res => {
  292 + if (res.data.code == 0) {
  293 + var plusCard = res.data.data;
  294 + //-- 循环判断,拿到最贵的那张卡 --
  295 + for (var ih in plusCard) {
  296 + if (plusCard[ih].IsStopBuy == true) { continue; }
  297 + if (max_price < 0) {
  298 + max_price = plusCard[ih].CardFee;
  299 + name = 'card' + plusCard[ih]['CorrPrice'];
  300 + show_card = plusCard[ih];
  301 + } else {
  302 + if (max_price < plusCard[ih].CardFee) {
  303 + max_price = plusCard[ih].CardFee;
  304 + name = 'card' + plusCard[ih]['CorrPrice'];
  305 + show_card = plusCard[ih];
  306 + }
  307 + }
  308 + }
321 309  
322   - },
323   - //---------------检查是否有收货地址-------------------
324   - checkAddressList: function () {
325   - var t = this;
326   - return !(!this.data.order || null == this.data.order.userAddress) || (wx.showModal({
327   - title: "请先填写或选择收货地址~",
328   - success: function (a) {
329   - a.confirm ? t.enterAddressPage() : wx.navigateBack();
330   - },
331   - fail: function () {
332   - wx.navigateBack();
  310 + if (show_card) {
  311 + name = name.toLowerCase();
  312 + th.setData({ card_name: name, show_card: show_card })
  313 + }
333 314 }
334   - }), !1);
335   - },
336   - showInvoice: function () {
  315 + //-----先获取物流,再获取用户信息,再展示页面-----
  316 + th.get_wuliu(th.get_info(th.show_page));
  317 + })
  318 + } else {
  319 + //-----先获取物流,再获取用户信息,再展示页面-----
  320 + th.get_wuliu(th.get_info(th.show_page));
  321 + }
  322 + }, 1)
  323 +
  324 + },
  325 + //获取预存款余额
  326 + async getAdvancesum() {
  327 + /*-----获取线下会员的预存款和优惠券的数量-----*/
  328 + let url = "/api/weshop/users/getinfo/" + os.stoid + "/" + getApp().globalData.userInfo.user_id
  329 + await getApp().request.promiseGet(url, {
  330 + data: {
  331 + isShowLoading: 0,
  332 + },
  333 + }).then(su => {
  334 + if (su.data.code == 0 && su.data.data) {
  335 + var data = su.data.data;
  336 + if (!data) data = {};
  337 + data.cashcount = parseInt(data.cashcount);
337 338 this.setData({
338   - invoiceToggle: !this.data.invoiceToggle
  339 + udata: data,
339 340 });
340   - },
341   - keyUpChangePay1: function (t) {
342   - this.setData({
343   - payWithUserMoney: !(t.detail.value.length > 0)
344   - });
345   - },
346   - keyUpChangePay2: function (t) {
347   - this.setData({
348   - payWithPoints: !(t.detail.value.length > 0)
349   - });
350   - },
351   - keyUpChangeNum: function (t) {
352   - this.setData({
353   - maxWord: t.detail.value.length
  341 + }
  342 + })
  343 +
  344 + },
  345 + //购物车预存开启关闭
  346 + prestore(e) {
  347 + let ind = e.currentTarget.dataset.ind;
  348 + let item = e.currentTarget.dataset.item
  349 + let txt = 'cartlist[' + ind + '].yck_off';
  350 + let txt1 = 'old_cartlist[' + ind + '].yck_off';
  351 + if (item.yck_off == 2) {
  352 + this.setData({ [txt]: 1, [txt1]: 1 })
  353 + } else if (item.yck_off == 1) {
  354 + this.setData({ [txt]: 2, [txt1]: 2 })
  355 + }
  356 + this.calculatePrice()//计算金额
  357 + },
  358 + //直接购买预存开启关闭
  359 + prestore2() {
  360 + let txt = 'bn_goods.yck_off';
  361 + if (this.data.bn_goods.yck_off == 2) {
  362 + this.setData({ [txt]: 1 })
  363 + } else if (this.data.bn_goods.yck_off == 1) {
  364 + this.setData({ [txt]: 2 })
  365 + }
  366 + this.calculatePrice2()//计算金额
  367 + },
  368 + //计算商品预存款前置方法------------------------------------
  369 + async beforAdvancesum(cartList) {
  370 + // let cartList= this.data.cartlist
  371 + // let cartList= arr
  372 + // let length = cartList.length
  373 + wx.showLoading({
  374 + title: '加载中',
  375 + mask: true
  376 + })
  377 + // for (let i = 0; i < length; i++) {
  378 + let item = cartList;
  379 + let goods = item.goods
  380 + let keyid = item.sto.keyid
  381 + let listform = []
  382 + goods.map(ite => {
  383 + let obj = {
  384 + wareno: ite.goods_sn,
  385 + price: ite.goods_price,
  386 + qty: ite.goods_num
  387 + }
  388 + listform.push(obj)
  389 + })
  390 + let arr = await this.getGoodsAdvancesum(keyid, listform, cartList)
  391 + // }
  392 + wx.hideLoading()
  393 + return arr
  394 + },
  395 + //计算商品预存款请求方法------------------------------------
  396 + async getGoodsAdvancesum(storageid, listform, cartList) {
  397 + let res = await getApp().request.promisePost(`/api/weshop/delphiapi/saveErpApi`, {
  398 + data: {
  399 + accdb: getApp().globalData.config.erpid,
  400 + ApiName: 'api.pos.shop.advancesum.seek',
  401 + usercode: "admin",
  402 + vipid: this.data.userinfo.erpvipid,
  403 + oddsum: "0",
  404 + advancesum: cartList.order_amount,
  405 + storageid: storageid,
  406 + listform
  407 + },
  408 + is_json: 1
  409 + })
  410 + console.log('计算商品的预存款');
  411 + console.log(res);
  412 + let yck = 0
  413 + let yckid = ""
  414 + let yckIdArr = []
  415 + let pre_json = null
  416 + if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
  417 + let resData = res.data.data
  418 + resData.map(ite => {
  419 + yck += ite.advancesum
  420 + yckIdArr.push(ite.advanceitemid)
  421 + })
  422 + pre_json = resData
  423 + }
  424 + yckid = yckIdArr.join()
  425 + let obj = {}
  426 + if (yck * 1 > 0) {
  427 + obj.yck_off = 1
  428 + } else {
  429 + obj.yck_off = 0
  430 + }
  431 + obj.yck = yck
  432 + obj.yckid = yckid
  433 + obj.pre_json = pre_json
  434 + return obj
  435 + },
  436 +
  437 +
  438 +
  439 +
  440 + //---------------检查是否有收货地址-------------------
  441 + checkAddressList: function () {
  442 + var t = this;
  443 + return !(!this.data.order || null == this.data.order.userAddress) || (wx.showModal({
  444 + title: "请先填写或选择收货地址~",
  445 + success: function (a) {
  446 + a.confirm ? t.enterAddressPage() : wx.navigateBack();
  447 + },
  448 + fail: function () {
  449 + wx.navigateBack();
  450 + }
  451 + }), !1);
  452 + },
  453 + showInvoice: function () {
  454 + this.setData({
  455 + invoiceToggle: !this.data.invoiceToggle
  456 + });
  457 + },
  458 + keyUpChangePay1: function (t) {
  459 + this.setData({
  460 + payWithUserMoney: !(t.detail.value.length > 0)
  461 + });
  462 + },
  463 + keyUpChangePay2: function (t) {
  464 + this.setData({
  465 + payWithPoints: !(t.detail.value.length > 0)
  466 + });
  467 + },
  468 + keyUpChangeNum: function (t) {
  469 + this.setData({
  470 + maxWord: t.detail.value.length
  471 + });
  472 + },
  473 + //---------计算立即购买----------
  474 + calculatePrice2: function () {
  475 + console.log('calculatePrice2');
  476 + var th = this, good = this.data.bn_goods;
  477 + //-----------计算商品总价--------------
  478 + var allpice = good.shop_price * good.buynum;
  479 + allpice = parseFloat(allpice).toFixed(2);
  480 + var txt = "formData.all_price";
  481 + th.setData({ [txt]: allpice, });
  482 + console.log(th.data.formData);
  483 +
  484 + app.getwuliuprice(async function (rs) {
  485 + var o_shipping_price = 0, goods_weight = -1, goods_piece = -1;
  486 + var out_of_weight = null; //超出多少重量
  487 +
  488 + //-----------当地址不为空,且是物流时,计算物流费用,同时阶梯团不计算拼团价格----------
  489 + if (th.data.user_addr != null && th.data.bn_exp_type == 0
  490 + && good.is_free_shipping == 0 && (th.data.kt_type != 3 || th.data.bn_goods.is_normal == 1)) {
  491 +
  492 + var user_addr = th.data.user_addr;
  493 + var req_d = {
  494 + province: user_addr.province, city: user_addr.city, district: user_addr.district,
  495 + wuliu: parseFloat(allpice).toFixed(2), store_id: os.stoid
  496 + }
  497 + var back_data = null;
  498 + await getApp().request.promisePost("/api/weshop/order/areaFreight", {
  499 + is_json: 1, data: req_d
  500 + }).then(rs => {
  501 + if (rs.data.code == 0) back_data = rs.data.data;
354 502 });
355   - },
356   - //---------计算立即购买----------
357   - calculatePrice2: function () {
358   - console.log('calculatePrice2');
359   - var th = this, good = this.data.bn_goods;
360   - //-----------计算商品总价--------------
361   - var allpice = good.shop_price * good.buynum;
362   - allpice = parseFloat(allpice).toFixed(2);
363   - var txt = "formData.all_price";
364   - th.setData({ [txt]: allpice, });
365   - console.log(th.data.formData);
366   -
367   - app.getwuliuprice(async function (rs) {
368   - var o_shipping_price = 0, goods_weight = -1, goods_piece = -1;
369   - var out_of_weight = null; //超出多少重量
370   -
371   - //-----------当地址不为空,且是物流时,计算物流费用,同时阶梯团不计算拼团价格----------
372   - if (th.data.user_addr != null && th.data.bn_exp_type == 0
373   - && good.is_free_shipping == 0 && (th.data.kt_type != 3 || th.data.bn_goods.is_normal == 1)) {
374   -
375   - var user_addr=th.data.user_addr;
376   - var req_d = {
377   - province: user_addr.province, city: user_addr.city, district: user_addr.district,
378   - wuliu: parseFloat(allpice).toFixed(2), store_id: os.stoid
379   - }
380   - var back_data = null;
381   - await getApp().request.promisePost("/api/weshop/order/areaFreight", {
382   - is_json: 1, data: req_d
383   - }).then(rs => {
384   - if (rs.data.code == 0) back_data =rs.data.data;
385   - });
386   -
387   - var gd_arr_list = [];
388   - gd_arr_list.push(good);
389   - var cut_good_weight = 0;
390   - for (let i in gd_arr_list) {
391   - let item = data[i];
392   -
393   - if (back_data && back_data['is_by_all'] && (!back_data.no_free_goods || back_data.no_free_goods.indexOf(item.goods_id) == -1)) {
394   - if (item['exp_sum_type'] == 2 && back_data.weight_free > 0) {
395   - goods_weight += item['weight'] * item['buynum'];
396   - cut_good_weight += item['weight'] * item['buynum'];
397   - }
398   - if (back_data.weight_free > 0) {
399   - out_of_weight = (back_data.weight_free * 1000) - cut_good_weight;
400   - }
401   - continue;
402   -
403   - }
404   -
405   - switch (item['exp_sum_type']) {
406   - case 1:
407   - //统一运费
408   - o_shipping_price += item['uniform_exp_sum'];
409   - break;
410   - case 2:
411   - if (goods_weight < 0) goods_weight = 0;
412   - //累积商品重量 每种商品的重量 * 数量
413   - goods_weight += item['weight'] * item['buynum'];
414   -
415   - if (back_data && back_data.is_by_all && !back_data.no_free_goods) {
416   - cut_good_weight += item['weight'] * item['buynum'];
417   - if (back_data.weight_free > 0) {
418   - out_of_weight = (back_data.weight_free * 1000) - cut_good_weight;
419   - }
420   - }
421   - break;
422   - case 3:
423   - if (goods_piece < 0) goods_piece = 0;
424   - //累积商品数量
425   - goods_piece += item['buynum'];
426   - break;
427   - }
428   - }
429   -
430   - //如果是正值的时候
431   - if (out_of_weight >= 0) out_of_weight = -cut_good_weight;
432   - else out_of_weight = -back_data.weight_free * 1000;
433   -
434   -
435   - var code = th.data.wu_arr[th.data.index].code;
436   - var shipping_price =
437   - th.calculatewuliu(code, o_shipping_price, goods_weight, out_of_weight,
438   - goods_piece, th.data.user_addr, freight_free, allpice, rs);
439   -
440   - shipping_price = parseFloat(shipping_price).toFixed(2);
441   - var wl_txt = "formData.shipping_price";
442   - th.setData({ [wl_txt]: shipping_price, })
443   -
444   - } else {
445   - var wl_txt = "formData.shipping_price";
446   - th.setData({ [wl_txt]: 0, })
447   - }
448   - //-----------------总价-----------------
449   - var total_m = parseFloat(allpice) + parseFloat(th.data.formData.shipping_price);
450   - total_m = parseFloat(total_m).toFixed(2);
451   -
452   - var atxt = "formData.total_amount";
453   - th.setData({ [atxt]: total_m, })
454   - var order_m = total_m;
455   -
456   - var txt = "formData.user_money";
457   - var txt2 = "formData.order_amount";
458   - //--------------如果使用余额---------------------
459   - if (th.data.bn_use_money == 1 && th.data.yuer > 0) {
460   - if (parseFloat(th.data.yuer) > total_m) {
461   - th.setData({ [txt]: total_m, [txt2]: 0 })
462   - } else {
463   - order_m = parseFloat(order_m) - parseFloat(th.data.yuer);
464   - order_m = order_m.toFixed(2);
465   - th.setData({ [txt]: th.data.yuer, [txt2]: order_m })
466   - }
467   - } else {
468   - th.setData({ [txt]: 0, [txt2]: order_m })
469   - }
470 503  
471   - });
  504 + var gd_arr_list = [];
  505 + gd_arr_list.push(good);
  506 + var cut_good_weight = 0;
  507 + for (let i in gd_arr_list) {
  508 + let item = data[i];
472 509  
473   - },
474   -
475   - // -- 支付的下一步 --
476   - submitForm_next: async function (t) {
477   - if (this.data.is_summit_ing == 1) return false; //--提交中退出--
478   - this.data.is_summit_ing = 1;
479   -
480   - var th = this, pdata = new Array();
481   - var ff = true;
482   - //------------立即购买-------------
483   -
484   - //如果不是阶梯团,或者是普通购买,商家选择了物流,以及地址为空的时候
485   - if (th.data.bn_exp_type == 0 && th.data.user_addr == null && (th.data.kt_type != 3 || th.data.bn_goods.is_normal == 1)) {
486   - ff = false;
487   - getApp().my_warnning("请选择收货地址", 0, this);
488   - this.data.is_summit_ing = 0;
489   - }
490   - if (!ff) return false;
491   - var addr = th.data.user_addr;
492   - if (th.data.bn_exp_type == 1) addr = null;
493   -
494   - if (th.data.bn_exp_type == 0 && (th.data.kt_type != 3)) {
495   - if (th.data.wu_arr == null || th.data.wu_arr.length <= 0) {
496   - getApp().my_warnning("读取物流失败", 0, this);
497   - this.data.is_summit_ing = 0;
498   - return false;
  510 + if (back_data && back_data['is_by_all'] && (!back_data.no_free_goods || back_data.no_free_goods.indexOf(item.goods_id) == -1)) {
  511 + if (item['exp_sum_type'] == 2 && back_data.weight_free > 0) {
  512 + goods_weight += item['weight'] * item['buynum'];
  513 + cut_good_weight += item['weight'] * item['buynum'];
499 514 }
  515 + if (back_data.weight_free > 0) {
  516 + out_of_weight = (back_data.weight_free * 1000) - cut_good_weight;
  517 + }
  518 + continue;
  519 +
  520 + }
  521 +
  522 + switch (item['exp_sum_type']) {
  523 + case 1:
  524 + //统一运费
  525 + o_shipping_price += item['uniform_exp_sum'];
  526 + break;
  527 + case 2:
  528 + if (goods_weight < 0) goods_weight = 0;
  529 + //累积商品重量 每种商品的重量 * 数量
  530 + goods_weight += item['weight'] * item['buynum'];
  531 +
  532 + if (back_data && back_data.is_by_all && !back_data.no_free_goods) {
  533 + cut_good_weight += item['weight'] * item['buynum'];
  534 + if (back_data.weight_free > 0) {
  535 + out_of_weight = (back_data.weight_free * 1000) - cut_good_weight;
  536 + }
  537 + }
  538 + break;
  539 + case 3:
  540 + if (goods_piece < 0) goods_piece = 0;
  541 + //累积商品数量
  542 + goods_piece += item['buynum'];
  543 + break;
  544 + }
500 545 }
501 546  
502   - //阶梯团强制带1,自提~~~
503   - if (th.data.kt_type == 3) {
504   - th.data.bn_exp_type = 1;
505   - }
506   -
507   - var item = {
508   - 'user_id': app.globalData.user_id,
509   - 'consignee': addr == null ? "" : addr.consignee,
510   - 'province': addr == null ? 0 : addr.province,
511   - 'city': addr == null ? 0 : addr.city,
512   - 'district': addr == null ? 0 : addr.district,
513   - 'twon': addr == null ? 0 : addr.twon,
514   - 'address': addr == null ? "" : addr.address,
515   - 'more_address': addr == null ? "" : addr.more_address,
516   - 'mobile': addr == null ? th.data.userinfo.mobile : addr.mobile,
517   - 'email': '',
518   - 'invoice_title': '',
519   - 'goods_price': th.data.formData.all_price, //商品总价
520   - 'shipping_price': th.data.formData.shipping_price, //物流金额
521   - 'user_money': th.data.formData.user_money, //使用余额
522   - 'total_amount': th.data.formData.total_amount, //订单总价
523   - 'order_amount': th.data.formData.order_amount, //应付
524   - 'user_note': t.detail.value.user_note, //用户备注
525   - 'store_id': os.stoid, //商家
526   - 'pickup_id': th.data.bn_pick, //门店
527   - 'prom_type': th.data.bn_goods.prom_type, //促销活动类型
528   - 'prom_id': th.data.bn_goods.prom_id, //促销活动id
529   - 'order_goods': new Array(),
530   - };
531   -
532   - //老会员成为分销下线需要的参数
533   - if (getApp().globalData.first_leader && !getApp().globalData.userInfo.first_leader) {
534   - //判断一下分享人是不是分享商
535   - await app.request.promiseGet("/api/weshop/users/get/" + os.stoid + "/" + getApp().globalData.first_leader, {}).then(res => {
536   - if (res.data.code == 0) {
537   - var user = res.data.data;
538   - if (user.is_distribut == 1) {
539   - item.first_leader = parseInt(getApp().globalData.first_leader);
540   - }
  547 + //如果是正值的时候
  548 + if (out_of_weight >= 0) out_of_weight = -cut_good_weight;
  549 + else out_of_weight = -back_data.weight_free * 1000;
  550 +
  551 +
  552 + var code = th.data.wu_arr[th.data.index].code;
  553 + var shipping_price =
  554 + th.calculatewuliu(code, o_shipping_price, goods_weight, out_of_weight,
  555 + goods_piece, th.data.user_addr, freight_free, allpice, rs);
  556 +
  557 + shipping_price = parseFloat(shipping_price).toFixed(2);
  558 + var wl_txt = "formData.shipping_price";
  559 + th.setData({ [wl_txt]: shipping_price, })
  560 +
  561 + } else {
  562 + var wl_txt = "formData.shipping_price";
  563 + th.setData({ [wl_txt]: 0, })
  564 + }
  565 + //-----------------总价-----------------
  566 + var total_m = parseFloat(allpice) + parseFloat(th.data.formData.shipping_price);
  567 + total_m = parseFloat(total_m).toFixed(2);
  568 +
  569 + var atxt = "formData.total_amount";
  570 + th.setData({ [atxt]: total_m, })
  571 + var order_m = total_m;
  572 +
  573 + //预存金额使用参与计算
  574 + if (th.data.udata && th.data.udata.Balance > 0 && order_m * 1 > 0) {
  575 + if (!th.data.bn_goods.keyid) {
  576 + //获取门店信息
  577 + await getApp().request.promiseGet("/api/weshop/pickup/list", {
  578 + data: {
  579 + store_id: os.stoid,
  580 + ids: th.data.bn_pick
  581 + }
  582 + }).then(res => {
  583 + if (ut.ajax_ok(res)) {
  584 + console.log(res);
  585 + if (res.data.code == 0) {
  586 + let resData = res.data.data.pageData
  587 + if (resData && resData[0]) {
  588 + let keyid = resData[0].keyid
  589 + let txt = 'bn_goods.keyid'
  590 + th.setData({
  591 + [txt]: keyid
  592 + })
541 593 }
542   - })
  594 + }
  595 + }
  596 + })
543 597 }
544   -
545   - if (th.data.qh != '') {
546   - item.team_qh = th.data.qh;
547   - item.pt_listno = th.data.qh;
  598 + if (th.data.bn_goods.keyid) {
  599 + let cart_yc = await th.beforAdvancesum({
  600 + order_amount: order_m,
  601 + goods: [{
  602 + goods_sn: th.data.bn_goods.goods_sn,
  603 + goods_price: th.data.bn_goods.shop_price || th.data.bn_goods.goods_price,
  604 + goods_num: th.data.bn_goods.buynum || th.data.bn_goods.goods_num,
  605 + }],
  606 + sto: {
  607 + keyid: th.data.bn_goods.keyid
  608 + }
  609 + })
  610 +
  611 + if (!good.yck_off) {
  612 + good.yck_off = cart_yc.yck_off
  613 + }
  614 + good.yck = cart_yc.yck
  615 + good.yckid = cart_yc.yckid
  616 + good.pre_json = cart_yc.pre_json
  617 + let yct1 = 'bn_goods.yck_off';
  618 + let yct2 = 'bn_goods.yck';
  619 + let yct3 = 'bn_goods.yckid';
  620 + let yct4 = 'bn_goods.pre_json';
  621 + th.setData({
  622 + [yct1]: good.yck_off,
  623 + [yct2]: good.yck,
  624 + [yct3]: good.yckid,
  625 + [yct4]: good.pre_json,
  626 + })
  627 +
  628 + if (good.yck_off && good.yck_off == 2) {
  629 + let order_amount = (order_m - good.yck).toFixed(2);
  630 + let yck = 0
  631 + if (order_amount * 1 > 0) {
  632 + order_m = order_amount;
  633 + // all_prestore+=parseFloat(good.yck);
  634 + yck = parseFloat(good.yck)
  635 + } else {
  636 + // all_prestore+=order_m*1
  637 + yck = parseFloat(order_m)
  638 + order_m = 0
  639 + }
  640 + let atxt10 = "formData.prestore"; //预存金额
  641 + let atxt11 = "formData.pre_json"; //预存json
  642 + let atxt12 = "formData.all_yck_arr"; //预存真实抵扣列表
  643 + th.setData({
  644 + [atxt10]: yck,
  645 + [atxt11]: [good.pre_json],
  646 + [atxt12]: [yck],
  647 + })
  648 + // formData.prestore
  649 + // all_yck_arr.push(yck) //真实预存款抵扣金额
  650 + // all_pre_json.push(good.pre_json)
  651 + // all_prestore = parseFloat(all_prestore); //真实预存款抵扣金额总和
  652 + }
548 653 }
549   -
550   - var gg = app.get_b_now();
551   - var goods = {
552   - 'goods_id': gg.goods_id,
553   - 'goods_name': gg.goods_name,
554   - 'goods_sn': gg.goods_sn,
555   - 'goods_num': gg.goods_num,
556   - 'market_price': th.data.bn_goods.market_price,
557   - 'goods_price': th.data.bn_goods.shop_price,
558   - 'member_goods_price': th.data.bn_goods.shop_price,
559   - 'store_id': os.stoid,
560   - 'prom_type': th.data.bn_goods.prom_type, //促销活动类型
561   - 'prom_id': th.data.bn_goods.prom_id, //促销活动id
562   - };
563   -
564   - if(getApp().globalData.skinface_id){
565   - goods.skinface_id=getApp().globalData.skinface_id;
  654 + } else {
  655 + let yct1 = 'bn_goods.yck_off';
  656 + let yct2 = 'bn_goods.yck';
  657 + let yct3 = 'bn_goods.yckid';
  658 + let yct4 = 'bn_goods.pre_json';
  659 + let atxt10 = "formData.prestore"; //预存金额
  660 + let atxt11 = "formData.pre_json"; //预存json
  661 + let atxt12 = "formData.all_yck_arr"; //预存真实抵扣列表
  662 + th.setData({
  663 + [yct2]: 0,
  664 + [yct3]: '',
  665 + [yct4]: '',
  666 + [atxt10]: 0,
  667 + [atxt11]: '',
  668 + [atxt12]: [],
  669 + })
  670 + }
  671 +
  672 + var txt = "formData.user_money";
  673 + var txt2 = "formData.order_amount";
  674 + //--------------如果使用余额---------------------
  675 + if (th.data.bn_use_money == 1 && th.data.yuer > 0) {
  676 + if (parseFloat(th.data.yuer) > total_m) {
  677 + th.setData({ [txt]: total_m, [txt2]: 0 })
  678 + } else {
  679 + order_m = parseFloat(order_m) - parseFloat(th.data.yuer);
  680 + order_m = order_m.toFixed(2);
  681 + th.setData({ [txt]: th.data.yuer, [txt2]: order_m })
566 682 }
  683 + } else {
  684 + th.setData({ [txt]: 0, [txt2]: order_m })
  685 + }
567 686  
568   - if(th.data.bn_goods.whsle_id){
569   - item.is_whsle=1;
570   - goods.is_whsle_goods=1;
571   - }
  687 + });
572 688  
573   - //--导购分享过来的id--
574   - if (gg.guide_id) {
575   - goods.guide_id = gg.guide_id;
576   - goods.guide_type = gg.guide_type;
577   - //调用接口判断是不是会员
578   - await getApp().request.promiseGet("/api/weshop/shoppingGuide/getId/" + os.stoid + "/" + gg.guide_id, {}).then(res => {
579   - if (res.data.code == 0) {
580   - goods.guide_name = res.data.data.salesman;
581   - goods.guide_sn = res.data.data.salesman_no;
582   - }
583   - })
584   - }
  689 + },
585 690  
586   - //--商品的房间号--
587   - if (gg.room_id && gg.room_id > 0) {
588   - item.room_ids = gg.room_id;
589   - goods.room_id = gg.room_id;
590   - }
  691 + // -- 支付的下一步 --
  692 + submitForm_next: async function (t) {
  693 + if (this.data.is_summit_ing == 1) return false; //--提交中退出--
  694 + this.data.is_summit_ing = 1;
591 695  
592   - if (th.data.bn_goods.is_normal) { goods.is_pd_normal = 1; }
593   -
594   - item.order_goods.push(goods);
595   - pdata.push(item);
596   -
597   - if (pdata.length == 0) return;
598   - var str = JSON.stringify(pdata);
599   - wx.showLoading({ title: "加载中" });
600   - wx.request({
601   - url: os.url + '/api/weshop/order/createWxdOrder',
602   - data: str,
603   - method: 'POST',
604   - header: {
605   - 'content-type': 'application/json'
606   - },// 设置请求的 header
607   - success: function (res) {
608   -
609   - wx.hideLoading();
610   - if (res.statusCode == 200) {
611   - var data = res.data;
612   - if (data.code == 0) {
613   - console.log(th.data.is_b_now);
614   - //如果是购物车结算,还要删除购物车
615   - if (th.data.is_b_now == 0) {
616   - console.log(th.data.cartlist_y);
617   - var list = th.data.cartlist_y;
618   - for (var i = 0; i < list.length; i++) {
619   - //删除购物车
620   - getApp().request.delete("/api/weshop/cart/del/" + os.stoid + "/" + list[i].id, {});
621   - }
622   - }
623   - var order_amount = 0;
624   - pdata.forEach(function (em, ind) {
625   - order_amount += em.order_amount;
626   - })
627   - //要进行判断,如果是用微信支付,就要跳转到支付界面
628   - if (order_amount > 0) {
629   - th.setData({ isclose: 0 });
630   - util_pay.pay(data.data, function () {
631   - var url = "/packageC/pages/presell/cart/cart?order_sn=" + data.data;
632   - setTimeout(function () {
633   - wx.reLaunch({ url: url, })
634   - }, 1000)
635   - }, function () {
636   - //支付失败
637   - setTimeout(function () {
638   - //wx.navigateBack({ delta: 1 })
639   - wx.reLaunch({
640   - url: "/pages/user/order_list/order_list",
641   - })
642   - }, 1000)
643   -
644   - }, os.stoid, 1);
645   -
646   - } else {
647   - var dd = {
648   - parent_sn: data.data,
649   - store_id: os.stoid,
650   - type: 1,
651   - };
652   - //return false;
653   - getApp().request.post("/api/weshop/order/pay/createOrder", {
654   - data: dd,
655   - success: function (t) {
656   - console.log(t);
657   - app.my_warnning("支付成功", 1, th);
658   - setTimeout(function () {
659   - th.setData({ isclose: 0 });
660   -
661   -
662   - var url = "/packageC/pages/presell/cart/cart?order_sn=" + data.data;
663   - wx.reLaunch({
664   - url: url
665   - })
666   -
667   -
668   -
669   - }, 1000)
670   - }
671   - });
672   - }
673   - }
674   - else {
675   - th.data.is_summit_ing = 0; //是否提交中
676   - getApp().confirmBox(data.msg);
677   - }
678   - } else {
679   - th.data.is_summit_ing = 0; //是否提交中
680   - console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode);
681   - }
682   - },
683   - fail: function () {
684   - th.data.is_summit_ing = 0; //是否提交中
685   - wx.hideLoading();
686   - console.log("index.js wx.request CheckCallUser fail");
687   - },
688   - complete: function () { }
689   - })
690   - },
  696 + var th = this, pdata = new Array();
  697 + var ff = true;
  698 + //------------立即购买-------------
691 699  
  700 + //如果不是阶梯团,或者是普通购买,商家选择了物流,以及地址为空的时候
  701 + if (th.data.bn_exp_type == 0 && th.data.user_addr == null && (th.data.kt_type != 3 || th.data.bn_goods.is_normal == 1)) {
  702 + ff = false;
  703 + getApp().my_warnning("请选择收货地址", 0, this);
  704 + this.data.is_summit_ing = 0;
  705 + }
  706 + if (!ff) return false;
  707 + var addr = th.data.user_addr;
  708 + if (th.data.bn_exp_type == 1) addr = null;
  709 +
  710 + if (th.data.bn_exp_type == 0 && (th.data.kt_type != 3)) {
  711 + if (th.data.wu_arr == null || th.data.wu_arr.length <= 0) {
  712 + getApp().my_warnning("读取物流失败", 0, this);
  713 + this.data.is_summit_ing = 0;
  714 + return false;
  715 + }
  716 + }
692 717  
693   - //--------------------提交订单-----------------------
694   - submitForm: function (t) {
695   - var th = this;
696   - //如果是部分定金,商家不同意退定金,
697   - if (this.data.act.presell_type != 1 && !this.data.act.is_refundmoney && !th.agree_no_ref) {
698   - wx.showModal({
699   - content: ' 预售商品不允许退定金!是否继续下单?',
700   - showCancel: true,//是否显示取消按钮
701   - cancelText: "我在想想",//默认是“取消”
702   - confirmText: "继续下单",//默认是“确定”
703   - success: function (res) {
704   - if (res.cancel) {
705   - //点击取消,默认隐藏弹框
706   - } else {
707   - th.setData({ agree_no_ref: 1 })
708   - th.submitForm_next(t)
709   - }
710   - },
711   - })
  718 + //阶梯团强制带1,自提~~~
  719 + if (th.data.kt_type == 3) {
  720 + th.data.bn_exp_type = 1;
  721 + }
712 722  
713   - } else {
714   - this.submitForm_next(t);
  723 + var item = {
  724 + 'user_id': app.globalData.user_id,
  725 + 'consignee': addr == null ? "" : addr.consignee,
  726 + 'province': addr == null ? 0 : addr.province,
  727 + 'city': addr == null ? 0 : addr.city,
  728 + 'district': addr == null ? 0 : addr.district,
  729 + 'twon': addr == null ? 0 : addr.twon,
  730 + 'address': addr == null ? "" : addr.address,
  731 + 'more_address': addr == null ? "" : addr.more_address,
  732 + 'mobile': addr == null ? th.data.userinfo.mobile : addr.mobile,
  733 + 'email': '',
  734 + 'invoice_title': '',
  735 + 'goods_price': th.data.formData.all_price, //商品总价
  736 + 'shipping_price': th.data.formData.shipping_price, //物流金额
  737 + 'user_money': th.data.formData.user_money, //使用余额
  738 + 'total_amount': th.data.formData.total_amount, //订单总价
  739 + 'order_amount': th.data.formData.order_amount, //应付
  740 + 'user_note': t.detail.value.user_note, //用户备注
  741 + 'store_id': os.stoid, //商家
  742 + 'pickup_id': th.data.bn_pick, //门店
  743 + 'prom_type': th.data.bn_goods.prom_type, //促销活动类型
  744 + 'prom_id': th.data.bn_goods.prom_id, //促销活动id
  745 + 'order_goods': new Array(),
  746 + };
  747 +
  748 + //老会员成为分销下线需要的参数
  749 + if (getApp().globalData.first_leader && !getApp().globalData.userInfo.first_leader) {
  750 + //判断一下分享人是不是分享商
  751 + await app.request.promiseGet("/api/weshop/users/get/" + os.stoid + "/" + getApp().globalData.first_leader, {}).then(res => {
  752 + if (res.data.code == 0) {
  753 + var user = res.data.data;
  754 + if (user.is_distribut == 1) {
  755 + item.first_leader = parseInt(getApp().globalData.first_leader);
  756 + }
715 757 }
716   - },
  758 + })
  759 + }
717 760  
718   - useCoupon: function () {
719   - if (this.data.order.couponNum <= 0) {
720   - //return t.showWarning("无可用优惠券");
721   - getApp().my_warnning("无可用优惠券", 0, this);
722   - return;
723   - }
724   - var a = {
725   - lid: this.data.coupon ? this.data.coupon.id : "0"
726   - };
727   - wx.navigateTo({
728   - url: "/pages/user/checkcoupon/checkcoupon?" + s.Obj2Str(a)
729   - });
730   - },
731   - enterAddressPage: function () {
732   - getApp().globalData.is_cart_old = 1;
733   - this.data.enterAddressPage = !0, wx.navigateTo({
734   - url: "/pages/user/address_list/address_list"
735   - });
736   - },
  761 + if (th.data.qh != '') {
  762 + item.team_qh = th.data.qh;
  763 + item.pt_listno = th.data.qh;
  764 + }
737 765  
738   - //--------立即购买时,选择自提和物流-----------
739   - setexptype_w: function (t) {
740   - var th = this;
741   - var ty = t.currentTarget.dataset.t, txt = t.currentTarget.dataset.txt;
742   - th.setData({ [txt]: ty });
743   - var iszt = 1;
744   - if (ty == 0) {
745   - th.setData({ is_all_zt: 0 });
746   - } else {
747   - for (var i = 0; i < th.data.cartlist.length; i++) {
748   - var item = th.data.cartlist[i];
749   - if (item.exp_type == 0) { iszt = 0; break; }
750   - }
751   - th.setData({ is_all_zt: iszt });
752   - }
753   - //----计算此时购物车的价格----
754   - th.calculatePrice();
755   - },
  766 + var gg = app.get_b_now();
  767 + var goods = {
  768 + 'goods_id': gg.goods_id,
  769 + 'goods_name': gg.goods_name,
  770 + 'goods_sn': gg.goods_sn,
  771 + 'goods_num': gg.goods_num,
  772 + 'market_price': th.data.bn_goods.market_price,
  773 + 'goods_price': th.data.bn_goods.shop_price,
  774 + 'member_goods_price': th.data.bn_goods.shop_price,
  775 + 'store_id': os.stoid,
  776 + 'prom_type': th.data.bn_goods.prom_type, //促销活动类型
  777 + 'prom_id': th.data.bn_goods.prom_id, //促销活动id
  778 + };
  779 +
  780 + if (getApp().globalData.skinface_id) {
  781 + goods.skinface_id = getApp().globalData.skinface_id;
  782 + }
  783 +
  784 + if (th.data.bn_goods.whsle_id) {
  785 + item.is_whsle = 1;
  786 + goods.is_whsle_goods = 1;
  787 + }
756 788  
757   - //--------立即购买时,选择自提和物流----------
758   - setexptype: function (t) {
759   - var th = this;
760   - var ty = t.currentTarget.dataset.t;
761   - th.setData({ bn_exp_type: ty });
762   - //当物流为空的时候。
763   - if (ty == 0 && th.data.wu_arr == null) {
764   - return th.get_wuliu(th.calculatePrice2());
  789 + //--导购分享过来的id--
  790 + if (gg.guide_id) {
  791 + goods.guide_id = gg.guide_id;
  792 + goods.guide_type = gg.guide_type;
  793 + //调用接口判断是不是会员
  794 + await getApp().request.promiseGet("/api/weshop/shoppingGuide/getId/" + os.stoid + "/" + gg.guide_id, {}).then(res => {
  795 + if (res.data.code == 0) {
  796 + goods.guide_name = res.data.data.salesman;
  797 + goods.guide_sn = res.data.data.salesman_no;
765 798 }
766   - th.calculatePrice2()
767   - console.log('setexptype');
768   - },
  799 + })
  800 + }
769 801  
770   - //--------立即购买时,使用余额--------
771   - set_bn_useyuer: function () {
772   - var th = this;
773   - th.setData({ bn_use_money: !th.data.bn_use_money });
774   - th.calculatePrice2();
775   - },
776   - set_js_useyuer: function () {
777   - var th = this;
778   - th.setData({ js_use_money: !th.data.js_use_money });
779   - th.calculatePrice();
780   - },
  802 + //--商品的房间号--
  803 + if (gg.room_id && gg.room_id > 0) {
  804 + item.room_ids = gg.room_id;
  805 + goods.room_id = gg.room_id;
  806 + }
781 807  
782   - //-------------------计算物流---------------
783   - calculatewuliu: function (code, o_shipping_price, goods_weight, out_of_weight,
784   - goods_piece, user_addr, freight_free, o_price, rs) {
785   - var price = 0, th = this;
786   - price += parseFloat(o_shipping_price);
787   - //如果是包邮
788   - if (freight_free > 0 && o_price >= freight_free && out_of_weight >= 0) { return 0; }
789   - if (user_addr == null) { return 0; }
790   - //计算物流的config item;
791   - var item = null;
792   - //先根据 镇 县 区找计算的config
793   - item = th.get_wuliu_config(user_addr.district, code, rs);
794   - if (item == null) item = th.get_wuliu_config(user_addr.city, code, rs);
795   - if (item == null) item = th.get_wuliu_config(user_addr.province, code, rs);
796   - if (item == null) item = th.get_wuliu_default(code, rs);
797   - if (item == null) return o_shipping_price;
798   - var fw_price = 0, fp_price = 0;
799   - item = item.config;
800   - if (item == null) return o_shipping_price;
801   - //------按重量----------
802   - if (goods_weight >= 0 && item['money']) {
803   - fw_price = parseFloat(item['money']);
804   - if (goods_weight > item['first_weight']) {
805   - var fw = goods_weight - item['first_weight'];
806   - var n = Math.ceil(fw / item['second_weight'])
807   - fw_price = fw_price + n * parseFloat(item['add_money']);
808   - }
809   - }
810   - //------超出重量----------
811   - if (out_of_weight < 0 && o_price >= freight_free) {
812   - fw_price = parseFloat(item['money']);
813   - var out_of_weight = Math.abs(out_of_weight);
814   - if (out_of_weight > item['first_weight']) {
815   - var fw = out_of_weight - item['first_weight'];
816   - var n = Math.ceil(fw / item['second_weight'])
817   - fw_price = fw_price + n * parseFloat(item['add_money']);
818   - }
819   - }
820   - //------按件数----------
821   - if (goods_piece > 0) {
822   - fp_price = parseFloat(item['piecemoney']);
823   - if (goods_piece > item['first_piece']) {
824   - var fp = goods_piece - item['first_piece'];
825   - var m = Math.ceil(fp / item['second_piece'])
826   - fp_price = fp_price + m * parseFloat(item['add_piecemoney']);
827   - }
828   - }
829   - var rspice = parseFloat(price + fw_price + fp_price);
830   - return rspice;
831   - },
  808 + if (th.data.bn_goods.is_normal) { goods.is_pd_normal = 1; }
832 809  
833   - //------------循环获取config-----------
834   - get_wuliu_config: function (region_id, code, rs) {
835   - var item = null, rslist = rs.pageData;
836   - for (var i = 0; i < rslist.length; i++) {
837   - if (rslist[i].code == code && rslist[i].region_id == region_id) { item = rslist[i]; }
838   - }
839   - return item;
840   - },
841   - //-------循环获取config,code default-------
842   - get_wuliu_default: function (code, rs) {
843   - var item = null, rslist = rs.pageData;
844   - for (var i = 0; i < rslist.length; i++) {
845   - if (rslist[i].shipping_code == code && rslist[i].is_default == 1) { item = rslist[i]; }
846   - }
847   - return item;
848   - },
  810 + item.order_goods.push(goods);
  811 + pdata.push(item);
849 812  
850   - //----------立即购买,选择物流-------------
851   - bindPickerChange: function (e) {
852   - var ind = e.detail.value
853   - this.setData({ index: ind });
854   - this.calculatePrice2();
855   - },
  813 + if (pdata.length == 0) return;
856 814  
857   - //----------购物车结算,选择物流-------------
858   - bindPickerChange_w: function (e) {
859   - var ind = e.detail.value, txt = e.currentTarget.dataset.txt;
860   - this.setData({ [txt]: ind });
861   - this.calculatePrice();
862   - },
  815 + //如果有使用预存,要处理
  816 + if (th.data.formData && th.data.formData.prestore * 1 > 0) {
  817 + let formData = th.data.formData
  818 + let pre_json = formData.pre_json
  819 + let all_yck_arr = formData.all_yck_arr
  820 + pdata.map((item, i) => {
  821 + item.pre_cut = all_yck_arr[i] ? all_yck_arr[i] : 0
  822 + item.pre_preferential = 0
  823 + item.pre_json = pre_json[i] ? JSON.stringify(pre_json[i]) : ''
  824 + })
  825 + }
863 826  
864   - cart_set_err: function (e) {
865   - var txt = e.currentTarget.dataset.err;
866   - var ob = {};
867   - ob[txt] = this.data.imgUrl + "/miniapp/images/default_g_img.gif";
868   - this.setData(ob);
869   - },
870 827  
871   - //// 开启物流的弹窗
872   - show_wu_arr: function (e) {
873   - this.setData({ open_express: 1 });
874   - },
  828 + if (!pdata.keyid && th.data.bn_goods) {
  829 + pdata.map(ite => {
  830 + ite.keyid = th.data.bn_goods.keyid
  831 + })
  832 + // pdata.keyid = th.data.bn_goods.keyid
  833 + }
875 834  
876   - //更新下默认,在onshow里面
877   - update_code() {
878   - var th = this, m_wind = 0, def_exp_code = getApp().globalData.userInfo.def_exp_code;
879   -
880   - var uii = setInterval(function () {
881   - if (th.data.wu_arr) {
882   - clearInterval(uii);
883   - for (var k = 0; k < th.data.wu_arr.length; k++) {
884   - var item = th.data.wu_arr[k];
885   - if (def_exp_code == item.code) {
886   - m_wind = k;
887   - }
888   - }
889   - //--如果是立即购买--
890   - th.setData({ index: m_wind, is_express: m_wind });
  835 +
  836 + var str = JSON.stringify(pdata);
  837 + wx.showLoading({ title: "加载中" });
  838 + wx.request({
  839 + url: os.url + '/api/weshop/order/createWxdOrder',
  840 + data: str,
  841 + method: 'POST',
  842 + header: {
  843 + 'content-type': 'application/json'
  844 + },// 设置请求的 header
  845 + success: function (res) {
  846 +
  847 + wx.hideLoading();
  848 + if (res.statusCode == 200) {
  849 + var data = res.data;
  850 + if (data.code == 0) {
  851 + console.log(th.data.is_b_now);
  852 + //如果是购物车结算,还要删除购物车
  853 + if (th.data.is_b_now == 0) {
  854 + console.log(th.data.cartlist_y);
  855 + var list = th.data.cartlist_y;
  856 + for (var i = 0; i < list.length; i++) {
  857 + //删除购物车
  858 + getApp().request.delete("/api/weshop/cart/del/" + os.stoid + "/" + list[i].id, {});
  859 + }
891 860 }
892   - }, 500)
893   - },
  861 + var order_amount = 0;
  862 + pdata.forEach(function (em, ind) {
  863 + order_amount += em.order_amount;
  864 + })
  865 + //要进行判断,如果是用微信支付,就要跳转到支付界面
  866 + if (order_amount > 0) {
  867 + th.setData({ isclose: 0 });
  868 + util_pay.pay(data.data, function () {
  869 + var url = "/packageC/pages/presell/cart/cart?order_sn=" + data.data;
  870 + setTimeout(function () {
  871 + wx.reLaunch({ url: url, })
  872 + }, 1000)
  873 + }, function () {
  874 + //支付失败
  875 + setTimeout(function () {
  876 + //wx.navigateBack({ delta: 1 })
  877 + wx.reLaunch({
  878 + url: "/pages/user/order_list/order_list",
  879 + })
  880 + }, 1000)
  881 +
  882 + }, os.stoid, 1);
894 883  
895   - // 关闭物流的弹窗
896   - close_express: function () {
897   - this.setData({ open_express: 0 });
898   - },
899   - // 选择物流
900   - click_express_name: function (e) {
901   - var express_name = e.currentTarget.dataset.name, shippingcode = e.currentTarget.dataset.shippingcode;
902   - var index = e.currentTarget.dataset.idxe;
903   - var ob = { is_express: index, is_shipping_code: shippingcode, index: index };
904   - this.setData(ob);
905   - },
  884 + } else {
  885 + var dd = {
  886 + parent_sn: data.data,
  887 + store_id: os.stoid,
  888 + type: 1,
  889 + };
  890 + //return false;
  891 + getApp().request.post("/api/weshop/order/pay/createOrder", {
  892 + data: dd,
  893 + success: function (t) {
  894 + console.log(t);
  895 + app.my_warnning("支付成功", 1, th);
  896 + setTimeout(function () {
  897 + th.setData({ isclose: 0 });
  898 +
  899 +
  900 + var url = "/packageC/pages/presell/cart/cart?order_sn=" + data.data;
  901 + wx.reLaunch({
  902 + url: url
  903 + })
906 904  
907   - //点击确定物流
908   - determine_expres: function (e) {
909   - this.setData({ open_express: 0 });
910   - this.calculatePrice2();
911   - },
912   - //设置默认物流
913   - select_default_logistics: function () {
914   - var th = this;
915   - var is_shipping_code = this.data.is_shipping_code
916   - getApp().request.put("/api/weshop/users/update", {
917   - data: { user_id: getApp().globalData.user_id, store_id: os.stoid, def_exp_code: is_shipping_code },
918   - success: function (rse) {
919   - if (rse.data.code == 0) {
920   - getApp().globalData.userInfo.def_exp_code = is_shipping_code;
921   - th.setData({ open_express: 0 });
922   - //----计算此时购物车的价格,这个页面没有calculatePrice(),2021.7.19----
923   - //if(th.data.is_b_now==1) th.calculatePrice2();
924   - //else th.calculatePrice();
925   - th.calculatePrice2();
  905 +
  906 +
  907 + }, 1000)
926 908 }
  909 + });
927 910 }
928   - })
929   - },
930   -
  911 + }
  912 + else {
  913 + th.data.is_summit_ing = 0; //是否提交中
  914 + getApp().confirmBox(data.msg);
  915 + }
  916 + } else {
  917 + th.data.is_summit_ing = 0; //是否提交中
  918 + console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode);
  919 + }
  920 + },
  921 + fail: function () {
  922 + th.data.is_summit_ing = 0; //是否提交中
  923 + wx.hideLoading();
  924 + console.log("index.js wx.request CheckCallUser fail");
  925 + },
  926 + complete: function () { }
  927 + })
  928 + },
  929 +
  930 +
  931 + //--------------------提交订单-----------------------
  932 + submitForm: function (t) {
  933 + var th = this;
  934 + //如果是部分定金,商家不同意退定金,
  935 + if (this.data.act.presell_type != 1 && !this.data.act.is_refundmoney && !th.agree_no_ref) {
  936 + wx.showModal({
  937 + content: ' 预售商品不允许退定金!是否继续下单?',
  938 + showCancel: true,//是否显示取消按钮
  939 + cancelText: "我在想想",//默认是“取消”
  940 + confirmText: "继续下单",//默认是“确定”
  941 + success: function (res) {
  942 + if (res.cancel) {
  943 + //点击取消,默认隐藏弹框
  944 + } else {
  945 + th.setData({ agree_no_ref: 1 })
  946 + th.submitForm_next(t)
  947 + }
  948 + },
  949 + })
931 950  
932   - //跳转到购买卡
933   - buycard: function () {
934   - getApp().goto("/pages/user/plus/plus");
935   - getApp().globalData.plus_buy_back = 1;
936   - },
  951 + } else {
  952 + this.submitForm_next(t);
  953 + }
  954 + },
937 955  
938   - switchChange: function (e) {
939   - console.log(e, 111);
940   - this.setData({ agree_no_ref: e.detail.value });
  956 + useCoupon: function () {
  957 + if (this.data.order.couponNum <= 0) {
  958 + //return t.showWarning("无可用优惠券");
  959 + getApp().my_warnning("无可用优惠券", 0, this);
  960 + return;
  961 + }
  962 + var a = {
  963 + lid: this.data.coupon ? this.data.coupon.id : "0"
  964 + };
  965 + wx.navigateTo({
  966 + url: "/pages/user/checkcoupon/checkcoupon?" + s.Obj2Str(a)
  967 + });
  968 + },
  969 + enterAddressPage: function () {
  970 + getApp().globalData.is_cart_old = 1;
  971 + this.data.enterAddressPage = !0, wx.navigateTo({
  972 + url: "/pages/user/address_list/address_list"
  973 + });
  974 + },
  975 +
  976 + //--------立即购买时,选择自提和物流-----------
  977 + setexptype_w: function (t) {
  978 + var th = this;
  979 + var ty = t.currentTarget.dataset.t, txt = t.currentTarget.dataset.txt;
  980 + th.setData({ [txt]: ty });
  981 + var iszt = 1;
  982 + if (ty == 0) {
  983 + th.setData({ is_all_zt: 0 });
  984 + } else {
  985 + for (var i = 0; i < th.data.cartlist.length; i++) {
  986 + var item = th.data.cartlist[i];
  987 + if (item.exp_type == 0) { iszt = 0; break; }
  988 + }
  989 + th.setData({ is_all_zt: iszt });
941 990 }
  991 + //----计算此时购物车的价格----
  992 + th.calculatePrice();
  993 + },
  994 +
  995 + //--------立即购买时,选择自提和物流----------
  996 + setexptype: function (t) {
  997 + var th = this;
  998 + var ty = t.currentTarget.dataset.t;
  999 + th.setData({ bn_exp_type: ty });
  1000 + //当物流为空的时候。
  1001 + if (ty == 0 && th.data.wu_arr == null) {
  1002 + return th.get_wuliu(th.calculatePrice2());
  1003 + }
  1004 + th.calculatePrice2()
  1005 + console.log('setexptype');
  1006 + },
  1007 +
  1008 + //--------立即购买时,使用余额--------
  1009 + set_bn_useyuer: function () {
  1010 + var th = this;
  1011 + th.setData({ bn_use_money: !th.data.bn_use_money });
  1012 + th.calculatePrice2();
  1013 + },
  1014 + set_js_useyuer: function () {
  1015 + var th = this;
  1016 + th.setData({ js_use_money: !th.data.js_use_money });
  1017 + th.calculatePrice();
  1018 + },
  1019 +
  1020 + //-------------------计算物流---------------
  1021 + calculatewuliu: function (code, o_shipping_price, goods_weight, out_of_weight,
  1022 + goods_piece, user_addr, freight_free, o_price, rs) {
  1023 + var price = 0, th = this;
  1024 + price += parseFloat(o_shipping_price);
  1025 + //如果是包邮
  1026 + if (freight_free > 0 && o_price >= freight_free && out_of_weight >= 0) { return 0; }
  1027 + if (user_addr == null) { return 0; }
  1028 + //计算物流的config item;
  1029 + var item = null;
  1030 + //先根据 镇 县 区找计算的config
  1031 + item = th.get_wuliu_config(user_addr.district, code, rs);
  1032 + if (item == null) item = th.get_wuliu_config(user_addr.city, code, rs);
  1033 + if (item == null) item = th.get_wuliu_config(user_addr.province, code, rs);
  1034 + if (item == null) item = th.get_wuliu_default(code, rs);
  1035 + if (item == null) return o_shipping_price;
  1036 + var fw_price = 0, fp_price = 0;
  1037 + item = item.config;
  1038 + if (item == null) return o_shipping_price;
  1039 + //------按重量----------
  1040 + if (goods_weight >= 0 && item['money']) {
  1041 + fw_price = parseFloat(item['money']);
  1042 + if (goods_weight > item['first_weight']) {
  1043 + var fw = goods_weight - item['first_weight'];
  1044 + var n = Math.ceil(fw / item['second_weight'])
  1045 + fw_price = fw_price + n * parseFloat(item['add_money']);
  1046 + }
  1047 + }
  1048 + //------超出重量----------
  1049 + if (out_of_weight < 0 && o_price >= freight_free) {
  1050 + fw_price = parseFloat(item['money']);
  1051 + var out_of_weight = Math.abs(out_of_weight);
  1052 + if (out_of_weight > item['first_weight']) {
  1053 + var fw = out_of_weight - item['first_weight'];
  1054 + var n = Math.ceil(fw / item['second_weight'])
  1055 + fw_price = fw_price + n * parseFloat(item['add_money']);
  1056 + }
  1057 + }
  1058 + //------按件数----------
  1059 + if (goods_piece > 0) {
  1060 + fp_price = parseFloat(item['piecemoney']);
  1061 + if (goods_piece > item['first_piece']) {
  1062 + var fp = goods_piece - item['first_piece'];
  1063 + var m = Math.ceil(fp / item['second_piece'])
  1064 + fp_price = fp_price + m * parseFloat(item['add_piecemoney']);
  1065 + }
  1066 + }
  1067 + var rspice = parseFloat(price + fw_price + fp_price);
  1068 + return rspice;
  1069 + },
  1070 +
  1071 + //------------循环获取config-----------
  1072 + get_wuliu_config: function (region_id, code, rs) {
  1073 + var item = null, rslist = rs.pageData;
  1074 + for (var i = 0; i < rslist.length; i++) {
  1075 + if (rslist[i].code == code && rslist[i].region_id == region_id) { item = rslist[i]; }
  1076 + }
  1077 + return item;
  1078 + },
  1079 + //-------循环获取config,code default-------
  1080 + get_wuliu_default: function (code, rs) {
  1081 + var item = null, rslist = rs.pageData;
  1082 + for (var i = 0; i < rslist.length; i++) {
  1083 + if (rslist[i].shipping_code == code && rslist[i].is_default == 1) { item = rslist[i]; }
  1084 + }
  1085 + return item;
  1086 + },
  1087 +
  1088 + //----------立即购买,选择物流-------------
  1089 + bindPickerChange: function (e) {
  1090 + var ind = e.detail.value
  1091 + this.setData({ index: ind });
  1092 + this.calculatePrice2();
  1093 + },
  1094 +
  1095 + //----------购物车结算,选择物流-------------
  1096 + bindPickerChange_w: function (e) {
  1097 + var ind = e.detail.value, txt = e.currentTarget.dataset.txt;
  1098 + this.setData({ [txt]: ind });
  1099 + this.calculatePrice();
  1100 + },
  1101 +
  1102 + cart_set_err: function (e) {
  1103 + var txt = e.currentTarget.dataset.err;
  1104 + var ob = {};
  1105 + ob[txt] = this.data.imgUrl + "/miniapp/images/default_g_img.gif";
  1106 + this.setData(ob);
  1107 + },
  1108 +
  1109 + //// 开启物流的弹窗
  1110 + show_wu_arr: function (e) {
  1111 + this.setData({ open_express: 1 });
  1112 + },
  1113 +
  1114 + //更新下默认,在onshow里面
  1115 + update_code() {
  1116 + var th = this, m_wind = 0, def_exp_code = getApp().globalData.userInfo.def_exp_code;
  1117 +
  1118 + var uii = setInterval(function () {
  1119 + if (th.data.wu_arr) {
  1120 + clearInterval(uii);
  1121 + for (var k = 0; k < th.data.wu_arr.length; k++) {
  1122 + var item = th.data.wu_arr[k];
  1123 + if (def_exp_code == item.code) {
  1124 + m_wind = k;
  1125 + }
  1126 + }
  1127 + //--如果是立即购买--
  1128 + th.setData({ index: m_wind, is_express: m_wind });
  1129 + }
  1130 + }, 500)
  1131 + },
  1132 +
  1133 + // 关闭物流的弹窗
  1134 + close_express: function () {
  1135 + this.setData({ open_express: 0 });
  1136 + },
  1137 + // 选择物流
  1138 + click_express_name: function (e) {
  1139 + var express_name = e.currentTarget.dataset.name, shippingcode = e.currentTarget.dataset.shippingcode;
  1140 + var index = e.currentTarget.dataset.idxe;
  1141 + var ob = { is_express: index, is_shipping_code: shippingcode, index: index };
  1142 + this.setData(ob);
  1143 + },
  1144 +
  1145 + //点击确定物流
  1146 + determine_expres: function (e) {
  1147 + this.setData({ open_express: 0 });
  1148 + this.calculatePrice2();
  1149 + },
  1150 + //设置默认物流
  1151 + select_default_logistics: function () {
  1152 + var th = this;
  1153 + var is_shipping_code = this.data.is_shipping_code
  1154 + getApp().request.put("/api/weshop/users/update", {
  1155 + data: { user_id: getApp().globalData.user_id, store_id: os.stoid, def_exp_code: is_shipping_code },
  1156 + success: function (rse) {
  1157 + if (rse.data.code == 0) {
  1158 + getApp().globalData.userInfo.def_exp_code = is_shipping_code;
  1159 + th.setData({ open_express: 0 });
  1160 + //----计算此时购物车的价格,这个页面没有calculatePrice(),2021.7.19----
  1161 + //if(th.data.is_b_now==1) th.calculatePrice2();
  1162 + //else th.calculatePrice();
  1163 + th.calculatePrice2();
  1164 + }
  1165 + }
  1166 + })
  1167 + },
  1168 +
  1169 +
  1170 + //跳转到购买卡
  1171 + buycard: function () {
  1172 + getApp().goto("/pages/user/plus/plus");
  1173 + getApp().globalData.plus_buy_back = 1;
  1174 + },
  1175 +
  1176 + switchChange: function (e) {
  1177 + console.log(e, 111);
  1178 + this.setData({ agree_no_ref: e.detail.value });
  1179 + }
942 1180  
943 1181 });
... ...
packageC/pages/presell/cart/cart2_pre.wxml
... ... @@ -136,6 +136,13 @@
136 136 <view class="yu_er">使用余额 :¥{{yuer}} </view>
137 137 </view>
138 138 </view>
  139 + <!-----使用预存------>
  140 + <view class="set-mes" wx:if="{{bn_goods.yck_off}}">
  141 + <view class="use-item" bindtap='prestore2' style="padding-left:0;padding-right:0;">
  142 + <icon color="{{bn_goods.yck_off==2 ? 'red' : '#808080'}}" size="16" type="success"></icon>
  143 + <view class="yu_er">使用预存 </view>
  144 + </view>
  145 + </view>
139 146 <view class="item" wx:if="{{act.presell_type==1}}">
140 147 <view>商品金额</view>
141 148 <view class="co-red">¥ {{formData.all_price}}元</view>
... ... @@ -150,6 +157,11 @@
150 157 <view>配送费用</view>
151 158 <view class="co-red">¥ {{formData.shipping_price}}元</view>
152 159 </view>
  160 + <!-- 使用预存优惠金额 -->
  161 + <view class="item" wx:if="{{formData.prestore>0}}">
  162 + <view>使用预存</view>
  163 + <view class="co-red">- ¥ {{filters.toFix(formData.prestore,2)}}元</view>
  164 + </view>
153 165 <view class="item" wx:if="{{formData.user_money>0}}">
154 166 <view>使用余额</view>
155 167 <view class="co-red">- ¥ {{formData.user_money}}元</view>
... ...
pages/cart/cart2_inte/cart2_inte.wxml
... ... @@ -147,6 +147,17 @@
147 147 <view class="yu_er">使用余额 :¥{{yuer}} </view>
148 148 </view>
149 149 </view>
  150 +
  151 + <!-- 预存款 -->
  152 + <view class="set-mes" catchtap="prestore2" wx:if="{{bn_goods.yck_off}}">
  153 + <view class="use-item" style="justify-content: space-between;">
  154 + <view>
  155 + <icon color="{{bn_goods.yck_off==2 ? 'red' : '#808080'}}" size="16" type="success"></icon>
  156 + <view class="yu_er">使用预存</view>
  157 + </view>
  158 + <view wx:if="{{bn_goods.yck_off==2 }}">¥{{filters.toFix(bn_goods.yck,2)}}</view>
  159 + </view>
  160 + </view>
150 161  
151 162 </block>
152 163  
... ... @@ -163,6 +174,11 @@
163 174 <view>配送费用</view>
164 175 <view class="co-red">¥ {{formData.shipping_price}}元</view>
165 176 </view>
  177 + <!-- 使用预存优惠金额 -->
  178 + <view class="item" wx:if="{{formData.prestore>0}}">
  179 + <view>使用预存</view>
  180 + <view class="co-red">- ¥ {{filters.toFix(formData.prestore,2)}}元</view>
  181 + </view>
166 182 <view class="item" wx:if="{{formData.user_money>0}}">
167 183 <view>使用余额</view>
168 184 <view class="co-red">- ¥ {{formData.user_money}}元</view>
... ...