Commit 4ef8f9cc294bd6379b905453ca94e3a1ba4d7a7d

Authored by yvan.ni
1 parent 316ca131

组合购~~

packageB/components/catch/catch.js
... ... @@ -10,9 +10,7 @@ Component({
10 10 object:null,
11 11 index:0,
12 12 is_fw:0,
13   -
14   - barcode_canvas:null,
15   - qrcode_canvas:null,
  13 +
16 14 },
17 15 properties: {
18 16 // 这里定义了innerText属性,属性值可以在组件使用时指定
... ... @@ -21,23 +19,10 @@ Component({
21 19 },
22 20  
23 21 methods: {
24   - //关闭
25   - close: function (e) {
26   - this.setData({q_show: 0,barcode_canvas:null,qrcode_canvas:null });
27   - this.triggerEvent('close',{},{bubbles: true});
28   - },
29   -
30   - //打开
31   - open:function (e) {
32   - this.data.index++;
33   - var list=[{index:this.data.index }];
34   -
35   - this.setData({q_show: 1,object:e,barcode_canvas:list,qrcode_canvas:list,is_fw:e.is_fw });
36   - var val=e.val;
37   -
38   - // barcode('barcode'+this.data.index,val, 620, 160,this);
39   - qrcode('qrcode'+this.data.index, val, 520, 520,this);
40   - }
  22 + go_url:function (e) {
  23 + var url=e.currentTarget.dataset.url;
  24 + getApp().goto(url);
  25 + }
41 26 },
42 27  
43 28  
... ...
packageB/components/catch/catch.wxml
... ... @@ -4,7 +4,7 @@
4 4 <text class="t-icon t-icon-gowudai mgb20"></text>
5 5 <view class="fs28"><slot></slot></view>
6 6 </view>
7   - <view class="mgt60">
  7 + <view class="mgt60" bindtap="go_url" data-url="/pages/index/index/index">
8 8 <text class="btn">进店逛逛</text>
9 9 </view>
10 10 </view>
... ...
packageB/pages/zuhegou/index/index.js
... ... @@ -125,27 +125,12 @@ Page({
125 125 onLoad: function (options) {
126 126 self = this;
127 127 this.data.id = options.id;
128   -
129   - //获取活动信息
130   - var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + options.id;
131   - getApp().request.get(url, {
132   - success: function (e) {
133   - if (e.data.code == 0 && e.data.data) {
134   - self.setData({act: e.data.data});
135   - if (e.data.data.is_end == 0) {
136   - //-- 获取商品列表 --
137   - self.get_list();
138   - self.countDown();
139   - }
140   - } else {
141   - wx.showToast({
142   - title: e.data.msg,
143   - icon: 'none',
144   - duration: 2000
145   - })
146   - }
147   - }
148   - });
  128 + //如果有会员的时候
  129 + var userInfo = getApp().globalData.userInfo;
  130 + if(!userInfo){
  131 + getApp().goto("/pages/togoin/togoin");
  132 + return false;
  133 + }
149 134 },
150 135  
151 136 /**
... ... @@ -158,8 +143,50 @@ Page({
158 143 //如果有会员的时候
159 144 var userInfo = getApp().globalData.userInfo;
160 145 if (userInfo) {
  146 + if(!th.data.is_get_act){
  147 + //获取活动信息
  148 + var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + th.data.id+"/"+userInfo.user_id;
  149 + getApp().request.get(url, {
  150 + success: function (e) {
  151 + th.data.is_get_act=1;
  152 + if (e.data.code == 0 && e.data.data) {
  153 + self.setData({act: e.data.data});
  154 + if(e.data.data.is_show!=1){
  155 + th.setData({error:'活动未开启'});
  156 + return false;
  157 + }
  158 +
  159 + if(ut.gettimestamp()<e.data.data.start_time){
  160 + th.setData({error:'活动还未开始'});
  161 + return false;
  162 + }
  163 + if (e.data.data.is_end == 0 && ut.gettimestamp()<e.data.data.end_time ) {
  164 + //-- 获取商品列表 --
  165 + self.get_list();
  166 + self.countDown();
  167 + }
  168 + else{
  169 + th.setData({error:'活动已经过期'});
  170 + return false;
  171 + }
  172 + } else {
  173 + th.data.is_get_act=0;
  174 + th.setData({error:e.data.msg});
  175 + return false;
  176 + }
  177 + }
  178 + });
  179 + }
  180 +
161 181 //等待活动值
162   - this.waitfor(10, th.data.act, function () {
  182 + this.waitfor2(10, 'act', function () {
  183 + if(!th.data.act) return false;
  184 + if(ut.gettimestamp()<th.data.act.start_time){
  185 + return false;
  186 + }
  187 + if (th.data.act.is_end == 10 || ut.gettimestamp()>=th.data.act.end_time ) {
  188 + return false;
  189 + }
163 190 //获取头像的分享
164 191 th.get_head_temp(function () {
165 192 var txt = th.data.act.zhprice + "元任选" + th.data.act.zhbuyqty + "件";
... ... @@ -172,7 +199,7 @@ Page({
172 199 txt = "活动时间:" + start + " - " + end;
173 200 imgDraw.views[3].text = txt;
174 201  
175   - var scene = th.data.gid + "";
  202 + var scene = th.data.id + "";
176 203 var user_id = getApp().globalData.user_id;
177 204 scene += "_" + user_id;
178 205 ///二微码
... ... @@ -187,105 +214,113 @@ Page({
187 214 }
188 215 })
189 216 })
190   - })
191   - //获取用户的默认门店
192   - getApp().get_user_store(function (e) {
193   - if (!e) {
194   - th.data.fir_def_store = {}; //赋值空对象
195   - return false;
196   - }
197   - var ee = JSON.parse(JSON.stringify(e));
198   - var appd = getApp().globalData;
199   - //-- 等待定位系统的开启 --
200   - th.waitfor(15, th.data.is_get_local_ok, function () {
201   - var e = JSON.parse(JSON.stringify(ee));
202   - //如果有开启近距离的话,同时距离优不一样了
203   - if (that.data.lat != null) {
204   - //如果经纬度有变化的话
205   - if (e && appd.lat == that.data.lat && appd.lon == that.data.lon && e.distance > 0) {
206   - that.set_def_storage(e);
207   - } else {
208   - //要用接口是获取距离,js的计算不准
209   - getApp().request.promiseGet("/api/weshop/pickup/list", {
210   - data: {
211   - store_id: os.stoid,
212   - pickup_id: e.pickup_id,
213   - lat: th.data.lat,
214   - lon: th.data.lon
215   - },
216   - }).then(res => {
217   - if (res.data.code == 0) {
218   - e = res.data.data.pageData[0];
219   - if (e) {
220   - e.is_no_dis = ee.is_no_dis;
221   - appd.pk_store = e;
222   - that.set_def_storage(e);
  217 +
  218 + //获取用户的默认门店
  219 + getApp().get_user_store(function (e) {
  220 + if (!e) {
  221 + th.data.fir_def_store = {}; //赋值空对象
  222 + return false;
  223 + }
  224 + var ee = JSON.parse(JSON.stringify(e));
  225 + var appd = getApp().globalData;
  226 + //-- 等待定位系统的开启 --
  227 + th.waitfor2(15, 'is_get_local_ok', function () {
  228 +
  229 + if(!th.data.is_get_local_ok) return false;
  230 +
  231 + var e = JSON.parse(JSON.stringify(ee));
  232 + //如果有开启近距离的话,同时距离优不一样了
  233 + if (that.data.lat != null) {
  234 + //如果经纬度有变化的话
  235 + if (e && appd.lat == that.data.lat && appd.lon == that.data.lon && e.distance > 0) {
  236 + that.set_def_storage(e);
  237 + } else {
  238 + //要用接口是获取距离,js的计算不准
  239 + getApp().request.promiseGet("/api/weshop/pickup/list", {
  240 + data: {
  241 + store_id: os.stoid,
  242 + pickup_id: e.pickup_id,
  243 + lat: th.data.lat,
  244 + lon: th.data.lon
  245 + },
  246 + }).then(res => {
  247 + if (res.data.code == 0) {
  248 + e = res.data.data.pageData[0];
  249 + if (e) {
  250 + e.is_no_dis = ee.is_no_dis;
  251 + appd.pk_store = e;
  252 + that.set_def_storage(e);
  253 + }
  254 +
223 255 }
  256 + })
  257 + }
  258 + appd.lat = that.data.lat;
  259 + appd.lon = that.data.lon;
  260 + } else {
  261 + if (e) {
  262 + e.distance = null;
  263 + that.set_def_storage(e);
  264 + }
  265 + }
  266 + })
  267 + });
  268 +
  269 + //----获取系统参数-----
  270 + getApp().getConfig2(function (e) {
  271 + ee.setData({
  272 + bconfig: e,
  273 + sales_rules: e.sales_rules,
  274 + });
  275 + //设置基本参数
  276 + th.wait_for_store_config(e);
  277 +
  278 + var json_d = JSON.parse(e.switch_list);
  279 + ee.setData({
  280 + store_config: e,
  281 + sys_switch: json_d,
  282 + is_closecoupon: json_d.is_closecoupon,
  283 + is_newsales_rules: json_d.is_newsales_rules,
  284 + is_open_offline: json_d.is_pricing_open,
  285 + sales_rules: e.sales_rules
  286 + });
224 287  
  288 + //-- 计算等级价相关 --
  289 + var swithc_list = e.switch_list;
  290 + var sw_arr = JSON.parse(swithc_list);
  291 + //---如果后台又开等级卡的开关---
  292 + if (sw_arr.rank_switch && sw_arr.rank_switch == "2") {
  293 + th.setData({rank_switch: true});
  294 + //---回调卡的列表---
  295 + th.getPlusCardType(function (ob) {
  296 + th.setData({card_list: ob.card_list});
  297 + var user = getApp().globalData.userInfo;
  298 + if (!user) return false;
  299 + if (user.card_field && user['card_expiredate']) {
  300 + var str = user['card_expiredate'].replace(/-/g, '/');
  301 + var end = new Date(str);
  302 + end = Date.parse(end) / 1000;
  303 + var now = ut.gettimestamp();
  304 + //--- 判断是等级会员,且在有效期范围内 ---
  305 + if (user.card_field && now < end) {
  306 + var card_name = ob.name_map.get(user.card_field);
  307 + th.setData({
  308 + card_field: user.card_field,
  309 + card_name: card_name,
  310 + card_list: ob.card_list
  311 + });
225 312 }
226   - })
227   - }
228   - appd.lat = that.data.lat;
229   - appd.lon = that.data.lon;
230   - } else {
231   - if (e) {
232   - e.distance = null;
233   - that.set_def_storage(e);
234   - }
  313 + }
  314 +
  315 + })
235 316 }
236   - })
237   - });
238   - }
  317 + }, 1);
239 318  
240   - //----获取系统参数-----
241   - getApp().getConfig2(function (e) {
242   - ee.setData({
243   - bconfig: e,
244   - sales_rules: e.sales_rules,
245   - });
246   - //设置基本参数
247   - th.wait_for_store_config(e);
248   -
249   - var json_d = JSON.parse(e.switch_list);
250   - ee.setData({
251   - store_config: e,
252   - sys_switch: json_d,
253   - is_closecoupon: json_d.is_closecoupon,
254   - is_newsales_rules: json_d.is_newsales_rules,
255   - is_open_offline: json_d.is_pricing_open,
256   - sales_rules: e.sales_rules
257   - });
  319 + })
  320 +
  321 + }
258 322  
259   - //-- 计算等级价相关 --
260   - var swithc_list = e.switch_list;
261   - var sw_arr = JSON.parse(swithc_list);
262   - //---如果后台又开等级卡的开关---
263   - if (sw_arr.rank_switch && sw_arr.rank_switch == "2") {
264   - th.setData({rank_switch: true});
265   - //---回调卡的列表---
266   - th.getPlusCardType(function (ob) {
267   - th.setData({card_list: ob.card_list});
268   - var user = getApp().globalData.userInfo;
269   - if (!user) return false;
270   - if (user.card_field && user['card_expiredate']) {
271   - var str = user['card_expiredate'].replace(/-/g, '/');
272   - var end = new Date(str);
273   - end = Date.parse(end) / 1000;
274   - var now = ut.gettimestamp();
275   - //--- 判断是等级会员,且在有效期范围内 ---
276   - if (user.card_field && now < end) {
277   - var card_name = ob.name_map.get(user.card_field);
278   - th.setData({
279   - card_field: user.card_field,
280   - card_name: card_name,
281   - card_list: ob.card_list
282   - });
283   - }
284   - }
285 323  
286   - })
287   - }
288   - }, 1);
289 324  
290 325 },
291 326  
... ... @@ -426,24 +461,44 @@ Page({
426 461 return false;
427 462 } else {
428 463 th.setData({is_no_pipei: 0});
429   - th.add_cart_func();
  464 + th.check_is_in_cart(function () {
  465 + th.add_cart_func();
  466 + })
430 467 }
431 468 } else {
  469 +
  470 + var txt = "list[" + index + "].haveAdded";
  471 + var txt1 = "list[" + index + "].num";
  472 + var txt2 = "list[" + index + "].showNum";
  473 + th.data.sele_g = this.data.list[index];
  474 +
  475 +
432 476 wx.showModal({
433 477 title: '温馨提示',
434 478 content: '确定将该商品移出购物车?',
435 479 success (res) {
436 480 if (res.confirm) {
437 481 console.log('用户点击确定');
438   - title = '移除购物车成功';
439   - th.setData({
440   - [txt1]: 1,
441   - [txt2]: false,
442   - [txt]: !haveAdded,
443   - });
444   - wx.showToast({
445   - title: title,
446   - icon: 'success',
  482 +
  483 + var url = '/api/weshop/cart/del/' + os.stoid + '/' + th.data.sele_g.cart_id;
  484 + getApp().request.delete(url, {
  485 + success:function (res) {
  486 +
  487 + if(res.data.code==0) {
  488 + title = '移除购物车成功';
  489 + th.setData({
  490 + [txt1]: 1,
  491 + [txt2]: false,
  492 + [txt]: false,
  493 + });
  494 + wx.showToast({
  495 + title: title,
  496 + icon: 'success',
  497 + });
  498 +
  499 + th.re_sum_price();
  500 + }
  501 + }
447 502 });
448 503 } else if (res.cancel) {
449 504 console.log('用户点击取消')
... ... @@ -469,6 +524,9 @@ Page({
469 524 return false;
470 525 }
471 526  
  527 + if(this.data.changing) return false;
  528 + this.data.changing=1;
  529 +
472 530 var index = e.currentTarget.dataset.index;
473 531 this.data.sele_g = this.data.list[index];
474 532 this.data.sele_index=index;
... ... @@ -503,6 +561,8 @@ Page({
503 561 return false;
504 562 }
505 563  
  564 + if(th.data.changing) return false;
  565 + th.data.changing=1;
506 566 th.data.sele_g = item;
507 567 th.data.sele_index = index;
508 568 th.data.goodsInputNum = check_num;
... ... @@ -510,21 +570,34 @@ Page({
510 570 return false;
511 571 }
512 572  
  573 + var txt = "list[" + index + "].haveAdded";
  574 + var txt1 = "list[" + index + "].num";
  575 + var txt2 = "list[" + index + "].showNum";
  576 +
513 577 wx.showModal({
514 578 title: '温馨提示',
515 579 content: '确定将该商品移出购物车?',
516 580 success (res) {
517 581 if (res.confirm) {
518   -
519   - self.setData({
520   - showNum: false,
521   - haveAdded: false,
522   - });
523   - wx.showToast({
524   - title: '移除购物车成功',
525   - icon: 'success',
  582 + var url = '/api/weshop/cart/del/' + os.stoid + '/' + item.cart_id;
  583 + getApp().request.delete(url, {
  584 + success:function (res) {
  585 + if(res.data.code==0) {
  586 + var title = '移除购物车成功';
  587 + th.setData({
  588 + [txt1]: 1,
  589 + [txt2]: false,
  590 + [txt]: false,
  591 + });
  592 + wx.showToast({
  593 + title: title,
  594 + icon: 'success',
  595 + });
  596 + th.re_sum_price();//重新统计数量和总金额
  597 + }
  598 + }
526 599 });
527   - th.re_sum_price();//重新统计数量和总金额
  600 +
528 601 } else if (res.cancel) {
529 602 console.log('用户点击取消')
530 603 self.setData({
... ... @@ -639,19 +712,19 @@ Page({
639 712  
640 713  
641 714 //------定时等待某个值,有值才进行运算--------
642   - waitfor: function (n, pop_value, func) {
  715 + waitfor2: function (n, pop_value, func) {
643 716 var th = this;
644 717 if (n <= 0) {
645 718 func()
646 719 return false
647 720 }
648   - if (pop_value) {
  721 + if (th.data[pop_value]) {
649 722 func();
650 723 return false;
651 724 }
652 725 setTimeout(function () {
653 726 --n;
654   - th.waitfor(n, pop_value, func)
  727 + th.waitfor2(n, pop_value, func)
655 728 }, 1000);
656 729 },
657 730  
... ... @@ -808,7 +881,7 @@ Page({
808 881 th.data.adding = 0;
809 882 return getApp().my_warnning("库存不足!", 0, th);
810 883 }
811   - if (th.data.goodsInputNum > o.buyqty) {
  884 + if (th.data.goodsInputNum > o.buyqty && o.buyqty>0) {
812 885 th.data.adding = 0;
813 886 return getApp().my_warnning("超出商品活动限购!", 0, th);
814 887 }
... ... @@ -953,10 +1026,11 @@ Page({
953 1026 //---------拿出门店分类和门店------------
954 1027 get_sto(e) {
955 1028 var th = this;
956   - this.waitfor(15, th.data.is_get_local_ok, function () {
  1029 + this.waitfor2(15, 'is_get_local_ok', function () {
957 1030 if (!th.data.sele_g) return false;
958 1031 var dd = null;
959   - var g_distr_type = th.data.sele_g.distr_type;
  1032 + var g_distr_type =0;
  1033 + if(th.data.sele_g) g_distr_type=th.data.sele_g.distr_type;
960 1034 if (g_distr_type != 0) {
961 1035 dd = {
962 1036 store_id: os.stoid,
... ... @@ -1452,8 +1526,6 @@ Page({
1452 1526 var txt3 = "list[" + index + "].cart_id";
1453 1527 var txt4 = "list[" + index + "].current_price";
1454 1528  
1455   -
1456   -
1457 1529 //----先看会员在购物车中是否加入了该商品-----
1458 1530 getApp().request.get("/api/weshop/cart/page", {
1459 1531 data: {
... ... @@ -1573,12 +1645,17 @@ Page({
1573 1645 }
1574 1646 all_price = aprice;
1575 1647 }
1576   -
  1648 + this.data.changing=0;
1577 1649 this.setData({
1578 1650 all_price: all_price,
1579 1651 need_to_buy: need_to_buy,
1580 1652 all_num: all_num
1581 1653 })
  1654 +
  1655 + if(all_num<=0){
  1656 + th.data.sele_store = 0; //什么都没有选,就没有选择了门店
  1657 + }
  1658 +
1582 1659 },
1583 1660  
1584 1661 go_cart:function () {
... ...
packageB/pages/zuhegou/index/index.wxml
1 1 <wxs module="filters" src="../../../../utils/filter.wxs"></wxs>
2   -<view class="container">
  2 +<view wx:if="{{act}}" class="container">
3 3 <view class="flex jc_sb">
4 4 <view class="white">以下商品{{act.zhprice}}元任选{{act.zhbuyqty}}件</view>
5 5 <view class="rule-container" bindtap="showRule">规则详情
... ... @@ -149,7 +149,7 @@
149 149  
150 150 <painter style="position: absolute; top: -9999rpx;" palette="{{imgDraw}}" bind:imgOK="onImgOK"/>
151 151 <!-- 活动异常提醒 -->
152   -<!-- <catch>当前活动已结束</catch> -->
  152 +<catch wx:if="{{error}}">{{error}}</catch>
153 153 <warn id="warn"></warn>
154 154 <!-- 选择门店的弹框,1.1版最新的 -->
155 155 <block wx:if="{{store==1}}">
... ...
pages/cart/cart/cart.js
... ... @@ -4,8 +4,9 @@ var t = getApp(),
4 4 os=oo,
5 5 app = getApp(),
6 6 rq = t.request,
7   - ut = require("../../../utils/util.js");
8   -var regeneratorRuntime = require('../../../utils/runtime.js');
  7 + ut = require("../../../utils/util.js"),
  8 + zh_calc = require("zh_calculate.js");
  9 + var regeneratorRuntime = require('../../../utils/runtime.js');
9 10  
10 11 Page({
11 12 data: {
... ... @@ -32,6 +33,8 @@ Page({
32 33  
33 34 service_data:null,
34 35 max_sw_height:200,
  36 +
  37 + zhhe_prom:[], //组合活动需要显示差多少件
35 38 },
36 39 onLoad: function() {
37 40 var a = this,ee=a;
... ... @@ -49,7 +52,7 @@ Page({
49 52  
50 53 //判断是否有登录
51 54 t.auth.hadAuth() && t.getUserInfo(function() {
52   - a.getCardList();
  55 + //a.getCardList();
53 56 });
54 57  
55 58 },
... ... @@ -139,7 +142,9 @@ Page({
139 142 clearInterval(i);
140 143 }
141 144 },
142   -
  145 + onUnLoad(){
  146 + getApp().globalData.cart_zh_act=null;
  147 + },
143 148 //-------------获取购物车列表,要安装门店进行分类订单-----------
144 149 getCardList: function() {
145 150 var th = this;
... ... @@ -291,7 +296,42 @@ Page({
291 296 }
292 297 })
293 298 if (!isok) continue;
294   - } else if(item.prom_type == 0) {
  299 + }
  300 + else if (item.prom_type == 7) {
  301 + var isok = 1;
  302 + //如果有组合购
  303 + var url="/api/weshop/prom/zhbuy/get/"+os.stoid+"/"+item.prom_id+"/"+getApp().globalData.userInfo.user_id;
  304 + await getApp().request.promiseGet(url, {}).then(res => {
  305 + if(res.data.code==0 && res.data.data){
  306 + if(res.data.data.is_show!=1){
  307 + return false;
  308 + }
  309 + //如果活动已经结束
  310 + if(res.data.data.is_end==1){
  311 + isok=0;
  312 + }
  313 + //已经结束
  314 + if(ut.gettimestamp()>res.data.data.end_time){
  315 + isok=0;
  316 + }
  317 + //还未开始
  318 + if(ut.gettimestamp()<res.data.data.start_time){
  319 + isok=0;
  320 + }
  321 +
  322 + }else{
  323 + //未找到商品的活动
  324 + isok = 0;
  325 + }
  326 + item.act=res.data.data;
  327 + })
  328 + if (!isok){
  329 + var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id;
  330 + getApp().request.delete(url, {});
  331 + continue;
  332 + }
  333 + }
  334 + else if(item.prom_type == 0) {
295 335 //如果有优惠活动,要更新活动
296 336 await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + item.goods_id + "/1", {}).then(res => {
297 337 if (res.data.code == 0) {
... ... @@ -306,7 +346,6 @@ Page({
306 346 }
307 347 }
308 348 })
309   -
310 349 }
311 350  
312 351 all_num += item.goods_num;
... ... @@ -351,9 +390,7 @@ Page({
351 390 }
352 391 }
353 392  
354   -
355   -
356   - if(th.data.is_open_offline && th.data.is_open_offline>0){
  393 + if(th.data.is_open_offline && th.data.is_open_offline>0 && th.data.sales_rules==2){
357 394 //-- 此时要实时更新线下取价价格 --
358 395 for(var i=0;i<arr.length;i++){
359 396 //每个门店都去看下线下取价
... ... @@ -361,8 +398,38 @@ Page({
361 398 await th.set_offline(list);
362 399 }
363 400 }
  401 +
  402 + for (let u1 in arr) {
  403 + var u_item=arr[u1];
  404 + //把组合购进行分组
  405 + var obj=zh_calc.find_split(u_item);
  406 + if(!obj) continue;
  407 + //存储不同活动的商品列表
  408 + u_item.zh_prom_goods={};
  409 + for (let var1 in obj) {
  410 + var h_item=obj[var1];
  411 + var gdlist=null;
  412 + var url1 = "/api/weshop/prom/zhbuyGoods/page";
  413 + var req_data = {
  414 + page: 1,
  415 + pageSize: 2000,
  416 + store_id: os.stoid,
  417 + zh_id: h_item.prom_id,
  418 + }
  419 + await getApp().request.promiseGet(url1, {
  420 + data: req_data
  421 + }).then(res => {
  422 + if (ut.ajax_ok(res)) {
  423 + gdlist = res.data.data.pageData;
  424 + }
  425 + })
  426 + //获取活动需要的商品列表
  427 + u_item.zh_prom_goods[h_item.prom_id]=gdlist;
  428 + }
  429 + }
364 430  
365   - th.setData({
  431 +
  432 + th.setData({
366 433 requestData: arr,
367 434 all_num: all_num,
368 435 is_load: 1,
... ... @@ -407,8 +474,7 @@ Page({
407 474 });
408 475 continue;
409 476 }
410   -
411   -
  477 +
412 478 //如果商品下架了,或者商品是赠品,一开始都要清除
413 479 if (good.is_show == 0) {
414 480 var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id;
... ... @@ -482,7 +548,7 @@ Page({
482 548 var wlist="";
483 549 for(var i in list.goods){
484 550 //如果商品有促销活动
485   - if(list.goods[i].prom_type>0) continue;
  551 + if(list.goods[i].prom_type>0 || list.goods[i].prom_type==7 ) continue;
486 552 wlist+= encodeURIComponent(list.goods[i].erpwareid)+",";
487 553 }
488 554 wlist=ut.sub_last(wlist);
... ... @@ -712,6 +778,7 @@ Page({
712 778 if(dda && dda.length>0){
713 779 for (var i = 0; i < dda.length; i++) {
714 780 var item = dda[i].goods;
  781 +
715 782 if (!e.data.checkAllToggle) {
716 783 var txt = "requestData[" + i + "].selected";
717 784 e.setData({
... ... @@ -721,6 +788,12 @@ Page({
721 788 var fir = 0;
722 789 for (var j = 0; j < item.length; j++) {
723 790 if(item[j].is_gift) continue;
  791 +
  792 + var obj=JSON.parse(JSON.stringify(item[j]));
  793 + //计算之前先移除
  794 + zh_calc.remove_zhprom(dda,i,obj);
  795 +
  796 +
724 797 if (fir == 0) {
725 798 fir = item[j].distr_type;
726 799 } else {
... ... @@ -730,16 +803,24 @@ Page({
730 803 break;
731 804 }
732 805 }
733   - var txt = "requestData[" + i + "].goods[" + j + "].selected"
734   - e.setData({
  806 + var txt = "requestData[" + i + "].goods[" + j + "].selected";
  807 +
  808 + if(e.data.checkAllToggle) obj.goods_num=0;
  809 + zh_calc.add_zhprom(dda,i,obj);
  810 +
  811 + e.setData({
735 812 [txt]: !e.data.checkAllToggle,
736 813 })
  814 +
737 815 if (!e.data.checkAllToggle) {
738   - tfeel += item[j].goods_num * item[j].goods_price;
  816 + //组合购的金额要另外算
  817 + if(item[j].prom_type!=7)
  818 + tfeel += item[j].goods_num * item[j].goods_price;
739 819 t_num += item[j].goods_num;
740 820 }
741   - }
742   - }
  821 + }
  822 + }
  823 +
743 824  
744 825 if (text_arr != "") {
745 826 wx.showModal({
... ... @@ -748,6 +829,13 @@ Page({
748 829 });
749 830 return false;
750 831 } else {
  832 +
  833 + for (var i = 0; i < dda.length; i++) {
  834 + //总的价格,把组合商品的价格拿出来
  835 + var zh_calc_res=zh_calc.calculate_zh(dda,i,this);
  836 + tfeel+=zh_calc_res.tfeel;
  837 + }
  838 +
751 839 e.setData({
752 840 checkAllToggle: !e.data.checkAllToggle,
753 841 total_fee: tfeel.toFixed(2),
... ... @@ -1031,7 +1119,6 @@ Page({
1031 1119 //-- 购物车 --
1032 1120 if(car && car.length>0){
1033 1121 for (var a = 0; a < car.length; a++) {
1034   - var c_item=car[a];
1035 1122 var item = car[a].goods,
1036 1123 is_s_sele = 1;
1037 1124 var offline_price=0;
... ... @@ -1039,21 +1126,38 @@ Page({
1039 1126 for (var c = 0; c < item.length; c++) {
1040 1127 if(item[c].is_gift) continue;
1041 1128 all_num += item[c].goods_num;
  1129 +
  1130 + //不管怎么样都要移出去
  1131 + var obj=JSON.parse(JSON.stringify(item[c]));
  1132 + zh_calc.remove_zhprom(car,a,obj);
1042 1133 if (item[c].selected == 0) {
1043 1134 ischeck = 0;
1044 1135 is_s_sele = 0;
  1136 + if(item[c].prom_type==7) {
  1137 + obj.goods_num=0;
  1138 + zh_calc.add_zhprom(car,a,obj);
  1139 + }
1045 1140 } else {
1046   - tfeel += item[c].goods_num * item[c].goods_price;
  1141 + if(item[c].prom_type==7){
  1142 + //先把商品放入组合计算的专用的区域
  1143 + zh_calc.add_zhprom(car,a,obj);
  1144 + }else{
  1145 + tfeel += item[c].goods_num * item[c].goods_price;
  1146 + }
1047 1147 t_num += item[c].goods_num;
1048 1148 }
1049 1149  
1050 1150 //-- 如果这个商品是线下取价的时候 --
1051   - if(item[c].is_offline){
  1151 + if(item[c].is_offline && item[c].prom_type!=7){
1052 1152 offline_price+= (item[c].goods_price-item[c].offline_price)*item[c].goods_num;
1053 1153 offline_num+=item[c].goods_num;
1054 1154 }
1055   -
1056 1155 }
  1156 + //总的价格,把组合商品的价格拿出来
  1157 + var zh_calc_res=zh_calc.calculate_zh(car,a,th);
  1158 + tfeel+=zh_calc_res.tfeel;
  1159 + offline_price+=zh_calc_res.offline_price;
  1160 + offline_num+=zh_calc_res.offline_num;
1057 1161  
1058 1162 var txt = "requestData[" + a + "].selected";
1059 1163 th.setData({
... ... @@ -1358,7 +1462,10 @@ Page({
1358 1462 ob.code=-1;ob.CanOutQty=0;func(ob); return false;
1359 1463 }
1360 1464  
1361   - if( t.goods_num>plist.CanOutQty-lock){
  1465 + var c_num=t.goods_num;
  1466 + if(t.need_downlow_num) c_num=t.need_downlow_num;
  1467 +
  1468 + if( c_num>plist.CanOutQty-lock){
1362 1469 ob.code=-1;
1363 1470 ob.CanOutQty=plist.CanOutQty-lock
1364 1471 if(ob.CanOutQty<0) ob.CanOutQty=0;
... ... @@ -1480,7 +1587,7 @@ Page({
1480 1587 glist += i_arr[j].goods_id + ",";
1481 1588 ab = 1;
1482 1589 //--普通商品,如果有开启线下库存的功能,要调用线下库存进行计算,赠品不要进行调用线下库存---
1483   - if ((i_arr[j].prom_type == 0 || i_arr[j].prom_type == 3 || i_arr[j].prom_type == 5) && th.data.sales_rules == 2 && i_arr[j].is_gift != 1) {
  1590 + if ((i_arr[j].prom_type == 0 || i_arr[j].prom_type == 3 || i_arr[j].prom_type == 5 || i_arr[j].need_downlow_num ) && th.data.sales_rules == 2 && i_arr[j].is_gift != 1) {
1484 1591 //--获取商品的线下商品ID--
1485 1592 var gd = null;
1486 1593 await getApp().request.promiseGet("/api/weshop/goods/get/" + oo.stoid + "/" + i_arr[j].goods_id, {}).then(res => {
... ... @@ -2072,4 +2179,5 @@ Page({
2072 2179 var url=e.currentTarget.dataset.url;
2073 2180 getApp().goto(url);
2074 2181 }
  2182 +
2075 2183 });
2076 2184 \ No newline at end of file
... ...
pages/cart/cart/cart.wxml
... ... @@ -88,6 +88,16 @@
88 88 <view class="abs flex-center fs26" wx:if="{{items.distr_type==2}}">物流</view>
89 89 </block>
90 90  
  91 + <block wx:if="{{items.prom_type==7 && items.zhqty}}">
  92 + <block wx:if="{{items.selected}}">
  93 + <text wx:if="{{items.zhqty>items.goods_num}}" class="abs2">还需购买{{items.zhqty-items.goods_num}}件</text>
  94 + </block>
  95 + <block wx:else>
  96 + <text class="abs2">需购买{{items.zhqty}}件</text>
  97 + </block>
  98 + </block>
  99 +
  100 +
91 101 </navigator>
92 102 <view class="goods-cont">
93 103 <view class="goods-name">
... ... @@ -144,6 +154,15 @@
144 154 </view>
145 155 </view>
146 156  
  157 + <!-- 还差多少件立即享受组合购 -->
  158 + <block wx:if="{{item.need_list && item.need_list.length>0 && !is_edit}}">
  159 + <view class="fs28 pdr20 pdl20 pdb20 c-red2 flex jc_sb" wx:for="{{item.need_list}}">
  160 + <text>{{item.title}}</text>
  161 + <text data-url="/packageB/pages/zuhegou/index/index?id={{item.id}}" bindtap="go_url">去凑单</text>
  162 + </view>
  163 + </block>
  164 +
  165 +
147 166 <!-- 线下取价 -->
148 167 <view style="margin:10rpx 0; padding: 0 30rpx;color: #999" wx:if="{{item.offline_price}}" class="fs28">
149 168 当前<text class="red_c">{{item.offline_num}}</text>件商品,可使用<text class="red_c">{{item.offline_price}}</text>元店铺优惠
... ...
pages/cart/cart/cart.wxss
... ... @@ -378,3 +378,10 @@ page {
378 378 /* background-color: #ddd; */
379 379 color: #ccc;
380 380 }
  381 +
  382 +.abs2{
  383 + position: absolute; z-index: 1000;
  384 + width: 100%;height: 30rpx; background-color: rgba(9,9,9,0.5);
  385 + text-align: center; line-height: 30rpx;
  386 + left: 0;bottom: 0;color: #fff; font-size: 20rpx;
  387 +}
... ...
pages/cart/cart/zh_calculate.js 0 → 100644
  1 +module.exports = {
  2 + //辅助数组添加元素功能
  3 + find_in_add: function(list, ele) {
  4 + for (var i in list) {
  5 + var item = list[i];
  6 + if (item.goods_id == ele.goods_id) {
  7 + return false;
  8 + }
  9 + }
  10 + list.push(ele);
  11 + },
  12 + //辅助数组添加元素功能
  13 + find_in_remove: function(list, ele) {
  14 + for (var i in list) {
  15 + var item = list[i];
  16 + if (item.goods_id == ele.goods_id) {
  17 + list.splice(i, 1);
  18 + }
  19 + }
  20 + },
  21 +
  22 + //主要是把组合购的商品分离出来
  23 + add_zhprom: function(car, a, ele) {
  24 + var point = car[a];
  25 + if (point.zh_map) {
  26 + if (point.zh_map[ele.prom_id]) {
  27 + this.find_in_add(point.zh_map[ele.prom_id].goods, ele);
  28 + } else {
  29 + point.zh_map[ele.prom_id] = {
  30 + goods: [],
  31 + act: ele.act
  32 + };
  33 + point.zh_map[ele.prom_id].goods.push(ele);
  34 + }
  35 + } else {
  36 + point.zh_map = {};
  37 + point.zh_map[ele.prom_id] = {
  38 + goods: [],
  39 + act: ele.act
  40 + };
  41 + point.zh_map[ele.prom_id].goods.push(ele);
  42 + }
  43 + },
  44 + //未选中的商品,要从中剔除
  45 + remove_zhprom: function(car, a, ele) {
  46 + var point = car[a];
  47 + if (point.zh_map) {
  48 + if (point.zh_map[ele.prom_id]) {
  49 + this.find_in_remove(point.zh_map[ele.prom_id].goods, ele);
  50 + }
  51 + }
  52 + },
  53 +
  54 + //把组合购的商品价格计算出来
  55 + calculate_zh: function(car, a, th) {
  56 + var car_item = car[a];
  57 + var tfeel = 0,
  58 + offline_price = 0,
  59 + offline_num = 0;
  60 + var txt = "requestData[" + a + "].need_list";
  61 + if (!car_item.zh_map) {
  62 + var res = {
  63 + tfeel: tfeel,
  64 + offline_price: offline_price,
  65 + offline_num: offline_num
  66 + };
  67 + th.setData({
  68 + [txt]: null
  69 + });
  70 + return res;
  71 + }
  72 +
  73 + //活动的列表都存储在这里面,可以快速查询
  74 + var zh_prom_goods=car_item.zh_prom_goods;
  75 + //因为可能有多个组合购的活动
  76 + for (var i in car_item.zh_map) {
  77 + var bitem = car_item.zh_map[i];
  78 + var act = bitem.act; //获取到组合购的详情
  79 + var all_num = 0; //商品数量之和
  80 + var all_price = 0;
  81 + var need_to_buy = 0;
  82 + var all_zhqty = 0; //所有商品要求起购数之和
  83 + var no_in_arr = []; //剩余的未加入组合购
  84 +
  85 + var title =""; //提示语;
  86 + //var goods = bitem.goods;
  87 + var goods = zh_prom_goods[act.id];
  88 + //寻找一下
  89 + function get_num(ite) {
  90 + for (let v1 in car_item.goods) {
  91 + var vh = car_item.goods[v1];
  92 + if (vh.goods_id == ite.goods_id) {
  93 + return vh;
  94 + }
  95 + }
  96 + return 0;
  97 + }
  98 +
  99 + for (var i in goods) {
  100 + var item = goods[i];
  101 + item.num = get_num(item).goods_num;
  102 + item.goods_price=get_num(item).goods_price;
  103 + item.offline_price=get_num(item).offline_price;
  104 +
  105 + if (item.num) {
  106 + all_num += item.num;
  107 + all_price += item.num * item.goods_price;
  108 + //当有起购数的控制的时候
  109 + if (item.zhqty) {
  110 + all_zhqty += item.zhqty;
  111 + if (item.num < item.zhqty) {
  112 + need_to_buy += item.zhqty - item.num;
  113 + }
  114 + if (item.num > item.zhqty) {
  115 + for (var i = 0; i < item.num - item.zhqty; i++) {
  116 + no_in_arr.push({
  117 + price: item.goods_price,offline_price:item.offline_price
  118 + })
  119 + }
  120 + }
  121 + } else {
  122 + for (var j = 0; j < item.num; j++) {
  123 + no_in_arr.push({
  124 + price: item.goods_price,offline_price:item.offline_price
  125 + })
  126 + }
  127 + }
  128 + } else {
  129 + if (item.zhqty) {
  130 + title="必买商品未加购,下单立享【"+act.zhprice+"元任选"+act.zhbuyqty+"件】";
  131 + need_to_buy += item.zhqty;
  132 + }
  133 + }
  134 + }
  135 +
  136 + //当满足组合的要求:总数要满足,起购数要满足
  137 + if (all_num >= act.zhbuyqty && !need_to_buy) {
  138 + function sortData(a, b) {
  139 + return a.price - b.price
  140 + }
  141 +
  142 + no_in_arr.sort(sortData);
  143 + var aprice = act.zhprice;
  144 + if (act.zhbuyqty > all_zhqty) {
  145 + for (var n = 0; n < act.zhbuyqty; n++) {
  146 + no_in_arr.pop();
  147 + }
  148 + }
  149 + //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增
  150 + if (act.is_bz && no_in_arr.length > act.zhbuyqty) {
  151 + //看一下是几倍
  152 + var be = parseInt(no_in_arr / act.zhbuyqty);
  153 + aprice += be * act.zhprice;
  154 + for (var m = 0; m < be * act.zhbuyqty; m++) {
  155 + no_in_arr.pop();
  156 + }
  157 + }
  158 + //算一下剩余的钱
  159 + if (no_in_arr.length) {
  160 + for (var ii in no_in_arr) {
  161 + var item = no_in_arr[ii];
  162 + var gitem=get_num(item);
  163 + if(gitem) {
  164 + if (!gitem.need_downlow_num) {
  165 + gitem.need_downlow_num = 1;
  166 + }
  167 + else {
  168 + gitem.need_downlow_num++;
  169 + }
  170 + aprice += item.price;
  171 + if (item.offline_price) {
  172 + offline_price += item.goods_price - item.offline_price;
  173 + offline_num += 1;
  174 + }
  175 + }
  176 + }
  177 + }
  178 + all_price = aprice;
  179 +
  180 + //-- 设置还需要购买多少件,享受活动,前段显示 --
  181 + var need_to = car_item.need_list;
  182 + var index = this.find_need_to(need_to, act);
  183 + if (index > -1) {
  184 + need_to.splice(index, 1);
  185 + th.setData({
  186 + [txt]: need_to
  187 + });
  188 + }
  189 +
  190 + } else {
  191 + for (var ii in goods) {
  192 + var item = goods[ii];
  193 +
  194 +
  195 + var gitem=get_num(item);
  196 + if(gitem) {
  197 + gitem.need_downlow_num = item.num;
  198 +
  199 + if (item.offline_price) {
  200 + offline_price += (item[ii].goods_price - item[ii].offline_price) * item[ii]
  201 + .goods_num;
  202 + offline_num += item[ii].goods_num;
  203 + }
  204 + }
  205 + }
  206 + if (act.zhbuyqty - all_num > need_to_buy) {
  207 + need_to_buy = act.zhbuyqty - all_num;
  208 + }
  209 + //-- 设置还需要购买多少件,享受活动,前段显示 --
  210 + var need_to = car_item.need_list;
  211 + if (all_num <= 0) {
  212 + var index = this.find_need_to(need_to, act);
  213 + if (index > -1) {
  214 + need_to.splice(index, 1);
  215 + th.setData({
  216 + [txt]: need_to
  217 + });
  218 + }
  219 + } else {
  220 + var index = this.find_need_to(need_to, act);
  221 + if(title=='')
  222 + title = "再买" + need_to_buy + "件,下单立享【" + act.zhprice + "元任选" + act.zhbuyqty + "件】";
  223 + if (index != -1) {
  224 + need_to[index].title = title;
  225 + } else {
  226 + if (!need_to) need_to = [];
  227 + var it = {
  228 + id: act.id,
  229 + pickup_id: car_item.pickup_id,
  230 + title: title
  231 + };
  232 + need_to.push(it);
  233 + }
  234 + th.setData({
  235 + [txt]: need_to
  236 + });
  237 + }
  238 +
  239 + }
  240 + tfeel += all_price;
  241 + }
  242 +
  243 + console.log('nyf111');
  244 + console.log(car_item);
  245 +
  246 +
  247 + var res = {
  248 + tfeel: tfeel,
  249 + offline_price: offline_price,
  250 + offline_num: offline_num
  251 + };
  252 + return res;
  253 +
  254 +
  255 + },
  256 +
  257 + find_need_to: function(list, iter) {
  258 + if (!list || list.length <= 0) return -1;
  259 + for (var i in list) {
  260 + var item = list[i];
  261 + if (item.id == iter.id) {
  262 + return i;
  263 + }
  264 + }
  265 + return -1;
  266 + },
  267 +
  268 + //筛选组合购,纯粹的数组按活动id分组
  269 + find_split: function(arr) {
  270 + //过滤只有团购的商品
  271 + var oarr = arr.goods.filter(function(ele) {
  272 + return ele.prom_type == 7
  273 + })
  274 + if(!oarr || oarr.length==0) return null;
  275 + //看一下有多少个不同的团购
  276 + var map = {},dest = [];
  277 + for (var i = 0; i < oarr.length; i++) {
  278 + var ai = oarr[i];
  279 + var index=map[ai.prom_id]
  280 + if (!index) {
  281 + dest.push({
  282 + prom_id: ai.prom_id,
  283 + data: [ai]
  284 + });
  285 + map[ai.prom_id]=dest.length; //存储下标
  286 + } else {
  287 + var dj = dest[index-1];
  288 + dj.data.push(ai);
  289 + }
  290 + }
  291 + return dest;
  292 + }
  293 +
  294 +
  295 +}
... ...
pages/cart/cart2/cart2.js
Changes suppressed. Click to show
1   -var t = getApp(),app=t, a = t.request, e = require("../../../utils/common.js"),
2   - s = require("../../../utils/util.js"),ut=s, o = require("../../../utils/md5.js"), to = getApp();
3   -var oo=t.globalData.setting,os=oo;
  1 +var t = getApp(), app = t, a = t.request, e = require("../../../utils/common.js"),
  2 + s = require("../../../utils/util.js"), ut = s, o = require("../../../utils/md5.js"), to = getApp();
  3 +var oo = t.globalData.setting, os = oo;
4 4 var regeneratorRuntime = require('../../../utils/runtime.js');
5 5 var util_pay = require("../../../utils/pay.js");
  6 +var zh_calc = require("zh_calculate.js");
  7 +
  8 +Page({
  9 + data: {
  10 + url: t.globalData.setting.url,
  11 + resourceUrl: t.globalData.setting.resourceUrl,
  12 + imgUrl: t.globalData.setting.imghost,
  13 + goods: null,
  14 + order: null,
  15 + orderPrices: null,
  16 + coupons: null,
  17 + coupon: null,
  18 + invoiceToggle: !0,
  19 + payWithUserMoney: !0,
  20 + payWithPoints: !0,
  21 + maxWord: 0,
  22 + enterAddressPage: !1,
  23 + firstEnter: !0,
  24 + //页面获取的参数
  25 + param: 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 + cartlist: null,
  38 + old_cartlist: null,
  39 + cartlist_y: null, //购物车原始列表
  40 + js_use_money: 0, //是否使用余额
  41 + is_all_zt: 1, //是否全部都是自提
  42 +
  43 + /*----------------立即购买---------------------*/
  44 + is_b_now: 0, //0是购物车结算 1立即购买
  45 + bn_goods: null, //立即购买时候的调用商品
  46 + bn_use_money: 0,//是否使用余额
  47 + bn_exp_type: 1, //0是物流 1自提
  48 + bn_pick: 0, //选择的门店
  49 + bn_pickname: "", //选择的门店名称
  50 + bn_t_exp_t: 0, //判断商品和门店一起决定的物流自提的方式0 都可以 1自提 2物流
  51 +
  52 + bn_plus_cut_price: 0, //显示等级卡会优惠多少钱
  53 + /*------------------------*/
  54 + user_addr: null,//物流
  55 + userinfo: null, //获取会员
  56 + /*----------物流选择--------*/
  57 + wu_arr: null,
  58 + index: 0,
  59 + w_sele_index: 0,
  60 +
  61 + //判断页面是返回回来的还是 首次进入的
  62 + isclose: 1,
  63 + //申请提现的金额
  64 + txmon: 0,
  65 + yuer: 0,
  66 + //提交中,不重复提交
  67 + is_summit_ing: 0,
  68 + //--更优惠券抵用有关,立即购买的,如果是购物车,就要把相应的值,写入cartlist数组中--
  69 + ckeck_quan_price: 0,
  70 + check_quan_price_list: '',
  71 + check_quan_ware_list: '',
  72 +
  73 + // 设计一个数组来存放已经选择了的券编号,coupon_no是券号,money是面值,coupon_price是真正优惠的价格,数组的下标是pickid
  74 + //using_quan[11]={coupon_no:"1212121",money:"20",coupon_price:"45"}
  75 + using_quan: {},
  76 + open_quan: 0,
  77 + //选择的券列表
  78 + selected_quan_list: null,
  79 + //选择的券的门店
  80 + selected_quan_pick: null,
  81 + is_close_quan: 0,
  82 + disabled: 0,
  83 + open_express: 0,//控制选择物流名列表 的属性
  84 +
  85 + is_express: 0, //选中物流的属性
  86 + expres_name: "", //点击选定
  87 + isopen: 0, //券的说明
  88 + is_coupon: null, //选择券的控制属性
  89 + is_shipping_code: "",//插入用户默认地址
  90 + wu_arr_txt: "", //要更新的物流的字段
  91 +
  92 + sales_rules: 1, //默认是显示线上库存
  93 + isget_by_quan: {}, //是否调用了接口获取包邮券
  94 + get_by_quan_list: null, //立即购买的
  95 + get_by_quan_list_cart: {}, //购物车的
  96 + by_quan_list_cart: null, //点击选择的包邮列表
  97 +
  98 + //如果是全场包邮了,或者是全场不包邮了,就不要选包邮券
  99 + is_no_by: {},
  100 + is_by: {},
  101 + is_quan_by: {},
  102 + //--购买赠送的商品--
  103 + buy_now_gift_goods: null,
  104 + //--订单优惠--
  105 + order_prom: {},
  106 + //-- 购物车优惠活动 --
  107 + prom_goods_map: {},
  108 + //-- order_prom_list --
  109 + order_prom_list_cart: null,
  110 +
  111 + ispt_goods: 0, //是否平摊至单品,0要平摊 1不平摊
  112 +
  113 + rank_switch: 0, //是不是开同等级卡
  114 + show_card: null, //显示的等级卡
  115 + card_name: '', //显示的卡的名称
  116 + card_cut_price: null,//减价多少钱
  117 +
  118 + show_submit: 0, //提交按钮变正常显示
  119 + is_get_offline: 1,
  120 +
  121 + tabs: ['门店自提', '快递邮寄'],
  122 + currentTabIndex: 1,
  123 + },
  124 + onLoad: function (t) {
  125 + wx.setNavigationBarTitle({title: "填写订单",})
  126 + var th = this;
  127 + this.setData({is_b_now: t.is_bnow == undefined ? 0 : t.is_bnow,});
  128 + th.data.param = t;
  129 + //清理一下,确保最新的系统配置
  130 + getApp().globalData.config2 = null;
  131 + //清空is_pick_up
  132 + getApp().request.put("/api/weshop/useraddress/updatePickUp", {
  133 + data: {user_id: getApp().globalData.user_id, is_pickup: 0},
  134 + success: function (s) {
  135 + }
  136 + });
  137 +
  138 +
  139 + },
  140 + onUnload: function () {
  141 + this.setData({isclose: 1})
  142 + },
  143 + onHide: function () {
  144 + this.setData({
  145 + isget_by_quan: {},
  146 + is_no_by: {},
  147 + is_by: {}
  148 + })
  149 + },
  150 +
  151 + //----------子页返回父页触发----------
  152 + onShow: function () {
  153 + var th = this;
  154 + th.setData({show_submit: 0}); //让提交先掩藏
  155 + th.data.g_cart_q_time = null;
  156 +
  157 + if (th.data.isclose == 0) {
  158 + wx.navigateTo({
  159 + url: "/pages/index/index/index"
  160 + })
  161 +
  162 + } else {
  163 + this.getuser_addr(function (ie) {
  164 +
  165 + console.log("getuser_addr")
  166 + console.log(ie)
  167 +
  168 + //地址切换要把包邮券清空
  169 + if (!th.data.user_addr || !ie || th.data.user_addr.address_id != ie.address_id) {
  170 + var using_quan = th.data.using_quan;
  171 + for (var i in using_quan) {
  172 + var item = using_quan[i];
  173 + if (item.isby == 1) {
  174 + var ob = {}, txt = "using_quan[" + i + "]";
  175 + ob[txt] = {};
  176 + th.setData(ob);
  177 + }
  178 + }
  179 + th.data.isget_by_quan = {};
  180 + }
  181 +
  182 +
  183 + th.data.prom_goods_map = {};
  184 + th.data.is_summit_ing = 0;
  185 + //更换地址回来要重新调用计算价钱的接口
  186 + if (!th.data.user_addr || th.data.user_addr.address_id != ie.address_id) {
  187 + th.setData({user_addr: ie});
  188 + if (th.data.is_b_now == 1) {
  189 + if (th.data.bn_goods) {
  190 + th.setData({add_back: 1});
  191 + //th.calculatePrice2();
  192 + }
  193 + } else {
  194 + if (th.data.cartlist) {
  195 + th.setData({add_back: 1});
  196 + //th.calculatePrice();
  197 + }
  198 + }
  199 + } else {
  200 + th.setData({user_addr: ie});
  201 + }
  202 + var going = 0;
  203 +
  204 +
  205 + //使用计时器,避免空现象
  206 + /*---
  207 + var jishi= setInterval(function () {
  208 + if (th.data.is_b_now == 1 && going==0) {
  209 + if(th.data.bn_goods) {
  210 + th.calculatePrice2();going=1;clearInterval(jishi);
  211 + }
  212 + }else if(going==0) {
  213 + if (th.data.cartlist){
  214 + th.calculatePrice();going = 1; clearInterval(jishi);
  215 + }
  216 + }
  217 + },500)--*/
  218 +
  219 + });
  220 + var is_card_back = getApp().globalData.is_card_back;
  221 + //--更新默认地址--,看一下是不是跳到地址页面,同时也不是购买等级卡返回的,这里很重要,否则会重新更新收货物流公司
  222 + if (!getApp().globalData.is_cart_old && !is_card_back && !getApp().globalData.plus_buy_back) {
  223 + this.update_code();
  224 + } else {
  225 + getApp().globalData.is_cart_old = 0;
  226 + getApp().globalData.plus_buy_back = 0;
  227 + }
  228 + }
  229 +
  230 + //先获取是否有关闭使用优惠券
  231 + getApp().getConfig2(function (ee) {
  232 + var json_d = JSON.parse(ee.switch_list);
  233 + th.data.json_d = json_d;
  234 + th.data.ispt_goods = json_d.ispt_goods; //是不是平摊到单品的控制参数赋值
  235 + var is_default_logistics = json_d.is_default_logistics;
  236 +
  237 + th.setData({
  238 + is_close_quan: json_d.is_close_quan,
  239 + sales_rules: ee.sales_rules,
  240 + rank_switch: json_d.rank_switch,
  241 + is_default_logistics: is_default_logistics
  242 + });
  243 +
  244 + var rank_switch = json_d.rank_switch;
  245 + var max_price = -1;
  246 + var show_card = null;
  247 + var name = "";
  248 + //如果有开等级卡的时候,
  249 + //因为都是调接口,要返回在计算
  250 + if (rank_switch == 2) {
  251 + //-- 获取所有的等级卡, --
  252 + getApp().request.promiseGet("/api/weshop/plus/vip/mem/bership/list?storeId=" + os.stoid,
  253 + {}).then(res => {
  254 + if (res.data.code == 0) {
  255 + var plusCard = res.data.data;
  256 + //-- 循环判断,拿到最贵的那张卡 --
  257 + for (var ih in plusCard) {
  258 + if (plusCard[ih].IsStopBuy == true) {
  259 + continue;
  260 + }
  261 + if (max_price < 0) {
  262 + max_price = plusCard[ih].CardFee;
  263 + name = 'card' + plusCard[ih]['CorrPrice'];
  264 + show_card = plusCard[ih];
  265 + } else {
  266 + if (max_price < plusCard[ih].CardFee) {
  267 + max_price = plusCard[ih].CardFee;
  268 + name = 'card' + plusCard[ih]['CorrPrice'];
  269 + show_card = plusCard[ih];
  270 + }
  271 + }
  272 + }
  273 +
  274 + if (show_card) {
  275 + name = name.toLowerCase();
  276 + th.setData({card_name: name, show_card: show_card})
  277 + }
  278 + }
  279 + //-----先获取物流,再获取用户信息,再展示页面-----
  280 + th.get_wuliu(th.get_info(th.show_page));
  281 + })
  282 + } else {
  283 + //-----先获取物流,再获取用户信息,再展示页面-----
  284 + th.get_wuliu(th.get_info(th.show_page));
  285 + }
  286 +
  287 + }, 1);
  288 +
  289 + //值在这里换
  290 + getApp().globalData.plus_buy_back = 0;
  291 + },
  292 +
  293 + //-------------------获取物流---------------
  294 + get_wuliu(func) {
  295 + var th = this;
  296 + to.getwuliu(function (e) {
  297 + //系统是是否开启了默认的物流
  298 + if (th.data.is_default_logistics) {
  299 + //如果第一个不是开启默认,说明要让用户自己选
  300 + if (!e[0].is_default) {
  301 + th.setData({is_default_logistics: 0});
  302 + }
  303 + }
  304 + th.setData({wu_arr: e})
  305 + typeof func == "function" && func();
  306 + })
  307 + },
  308 + //------获取会员信息-----先获取用户信息,在进行下一步---
  309 + get_info: function (func) {
  310 + var user_id = t.globalData.user_id;
  311 + to.auth.get_u(func);
  312 + },
  313 +
  314 + //------获取会员收货地址-----
  315 + getuser_addr: function (func) {
  316 + var th = this;
  317 + a.get("/api/weshop/useraddress/page", {
  318 + data: {user_id: to.globalData.user_id, store_id: oo.stoid, pageSize: 600, t: Math.random()},
  319 + success: function (su) {
  320 + /*---
  321 + var user_addr=[
  322 + { 'address_id': 882, 'user_id': 2661, 'consignee': '测试测试测', 'province': 3102, 'city': 3431, 'district': 3466,
  323 + 'address': 'ed', 'more_address': '山西-长治市-襄垣县-虎(音si)亭镇', 'mobile': 13012345678,'is_default':1},
  324 + ];---*/
  325 + var item = null;
  326 + if (su.data.code == 0 && su.data.data && su.data.data.pageData) {
  327 + var user_addr = su.data.data.pageData;
  328 + var def_item = null;
  329 + for (var i = 0; i < user_addr.length; i++) {
  330 + if (user_addr[i]['is_default'] == 1) {
  331 + def_item = user_addr[i];
  332 + }
  333 + if (user_addr[i]['is_pickup'] == 1) {
  334 + item = user_addr[i];
  335 + }
  336 + }
  337 +
  338 + if (item == null) item = def_item;
  339 + if (item == null) item = user_addr[0];
  340 + }
  341 +
  342 + if (item == undefined) item = null;
  343 + if (!item) th.setData({user_addr: null}); //地址为空的时候,要清空,因为返回的时候,有缓存
  344 +
  345 + func(item);
  346 + }
  347 + });
  348 + },
  349 +
  350 + //----------------展示页面,是再获取用户信息之后--------------
  351 + show_page: function () {
  352 + var th = this, ta = this.data.param;
  353 + //th.setData({ userinfo: getApp().globalData.userInfo,}); //这个余额被缓存了
  354 +
  355 + //会员的信息,要获取最新
  356 + var user = getApp().globalData.userInfo;
  357 + getApp().request.get("/api/weshop/users/get/" + oo.stoid + "/" + user.user_id, {
  358 + data: {r: Math.random()},
  359 + success: function (e) {
  360 + getApp().globalData.userInfo = e.data.data;
  361 + th.setData({userinfo: e.data.data});
  362 +
  363 + //选获取地址
  364 + th.getuser_addr(function (addr) {
  365 + th.setData({user_addr: addr});
  366 + //--------------------------立即购买------------------
  367 + if (ta.is_bnow == 1) {
  368 + //读取门店
  369 + to.get_allsto(function (e) {
  370 + th.setData({allsto: e});
  371 + //获取立即购买的商品信息
  372 + th.get_buy_goods(ta.goods_id);
  373 + });
  374 + } else {
  375 + //------------------------购物车结算----------------------
  376 + //读取门店
  377 + to.get_allsto(function (e) {
  378 + th.setData({allsto: e});
  379 + //-------获取购物车已经选择的商品--------
  380 + th.get_cart();
  381 + })
  382 + }
  383 + });
  384 +
  385 + //获取提现金额
  386 + getApp().request.get("/api/weshop/withdrawals/summoney", {
  387 + data: {user_id: to.globalData.user_id, store_id: oo.stoid, status: 0},
  388 + success: function (su) {
  389 + if (su.data.code == 0) {
  390 + var yuer = parseFloat(th.data.userinfo.user_money -
  391 + (th.data.userinfo.frozen_money > 0 ? th.data.userinfo.frozen_money : 0) - su.data.data.summoney).toFixed(2);
  392 + th.setData({txmon: su.data.data.summoney, yuer: yuer});
  393 + }
  394 + }
  395 + });
  396 +
  397 + },
  398 + });
  399 +
  400 + },
  401 +
  402 +
  403 + //-----真的获取购物车,入口--------
  404 + get_cart: function () {
  405 + var th = this, app = getApp();
  406 + a.get("/api/weshop/cart/list", {
  407 + data: {
  408 + user_id: to.globalData.user_id, selected: 1, state: 0,
  409 + store_id: oo.stoid, pageSize: 600
  410 + },
  411 + success: async function (su) {
  412 + //按门店分类的数组
  413 + var arr = new Array();
  414 + var carr = su.data.data.pageData;
  415 + th.data.cartlist_y = carr; //存储原始购物车列表
  416 +
  417 + //---是不是购买等级卡成功的返回---等级卡显示的判断---
  418 + var is_card_back = getApp().globalData.is_card_back;
  419 +
  420 + for (var i = 0; i < carr.length; i++) {
  421 + var item1 = carr[i];
  422 + //要把优惠活动加入,prom_goods_map中,赠品不要运算
  423 + if (item1.prom_type == 3 && item1.is_gift != 1) {
  424 + await th.add_prom_goods_map(item1);
  425 + }
  426 +
  427 + //要把组合购的东西拿出来算一下
  428 + if (item1.prom_type == 7) {
  429 + var isok = 1;
  430 + //如果有组合购
  431 + var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + item1.prom_id+'/'+getApp().globalData.userInfo.user_id;
  432 + await getApp().request.promiseGet(url, {}).then(res => {
  433 + if (res.data.code == 0 && res.data.data) {
  434 + //如果活动已经结束
  435 + if (res.data.data.is_end == 1) {
  436 + isok = 0;
  437 + }
  438 + if (ut.gettimestamp() > res.data.data.end_time) {
  439 + isok = 0;
  440 + }
  441 + } else {
  442 + //未找到商品的活动
  443 + isok = 0;
  444 + }
  445 + item1.act = res.data.data;
  446 + })
  447 +
  448 + if (!isok) {
  449 + getApp().my_warnning("组合购的活动已经过期", 0, th);
  450 + return false;
  451 + }
  452 +
  453 + }
  454 + }
  455 +
  456 + //在分组的时候,就不要再调用接口,await
  457 + for (var i = 0; i < carr.length; i++) {
  458 + var item = carr[i];
  459 +
  460 + //-- 如果是等级会员注册返回 --
  461 + if (is_card_back) {
  462 + th.data.card_name = th.data.userinfo.card_field;
  463 + //如果是秒杀的返回,就要把活动弄回0
  464 + if (item['prom_type'] == 1) {
  465 + item['prom_type'] = 0;
  466 + item['prom_id'] = 0;
  467 + }
  468 + // 拼团,搭配购不计算,赠品也不计算
  469 + if (item['prom_type'] != 5 && item['prom_type'] != 6 && !item.is_gift && !item['is_collocation'] && item.goods_price > item[th.data.card_name]) {
  470 + item.goods_price = item[th.data.card_name];
  471 + carr[i].goods_price = item[th.data.card_name];
  472 +
  473 + }
  474 + } else {
  475 + // 拼团,搭配购不计算,赠品也不计算,同时会员还未购买等级会员
  476 + if (item[th.data.card_name] > 0 && item['prom_type'] != 5 && item['prom_type'] != 6 && !th.data.userinfo.card_field
  477 + && !item.is_gift && !item['is_collocation'] && item.goods_price > item[th.data.card_name]) {
  478 + item.cut_price1 = item.goods_price - item[th.data.card_name];
  479 + carr[i].cut_price1 = (item.goods_price - item[th.data.card_name]) * item.goods_num;
  480 + }
  481 +
  482 + }
  483 +
  484 + item.original_img = oo.imghost + item.original_img;
  485 + /*----接口要弄出来的,先顶着-----*/
  486 + var pcid = item.pick_id;
  487 + var find = 0;
  488 + //----如果有就加进去,没有就新增一个----
  489 + //-----------循环查找门店-------------
  490 + if (arr.length > 0) {
  491 + for (var j = 0; j < arr.length; j++) {
  492 + if (arr[j].pickup_id == pcid) {
  493 + arr[j].goods.push(item);
  494 + //if(item.is_gift!=1){
  495 + //确定配送方式
  496 + if (arr[j].distr_t == 0) {
  497 + arr[j].distr_t = item.distr_type;
  498 + }
  499 + var e_t = 0
  500 + switch (arr[j].distr_t) {
  501 + case 0:
  502 + e_t = 1;
  503 + if (th.data.json_d.pickupway && th.data.json_d.pickupway == 1) e_t = 0;
  504 + break;
  505 + case 1:
  506 + e_t = 1;
  507 + break;
  508 + case 2:
  509 + e_t = 0;
  510 + break;
  511 + }
  512 + arr[j].exp_type = e_t;
  513 + if (e_t == 0) th.setData({is_all_zt: 0});
  514 + //}
  515 +
  516 + //-- 把等级卡会优惠多少钱装进去 --
  517 + if (item.cut_price) arr[j].card_cut_price += item.cut_price;
  518 + find = 1;
  519 + break;
  520 + }
  521 + }
  522 + }
  523 + //------如果没有找到-----
  524 + if (find == 0) {
  525 + var pikname = '', sto = null;
  526 + //----找到门店名称-----
  527 + for (var k = 0; k < th.data.allsto.length; k++) {
  528 + if (pcid == th.data.allsto[k].pickup_id) {
  529 + pikname = th.data.allsto[k].pickup_name;
  530 + sto = th.data.allsto[k];
  531 + break;
  532 + }
  533 + }
  534 + var e_t = 0, dis_t = 0;//物流方式,配送方式
  535 + if (item.distr_type == 0) {
  536 + dis_t = sto.distr_type;
  537 + } else {
  538 + dis_t = item.distr_type;
  539 + }
  540 + switch (dis_t) {
  541 + case 0:
  542 + e_t = 1;
  543 + //-- 系统后台有设置要默认的 --
  544 + if (th.data.json_d.pickupway && th.data.json_d.pickupway == 1) e_t = 0;
  545 + break;
  546 + case 1:
  547 + e_t = 1;
  548 + break;
  549 + case 2:
  550 + e_t = 0;
  551 + break;
  552 + }
  553 + //如果是物流的话,全部自提的控制要弄成0
  554 + if (e_t == 0) th.setData({is_all_zt: 0});
  555 +
  556 + var narr = new Array();
  557 + narr.push(item);
  558 +
  559 + //-----------拼装购物车结算的数组,如果有默认物流时要用默认物流编号,计算默认的物流,不管是不是自提都算一下-----------------
  560 + var m_wind = 0, def_exp_code = getApp().globalData.userInfo.def_exp_code;
  561 + if (def_exp_code) {
  562 + for (var k = 0; k < th.data.wu_arr.length; k++) {
  563 + var item = th.data.wu_arr[k];
  564 + if (def_exp_code == item.code) {
  565 + m_wind = k;
  566 + }
  567 + }
  568 + }
  569 +
  570 + var ie = {
  571 + pickup_id: pcid,
  572 + pname: pikname,
  573 + goods: narr,
  574 + wind: m_wind,
  575 + distr_t: dis_t,
  576 + card_cut_price: 0,
  577 + exp_type: e_t,
  578 + goods_price: 0,
  579 + shipping_price: 0,
  580 + user_money: 0,
  581 + total_amount: 0,
  582 + order_amount: 0,
  583 + user_note: 0
  584 + };
  585 +
  586 + //-- 把等级卡会优惠多少钱装进去 --
  587 + if (item.cut_price1) ie.card_cut_price += item.cut_price1;
  588 + arr.push(ie);
  589 +
  590 + }
  591 + }
  592 + //-- 如果是回退回来的情况 --
  593 + if (th.data.cartlist && th.data.cartlist.length > 0) {
  594 + for (var kj in th.data.cartlist) {
  595 + for (var ih in arr) {
  596 + var ie = arr[ih];
  597 + if (ie.pickup_id == th.data.cartlist[kj].pickup_id) {
  598 + ie.exp_type = parseInt(th.data.cartlist[kj].exp_type);
  599 + ie.wind = parseInt(th.data.cartlist[kj].wind);
  600 + break;
  601 + }
  602 + }
  603 + }
  604 + }
  605 +
  606 + //-- 循环计算一下线下取价 --
  607 + for (var k = 0; k < arr.length; k++) {
  608 + var c_item = arr[k];
  609 + var item = arr[k].goods;
  610 + var offline_price = 0;
  611 + var offline_num = 0;
  612 + for (var c = 0; c < item.length; c++) {
  613 + //-- 如果这个商品是线下取价的时候 --
  614 + if (item[c].offline_price > 0 && item[c].prom_type != 7) {
  615 + offline_price += (item[c].goods_price - item[c].offline_price) * item[c].goods_num;
  616 + offline_num += item[c].goods_num;
  617 + }
  618 + }
  619 + if (offline_price > 0) {
  620 + c_item.offline_price = offline_price;
  621 + c_item.offline_num = offline_num;
  622 + c_item.is_offline = 1;
  623 + }
  624 + }
  625 +
  626 + //每一个门店内的组合购要进行拆分,
  627 + //还得把组合商品的多余商品的线下价格算一算
  628 + for (let var1 in arr) {
  629 + var u_item = arr[var1];
  630 + //把组合购进行分组
  631 + var obj = zh_calc.find_split(u_item);
  632 + if (!obj) continue;
  633 + //存储不同活动的商品列表
  634 + u_item.zh_prom_goods = {};
  635 + for (let var1 in obj) {
  636 + var h_item = obj[var1];
  637 + var gdlist = null;
  638 + var url1 = "/api/weshop/prom/zhbuyGoods/page";
  639 + var req_data = {
  640 + page: 1,
  641 + pageSize: 2000,
  642 + store_id: os.stoid,
  643 + zh_id: h_item.prom_id,
  644 + }
  645 + await getApp().request.promiseGet(url1, {
  646 + data: req_data
  647 + }).then(res => {
  648 + if (ut.ajax_ok(res)) {
  649 + gdlist = res.data.data.pageData;
  650 + }
  651 + })
  652 + //获取活动需要的商品列表
  653 + u_item.zh_prom_goods[h_item.prom_id] = {gdlist: gdlist, act: h_item.act};
  654 + }
  655 + zh_calc.fir_set_arr(u_item, th);
  656 + }
  657 + //深拷贝
  658 + th.data.old_cartlist = JSON.parse(JSON.stringify(arr));
  659 + th.setData({
  660 + cartlist: arr,
  661 + });
  662 + //--- 获取一下看有没有优惠券 ----
  663 + setTimeout(function () {
  664 + var frozenQuan = null;
  665 + var url0 = "/api/weshop/users/frozenQuan/listFrozenQuan/" + app.globalData.user_id;
  666 + app.request.promiseGet(url0, {1: 1}).then(res => {
  667 + if (res.data.code == 0) {
  668 + frozenQuan = res.data.data;
  669 + th.data.frozenQuan = frozenQuan;
  670 + }
  671 + th.calculatePrice();
  672 + th.get_cart_quan();
  673 + })
  674 +
  675 + }, 500)
  676 +
  677 + }
  678 + });
  679 + },
  680 +
  681 + //-----获取立即购买的商品信息,入口----
  682 + get_buy_goods: function (e) {
  683 + var th = this;
  684 + var gg = to.get_b_now();
  685 + //--------如果goods_id一样,就是要立即购买-----
  686 + if (e == gg.goods_id) {
  687 + a.get("/api/weshop/goods/get/" + oo.stoid + "/" + e, {
  688 + success: async function (t) {
  689 + var gd = t.data.data;
  690 + if (!gd) return false;
  691 +
  692 + t.data.data.original_img = oo.imghost + t.data.data.original_img;
  693 + t.data.data['buynum'] = gg.goods_num;
  694 + var distr_t = 0, et = 0
  695 + if (t.data.data.distr_type == 0) {
  696 + distr_t = gg.pick_dis;
  697 + } else {
  698 + distr_t = t.data.data.distr_type;
  699 + }
  700 +
  701 + switch (distr_t) {
  702 + case 0:
  703 + et = 1;
  704 + //-- 系统后台有设置要默认的 --
  705 + if (th.data.json_d.pickupway && th.data.json_d.pickupway == 1) et = 0;
  706 + break;
  707 + case 1:
  708 + et = 1;
  709 + break;
  710 + case 2:
  711 + et = 0;
  712 + break;
  713 + }
  714 +
  715 +
  716 + var m_wind = 0, def_exp_code = getApp().globalData.userInfo.def_exp_code;
  717 + if (et == 0 && def_exp_code) {
  718 + for (var k = 0; k < th.data.wu_arr.length; k++) {
  719 + var item = th.data.wu_arr[k];
  720 + if (def_exp_code == item.code) {
  721 + m_wind = k;
  722 + }
  723 + }
  724 + }
  725 +
  726 + if (th.data.bn_goods) {
  727 + et = th.data.bn_exp_type;
  728 + m_wind = th.data.index;
  729 + }
  730 +
  731 + //---是不是购买等级卡成功的返回---等级卡显示的判断---
  732 + var is_card_back = getApp().globalData.is_card_back;
  733 + if (is_card_back) {
  734 + th.data.card_name = th.data.userinfo.card_field;
  735 + gg.goods_price = gd[th.data.card_name];
  736 + getApp().globalData.is_card_back = 0;
  737 + th.setData({card_cut_price: 0});
  738 + //如果是秒杀的返回
  739 + if (gd.prom_type == 1) gd.prom_type = 0;
  740 + } else {
  741 + //--- 商家等级卡开通的情况下, 会员不是等级会员的情况, 商品有设置等级卡价格,同时等级卡价格小于商品的价格
  742 + //-- 搭配购的商品也可以单独购买,所以此时搭配购的商品要进行计算优惠 --
  743 + if (!gg.collocation_goods && gd['prom_type'] != 6 && th.data.card_name && gd[th.data.card_name] > 0 && gg.goods_price > gd[th.data.card_name] && !th.data.userinfo.card_field) {
  744 + var cut_p = (gg.goods_price - gd[th.data.card_name]) * gg.goods_num;
  745 + th.setData({card_cut_price: cut_p});
  746 + }
  747 + }
  748 +
  749 + switch (gd.prom_type) {
  750 + case 0:
  751 + case 2:
  752 + case 3:
  753 + case 4:
  754 + case 5:
  755 + case 6:
  756 + case 7:
  757 + //--此时开始计算商品的使用券相关,如果有等级价还要计算和等级价相关的,
  758 + // 如果有优惠促销,还要把促销的部分计算在内,因为促销还有不能使用优惠券--
  759 + t.data.data.shop_price = gg.goods_price;
  760 + t.data.data.goods_price = gg.goods_price;
  761 + t.data.data.goods_num = gg.goods_num;
  762 + th.data.ckeck_quan_price = t.data.data.shop_price * gg.goods_num;
  763 + th.data.check_quan_price_list = t.data.data.shop_price * gg.goods_num + "";
  764 + th.data.check_quan_ware_list = t.data.data.erpwareid + "";
  765 +
  766 + //-- 如果有线下取价的时候 --
  767 + if (gg.offline_price) {
  768 + t.data.data.offline_price = gg.offline_price;
  769 + t.data.data.pricing_type = gg.pricing_type;
  770 + t.data.data.is_offline = 1;
  771 +
  772 + th.data.ckeck_quan_price = t.data.data.offline_price * gg.goods_num;
  773 + th.data.check_quan_price_list = t.data.data.offline_price * gg.goods_num + "";
  774 + th.data.check_quan_ware_list = t.data.data.erpwareid + "";
  775 + }
  776 +
  777 + t.data.data.prom_id = 0;
  778 + t.data.data.prom_type = 0;
  779 +
  780 + //如果立即购买那边过来,就要读取接口,查看活动的优惠内容
  781 + if (gg.prom_type == 3) {
  782 + t.data.data.prom_id = gg.prom_id;
  783 + t.data.data.prom_type = 3;
  784 + //如果是优惠活动,就要调用活动,计算价格
  785 + th.buy_now_prom_goods(gg.prom_id, t.data.data, function (data) {
  786 + //判断一下购买商品的数量是不是超过
  787 + if (data.gift_goods_id) {
  788 + var num = 1;
  789 + if (data.is_bz == 1) {
  790 + num = data.bs;
  791 + if (num > data.gift_limit_num) num = 0;
  792 + }
  793 + //如果赠品数量超出礼品库存,就取消
  794 + if (num > data['gift_storecount']) num = 0;
  795 + if (num > 0) {
  796 + var ob = {};
  797 + ob.is_gift = 1;
  798 + ob.prom_id = data.prom_id;
  799 + ob.goods_id = data.gift_goods_id;
  800 + ob.goods_name = data.gift_goods_name;
  801 + ob.goods_color = data.gift_goods_color;
  802 + ob.goods_spec = data.gift_goods_spec;
  803 + ob.original_img = os.imghost + data.gift_original_img;
  804 + ob.market_price = data.gift_market_price;
  805 + ob.gift_id = data.gift_id;
  806 + ob.shop_price = 0;
  807 + ob.buynum = num;
  808 + ob.weight = data.gift_weight; //商品的重量
  809 + ob.exp_sum_type = data.gift_exp_sum_type; //商品的物流计算方式
  810 + ob.uniform_exp_sum = data.gift_uniform_exp_sum //统一运费的金额
  811 +
  812 + th.setData({buy_now_gift_goods: ob});
  813 + }
  814 + }
  815 +
  816 + th.setData({
  817 + bn_goods: data, bn_pickname: gg.pick_name, index: m_wind,
  818 + bn_pick: gg.pick_id, bn_t_exp_t: distr_t, bn_exp_type: et
  819 + });
  820 +
  821 + //计算价格
  822 + th.calculatePrice2();
  823 + //获取优惠券
  824 + th.get_buy_now_quan();
  825 +
  826 + })
  827 + } else {
  828 + //--看是不是搭配促销--
  829 + if (gg.prom_type == 5) {
  830 + t.data.data.prom_id = gg.prom_id;
  831 + t.data.data.prom_type = 5;
  832 + if (gg.room_id) {
  833 + t.data.data.room_id = gg.room_id;
  834 + }
  835 + //--主商品要有导购id和导购类型--
  836 + if (gg.guide_id) {
  837 + t.data.data.guide_id = gg.guide_id;
  838 + t.data.data.guide_type = gg.guide_type;
  839 + }
  840 + th.setData({collocation_goods: gg.collocation_goods});
  841 +
  842 + var cart_arr = new Array();
  843 + //var narr=gg.collocation_goods;
  844 + //修改成深拷贝,确保返回是数据正确
  845 + var narr = JSON.parse(JSON.stringify(gg.collocation_goods));
  846 +
  847 + narr.push(t.data.data);
  848 +
  849 + //-- 搭配促销的门店配送方式的修复 --
  850 + et = 1;
  851 + distr_t = 0;
  852 + for (var hi in narr) {
  853 + var dis_t = narr[hi].distr_type;
  854 + if (dis_t == 2) {
  855 + th.setData({is_all_zt: 0});
  856 + et = 0;
  857 + }
  858 + if (dis_t > 0) {
  859 + distr_t = dis_t;
  860 + }
  861 + }
  862 +
  863 + //自选的时候,系统配置了默认的配送方式是物流的时候
  864 + if (distr_t == 0 && th.data.json_d.pickupway && th.data.json_d.pickupway == 1) {
  865 + et = 0;
  866 + }
  867 +
  868 +
  869 + var ie = {
  870 + pickup_id: gg.pick_id,
  871 + pname: gg.pick_name,
  872 + goods: narr,
  873 + exp_type: et,
  874 + wind: m_wind,
  875 + distr_t: distr_t,
  876 + bn_t_exp_t: distr_t,
  877 + goods_price: 0,
  878 + shipping_price: 0,
  879 + user_money: 0,
  880 + total_amount: 0,
  881 + order_amount: 0,
  882 + user_note: 0
  883 + };
  884 + cart_arr.push(ie);
  885 + th.data.old_cartlist = cart_arr;
  886 + }
  887 + th.setData({
  888 + bn_goods: t.data.data, bn_pickname: gg.pick_name, index: m_wind,
  889 + bn_pick: gg.pick_id, bn_t_exp_t: distr_t, bn_exp_type: et
  890 + });
  891 +
  892 +
  893 + //--搭配促销也是按照购物车的方式来计算优惠券--
  894 + if (gg.prom_type == 5) {
  895 + var frozenQuan = null;
  896 + var url0 = "/api/weshop/users/frozenQuan/listFrozenQuan/" + app.globalData.user_id;
  897 + app.request.promiseGet(url0, {1: 1}).then(res => {
  898 + if (res.data.code == 0) {
  899 + frozenQuan = res.data.data;
  900 + th.data.frozenQuan = frozenQuan;
  901 + }
  902 + //计算价格
  903 + th.calculatePrice2();
  904 + th.get_cart_quan();
  905 + });
  906 + } else {
  907 + //计算价格
  908 + th.calculatePrice2();
  909 + //获取优惠券,
  910 + th.get_buy_now_quan();
  911 + }
  912 + }
  913 +
  914 + break;
  915 + case 1: //---秒杀-----
  916 + var quanlist = null;
  917 + getApp().request.get("/api/weshop/activitylist/getSJGoodsPrice/" + gd.store_id
  918 + + "/" + gd.goods_id + "/1/" + gd.prom_id, {
  919 + success: async function (tt) {
  920 + if (tt.data.code == 0) {
  921 + t.data.data.shop_price = tt.data.data.prom_price;
  922 + } else {
  923 + t.data.data.prom_id = 0;
  924 + t.data.data.prom_type = 0;
  925 +
  926 + th.data.ckeck_quan_price = t.data.data.shop_price * gg.goods_num;
  927 + th.data.check_quan_price_list = t.data.data.shop_price * gg.goods_num + "";
  928 + th.data.check_quan_ware_list = t.data.data.erpwareid + "";
  929 + }
  930 +
  931 + th.setData({
  932 + bn_goods: t.data.data,
  933 + bn_pickname: gg.pick_name,
  934 + bn_exp_type: et,
  935 + index: m_wind,
  936 + bn_pick: gg.pick_id,
  937 + bn_t_exp_t: distr_t,
  938 + bn_exp_type: et
  939 + });
  940 +
  941 + //计算价格
  942 + th.calculatePrice2();
  943 + //获取优惠券
  944 + th.get_buy_now_quan();
  945 + }
  946 + });
  947 +
  948 + break;
  949 + }
  950 + },
  951 + });
  952 + }
  953 + },
  954 +
  955 + //---------------检查是否有收货地址-------------------
  956 + checkAddressList: function () {
  957 + var t = this;
  958 + return !(!this.data.order || null == this.data.order.userAddress) || (wx.showModal({
  959 + title: "请先填写或选择收货地址~",
  960 + success: function (a) {
  961 + a.confirm ? t.enterAddressPage() : wx.navigateBack();
  962 + },
  963 + fail: function () {
  964 + wx.navigateBack();
  965 + }
  966 + }), !1);
  967 + },
  968 + showInvoice: function () {
  969 + this.setData({
  970 + invoiceToggle: !this.data.invoiceToggle
  971 + });
  972 + },
  973 + keyUpChangePay1: function (t) {
  974 + this.setData({
  975 + payWithUserMoney: !(t.detail.value.length > 0)
  976 + });
  977 + },
  978 + keyUpChangePay2: function (t) {
  979 + this.setData({
  980 + payWithPoints: !(t.detail.value.length > 0)
  981 + });
  982 + },
  983 + keyUpChangeNum: function (t) {
  984 + this.setData({
  985 + maxWord: t.detail.value.length
  986 + });
  987 + },
  988 +
  989 + calc_per: async function (c_arr) {
  990 + var th = this;
  991 + //-- 循环处理 --
  992 + for (var i in c_arr) {
  993 + var cart_item = c_arr[i]; //就是每一单的意思
  994 + var pickid = cart_item.pickup_id;
  995 + var ord_goods = c_arr[i].goods; //就是每一单的从表的意思
  996 + var o_price = 0, q_conditin = 0;
  997 + //--------循环计算总价-----------
  998 + for (var j = 0; j < ord_goods.length; j++) {
  999 + o_price += ord_goods[j].goods_price * ord_goods[j].goods_num;
  1000 + }
  1001 +
  1002 + //---如果该门店的相关活动,就要算一下减价--
  1003 + if (th.data.prom_goods_map[pickid]) {
  1004 + var ob = th.data.prom_goods_map[pickid];
  1005 + for (var ii in ob) {
  1006 + var item_map = ob[ii];
  1007 + if (item_map.bs == undefined || item_map.bs == null) {
  1008 + //等待,获取一下优惠活动的信息
  1009 + await getApp().request.promiseGet("/api/weshop/goods/getDiscount", {
  1010 + data: {
  1011 + price: item_map.price, prom_id: item_map.prom_id,
  1012 + goods_num: item_map.goods_num, user_id: getApp().globalData.user_id,
  1013 + is_bz: item_map.is_bz
  1014 + }
  1015 + }).then(res => {
  1016 + if (res.data.code == 0 && res.data.data.condition) {
  1017 + var get_data = res.data.data;
  1018 + item_map.is_bz = get_data.is_bz; //是不是倍增
  1019 + item_map.bs = get_data.bs; //是不是倍数
  1020 + item_map.is_past = get_data.is_past; //是不是包邮
  1021 + item_map.prom_price = get_data.price >= 0 ? get_data.price : item_map.price;
  1022 + item_map.s_intValue = get_data.intValue;
  1023 + item_map.s_coupon_id = get_data.coupon_id;
  1024 + item_map.s_coupon_num = get_data.coupon_num;
  1025 + if (get_data.gift_id && get_data.goodsinfo) {
  1026 + item_map.gift_id = get_data.gift_id;
  1027 + item_map.gift_goods_id = get_data.goods_id;
  1028 + item_map.gift_goods_name = get_data.goods_name;
  1029 + item_map.gift_goods_color = get_data.goodsinfo.goods_color ? get_data.goodsinfo.goods_color : '';
  1030 + item_map.gift_goods_spec = get_data.goodsinfo.goods_spec ? get_data.goodsinfo.goods_spec : '';
  1031 + item_map.gift_original_img = get_data.goodsinfo.original_img;
  1032 + item_map.gift_limit_num = get_data.limit_num;
  1033 + item_map.gift_storecount = get_data.gift_storecount;
  1034 + item_map.gift_weight = get_data.goodsinfo.weight;
  1035 + item_map.gift_exp_sum_type = get_data.goodsinfo.exp_sum_type;
  1036 + item_map.uniform_exp_sum = get_data.goodsinfo.uniform_exp_sum;
  1037 +
  1038 + }
  1039 + item_map.s_libao = get_data.libao;
  1040 + item_map.s_lb_num = get_data.lb_num;
  1041 + }
  1042 + })
  1043 + }
  1044 +
  1045 + //有活动,且优惠活动并没有限制使用优惠券,且有减价
  1046 + //--看有没有减价--
  1047 + //if(item_map.prom_price>=0 && item_map.price-item_map.prom_price){
  1048 + if (item_map.price - item_map.prom_price && item_map.prom_price !== null) {
  1049 + if (cart_item.prom_pt_json) {
  1050 + cart_item.prom_pt_json.push({
  1051 + "prom_id": item_map.prom_id,
  1052 + "dis": (item_map.price - item_map.prom_price).toFixed(2),
  1053 + "ispt": 0
  1054 + })
  1055 + } else {
  1056 + cart_item.prom_pt_json = [{
  1057 + "prom_id": item_map.prom_id,
  1058 + "dis": (item_map.price - item_map.prom_price).toFixed(2),
  1059 + "ispt": 0
  1060 + }];
  1061 + }
  1062 +
  1063 + //-- 如果系统要平摊到单品 --
  1064 +
  1065 + var pt_data = {
  1066 + 'prom_id': item_map.prom_id,
  1067 + 'dis': parseFloat((item_map.price - item_map.prom_price).toFixed(2)),
  1068 + 'goods': item_map.goods
  1069 + }
  1070 +
  1071 + var pt_res = null;
  1072 + await getApp().request.promisePost("/api/weshop/order/getGoodsSplit", {
  1073 + is_json: 1,
  1074 + data: pt_data
  1075 + }).then(res => {
  1076 + if (res.data.code == 0) {
  1077 + pt_res = res.data.data;
  1078 + }
  1079 + })
  1080 + if (pt_res) {
  1081 + for (var io in item_map.goods) {
  1082 + //平摊赋值
  1083 + item_map.goods[io].account_fir = th.arr_get_goods(item_map.goods[io].goods_id, pt_res).fisrt_account;
  1084 + item_map.goods[io].account_yu_fir = th.arr_get_goods(item_map.goods[io].goods_id, pt_res).fisrt_account_yu;
  1085 + if (!th.data.ispt_goods) {
  1086 + item_map.goods[io].account = item_map.goods[io].account_fir;
  1087 + item_map.goods[io].account_yu = item_map.goods[io].account_yu_fir;
  1088 + }
  1089 + }
  1090 + }
  1091 +
  1092 +
  1093 + o_price -= (item_map.price - item_map.prom_price);
  1094 + //如果有限制使用优惠券,就要减掉参与的活动商品的钱
  1095 + if (!item_map.is_xz_yh) q_conditin = o_price;
  1096 + }
  1097 +
  1098 + //--------循环计算商品是不是包邮,是不是使用优惠券,此时循环是商品从表-----------
  1099 + for (var j = 0; j < ord_goods.length; j++) {
  1100 + if (ord_goods[j].is_gift) continue;
  1101 + if (ord_goods[j].prom_type == 3 && ord_goods[j].prom_id == item_map.prom_id) {
  1102 + ord_goods[j].is_xz_yh = item_map.is_xz_yh;
  1103 + ord_goods[j].is_past = item_map.is_past;
  1104 + ord_goods[j].account_fir = th.item_map_get_goods(ord_goods[j].goods_id, item_map).account_fir;
  1105 + ord_goods[j].account_yu_fir = th.item_map_get_goods(ord_goods[j].goods_id, item_map).account_yu_fir;
  1106 + ord_goods[j].account = th.item_map_get_goods(ord_goods[j].goods_id, item_map).account;
  1107 + ord_goods[j].account_yu = th.item_map_get_goods(ord_goods[j].goods_id, item_map).account_yu;
  1108 + }
  1109 + }
  1110 +
  1111 +
  1112 + //--优惠多少钱--
  1113 + if (!cart_item.cut_price) cart_item.cut_price = 0;
  1114 + //-- --
  1115 + if (item_map.price != undefined && item_map.price != null
  1116 + && item_map.prom_price != undefined && item_map.prom_price != null)
  1117 + cart_item.cut_price += (item_map.price - item_map.prom_price);
  1118 + //---如果有送积分---
  1119 + if (item_map.s_intValue) {
  1120 + if (!cart_item.s_intValue) cart_item.s_intValue = 0;
  1121 + cart_item.s_intValue += item_map.s_intValue;
  1122 + }
  1123 + //-- 如果有送优惠券的情况 --
  1124 + if (item_map.s_coupon_id) {
  1125 + if (!cart_item.s_coupon_id) {
  1126 + cart_item.s_coupon_id = item_map.s_coupon_id + "";
  1127 + cart_item.g_coupon_num = [{'c_id': item_map.s_coupon_id, "num": item_map.s_coupon_num}];
  1128 + }
  1129 + else {
  1130 + cart_item.s_coupon_id += "," + item_map.s_coupon_id;
  1131 + cart_item.g_coupon_num.push({'c_id': item_map.s_coupon_id, "num": item_map.s_coupon_num})
  1132 + }
  1133 + }
  1134 +
  1135 + //-- 如果有送优包邮券的情况 --
  1136 + if (item_map.s_libao) {
  1137 + if (!cart_item.s_libao) {
  1138 + cart_item.s_libao = item_map.s_libao + "";
  1139 + cart_item.g_lb_num = [{'l_id': item_map.s_libao, "num": item_map.s_lb_num}];
  1140 + }
  1141 + else {
  1142 + cart_item.s_libao += "," + item_map.s_libao;
  1143 + cart_item.g_lb_num.push({'l_id': item_map.s_libao, "num": item_map.s_lb_num})
  1144 + }
  1145 + }
  1146 + }
  1147 + }
  1148 + }
  1149 + },
  1150 +
  1151 + //-------------------计算订单价格-------------------
  1152 + calculatePrice: function (t, s) {
  1153 + var th = this;
  1154 + to.getConfig2(function (ee) {
  1155 + to.getwuliuprice(async function (rs) {
  1156 + wx.showLoading({
  1157 + title: "处理中."
  1158 + })
  1159 + var all_price = 0; //所有的商品总价
  1160 + var all_shipping_m = 0; //所有的物流总价
  1161 + var all_total_m = 0; //所有的订单应付总价
  1162 + var all_order_m = 0; //所有的订单应付总价
  1163 + var all_user_m = 0; //所有的订单用户使用金额
  1164 + var all_coupon_price_m = 0; //所有的订单用户使用优惠券价格
  1165 + var all_cutprice = 0; //所有的优惠减
  1166 + var all_zh_cutprice = 0; //所有的组合优惠减
  1167 + var all_order_prom = 0; //所有的订单优惠
  1168 +
  1169 + var umoney = th.data.userinfo.user_money - th.data.txmon - (th.data.userinfo.frozen_money ? th.data.userinfo.frozen_money : 0);
  1170 + var freight_free = ee.freight_free; //全场满多少包邮
  1171 + var no_ex_id = ee.no_ex_id;
  1172 + var no_ex_good = null;
  1173 + var by_qc = {};
  1174 +
  1175 + if (no_ex_id && freight_free > 0) {
  1176 + //-----------获取不包邮区域,不包邮商品-------
  1177 + await getApp().request.promiseGet("/api/weshop/areaFeemail/getAreaGoods", {
  1178 + data: {store_id: os.stoid, id: no_ex_id}
  1179 + }).then(res => {
  1180 + if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
  1181 + by_qc = res.data.data[0];
  1182 + }
  1183 + })
  1184 + }
  1185 + ;
  1186 + var c_arr = JSON.parse(JSON.stringify(th.data.old_cartlist));
  1187 +
  1188 + if (th.data.cartlist && th.data.cartlist.length > 0) {
  1189 + for (var i = 0; i < c_arr.length; i++) {
  1190 + c_arr[i].exp_type = th.data.cartlist[i].exp_type;
  1191 + c_arr[i].wind = th.data.cartlist[i].wind;
  1192 + }
  1193 + }
  1194 +
  1195 + //调用函数计算每件商品的单价
  1196 + await th.calc_per(c_arr);
  1197 + //调用函数计算每件组合购商品的单价,
  1198 + await zh_calc.calc_zh_split_price(c_arr,th);
  1199 + //调用函数计算,优惠券优惠什么商品价格,优惠券优惠什么商品
  1200 + await th.get_cart_quan(c_arr);
  1201 + //---循环购物车---
  1202 + for (var i in c_arr) {
  1203 + //因为搭配购买也是再这里计算,搭配购的is_b_now==1
  1204 + if (th.data.is_b_now == 0) {
  1205 + //此时物流的选择方式要用th.data.cartlist;
  1206 + c_arr[i].exp_type = th.data.cartlist[i].exp_type;
  1207 + c_arr[i].wind = th.data.cartlist[i].wind;
  1208 + if (th.data.cartlist[i].check_quan_price_list) c_arr[i].check_quan_price_list = th.data.cartlist[i].check_quan_price_list; //优惠券优惠什么商品价格
  1209 + if (th.data.cartlist[i].check_quan_ware_list) c_arr[i].check_quan_ware_list = th.data.cartlist[i].check_quan_ware_list; //优惠券优惠什么商品
  1210 + } else {
  1211 + c_arr[i].exp_type = th.data.bn_exp_type; //配送方式
  1212 + c_arr[i].wind = th.data.index; //立即购买选择的物流
  1213 + //c_arr[i].=th.data. //立即购买的使用余额
  1214 + if (th.data.cartlist) c_arr[i].check_quan_price_list = th.data.cartlist[i].check_quan_price_list; //优惠券优惠什么商品价格
  1215 + if (th.data.cartlist) c_arr[i].check_quan_ware_list = th.data.cartlist[i].check_quan_ware_list; //优惠券优惠什么商品
  1216 + }
  1217 +
  1218 + var cart_item = c_arr[i]; //就是每一单的意思
  1219 + var pickid = cart_item.pickup_id;
  1220 + var o_price = 0;
  1221 + var o_price_no_zh=0; //不包含限制优惠叠加组合购的金额汇总
  1222 + var o_shipping_price = 0, goods_weight = -1, goods_piece = -1;
  1223 + var item = c_arr[i].goods; //就是每一单的从表的意思
  1224 +
  1225 + //---如果有选择优惠券的情况下---
  1226 + var quan_price = 0;
  1227 + var coupon_price = 0;
  1228 + var quan_no = null;
  1229 + var is_has_zh=c_arr[i].is_has_zh;
  1230 + var zh_prom_goods=c_arr[i].zh_prom_goods; //组合购计算的原始数据存储空间
  1231 +
  1232 + if (th.data.using_quan[pickid] != null && th.data.using_quan[pickid] != undefined)
  1233 + quan_no = th.data.using_quan[pickid].coupon_no;
  1234 +
  1235 + //普通券的时候
  1236 + if (quan_no && th.data.using_quan[pickid].isby != 1) {
  1237 + //---获取优惠券优惠---
  1238 + await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice", {
  1239 + data: {
  1240 + storeId: oo.stoid,
  1241 + CashRepNo: quan_no,
  1242 + WaresSum: cart_item.check_quan_price_list,
  1243 + WareIds: cart_item.check_quan_ware_list
  1244 + }
  1245 + }).then(res => {
  1246 + if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
  1247 + var q_data = res.data.data;
  1248 + //--存储商品优惠的内容--
  1249 + cart_item.quan_youhui_list = q_data;
  1250 + for (var k in q_data)
  1251 + quan_price += q_data[k].WareCashSum;
  1252 + }
  1253 + })
  1254 + }
  1255 +
  1256 + //--------循环计算总价-----------
  1257 + for (var j = 0; j < item.length; j++) {
  1258 + if(item[j].prom_type!=7){
  1259 + o_price_no_zh += item[j].goods_price * item[j].goods_num;
  1260 + }
  1261 + //组合购的商品,且没有订单优惠的叠加,is_orderyh就是优惠叠加
  1262 + if(zh_prom_goods[item[j].prom_id] && !zh_prom_goods[item[j].prom_id].act.is_orderyh )
  1263 + {
  1264 + o_price_no_zh += item[j].goods_price * item[j].goods_num;
  1265 + }
  1266 + o_price += item[j].goods_price * item[j].goods_num;
  1267 + }
  1268 + //判断是不是有组合购的金额
  1269 + var f_o_price = o_price;
  1270 + //如果又优惠的钱,就要减价
  1271 + if (c_arr[i].cut_price > 0){
  1272 + o_price -= c_arr[i].cut_price;
  1273 + o_price_no_zh-=c_arr[i].cut_price;
  1274 + }
  1275 + //如果有组合购优惠的钱,就要减价
  1276 + if (c_arr[i].zh_cut_price > 0){
  1277 + o_price -= c_arr[i].zh_cut_price;
  1278 + if(o_price_no_zh>0){
  1279 + //找到那些可以订单优惠叠加的
  1280 + for(let ij in zh_prom_goods){
  1281 + let kitem=zh_prom_goods[ij];
  1282 + if(kitem.act.is_orderyh) continue;
  1283 + o_price_no_zh-=kitem.cut_price;
  1284 + }
  1285 + }
  1286 + }
  1287 +
  1288 + //-- 计算线下取价的功能 --
  1289 + if (cart_item.is_offline == 1) {
  1290 + o_price = o_price - cart_item.offline_price;
  1291 + o_price_no_zh-=c_arr[i].offline_price;
  1292 + }
  1293 + //判断包邮券的钱,组合购的商品不使用优惠券
  1294 + var q_conditin = 0;
  1295 + q_conditin = o_price - quan_price;
  1296 + if(is_has_zh){
  1297 + q_conditin = o_price_no_zh - quan_price;
  1298 + }
  1299 + cart_item.goods_price = f_o_price.toFixed(2); //商品总费用,用f_o_price来计算
  1300 + //计算物流费用
  1301 + cart_item.shipping_price = 0;
  1302 +
  1303 +
  1304 + //--有不包邮区域,且不免运费,全场的计算,要减到优惠金额 和券的金额--
  1305 + if (no_ex_id && freight_free > 0 && (o_price - quan_price) >= freight_free && cart_item.exp_type == 0 && (by_qc.region_list || by_qc.goods_list)) {
  1306 + //如果有设置不包邮区域的时候
  1307 + if (by_qc.region_list != "" && by_qc.region_list != null && by_qc.region_list != undefined) {
  1308 + if (th.check_by_area(by_qc.region_list)) {
  1309 + freight_free = 0;
  1310 + th.data.is_no_by[pickid] = 1;
  1311 + }
  1312 + }
  1313 + //如果有设置不包邮区商品
  1314 + if (by_qc.goods_list != "" && by_qc.goods_list != undefined && by_qc != null && freight_free > 0) {
  1315 + freight_free = 0;
  1316 + no_ex_good = by_qc.goods_list;
  1317 + }
  1318 + }
  1319 +
  1320 + //--如果是物流,且选择了地址,就要开始显示包邮券,且包邮券也已经优惠了优惠活动的金额--
  1321 + if (cart_item.exp_type == 0 && th.data.user_addr != null) {
  1322 + //看是不是有调用过包邮券
  1323 + if (!th.data.isget_by_quan[pickid]) {
  1324 + //--判断要不要显示包邮券,调用接口,因为有for循环---
  1325 + await getApp().request.promiseGet("/api/weshop/userfeemail/pageAndArea", {
  1326 + data: {
  1327 + store_id: os.stoid,
  1328 + isuse: 0,
  1329 + condition: q_conditin,
  1330 + user_id: getApp().globalData.user_id,
  1331 + pageSize: 2000
  1332 + }
  1333 + }).then(res => {
  1334 + if (res.data.code == 0 && res.data.data.total > 0) {
  1335 + //此时要循环判断包邮的地区,不包邮商品是不是符合
  1336 + var arr = [], quanlist = res.data.data.pageData;
  1337 + quanlist = th.check_is_frozenQuan(quanlist, th.data.frozenQuan, 1);
  1338 + for (var i in quanlist) {
  1339 + var item = quanlist[i];
  1340 + var goods = cart_item.goods;
  1341 + var g_arr = [];
  1342 + for (var ii in goods) {
  1343 + g_arr.push(goods[ii].goods_id);
  1344 + }
  1345 + if (item.region_list && th.check_by_area(item.region_list)) continue; //如果是不包邮区域
  1346 + if (item.goods_list) {
  1347 + var no_goods_arr = item.goods_list.split(",");
  1348 + if (ut.isContained(no_goods_arr, g_arr)) continue; //如果是不包邮商品
  1349 + }
  1350 + arr.push(item);
  1351 + }
  1352 + if (arr) {
  1353 + th.data.get_by_quan_list_cart[pickid] = arr;
  1354 + //th.setData({get_by_quan_list_cart:th.data.get_by_quan_list_cart});
  1355 + if (th.data.is_b_now) {
  1356 + th.setData({get_by_quan_list: arr});
  1357 + }
  1358 + }
  1359 + th.data.isget_by_quan[pickid] = 1;
  1360 + }
  1361 + })
  1362 + }
  1363 + }
  1364 +
  1365 + //如果是包邮券的时候,要看看券的情况
  1366 + if (quan_no && th.data.using_quan[pickid].isby == 1) {
  1367 + var quan = th.data.using_quan[pickid];
  1368 + if (!quan.goods_list) {
  1369 + th.data.is_quan_by[pickid] = 1; //专门给券的判断用的
  1370 + } else {
  1371 + th.data.is_quan_by[pickid] = 0;
  1372 + //看有没有模板的包邮
  1373 + if (no_ex_good) {
  1374 + var arr = no_ex_good.split(",");
  1375 + var arr2 = quan.goods_list.split(",");
  1376 + if (ut.isContained(arr, arr2)) {
  1377 + getApp().my_warnning("全场不包邮商品和包邮券的重复", 0, th);
  1378 + th.data.using_quan[pickid] = {};
  1379 + th.setData({using_quan: th.data.using_quan})
  1380 + return false;
  1381 + }
  1382 + var n_arr = ut.mergeArray(arr, arr2);
  1383 + no_ex_good = n_arr.join(",");
  1384 + } else {
  1385 + no_ex_good = quan.goods_list;
  1386 + }
  1387 + }
  1388 + } else {
  1389 + th.data.is_quan_by[pickid] = 0; //专门给券的判断用的
  1390 + }
  1391 +
  1392 + //--------循环计算总价-----------
  1393 + for (var j = 0; j < item.length; j++) {
  1394 + //如果都包邮,都没必要等级数量了
  1395 + if (th.data.is_quan_by[pickid]) continue;
  1396 + //如果是优惠活动是包邮,就不用计算包邮的费用了
  1397 + if (item[j].is_past) continue;
  1398 + //是不是不包邮的商品
  1399 + var is_good_no_by = 0;
  1400 + if (no_ex_good) {
  1401 + is_good_no_by = th.check_by_goods(no_ex_good, item[j].goods_id);
  1402 + }
  1403 +
  1404 + //如果达到全场包邮的条件,同时,没有地区不包邮,或者商品不包邮
  1405 + if (o_price - quan_price >= freight_free && freight_free > 0 && !is_good_no_by && th.data.is_no_by[pickid] != 1) {
  1406 + continue;
  1407 + }
  1408 +
  1409 + //--如果是包邮券使用的情况下,如果商品是包邮的,那么就不进行计算--
  1410 + if (th.data.using_quan[pickid] && th.data.using_quan[pickid].isby == 1 && !is_good_no_by) {
  1411 + continue;
  1412 + }
  1413 +
  1414 + var no_ex_good_arr = null;
  1415 + if (no_ex_good) no_ex_good_arr = no_ex_good.split(',');
  1416 +
  1417 + //----------------如果是选择了物流---------------------
  1418 + if (cart_item.exp_type == 0 && item[j].is_free_shipping == 0 && (!no_ex_good_arr || no_ex_good_arr.indexOf(item[j].goods_id + '') > -1 )) {
  1419 +
  1420 + //如果地址不为空
  1421 + if (th.data.user_addr != null) {
  1422 + switch (item[j]['exp_sum_type']) {
  1423 + case 1:
  1424 + //统一运费
  1425 + o_shipping_price += item[j]['uniform_exp_sum'];
  1426 + break;
  1427 + case 2:
  1428 + +''
  1429 + if (goods_weight < 0) goods_weight = 0;
  1430 + //累积商品重量 每种商品的重量 * 数量
  1431 + goods_weight += item[j]['weight'] * item[j]['goods_num'];
  1432 +
  1433 + break;
  1434 + case 3:
  1435 + if (goods_piece < 0) goods_piece = 0;
  1436 + //累积商品数量
  1437 + goods_piece += item[j]['goods_num'];
  1438 + break;
  1439 + }
  1440 + }
  1441 +
  1442 + }
  1443 + }
  1444 +
  1445 + //计算物流价格
  1446 + if (cart_item.exp_type == 0) {
  1447 + //freight_free=0; //后面不在进行判断
  1448 + var code = "";
  1449 + if (th.data.wu_arr && th.data.wu_arr[cart_item.wind])
  1450 + code = th.data.wu_arr[cart_item.wind].code;
  1451 + cart_item.shipping_price =
  1452 + th.calculatewuliu(code, o_shipping_price, goods_weight,
  1453 + goods_piece, th.data.user_addr, freight_free, o_price - quan_price, rs);
  1454 +
  1455 + if (!th.data.using_quan[pickid] || th.data.using_quan[pickid].isby != 1) {
  1456 + if (cart_item.shipping_price == 0) th.data.is_by[pickid] = 1; //已经全场包邮,就不要选择券了
  1457 + }
  1458 + } else {
  1459 + cart_item.shipping_price = 0;
  1460 + }
  1461 +
  1462 + cart_item.shipping_price = cart_item.shipping_price.toFixed(2);
  1463 +
  1464 + //总价计算,总价不包含运费
  1465 + cart_item.order_amount = (o_price - quan_price).toFixed(2);
  1466 + cart_item.total_amount = f_o_price.toFixed(2);
  1467 +
  1468 + var order_prom_amount = 0;
  1469 + var order_prom_id = 0;
  1470 + var o_condition = cart_item.order_amount;
  1471 + //看一下是不是不用组合购的订单优惠的叠加
  1472 + if(o_price_no_zh>0){
  1473 + o_condition=o_price_no_zh-quan_price;
  1474 + }
  1475 +
  1476 + var order_m = 0;
  1477 + //---判断是不是有订单优惠---
  1478 + await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", {
  1479 + data: {store_id: os.stoid, orderAmount: o_condition}
  1480 + }).then(res => {
  1481 + if (res.data.code == 0) {
  1482 + var ord_prom = res.data.data;
  1483 + order_prom_id = ord_prom['id'];
  1484 + switch (ord_prom['type']) {
  1485 + case 0:
  1486 + order_m = Math.round(o_condition * ord_prom['expression']) / 100;//满额打折
  1487 + order_prom_amount = (o_condition - order_m).toFixed(2);
  1488 + break;
  1489 + case 1:
  1490 + //order_m = o_condition - ord_prom['expression'];//满额优惠金额
  1491 + order_prom_amount = ord_prom['expression'];
  1492 + break;
  1493 + }
  1494 + }
  1495 + })
  1496 +
  1497 + cart_item.order_prom_amount = 0;
  1498 + //--订单优惠的显示--
  1499 + if (order_prom_id > 0) {
  1500 + cart_item.order_amount = (o_price - quan_price - order_prom_amount).toFixed(2);
  1501 + cart_item.order_prom_id = order_prom_id;
  1502 + cart_item.order_prom_amount = order_prom_amount;
  1503 + }
  1504 + coupon_price = quan_price;
  1505 + if (cart_item.order_amount < 0) {
  1506 + cart_item.order_amount = 0;
  1507 + coupon_price = o_price;
  1508 + }
  1509 +
  1510 + cart_item.total_amount = parseFloat(cart_item.total_amount) + parseFloat(cart_item.shipping_price); //总金额
  1511 + cart_item.order_amount = parseFloat(cart_item.order_amount) + parseFloat(cart_item.shipping_price); //总金额
  1512 + cart_item.total_amount = cart_item.total_amount.toFixed(2);
  1513 + cart_item.order_amount = cart_item.order_amount.toFixed(2);
  1514 +
  1515 + //搭配购在使用余额
  1516 + if (th.data.bn_use_money == 1 && th.data.is_b_now == 1) {
  1517 +
  1518 + if (umoney > cart_item.order_amount) {
  1519 + cart_item.user_money = cart_item.order_amount;
  1520 + umoney = umoney - cart_item.order_amount;
  1521 + } else {
  1522 + cart_item.user_money = umoney;
  1523 + umoney = 0;
  1524 + }
  1525 +
  1526 + } else {
  1527 + //--------------如果使用余额,购物车购买---------------------
  1528 + if (th.data.js_use_money == 1) {
  1529 + if (umoney > cart_item.order_amount) {
  1530 + cart_item.user_money = cart_item.order_amount;
  1531 + umoney = umoney - cart_item.order_amount;
  1532 + } else {
  1533 + cart_item.user_money = umoney;
  1534 + umoney = 0;
  1535 + }
  1536 + } else {
  1537 + cart_item.user_money = 0;
  1538 + }
  1539 + }
  1540 +
  1541 + cart_item.user_money = parseFloat(cart_item.user_money).toFixed(2);
  1542 + if (coupon_price > 0) cart_item.coupon_price = coupon_price.toFixed(2);
  1543 + else cart_item.coupon_price = coupon_price
  1544 + if (quan_no) cart_item.quan_no = quan_no;
  1545 +
  1546 +
  1547 + //cart_item.goods_price = o_price.toFixed(2);
  1548 + cart_item.order_amount = cart_item.order_amount - cart_item.user_money; //会员使用余额
  1549 +
  1550 +
  1551 + all_price += parseFloat(f_o_price);
  1552 + all_total_m += parseFloat(cart_item.total_amount);
  1553 + all_shipping_m += parseFloat(cart_item.shipping_price);
  1554 + all_order_m += parseFloat(cart_item.order_amount);
  1555 + all_user_m += parseFloat(cart_item.user_money);
  1556 + all_coupon_price_m += parseFloat(cart_item.coupon_price);
  1557 + all_cutprice += parseFloat(cart_item.cut_price);
  1558 + all_zh_cutprice += parseFloat(cart_item.zh_cut_price);
  1559 + all_order_prom += parseFloat(cart_item.order_prom_amount);
  1560 + }
  1561 +
  1562 + all_shipping_m = parseFloat(all_shipping_m).toFixed(2);
  1563 + all_total_m = parseFloat(all_total_m).toFixed(2);
  1564 + all_order_m = parseFloat(all_order_m).toFixed(2);
  1565 + all_price = parseFloat(all_price).toFixed(2);
  1566 + all_user_m = parseFloat(all_user_m).toFixed(2);
  1567 + all_total_m = parseFloat(all_total_m).toFixed(2);
  1568 + all_coupon_price_m = parseFloat(all_coupon_price_m).toFixed(2);
  1569 + all_cutprice = all_cutprice.toFixed(2);
  1570 + all_order_prom = all_order_prom.toFixed(2);
  1571 + all_zh_cutprice = parseFloat(all_zh_cutprice).toFixed(2);
  1572 +
  1573 + var atxt = "formData.total_amount";
  1574 + var atxt1 = "formData.order_amount";
  1575 + var atxt2 = "formData.all_price";
  1576 + var atxt3 = "formData.user_money";
  1577 + var atxt4 = "formData.shipping_price";
  1578 + var atxt5 = "formData.coupon_price";
  1579 + var atxt6 = "formData.cut_price";
  1580 + var atxt7 = "formData.order_prom_amount";
  1581 + var atxt8 = "formData.zh_cut_price";
  1582 +
  1583 + th.setData({
  1584 + [atxt]: all_total_m, [atxt1]: all_order_m,
  1585 + [atxt2]: all_price, [atxt3]: all_user_m, [atxt4]: all_shipping_m,
  1586 + [atxt5]: all_coupon_price_m, [atxt6]: all_cutprice,
  1587 + [atxt7]: all_order_prom, show_submit: 1, [atxt8]: all_zh_cutprice
  1588 + })
  1589 + th.data.order_prom_list_cart = c_arr;
  1590 + th.set_can_num();
  1591 + wx.hideLoading();
  1592 +
  1593 + });
  1594 + });
  1595 + },
  1596 +
  1597 + set_can_num: function () {
  1598 + var th = this;
  1599 + //-- 这个地方,循环计算几张优惠券可用--
  1600 + for (var iter in th.data.cartlist) {
  1601 + var num = 0;
  1602 + var c_item = th.data.cartlist[iter];
  1603 + var pkid = c_item.pickup_id;
  1604 + //-- 普通券 --
  1605 + if (c_item.quan_list) {
  1606 + for (var iter1 in c_item.quan_list) {
  1607 + //判断是不是其他订单有选用
  1608 + var is_other_is_use = th.check_other_use(c_item.quan_list[iter1], pkid);
  1609 + if (!is_other_is_use) num++;
  1610 + }
  1611 + }
  1612 + //-- 包邮券 --
  1613 + var by_quan = th.data.get_by_quan_list_cart[pkid];
  1614 + if (by_quan) {
  1615 + for (var iter2 in by_quan) {
  1616 + //判断是不是其他订单有选用
  1617 + var is_other_is_use = th.check_other_use_by(by_quan[iter2], pkid);
  1618 + if (!is_other_is_use) num++;
  1619 + }
  1620 + }
  1621 + var set_txt = "cartlist[" + iter + "].can_num";
  1622 + th.setData({[set_txt]: num});
  1623 + }
  1624 + },
  1625 +
  1626 +
  1627 + //---------计算立即购买----------
  1628 + calculatePrice2: function () {
  1629 + var th = this, good = this.data.bn_goods;
  1630 +
  1631 + if (!good) return false;
  1632 +
  1633 + //搭配的计算要用购物的车计算方法
  1634 + if (good.prom_type == 5) {
  1635 + th.calculatePrice();
  1636 + return false;
  1637 + }
  1638 +
  1639 + wx.showLoading({
  1640 + title: "处理中."
  1641 + })
  1642 + //-----------计算商品总价--------------
  1643 + var allpice = good.shop_price * good.buynum;
  1644 + var cut_price = 0;
  1645 + var allpice1 = allpice;
  1646 +
  1647 +
  1648 + if (good.prom_type == 3 && good.prom_price !== null) {
  1649 + cut_price = allpice - good.prom_price;
  1650 + }
  1651 +
  1652 + allpice = parseFloat(allpice).toFixed(2);
  1653 + var txt = "formData.all_price";
  1654 + th.setData({[txt]: allpice,});
  1655 + if (cut_price) {
  1656 + var c_txt = "formData.cut_price";
  1657 + th.setData({[c_txt]: cut_price,});
  1658 +
  1659 + }
  1660 +
  1661 + //如果有线下取价的时候
  1662 + if (good.is_offline) {
  1663 + allpice = good.offline_price * good.buynum;
  1664 + }
  1665 +
  1666 +
  1667 + to.getConfig2(function (ee) {
  1668 + to.getwuliuprice(async function (rs) {
  1669 +
  1670 + var o_shipping_price = 0, goods_weight = -1, goods_piece = -1;
  1671 +
  1672 + //---如果有选择优惠券的情况下---
  1673 + var quan_price = 0, bn_pick = th.data.bn_pick;
  1674 + var quan_no = null;
  1675 + if (th.data.using_quan[bn_pick] != null && th.data.using_quan[bn_pick] != undefined)
  1676 + quan_no = th.data.using_quan[bn_pick].coupon_no;
  1677 +
  1678 + if (quan_no) {
  1679 + if (th.data.using_quan[bn_pick].isby != 1) {
  1680 + //---获取优惠券优惠---
  1681 + await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice", {
  1682 + data: {
  1683 + storeId: oo.stoid,
  1684 + CashRepNo: quan_no,
  1685 + WaresSum: th.data.ckeck_quan_price,
  1686 + WareIds: th.data.check_quan_ware_list
  1687 + }
  1688 + }).then(res => {
  1689 + if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
  1690 + quan_price = res.data.data[0].WareCashSum;
  1691 + }
  1692 + })
  1693 + }
  1694 + }
  1695 +
  1696 + //-----------当地址不为空,且是物流时,计算物流费用,并同时商品不是优惠活动的包邮----------
  1697 + if (th.data.user_addr != null && th.data.bn_exp_type == 0 && good.is_free_shipping == 0 && good.is_past != 1) {
  1698 + //看是不是有调用过包邮券
  1699 + if (!th.data.isget_by_quan[th.data.bn_pick] && good.is_xz_yh != 1) {
  1700 + var condition = allpice - cut_price - quan_price;
  1701 + //--判断要不要显示包邮券,链式调用接口,调取包邮券,已经是减了优惠的金额,见到优惠券的钱---
  1702 + getApp().request.promiseGet("/api/weshop/userfeemail/pageAndArea", {
  1703 + data: {
  1704 + store_id: os.stoid,
  1705 + isuse: 0,
  1706 + condition: condition,
  1707 + user_id: getApp().globalData.user_id,
  1708 + pageSize: 2000
  1709 + }
  1710 + }).then(res => {
  1711 + if (res.data.code == 0 && res.data.data.total > 0) {
  1712 + //此时要循环判断包邮的地区,不包邮商品是不是符合
  1713 + var arr = [], quanlist = res.data.data.pageData;
  1714 + quanlist = th.check_is_frozenQuan(quanlist, th.data.frozenQuan, 1);
  1715 + for (var i in quanlist) {
  1716 + var item = quanlist[i];
  1717 + if (item.region_list && th.check_by_area(item.region_list)) continue; //如果是不包邮区域
  1718 + if (item.goods_list && th.check_by_goods(item.goods_list)) continue; //如果是不包邮商品
  1719 + arr.push(item);
  1720 + }
  1721 + if (arr) {
  1722 + th.setData({get_by_quan_list: arr});
  1723 + }
  1724 + th.data.isget_by_quan[th.data.bn_pick] = 1;
  1725 + }
  1726 + })
  1727 + }
  1728 +
  1729 + switch (good['exp_sum_type']) {
  1730 + case 1:
  1731 + //统一运费
  1732 + o_shipping_price += good['uniform_exp_sum'];
  1733 + break;
  1734 + case 2:
  1735 + if (goods_weight < 0) goods_weight = 0;
  1736 + //累积商品重量 每种商品的重量 * 数量
  1737 + goods_weight += good['weight'] * good['buynum'];
  1738 + break;
  1739 + case 3:
  1740 + if (goods_piece < 0) goods_piece = 0;
  1741 + //累积商品数量
  1742 + goods_piece += good['buynum'];
  1743 + break;
  1744 + }
  1745 +
  1746 + var code = "";
  1747 + if (th.data.wu_arr && th.data.wu_arr[th.data.index]) code = th.data.wu_arr[th.data.index].code;
  1748 + var freight_free = ee.freight_free; //全场满多少包邮
  1749 + var no_ex_id = ee.no_ex_id;
  1750 + th.data.is_no_by[th.data.bn_pick] = 0;
  1751 +
  1752 + var no_by_data = null;
  1753 + var gift_freight_free = freight_free;
  1754 +
  1755 +
  1756 + //有不包邮区域,且不免运费
  1757 + if (no_ex_id && freight_free > 0 && freight_free <= parseFloat(allpice) - cut_price - quan_price) {
  1758 + //-----------获取不包邮区域,不包邮商品-------
  1759 + await getApp().request.promiseGet("/api/weshop/areaFeemail/getAreaGoods", {
  1760 + data: {store_id: os.stoid, id: no_ex_id}
  1761 + }).then(res => {
  1762 + if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
  1763 + no_by_data = res.data.data[0];
  1764 + //如果有设置不包邮区域的时候
  1765 + if (res.data.data[0].region_list) {
  1766 + if (th.check_by_area(res.data.data[0].region_list)) {
  1767 + freight_free = 0;
  1768 + th.data.is_no_by[th.data.bn_pick] = 1;
  1769 + }
  1770 + }
  1771 + //如果有设置不包邮商品
  1772 + if (res.data.data[0].goods_list && freight_free) {
  1773 + if (th.check_by_goods(res.data.data[0].goods_list)) {
  1774 + freight_free = 0;
  1775 + th.data.is_no_by[th.data.bn_pick] = 1;
  1776 + }
  1777 + }
  1778 + }
  1779 + })
  1780 + }
  1781 +
  1782 + th.data.is_by[th.data.bn_pick] = 0;
  1783 + //--------------开始计算物流------------------
  1784 + var shipping_price =
  1785 + th.calculatewuliu(code, o_shipping_price, goods_weight,
  1786 + goods_piece, th.data.user_addr, freight_free, parseFloat(allpice) - cut_price - quan_price, rs);
  1787 +
  1788 + //如果有赠品的时候,也要计算赠品的物流费用
  1789 + if (th.data.buy_now_gift_goods) {
  1790 + shipping_price = th.get_now_gift_goods_wuliu(code, o_shipping_price, th.data.user_addr, gift_freight_free,
  1791 + parseFloat(allpice) - cut_price - quan_price, rs, shipping_price, no_by_data, goods_weight, goods_piece);
  1792 + }
  1793 +
  1794 + if (shipping_price <= 0) {
  1795 + th.data.is_by[th.data.bn_pick] = 1; //已经是包邮了,就不要选择包邮券
  1796 + }
  1797 +
  1798 + shipping_price = parseFloat(shipping_price).toFixed(2);
  1799 + var wl_txt = "formData.shipping_price";
  1800 + th.setData({[wl_txt]: shipping_price,})
  1801 +
  1802 + } else {
  1803 + var wl_txt = "formData.shipping_price";
  1804 + th.setData({[wl_txt]: 0,})
  1805 + }
  1806 +
  1807 + if (quan_no) {
  1808 + if (th.data.using_quan[bn_pick].isby == 1) {
  1809 + shipping_price = 0;
  1810 + var wl_txt = "formData.shipping_price";
  1811 + th.setData({[wl_txt]: 0,})
  1812 + }
  1813 + }
  1814 + //-----------------支付价,优惠券不减物流-----------------
  1815 + var total_m = (parseFloat(allpice1)).toFixed(2);
  1816 + var order_m = (parseFloat(allpice - cut_price) - quan_price).toFixed(2);
  1817 + var coupon_price = quan_price; //优惠券优惠了多少钱
  1818 + if (order_m < 0) {
  1819 + order_m = 0;
  1820 + coupon_price = parseFloat(order_m).toFixed(2);
  1821 + }
  1822 + //--看一下有没有订单优惠--
  1823 + var o_condition = parseFloat(order_m);
  1824 + if (o_condition > 0) {
  1825 + th.check_is_order_prom(o_condition, function () {
  1826 + var order_prom_amount = 0;
  1827 + var order_prom_id = 0;
  1828 + if (th.data.order_prom[th.data.bn_pick]) {
  1829 + var ord_prom = th.data.order_prom[th.data.bn_pick];
  1830 + order_prom_id = ord_prom['id'];
  1831 + switch (ord_prom['type']) {
  1832 + case 0:
  1833 + order_m = Math.round(o_condition * ord_prom['expression']) / 100;//满额打折
  1834 + order_prom_amount = (o_condition - order_m).toFixed(2);
  1835 + break;
  1836 + case 1:
  1837 + order_m = o_condition - ord_prom['expression'];//满额优惠金额
  1838 + order_prom_amount = ord_prom['expression'];
  1839 + break;
  1840 + }
  1841 + }
  1842 + //--订单优惠的显示--
  1843 + if (order_prom_id > 0) {
  1844 + var order_prom_txt1 = "formData.order_prom_id";
  1845 + var order_prom_txt2 = "formData.order_prom_amount";
  1846 + th.setData({[order_prom_txt1]: order_prom_id, [order_prom_txt2]: order_prom_amount})
  1847 + }
  1848 +
  1849 + total_m = parseFloat(total_m) + parseFloat(th.data.formData.shipping_price);
  1850 + order_m = parseFloat(order_m) + parseFloat(th.data.formData.shipping_price);
  1851 +
  1852 + total_m = total_m.toFixed(2);
  1853 + order_m = order_m.toFixed(2);
  1854 +
  1855 + var atxt = "formData.total_amount";
  1856 + th.setData({[atxt]: total_m,})
  1857 +
  1858 + var txt = "formData.user_money";
  1859 + var txt2 = "formData.order_amount";
  1860 + var txt3 = "formData.coupon_price";
  1861 + var amoney = parseFloat(th.data.userinfo.user_money - th.data.txmon - th.data.userinfo.frozen_money);
  1862 + //--------------如果使用余额---------------------
  1863 + if (th.data.bn_use_money == 1) {
  1864 + if (amoney > order_m) {
  1865 + order_m = parseFloat(order_m).toFixed(2);
  1866 + th.setData({[txt]: order_m, [txt2]: 0, [txt3]: coupon_price, show_submit: 1})
  1867 + } else {
  1868 + order_m = parseFloat(order_m) - parseFloat(amoney);
  1869 + order_m = order_m.toFixed(2);
  1870 + th.setData({[txt]: amoney, [txt2]: order_m, [txt3]: coupon_price, show_submit: 1})
  1871 + }
  1872 + } else {
  1873 + th.setData({[txt]: 0, [txt2]: order_m, [txt3]: coupon_price, show_submit: 1})
  1874 + }
  1875 + //优惠活动送积分
  1876 + if (good.s_intValue) {
  1877 + txt = "formData.give_integral";
  1878 + th.setData({[txt]: good.s_intValue});
  1879 + }
  1880 + //优惠送券
  1881 + if (good.s_coupon_id) {
  1882 + var i_txt = "formData.give_coupon_id";
  1883 + //这个是json格式的
  1884 + var i_txt1 = "formData.g_coupon_num";
  1885 + var ob = [{"num": good.s_coupon_num, "c_id": good.s_coupon_id}];
  1886 + ob = JSON.stringify(ob);
  1887 + th.setData({[i_txt]: good.s_coupon_id, [i_txt1]: ob});
  1888 + }
  1889 + //优惠礼包
  1890 + if (good.s_libao) {
  1891 + var l_txt = "formData.give_lb_id";
  1892 + //这个是json格式的
  1893 + var l_txt1 = "formData.g_lb_num";
  1894 + var ob = [{"num": good.s_lb_num, "l_id": good.s_libao}];
  1895 + ob = JSON.stringify(ob);
  1896 + th.setData({[l_txt]: good.s_libao, [l_txt1]: ob});
  1897 + }
  1898 + })
  1899 + } else {
  1900 + total_m = parseFloat(total_m) + parseFloat(th.data.formData.shipping_price);
  1901 + order_m = parseFloat(order_m) + parseFloat(th.data.formData.shipping_price);
  1902 + var atxt = "formData.total_amount";
  1903 +
  1904 + total_m = total_m.toFixed(2);
  1905 + order_m = order_m.toFixed(2);
  1906 +
  1907 + th.setData({[atxt]: total_m,})
  1908 +
  1909 + var txt = "formData.user_money";
  1910 + var txt2 = "formData.order_amount";
  1911 + var txt3 = "formData.coupon_price";
  1912 + var amoney = parseFloat(th.data.userinfo.user_money - th.data.txmon - th.data.userinfo.frozen_money);
  1913 + //--------------如果使用余额---------------------
  1914 + if (th.data.bn_use_money == 1) {
  1915 + if (amoney > order_m) {
  1916 + order_m = parseFloat(order_m).toFixed(2);
  1917 + th.setData({[txt]: order_m, [txt2]: 0, [txt3]: coupon_price, show_submit: 1})
  1918 + } else {
  1919 + order_m = parseFloat(order_m) - parseFloat(amoney);
  1920 + order_m = order_m.toFixed(2);
  1921 + th.setData({[txt]: amoney, [txt2]: order_m, [txt3]: coupon_price, show_submit: 1})
  1922 + }
  1923 + } else {
  1924 + th.setData({[txt]: 0, [txt2]: order_m, [txt3]: coupon_price, show_submit: 1})
  1925 + }
  1926 + //优惠活动送积分
  1927 + if (good.s_intValue) {
  1928 + txt = "formData.give_integral";
  1929 + th.setData({[txt]: good.s_intValue});
  1930 + }
  1931 + //优惠送券
  1932 + if (good.s_coupon_id) {
  1933 + var i_txt = "formData.give_coupon_id";
  1934 + //这个是json格式的
  1935 + var i_txt1 = "formData.g_coupon_num";
  1936 + var ob = [{"num": good.s_coupon_num, "c_id": good.s_coupon_id}];
  1937 + ob = JSON.stringify(ob);
  1938 + th.setData({[i_txt]: good.s_coupon_id, [i_txt1]: ob});
  1939 + }
  1940 + //优惠礼包
  1941 + if (good.s_libao) {
  1942 + var l_txt = "formData.give_lb_id";
  1943 + //这个是json格式的
  1944 + var l_txt1 = "formData.g_lb_num";
  1945 + var ob = [{"num": good.s_lb_num, "l_id": good.s_libao}];
  1946 + ob = JSON.stringify(ob);
  1947 + th.setData({[l_txt]: good.s_coupon_id, [l_txt1]: ob});
  1948 + }
  1949 + }
  1950 +
  1951 + wx.hideLoading();
  1952 +
  1953 + });
  1954 + });
  1955 + },
  1956 +
  1957 + //--------------------提交订单-----------------------
  1958 + async submitForm(t){
  1959 + var sub_value = t;
  1960 +
  1961 + if (this.data.is_summit_ing == 1) return false; //--提交中退出--
  1962 + this.data.is_summit_ing = 1;
  1963 + var th = this, pdata = new Array();
  1964 + var ff = true;
  1965 + //------------立即购买-------------
  1966 + if (th.data.is_b_now == 1 && th.data.bn_goods.prom_type != 5) {
  1967 +
  1968 + if (th.data.bn_exp_type == 0 && th.data.user_addr == null) {
  1969 + ff = false;
  1970 + getApp().my_warnning("请选择收货地址", 0, th);
  1971 + th.data.is_summit_ing = 0;
  1972 + }
  1973 + if (!ff) return false;
  1974 + var addr = th.data.user_addr;
  1975 + if (th.data.bn_exp_type == 1) addr = null;
  1976 +
  1977 + if (th.data.bn_exp_type == 0)
  1978 + if (th.data.wu_arr == null || th.data.wu_arr.length <= 0) {
  1979 + getApp().my_warnning("读取物流失败", 0, th);
  1980 + th.data.is_summit_ing = 0;
  1981 + return false;
  1982 + }
  1983 +
  1984 + var item = {
  1985 + 'user_id': to.globalData.user_id,
  1986 + 'consignee': addr == null ? "" : addr.consignee,
  1987 + 'province': addr == null ? 0 : addr.province,
  1988 + 'city': addr == null ? 0 : addr.city,
  1989 + 'district': addr == null ? 0 : addr.district,
  1990 + 'twon': addr == null ? 0 : addr.twon,
  1991 + 'address': addr == null ? "" : addr.address,
  1992 + 'more_address': addr == null ? "" : addr.more_address,
  1993 + //'mobile': th.data.userinfo.mobile,
  1994 + 'mobile': addr == null ? th.data.userinfo.mobile : addr.mobile,
  1995 + 'email': '',
  1996 + 'shipping_code': th.data.bn_exp_type == 1 ? 0 : th.data.wu_arr[th.data.index].code,
  1997 + 'shipping_name': th.data.bn_exp_type == 1 ? '' : th.data.wu_arr[th.data.index].name,
  1998 + 'invoice_title': '',
  1999 + 'goods_price': th.data.formData.all_price, //商品总价
  2000 + 'shipping_price': th.data.formData.shipping_price, //物流金额
  2001 + 'user_money': th.data.formData.user_money, //使用余额
  2002 + 'total_amount': th.data.formData.total_amount, //订单总价
  2003 + 'order_amount': th.data.formData.order_amount, //应付
  2004 + 'user_note': t.detail.value.user_note, //用户备注
  2005 + 'store_id': oo.stoid, //商家
  2006 + 'pickup_id': th.data.bn_pick, //门店
  2007 + 'exp_type': th.data.bn_exp_type, //配送方式
  2008 + 'order_goods': new Array(),
  2009 + };
  2010 + //是不是重新提交
  2011 + if (th.data.is_continue == 1) item.is_continue = 1;
  2012 +
  2013 + //获取立即购买的商品的信息
  2014 + var gg = to.get_b_now();
  2015 + //--商品的房间号--
  2016 + if (gg.room_id && gg.room_id > 0) {
  2017 + item.room_ids = gg.room_id;
  2018 + }
  2019 +
  2020 + var order_prom_list = {};
  2021 + //--判断有没有优惠活动--
  2022 + if (th.data.order_prom[item.pickup_id]) {
  2023 + if (th.data.formData.order_prom_amount > 0) {
  2024 + order_prom_list.order_prom_id = th.data.formData.order_prom_id;
  2025 + order_prom_list.order_prom_amount = th.data.formData.order_prom_amount;
  2026 + }
  2027 + }
  2028 +
  2029 + //--判断优惠活动的提交--
  2030 + if (th.data.formData.cut_price > 0) {
  2031 + order_prom_list.discount_amount = th.data.formData.cut_price.toFixed(2);
  2032 + var ob = [{
  2033 + "prom_id": th.data.bn_goods.prom_id,
  2034 + "dis": th.data.formData.cut_price.toFixed(2),
  2035 + "ispt": 0
  2036 + }]
  2037 + order_prom_list.prom_pt_json = JSON.stringify(ob);
  2038 + }
  2039 + if (th.data.formData.give_integral > 0) {
  2040 + order_prom_list.give_integral = th.data.formData.give_integral;
  2041 + }
  2042 + if (th.data.formData.give_coupon_id > 0) {
  2043 + order_prom_list.give_coupon_id = th.data.formData.give_coupon_id;
  2044 + order_prom_list.g_coupon_num = th.data.formData.g_coupon_num;
  2045 + }
  2046 + if (th.data.formData.give_lb_id > 0) {
  2047 + order_prom_list.give_lb_id = th.data.formData.give_lb_id;
  2048 + order_prom_list.g_lb_num = th.data.formData.g_lb_num;
  2049 + }
  2050 + item.order_prom_list = order_prom_list;
  2051 +
  2052 + //组装优惠券的钱
  2053 + if (parseFloat(th.data.formData.coupon_price) > 0) {
  2054 + item.coupon_price = th.data.formData.coupon_price;
  2055 + item.coupon_no = th.data.using_quan[th.data.bn_pick].coupon_no;
  2056 + }
  2057 + if (th.data.using_quan[th.data.bn_pick] && th.data.using_quan[th.data.bn_pick].coupon_no && th.data.using_quan[th.data.bn_pick].isby) {
  2058 + item.coupon_no = th.data.using_quan[th.data.bn_pick].coupon_no;
  2059 + item.coupon_price = 0;
  2060 + }
  2061 +
  2062 + //老会员成为分销下线需要的参数
  2063 + if (getApp().globalData.first_leader && !getApp().globalData.userInfo.first_leader) {
  2064 + //判断一下分享人是不是分享商
  2065 + await app.request.promiseGet("/api/weshop/users/get/" + os.stoid + "/" + getApp().globalData.first_leader, {}).then(res => {
  2066 + if (res.data.code == 0) {
  2067 + var user = res.data.data;
  2068 + if (user.is_distribut == 1) {
  2069 + item.first_leader = parseInt(getApp().globalData.first_leader);
  2070 + }
  2071 + }
  2072 + })
  2073 + }
  2074 +
  2075 + var goods = {
  2076 + 'goods_id': gg.goods_id,
  2077 + 'goods_name': gg.goods_name,
  2078 + 'goods_sn': gg.goods_sn,
  2079 + 'goods_num': gg.goods_num,
  2080 + 'market_price': th.data.bn_goods.market_price,
  2081 + 'goods_price': th.data.bn_goods.shop_price,
  2082 + 'member_goods_price': th.data.bn_goods.shop_price,
  2083 + 'store_id': oo.stoid,
  2084 + 'prom_type': th.data.bn_goods.prom_type, //促销活动类型
  2085 + 'prom_id': th.data.bn_goods.prom_id, //促销活动id
  2086 + };
  2087 +
  2088 + //-- 把导购的信息填入--
  2089 + if (gg.guide_id) {
  2090 + goods.guide_id = gg.guide_id;
  2091 + goods.guide_type = gg.guide_type;
  2092 + //调用接口判断是不是会员
  2093 + await getApp().request.promiseGet("/api/weshop/shoppingGuide/getId/" + oo.stoid + "/" + gg.guide_id, {}).then(res => {
  2094 + if (res.data.code == 0) {
  2095 + goods.guide_name = res.data.data.salesman;
  2096 + goods.guide_sn = res.data.data.salesman_no;
  2097 + }
  2098 + })
  2099 + }
  2100 +
  2101 + //--商品的房间号--
  2102 + if (gg.room_id && gg.room_id > 0) {
  2103 + goods.room_id = gg.room_id;
  2104 + }
  2105 +
  2106 + //积分购,先要带is_integral_normal=1
  2107 + if (gg.is_integral_normal) goods.is_integral_normal = 1;
  2108 +
  2109 + //先要带is_pd_normal=1
  2110 + if (gg.is_pd_normal) goods.is_pd_normal = 1;
  2111 +
  2112 + //如果不立即购买或者秒杀,如果是线下库存购买的时候
  2113 + if (goods.prom_type != 1 && goods.prom_type != 6 && th.data.sales_rules == 2) {
  2114 + var isok = 1;
  2115 + await th.check_store_num(goods.goods_id, th.data.bn_pick, gg.goods_num, function (res) {
  2116 + isok = res;
  2117 + });
  2118 + if (!isok) {
  2119 + getApp().confirmBox("商品的门店库存不足");
  2120 + th.data.is_summit_ing = 0;
  2121 + return false;
  2122 + }
  2123 + }
  2124 +
  2125 + //-- 如果有线下取价的话 --
  2126 + if (th.data.bn_goods.is_offline) {
  2127 + item.sum_offline_cut = (th.data.bn_goods.shop_price - th.data.bn_goods.offline_price).toFixed(2);
  2128 + goods.offline_cut = item.sum_offline_cut;
  2129 + goods.pricing_type = th.data.bn_goods.pricing_type;
  2130 + goods.goods_price = th.data.bn_goods.offline_price;
  2131 + goods.member_goods_price = th.data.bn_goods.offline_price;
  2132 + }
  2133 +
  2134 + //--- 如果有优惠促销的金额,要把金额先平摊下去 ---
  2135 + if (th.data.formData.cut_price > 0 && !th.data.ispt_goods) {
  2136 + var g_arr = new Array();
  2137 + g_arr.push(goods);
  2138 + var pt_data = {
  2139 + 'prom_id': goods.prom_id,
  2140 + 'dis': parseFloat(th.data.formData.cut_price),
  2141 + 'goods': g_arr,
  2142 + }
  2143 +
  2144 + var pt_res = null;
  2145 + await getApp().request.promisePost("/api/weshop/order/getGoodsSplit", {
  2146 + is_json: 1,
  2147 + data: pt_data
  2148 + }).then(res => {
  2149 + if (res.data.code == 0) {
  2150 + pt_res = res.data.data;
  2151 + }
  2152 + })
  2153 + if (pt_res) {
  2154 + //平摊赋值
  2155 + goods.account = pt_res[0].fisrt_account;
  2156 + goods.account_yu = pt_res[0].fisrt_account_yu;
  2157 + item.is_discount_amount = 1;
  2158 + }
  2159 + }
  2160 +
  2161 + //--组装优惠券的钱--
  2162 + if (th.data.formData.coupon_price) {
  2163 + item.coupon_price = th.data.formData.coupon_price;
  2164 + item.coupon_no = th.data.using_quan[th.data.bn_pick].coupon_no;
  2165 + goods.quan_num = th.data.formData.coupon_price;
  2166 + goods.quan_no = item.coupon_no;
  2167 + }
  2168 +
  2169 + item.order_goods.push(goods);
  2170 +
  2171 + //--如果有赠品的时候,赠品也要提交---
  2172 + if (th.data.buy_now_gift_goods) {
  2173 + var gift_gg = th.data.buy_now_gift_goods;
  2174 + var g_goods = {
  2175 + 'goods_id': gift_gg.goods_id,
  2176 + 'goods_name': gift_gg.goods_name,
  2177 + 'goods_sn': gift_gg.goods_sn,
  2178 + 'goods_num': gift_gg.buynum,
  2179 + 'market_price': gift_gg.market_price,
  2180 + 'goods_price': 0,
  2181 + 'member_goods_price': 0,
  2182 + 'store_id': oo.stoid,
  2183 + 'is_gift': 1,
  2184 + 'gift_id': gift_gg.gift_id,
  2185 + 'prom_id': gift_gg.prom_id,
  2186 + };
  2187 + item.order_goods.push(g_goods);
  2188 + }
  2189 + pdata.push(item);
  2190 +
  2191 + console.log(pdata);
  2192 + } else {
  2193 + //---------购物车的结算---------
  2194 + if (th.data.is_all_zt == 0 && th.data.user_addr == null) {
  2195 + th.data.is_summit_ing = 0;
  2196 + ff = false;
  2197 + getApp().confirmBox("请新建收货地址");
  2198 + }
  2199 + if (!ff) return false;
  2200 +
  2201 + var addr = th.data.user_addr;
  2202 + if (th.data.is_all_zt == 1) addr = null;
  2203 + var val_arr = t.detail.value;
  2204 +
  2205 +
  2206 + if (th.data.is_all_zt != 1)
  2207 + if (th.data.wu_arr == null || th.data.wu_arr.length <= 0) {
  2208 + th.data.is_summit_ing = 0;
  2209 + getApp().confirmBox("读取物流失败");
  2210 + return false;
  2211 + }
  2212 +
  2213 + var order_prom_list_cart = th.data.order_prom_list_cart;
  2214 +
  2215 + //--组装推送数据--
  2216 + for (var i = 0; i < order_prom_list_cart.length; i++) {
  2217 + var t_item = order_prom_list_cart[i];
  2218 + var item = {
  2219 + 'user_id': to.globalData.user_id,
  2220 + 'consignee': addr == null ? th.data.userinfo.mobile : addr.consignee,
  2221 + 'province': addr == null ? 0 : addr.province,
  2222 + 'city': addr == null ? 0 : addr.city,
  2223 + 'district': addr == null ? 0 : addr.district,
  2224 + 'twon': addr == null ? 0 : addr.twon,
  2225 + 'address': addr == null ? "" : addr.address,
  2226 + 'more_address': addr == null ? "" : addr.more_address,
  2227 + 'mobile': addr == null ? th.data.userinfo.mobile : addr.mobile,
  2228 + 'email': '',
  2229 + 'shipping_code': th.data.is_all_zt == 1 ? 0 : th.data.wu_arr[t_item.wind].code,
  2230 + 'shipping_name': th.data.is_all_zt == 1 ? '' : th.data.wu_arr[t_item.wind].name,
  2231 + 'invoice_title': '',
  2232 + 'goods_price': t_item.goods_price, //商品总价
  2233 + 'shipping_price': t_item.shipping_price, //物流金额
  2234 + 'user_money': t_item.user_money, //使用余额
  2235 + 'total_amount': t_item.total_amount, //订单总价
  2236 + 'order_amount': t_item.order_amount, //应付
  2237 + 'user_note': val_arr['user_note_' + t_item.pickup_id], //用户备注
  2238 + 'store_id': oo.stoid, //商家
  2239 + 'pickup_id': t_item.pickup_id, //门店
  2240 + 'exp_type': t_item.exp_type, //配送方式
  2241 + 'order_goods': new Array(),
  2242 + };
  2243 + //是不是重新提交
  2244 + if (th.data.is_continue == 1) item.is_continue = 1;
  2245 + //----- 如果有线下取价的话 ----
  2246 + if (t_item.is_offline == 1) {
  2247 + item.sum_offline_cut = t_item.offline_price.toFixed(2);
  2248 + }
  2249 +
  2250 + //组装优惠券的钱
  2251 + if (t_item.coupon_price) {
  2252 + item.coupon_price = t_item.coupon_price;
  2253 + item.coupon_no = th.data.using_quan[t_item.pickup_id].coupon_no;
  2254 + } else if (t_item.quan_no) {
  2255 + item.coupon_no = t_item.quan_no;
  2256 + item.coupon_price = 0;
  2257 + }
  2258 +
  2259 + var order_prom_list = {};
  2260 + //--判断有没有优惠活动--
  2261 + if (t_item.order_prom_amount > 0) {
  2262 + order_prom_list.order_prom_id = t_item.order_prom_id;
  2263 + order_prom_list.order_prom_amount = t_item.order_prom_amount;
  2264 + }
  2265 +
  2266 + order_prom_list.discount_amount =0;
  2267 + //--判断优惠活动的提交--
  2268 + if (t_item.cut_price > 0) {
  2269 + order_prom_list.discount_amount += t_item.cut_price.toFixed(2);
  2270 + order_prom_list.prom_pt_json = JSON.stringify(t_item.prom_pt_json);
  2271 + }
  2272 + //--判断组合优惠活动的提交--
  2273 + if (t_item.zh_cut_price > 0) {
  2274 + order_prom_list.discount_amount += t_item.zh_cut_price.toFixed(2);
  2275 + order_prom_list.zh_pt_json = JSON.stringify(t_item.zh_pt_json);
  2276 + }
  2277 + if (t_item.s_intValue > 0) {
  2278 + order_prom_list.give_integral = t_item.s_intValue;
  2279 + }
  2280 + if (t_item.s_coupon_id) {
  2281 + order_prom_list.give_coupon_id = t_item.s_coupon_id;
  2282 + order_prom_list.g_coupon_num = JSON.stringify(t_item.g_coupon_num);
  2283 + }
  2284 + if (t_item.s_libao) {
  2285 + order_prom_list.give_lb_id = t_item.s_libao;
  2286 + order_prom_list.g_lb_num = JSON.stringify(t_item.g_lb_num);
  2287 + }
  2288 + if (Object.keys(order_prom_list).length > 0)
  2289 + item.order_prom_list = order_prom_list;
  2290 +
  2291 + //老会员成为分销下线需要的参数
  2292 + if (getApp().globalData.first_leader && !getApp().globalData.userInfo.first_leader) {
  2293 + //判断一下分享人是不是分享商
  2294 + await app.request.promiseGet("/api/weshop/users/get/" + os.stoid + "/" + getApp().globalData.first_leader, {}).then(res => {
  2295 + if (res.data.code == 0) {
  2296 + var user = res.data.data;
  2297 + if (user.is_distribut == 1) {
  2298 + item.first_leader = parseInt(getApp().globalData.first_leader);
  2299 + }
  2300 + }
  2301 + })
  2302 + }
  2303 +
  2304 +
  2305 + //房间号的ids
  2306 + var room_ids = "";
  2307 + //-------------让商品添加到商品列表--------------------
  2308 + for (var k = 0; k < t_item.goods.length; k++) {
  2309 + var g_item = t_item.goods[k];
  2310 + var goods = {
  2311 + 'goods_id': g_item.goods_id,
  2312 + 'goods_name': g_item.goods_name,
  2313 + 'goods_sn': g_item.goods_sn,
  2314 + 'goods_num': g_item.goods_num,
  2315 + 'market_price': g_item.market_price,
  2316 + 'goods_price': g_item.goods_price,
  2317 + 'member_goods_price': g_item.goods_price,
  2318 + 'store_id': oo.stoid,
  2319 + };
  2320 +
  2321 + //-- 线下取价也要写入 --
  2322 + if (g_item.offline_price && t_item.is_offline == 1) {
  2323 + goods.goods_price = g_item.offline_price;
  2324 + goods.member_goods_price = g_item.offline_price;
  2325 + goods.offline_cut = (g_item.goods_price - g_item.offline_price).toFixed(2);
  2326 + goods.pricing_type = g_item.pricing_type;
  2327 + }
  2328 +
  2329 + //--把券的钱,写入从表---
  2330 + if (t_item.quan_youhui_list && t_item.coupon_price) {
  2331 + for (var kk in t_item.quan_youhui_list) {
  2332 + var you_item = t_item.quan_youhui_list[kk];
  2333 + if (g_item.prom_type!=7 && g_item.erpwareid == you_item.WareId) {
  2334 + goods.quan_num = you_item.WareCashSum;
  2335 + goods.quan_no = you_item.CashRepNo;
  2336 + }
  2337 + }
  2338 + }
  2339 +
  2340 + //--判断活动的类型--
  2341 + switch (g_item.prom_type) {
  2342 + case 1:
  2343 + goods.prom_type = g_item.prom_type;
  2344 + goods.prom_id = g_item.prom_id;
  2345 + break;
  2346 + case 3:
  2347 + goods.prom_type = 3;
  2348 + goods.prom_id = g_item.prom_id;
  2349 + if (g_item.is_gift) {
  2350 + goods.is_gift = g_item.is_gift;
  2351 + goods.gift_id = g_item.gift_id;
  2352 + }
  2353 + break;
  2354 + case 5:
  2355 + goods.prom_type = 5;
  2356 + goods.prom_id = g_item.prom_id;
  2357 + if (g_item.is_collocation) {
  2358 + goods.is_collocation = g_item.is_collocation;
  2359 + }
  2360 + break
  2361 + case 7:
  2362 + goods.prom_type = 7;
  2363 + goods.prom_id = g_item.prom_id;
  2364 + break
  2365 + default:
  2366 + goods.prom_type = 0;
  2367 + goods.prom_id = 0;
  2368 + }
  2369 +
  2370 + //如果不立即购买或者秒杀,如果是线下库存购买的时候
  2371 + if (goods.prom_type == 0 && th.data.sales_rules == 2) {
  2372 + var isok = 1;
  2373 + await th.check_store_num(goods.goods_id, t_item.pickup_id, goods.goods_num, function (res) {
  2374 + isok = res;
  2375 + });
  2376 + if (!isok) {
  2377 + getApp().confirmBox(goods.goods_name + "的门店库存不足");
  2378 + th.data.is_summit_ing = 0;
  2379 + return false;
  2380 + }
  2381 + }
  2382 +
  2383 + //把优惠的平摊结果写进去
  2384 + if (g_item.account >= 0 || g_item.account_yu != 0) {
  2385 + if (g_item.account >= 0) goods.account = g_item.account;
  2386 + if (g_item.account_yu != 0) goods.account_yu = g_item.account_yu;
  2387 + item.is_discount_amount = 1;
  2388 + }
  2389 +
  2390 + //导购ID
  2391 + if (g_item.guide_id) {
  2392 + goods.guide_id = g_item.guide_id;
  2393 + goods.guide_type = g_item.guide_type;
  2394 + //调用接口判断是不是会员
  2395 + await getApp().request.promiseGet("/api/weshop/shoppingGuide/getId/" + oo.stoid + "/" + g_item.guide_id, {}).then(res => {
  2396 + if (res.data.code == 0) {
  2397 + goods.guide_name = res.data.data.salesman;
  2398 + goods.guide_sn = res.data.data.salesman_no;
  2399 + }
  2400 + })
  2401 + }
  2402 + //如果房间号不为空的时候
  2403 + if (g_item.room_id) {
  2404 + goods.room_id = g_item.room_id;
  2405 + room_ids += g_item.room_id + ",";
  2406 + }
  2407 + item.order_goods.push(goods);
  2408 + }
  2409 +
  2410 + //如果房间号不为空的时候
  2411 + if (room_ids != "") item.room_ids = ut.sub_last(room_ids);
  2412 + pdata.push(item);
  2413 + }
  2414 +
  2415 +
  2416 + }
  2417 +
  2418 + if (pdata.length == 0) return;
  2419 + var str = JSON.stringify(pdata);
  2420 +
  2421 + wx.showLoading({title: "加载中"});
  2422 + wx.request({
  2423 + url: oo.url + '/api/weshop/order/createWxdOrder',
  2424 + data: str,
  2425 + method: 'POST',
  2426 + header: {
  2427 + 'content-type': 'application/json'
  2428 + },// 设置请求的 header
  2429 + success: function (res) {
  2430 +
  2431 +
  2432 + wx.hideLoading();
  2433 + if (res.statusCode == 200) {
  2434 + var data = res.data;
  2435 + if (data.code == 0) {
  2436 + console.log(th.data.is_b_now);
  2437 + //如果是购物车结算,还要删除购物车
  2438 + if (th.data.is_b_now == 0) {
  2439 + console.log(th.data.cartlist_y);
  2440 + var list = th.data.cartlist_y;
  2441 + for (var i = 0; i < list.length; i++) {
  2442 + //删除购物车
  2443 + a.delete("/api/weshop/cart/del/" + oo.stoid + "/" + list[i].id, {});
  2444 + }
  2445 + }
  2446 + var order_amount = 0;
  2447 + pdata.forEach(function (em, ind) {
  2448 + order_amount += em.order_amount;
  2449 + })
  2450 + //要进行判断,如果是用微信支付,就要跳转到支付界面
  2451 + if (order_amount > 0) {
  2452 + th.setData({isclose: 0});
  2453 + //void e.jumpToCart4({
  2454 + // order_sn: data.data,
  2455 + //}, 1);
  2456 + util_pay.pay(data.data, function () {
  2457 + //app.my_warnning("支付成功",1,th);
  2458 + //setTimeout(function () {
  2459 + wx.redirectTo({
  2460 + url: "/pages/payment/pay_success/pay_success?type=2&order_sn=" + data.data
  2461 + })
  2462 + //},1000)
  2463 +
  2464 + }, function () {
  2465 + //支付失败
  2466 + setTimeout(function () {
  2467 + wx.navigateBack({delta: 1})
  2468 + }, 1000)
  2469 + }, oo.stoid);
  2470 +
  2471 + } else {
  2472 + var dd = {
  2473 + parent_sn: data.data,
  2474 + store_id: oo.stoid,
  2475 + type: 2,
  2476 + };
  2477 + a.post("/api/weshop/order/pay/createOrder", {
  2478 + data: dd,
  2479 + success: function (t) {
  2480 + //console.log(t);
  2481 + if (t.data.code == 0) {
  2482 + //app.my_warnning("支付成功",1,th);
  2483 + //setTimeout(function () {
  2484 + th.setData({isclose: 0});
  2485 + wx.redirectTo({
  2486 + url: "/pages/payment/pay_success/pay_success?type=2&order_sn=" + data.data,
  2487 + })
  2488 + //}, 1000)
  2489 + }
  2490 + },
  2491 + fail: function () {
  2492 +
  2493 + }
  2494 + });
  2495 + }
  2496 +
  2497 + }
  2498 + else {
  2499 + //--内容换行--
  2500 + var msg = data.msg;
  2501 + //赠品活动已经取消,无法赠送,是否继续买单?
  2502 + if (msg.indexOf("是否继续买单") > 0) {
  2503 + wx.showModal({
  2504 + title: "提示",
  2505 + content: data.msg,
  2506 + cancelText: '取消',
  2507 + confirmText: '确定',
  2508 + showCancel: true,
  2509 + success(res){
  2510 + if (res.cancel) {
  2511 + return;
  2512 + } else if (res.confirm) {
  2513 + th.data.is_continue = 1;
  2514 + th.data.is_summit_ing = 0; //是否提交中
  2515 + th.submitForm(sub_value);
  2516 + }
  2517 + }
  2518 + })
  2519 + return;
  2520 + }
  2521 + if (msg.length > 13) {
  2522 + msg = msg.slice(0, 13) + "\r\n" + msg.slice(13);
  2523 + }
  2524 + getApp().confirmBox(msg);
  2525 + th.data.is_summit_ing = 0; //是否提交中
  2526 + }
  2527 + } else {
  2528 + th.data.is_summit_ing = 0; //是否提交中
  2529 + console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode);
  2530 + }
  2531 + },
  2532 + fail: function () {
  2533 + th.data.is_summit_ing = 0;
  2534 + wx.hideLoading();
  2535 + console.log("index.js wx.request CheckCallUser fail");
  2536 + },
  2537 + complete: function () {
  2538 + }
  2539 + })
  2540 +
  2541 + },
  2542 + //---确认线下门店的数量足不足---
  2543 + async check_store_num(goods_id, pick, goods_num, func){
  2544 + var lock = 0, pick_no, plist, erpwareid;
  2545 + //先读取门店的lock
  2546 + await getApp().request.promiseGet("/api/weshop/order/ware/lock/page", {
  2547 + data: {store_id: os.stoid, wareId: goods_id, storageId: pick, pageSize: 1000}
  2548 + }).then(res => {
  2549 + if (res.data.code == 0 && res.data.data.total > 0) {
  2550 + for (var i in res.data.data.pageData)
  2551 + lock += res.data.data.pageData[i].outQty;
  2552 + }
  2553 + })
  2554 + //先获取门店的编号
  2555 + await getApp().request.promiseGet("/api/weshop/pickup/get/" + os.stoid + "/" + pick, {
  2556 + data: {storeId: os.stoid, goodsId: t.goods_id, pickupId: pick}
  2557 + }).then(res => {
  2558 + if (res.data.code == 0) {
  2559 + pick_no = res.data.data.pickup_no;
  2560 + }
  2561 + })
  2562 + //先获取商品的线下库存
  2563 + await getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + goods_id, {
  2564 + data: {storeId: os.stoid, goodsId: t.goods_id, pickupId: pick}
  2565 + }).then(res => {
  2566 + if (res.data.code == 0) {
  2567 + erpwareid = res.data.data.erpwareid;
  2568 + }
  2569 + })
  2570 + //读取线下的门店库存
  2571 + await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", {
  2572 + data: {storageNos: pick_no, wareIds: encodeURIComponent(erpwareid), storeId: os.stoid, pageSize: 2000}
  2573 + }).then(res => {
  2574 + if (res.data.code == 0) {
  2575 + plist = res.data.data.pageData[0];
  2576 + }
  2577 + })
  2578 + var isok = 1;
  2579 + if (goods_num > plist.CanOutQty - lock) {
  2580 + isok = 0;
  2581 + }
  2582 + func(isok);
  2583 + },
  2584 +
  2585 + useCoupon: function () {
  2586 + if (this.data.order.couponNum <= 0) {
  2587 + getApp().my_warnning("无可用优惠券", 0, this);
  2588 + return;
  2589 + }
  2590 +
  2591 + var a = {
  2592 + lid: this.data.coupon ? this.data.coupon.id : "0"
  2593 + };
  2594 + wx.navigateTo({
  2595 + url: "/pages/user/checkcoupon/checkcoupon?" + s.Obj2Str(a)
  2596 + });
  2597 + },
  2598 + enterAddressPage: function () {
  2599 + getApp().globalData.is_cart_old = 1;
  2600 + this.data.isget_by_quan = {};
  2601 + this.data.enterAddressPage = !0, wx.navigateTo({
  2602 + url: "/pages/user/address_list/address_list"
  2603 + });
  2604 + },
  2605 +
  2606 + //--------购物车购买时,选择自提和物流-----------
  2607 + setexptype_w: function (t) {
  2608 +
  2609 + var def_exp_code = getApp().globalData.userInfo.def_exp_code, th = this;
  2610 + var ty = t.currentTarget.dataset.t, txt = t.currentTarget.dataset.txt,
  2611 + wl_txt = t.currentTarget.dataset.wl_txt,
  2612 + ont = t.currentTarget.dataset.ont;
  2613 +
  2614 + th.setData({[txt]: ty});
  2615 + var iszt = 1;
  2616 +
  2617 + if (ty == 0) {
  2618 + th.setData({is_all_zt: 0});
  2619 + } else {
  2620 + for (var i = 0; i < th.data.cartlist.length; i++) {
  2621 + var item = th.data.cartlist[i];
  2622 + if (item.exp_type == 0) {
  2623 + iszt = 0;
  2624 + break;
  2625 + }
  2626 + }
  2627 +
  2628 + th.setData({is_all_zt: iszt});
  2629 +
  2630 + var ind = t.currentTarget.dataset.ind;
  2631 + var c_item = th.data.cartlist[ind];
  2632 + var pickid = c_item.pickup_id;
  2633 +
  2634 + if (th.data.using_quan[pickid] && th.data.using_quan[pickid].isby == 1) {
  2635 + th.data.using_quan[pickid] = {};
  2636 + th.setData({using_quan: th.data.using_quan});
  2637 + }
  2638 +
  2639 +
  2640 + }
  2641 + //判断有没有默认的物流地址值
  2642 + if (def_exp_code != "" && def_exp_code != null && def_exp_code != undefined) {
  2643 + var wu_arr = this.data.wu_arr;
  2644 + if (wu_arr != null && wu_arr != "") {
  2645 + for (var i = 0; i < wu_arr.length; i++) {
  2646 + if (wu_arr[i].shipping_code == def_exp_code) {
  2647 + var set_txt = "cartlist"
  2648 + th.setData({wl_txt: i});
  2649 + }
  2650 + }
  2651 + }
  2652 + }
  2653 + //----计算此时购物车的价格----
  2654 + th.calculatePrice();
  2655 + },
  2656 +
  2657 + //--------立即购买时,选择自提和物流----------
  2658 + setexptype: function (t) {
  2659 + var th = this;
  2660 + var ty = t.currentTarget.dataset.t, def_exp_code = getApp().globalData.userInfo.def_exp_code;
  2661 + th.setData({bn_exp_type: ty});
  2662 + if (ty == 0) {
  2663 + th.setData({is_all_zt: 0});
  2664 + }
  2665 +
  2666 + //当物流为空的时候。
  2667 + if (ty == 0 && th.data.wu_arr == null) {
  2668 + th.data.isget_by_quan = {};
  2669 + return th.get_wuliu(th.calculatePrice2());
  2670 + }
6 2671  
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   - //提交订单的格式
26   - formData: {
27   - order_amount:0,//支付金额
28   - total_amount:0,//总价
29   - all_price:0,//商品卖的总价
30   - pay_points: 0,//使用积分
31   - user_money: 0,//使用余额
32   - couponCode: "",//使用优惠券(多单就用逗号隔开)
33   - shipping_price:0,//物流费用
34   - },
35   - /*-----------当是购物车结算的时候-------------*/
36   - cartlist:null,
37   - old_cartlist:null,
38   - cartlist_y:null, //购物车原始列表
39   - js_use_money: 0, //是否使用余额
40   - is_all_zt:1, //是否全部都是自提
41   -
42   - /*----------------立即购买---------------------*/
43   - is_b_now:0, //0是购物车结算 1立即购买
44   - bn_goods:null, //立即购买时候的调用商品
45   - bn_use_money:0,//是否使用余额
46   - bn_exp_type:1, //0是物流 1自提
47   - bn_pick:0, //选择的门店
48   - bn_pickname: "", //选择的门店名称
49   - bn_t_exp_t:0, //判断商品和门店一起决定的物流自提的方式0 都可以 1自提 2物流
50   -
51   - bn_plus_cut_price:0, //显示等级卡会优惠多少钱
52   - /*------------------------*/
53   - user_addr:null,//物流
54   - userinfo:null, //获取会员
55   - /*----------物流选择--------*/
56   - wu_arr:null,
57   - index:0,
58   - w_sele_index:0,
59   -
60   - //判断页面是返回回来的还是 首次进入的
61   - isclose:1,
62   - //申请提现的金额
63   - txmon:0,
64   - yuer:0,
65   - //提交中,不重复提交
66   - is_summit_ing:0,
67   - //--更优惠券抵用有关,立即购买的,如果是购物车,就要把相应的值,写入cartlist数组中--
68   - ckeck_quan_price:0,
69   - check_quan_price_list:'',
70   - check_quan_ware_list:'',
71   -
72   - // 设计一个数组来存放已经选择了的券编号,coupon_no是券号,money是面值,coupon_price是真正优惠的价格,数组的下标是pickid
73   - //using_quan[11]={coupon_no:"1212121",money:"20",coupon_price:"45"}
74   - using_quan:{},
75   - open_quan:0,
76   - //选择的券列表
77   - selected_quan_list:null,
78   - //选择的券的门店
79   - selected_quan_pick:null,
80   - is_close_quan:0,
81   - disabled:0,
82   - open_express:0,//控制选择物流名列表 的属性
83   -
84   - is_express:0, //选中物流的属性
85   - expres_name:"", //点击选定
86   - isopen:0, //券的说明
87   - is_coupon:null, //选择券的控制属性
88   - is_shipping_code:"",//插入用户默认地址
89   - wu_arr_txt:"", //要更新的物流的字段
90   -
91   - sales_rules:1, //默认是显示线上库存
92   - isget_by_quan:{}, //是否调用了接口获取包邮券
93   - get_by_quan_list:null, //立即购买的
94   - get_by_quan_list_cart:{}, //购物车的
95   - by_quan_list_cart:null, //点击选择的包邮列表
96   -
97   - //如果是全场包邮了,或者是全场不包邮了,就不要选包邮券
98   - is_no_by:{},
99   - is_by:{},
100   - is_quan_by:{},
101   - //--购买赠送的商品--
102   - buy_now_gift_goods:null,
103   - //--订单优惠--
104   - order_prom:{},
105   - //-- 购物车优惠活动 --
106   - prom_goods_map:{},
107   - //-- order_prom_list --
108   - order_prom_list_cart:null,
109   -
110   - ispt_goods:0, //是否平摊至单品,0要平摊 1不平摊
111   -
112   - rank_switch:0, //是不是开同等级卡
113   - show_card:null, //显示的等级卡
114   - card_name:'', //显示的卡的名称
115   - card_cut_price:null,//减价多少钱
116   -
117   - show_submit:0, //提交按钮变正常显示
118   - is_get_offline:1,
119   -
120   - tabs: ['门店自提','快递邮寄'],
121   - currentTabIndex: 1,
122   - },
123   - onLoad: function(t) {
124   - wx.setNavigationBarTitle({ title: "填写订单",})
125   - var th = this; this.setData({ is_b_now: t.is_bnow == undefined ? 0 : t.is_bnow,});
126   - th.data.param=t;
127   - //清理一下,确保最新的系统配置
128   - getApp().globalData.config2=null;
129   - //清空is_pick_up
130   - getApp().request.put("/api/weshop/useraddress/updatePickUp", {
131   - data: {user_id: getApp().globalData.user_id, is_pickup: 0},
132   - success: function (s) {
133   - }
134   - });
135   -
136   -
137   - },
138   - onUnload: function () { this.setData({ isclose: 1 })},
139   - onHide: function () {
140   - this.setData({
141   - isget_by_quan:{},
142   - is_no_by:{},
143   - is_by:{}
144   - })
145   - },
146   -
147   - //----------子页返回父页触发----------
148   - onShow: function() {
149   - var th=this;
150   - th.setData({show_submit:0}); //让提交先掩藏
151   - th.data.g_cart_q_time=null;
152   -
153   - if (th.data.isclose==0){
154   - wx.navigateTo({
155   - url: "/pages/index/index/index"
156   - })
157   -
158   - }else{
159   - this.getuser_addr(function(ie){
160   -
161   - console.log("getuser_addr")
162   - console.log(ie)
163   -
164   - //地址切换要把包邮券清空
165   - if( !th.data.user_addr || !ie || th.data.user_addr.address_id!=ie.address_id){
166   - var using_quan=th.data.using_quan;
167   - for(var i in using_quan){
168   - var item=using_quan[i];
169   - if(item.isby==1){
170   - var ob={},txt="using_quan["+i+"]";ob[txt]={};
171   - th.setData(ob);
172   - }
173   - }
174   - th.data.isget_by_quan={};
175   - }
176   -
177   -
178   - th.data.prom_goods_map={};
179   - th.data.is_summit_ing=0;
180   - //更换地址回来要重新调用计算价钱的接口
181   - if(!th.data.user_addr || th.data.user_addr.address_id!=ie.address_id){
182   - th.setData({user_addr: ie });
183   - if (th.data.is_b_now == 1) {
184   - if(th.data.bn_goods) {
185   - th.setData({add_back:1});
186   - //th.calculatePrice2();
187   - }
188   - }else{
189   - if (th.data.cartlist){
190   - th.setData({add_back:1});
191   - //th.calculatePrice();
192   - }
193   - }
194   - }else{
195   - th.setData({user_addr: ie });
196   - }
197   - var going=0;
198   -
199   -
200   - //使用计时器,避免空现象
201   - /*---
202   - var jishi= setInterval(function () {
203   - if (th.data.is_b_now == 1 && going==0) {
204   - if(th.data.bn_goods) {
205   - th.calculatePrice2();going=1;clearInterval(jishi);
206   - }
207   - }else if(going==0) {
208   - if (th.data.cartlist){
209   - th.calculatePrice();going = 1; clearInterval(jishi);
210   - }
211   - }
212   - },500)--*/
213   -
214   - });
215   - var is_card_back=getApp().globalData.is_card_back;
216   - //--更新默认地址--,看一下是不是跳到地址页面,同时也不是购买等级卡返回的,这里很重要,否则会重新更新收货物流公司
217   - if(!getApp().globalData.is_cart_old && !is_card_back && !getApp().globalData.plus_buy_back){
218   - this.update_code();
219   - }else{
220   - getApp().globalData.is_cart_old=0;
221   - getApp().globalData.plus_buy_back=0;
222   - }
223   - }
224   -
225   - //先获取是否有关闭使用优惠券
226   - getApp().getConfig2(function (ee) {
227   - var json_d = JSON.parse(ee.switch_list);
228   - th.data.json_d=json_d;
229   - th.data.ispt_goods=json_d.ispt_goods; //是不是平摊到单品的控制参数赋值
230   - var is_default_logistics=json_d.is_default_logistics;
231   -
232   - 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});
233   -
234   - var rank_switch=json_d.rank_switch;
235   - var max_price=-1;
236   - var show_card=null;
237   - var name="";
238   - //如果有开等级卡的时候,
239   - //因为都是调接口,要返回在计算
240   - if(rank_switch==2){
241   - //-- 获取所有的等级卡, --
242   - getApp().request.promiseGet("/api/weshop/plus/vip/mem/bership/list?storeId=" + os.stoid,
243   - {}).then(res => {
244   - if(res.data.code==0){
245   - var plusCard = res.data.data;
246   - //-- 循环判断,拿到最贵的那张卡 --
247   - for(var ih in plusCard){
248   - if(plusCard[ih].IsStopBuy == true){ continue; }
249   - if(max_price<0){
250   - max_price=plusCard[ih].CardFee;
251   - name='card'+plusCard[ih]['CorrPrice'];
252   - show_card=plusCard[ih];
253   - }else{
254   - if(max_price<plusCard[ih].CardFee){
255   - max_price=plusCard[ih].CardFee;
256   - name='card'+plusCard[ih]['CorrPrice'];
257   - show_card=plusCard[ih];
258   - }
259   - }
260   - }
261   -
262   - if(show_card){
263   - name=name.toLowerCase();
264   - th.setData({card_name:name,show_card:show_card})
265   - }
266   - }
267   - //-----先获取物流,再获取用户信息,再展示页面-----
268   - th.get_wuliu(th.get_info(th.show_page));
269   - })
270   - }else{
271   - //-----先获取物流,再获取用户信息,再展示页面-----
272   - th.get_wuliu(th.get_info(th.show_page));
273   - }
274   -
275   - },1);
276   -
277   - //值在这里换
278   - getApp().globalData.plus_buy_back=0;
279   - },
280   -
281   - //-------------------获取物流---------------
282   - get_wuliu(func) {
283   - var th = this;
284   - to.getwuliu(function (e) {
285   - //系统是是否开启了默认的物流
286   - if(th.data.is_default_logistics){
287   - //如果第一个不是开启默认,说明要让用户自己选
288   - if(!e[0].is_default){
289   - th.setData({is_default_logistics:0});
290   - }
291   - }
292   - th.setData({ wu_arr: e })
293   - typeof func == "function" && func();
294   - })
295   - },
296   - //------获取会员信息-----先获取用户信息,在进行下一步---
297   - get_info:function(func){
298   - var user_id = t.globalData.user_id;
299   - to.auth.get_u(func);
300   - },
301   -
302   - //------获取会员收货地址-----
303   - getuser_addr:function(func){
304   - var th=this;
305   - a.get("/api/weshop/useraddress/page", {
306   - data: { user_id: to.globalData.user_id, store_id: oo.stoid, pageSize: 600,t:Math.random()},
307   - success: function (su) {
308   - /*---
309   - var user_addr=[
310   - { 'address_id': 882, 'user_id': 2661, 'consignee': '测试测试测', 'province': 3102, 'city': 3431, 'district': 3466,
311   - 'address': 'ed', 'more_address': '山西-长治市-襄垣县-虎(音si)亭镇', 'mobile': 13012345678,'is_default':1},
312   - ];---*/
313   - var item = null;
314   - if(su.data.code==0 && su.data.data && su.data.data.pageData){
315   - var user_addr = su.data.data.pageData;
316   - var def_item=null;
317   - for (var i = 0; i < user_addr.length; i++) {
318   - if (user_addr[i]['is_default'] == 1) { def_item = user_addr[i];}
319   - if (user_addr[i]['is_pickup'] == 1) { item = user_addr[i]; }
320   - }
321   -
322   - if (item == null) item = def_item;
323   - if (item == null) item = user_addr[0];
324   - }
325   -
326   - if(item==undefined) item=null;
327   - if(!item) th.setData({user_addr:null}); //地址为空的时候,要清空,因为返回的时候,有缓存
328   -
329   - func(item);
330   - }
331   - });
332   - },
333   -
334   - //----------------展示页面,是再获取用户信息之后--------------
335   - show_page:function(){
336   - var th=this,ta = this.data.param;
337   - //th.setData({ userinfo: getApp().globalData.userInfo,}); //这个余额被缓存了
338   -
339   - //会员的信息,要获取最新
340   - var user=getApp().globalData.userInfo;
341   - getApp().request.get("/api/weshop/users/get/" + oo.stoid + "/" + user.user_id, {
342   - data:{r:Math.random()},
343   - success: function (e) {
344   - getApp().globalData.userInfo = e.data.data;
345   - th.setData({userinfo:e.data.data});
346   -
347   - //选获取地址
348   - th.getuser_addr(function(addr){
349   - th.setData({user_addr: addr});
350   - //--------------------------立即购买------------------
351   - if(ta.is_bnow== 1){
352   - //读取门店
353   - to.get_allsto(function (e) {
354   - th.setData({ allsto: e });
355   - //获取立即购买的商品信息
356   - th.get_buy_goods(ta.goods_id);
357   - });
358   - }else {
359   - //------------------------购物车结算----------------------
360   - //读取门店
361   - to.get_allsto(function (e) {
362   - th.setData({ allsto: e });
363   - //-------获取购物车已经选择的商品--------
364   - th.get_cart();
365   - })
366   - }
367   - });
368   -
369   - //获取提现金额
370   - getApp().request.get("/api/weshop/withdrawals/summoney", {
371   - data: { user_id: to.globalData.user_id, store_id: oo.stoid, status: 0 },
372   - success: function (su) {
373   - if (su.data.code == 0) {
374   - var yuer = parseFloat(th.data.userinfo.user_money -
375   - (th.data.userinfo.frozen_money>0?th.data.userinfo.frozen_money:0) - su.data.data.summoney).toFixed(2);
376   - th.setData({ txmon: su.data.data.summoney, yuer: yuer });
377   - }
378   - }
379   - });
380   -
381   -
382   - },
383   - });
384   -
385   - },
386   -
387   -
388   - //-----真的获取购物车,入口--------
389   - get_cart: function () {
390   - var th = this,app=getApp();
391   - a.get("/api/weshop/cart/list", {
392   - data: {
393   - user_id: to.globalData.user_id, selected:1,state:0,
394   - store_id: oo.stoid, pageSize: 600 },
395   - success:async function (su) {
396   - //按门店分类的数组
397   - var arr = new Array();
398   - var carr = su.data.data.pageData;
399   - th.data.cartlist_y = carr; //存储原始购物车列表
400   -
401   - //---是不是购买等级卡成功的返回---等级卡显示的判断---
402   - var is_card_back=getApp().globalData.is_card_back;
403   -
404   - for (var i = 0; i < carr.length; i++) {
405   - var item1 = carr[i];
406   - //要把优惠活动加入,prom_goods_map中,赠品不要运算
407   - if(item1.prom_type==3 && item1.is_gift!=1){
408   - await th.add_prom_goods_map(item1);
409   - }
410   -
411   - }
412   -
413   - //在分组的时候,就不要再调用接口,await
414   - for (var i = 0; i < carr.length; i++) {
415   - var item = carr[i];
416   -
417   - //-- 如果是等级会员注册返回 --
418   - if(is_card_back){
419   - th.data.card_name=th.data.userinfo.card_field;
420   - //如果是秒杀的返回,就要把活动弄回0
421   - if(item['prom_type']==1){
422   - item['prom_type']=0;
423   - item['prom_id']=0;
424   - }
425   - // 拼团,搭配购不计算,赠品也不计算
426   - if( item['prom_type']!=5 && item['prom_type']!=6 && !item.is_gift && !item['is_collocation'] && item.goods_price>item[th.data.card_name] ){
427   - item.goods_price=item[th.data.card_name];
428   - carr[i].goods_price=item[th.data.card_name];
429   -
430   - }
431   - }else{
432   - // 拼团,搭配购不计算,赠品也不计算,同时会员还未购买等级会员
433   - if(item[th.data.card_name]>0 && item['prom_type']!=5 && item['prom_type']!=6 && !th.data.userinfo.card_field
434   - && !item.is_gift && !item['is_collocation'] && item.goods_price>item[th.data.card_name] ){
435   - item.cut_price1= item.goods_price-item[th.data.card_name];
436   - carr[i].cut_price1=(item.goods_price-item[th.data.card_name])*item.goods_num;
437   - }
438   -
439   - }
440   -
441   - item.original_img = oo.imghost + item.original_img;
442   - /*----接口要弄出来的,先顶着-----*/
443   - var pcid = item.pick_id;
444   - var find = 0;
445   - //----如果有就加进去,没有就新增一个----
446   - //-----------循环查找门店-------------
447   - if (arr.length > 0) {
448   - for (var j = 0; j < arr.length; j++) {
449   - if (arr[j].pickup_id == pcid) {
450   - arr[j].goods.push(item);
451   - //if(item.is_gift!=1){
452   - //确定配送方式
453   - if(arr[j].distr_t==0){
454   - arr[j].distr_t=item.distr_type;
455   - }
456   - var e_t=0
457   - switch (arr[j].distr_t) {
458   - case 0:
459   - e_t = 1;
460   - if(th.data.json_d.pickupway && th.data.json_d.pickupway==1) e_t=0;
461   - break;
462   - case 1: e_t = 1; break;
463   - case 2: e_t = 0; break;
464   - }
465   - arr[j].exp_type=e_t;
466   - if (e_t == 0) th.setData({ is_all_zt:0});
467   - //}
468   -
469   - //-- 把等级卡会优惠多少钱装进去 --
470   - if(item.cut_price) arr[j].card_cut_price+=item.cut_price;
471   - find = 1;break;
472   - }
473   - }
474   - }
475   - //------如果没有找到-----
476   - if (find == 0) {
477   - var pikname = '',sto=null;
478   - //----找到门店名称-----
479   - for (var k = 0; k < th.data.allsto.length; k++) {
480   - if (pcid == th.data.allsto[k].pickup_id) {
481   - pikname = th.data.allsto[k].pickup_name; sto = th.data.allsto[k]; break;
482   - }
483   - }
484   - var e_t=0,dis_t=0;//物流方式,配送方式
485   - if (item.distr_type == 0) {
486   - dis_t = sto.distr_type;
  2672 + //--自提就要把包邮券清理掉--
  2673 + if (ty == 1) {
  2674 + th.data.isget_by_quan = {};
  2675 + if (th.data.using_quan[th.data.bn_pick] && th.data.using_quan[th.data.bn_pick].isby == 1) {
  2676 + th.setData({using_quan: {}});
  2677 + }
  2678 + }
  2679 +
  2680 + //判断有没有默认的物流地址值
  2681 + if (def_exp_code != "" && def_exp_code != null && def_exp_code != undefined) {
  2682 + var wu_arr = this.data.wu_arr;
  2683 + if (wu_arr != null && wu_arr != "") {
  2684 + for (var i = 0; i < wu_arr.length; i++) {
  2685 + if (wu_arr[i].shipping_code == def_exp_code) {
  2686 + th.setData({index: i});
  2687 + }
  2688 + }
  2689 + }
  2690 + }
  2691 + th.calculatePrice2()
  2692 +
  2693 + },
  2694 +
  2695 + //--------立即购买时,使用余额--------
  2696 + set_bn_useyuer: function () {
  2697 + var th = this;
  2698 + th.setData({bn_use_money: !th.data.bn_use_money});
  2699 + th.calculatePrice2();
  2700 + },
  2701 + set_js_useyuer: function () {
  2702 + var th = this;
  2703 + th.setData({js_use_money: !th.data.js_use_money});
  2704 + th.calculatePrice();
  2705 + },
  2706 + //-------------------计算物流---------------
  2707 + calculatewuliu: function (code, o_shipping_price, goods_weight,
  2708 + goods_piece, user_addr, freight_free, o_price, rs) {
  2709 + var price = 0, th = this;
  2710 + price += parseFloat(o_shipping_price);
  2711 + //如果是包邮
  2712 + if (freight_free > 0 && o_price >= freight_free) {
  2713 + return 0;
  2714 + }
  2715 + if (user_addr == null) {
  2716 + return 0;
  2717 + }
  2718 + //计算物流的config item;
  2719 + var item = null;
  2720 + //先根据 镇 县 区找计算的config
  2721 + item = th.get_wuliu_config(user_addr.district, code, rs);
  2722 + if (item == null) item = th.get_wuliu_config(user_addr.city, code, rs);
  2723 + if (item == null) item = th.get_wuliu_config(user_addr.province, code, rs);
  2724 + if (item == null) item = th.get_wuliu_default(code, rs);
  2725 + if (item == null) return o_shipping_price;
  2726 + var fw_price = 0, fp_price = 0;
  2727 + item = item.config;
  2728 + if (item == null) return o_shipping_price;
  2729 + //------按重量----------
  2730 + if (goods_weight >= 0 && item['money']) {
  2731 + fw_price = parseFloat(item['money']);
  2732 + if (goods_weight > item['first_weight']) {
  2733 + var fw = goods_weight - item['first_weight'];
  2734 + var n = Math.ceil(fw / item['second_weight'])
  2735 + fw_price = fw_price + n * parseFloat(item['add_money']);
  2736 + }
  2737 + }
  2738 + //------按件数----------
  2739 + if (goods_piece > 0 && item['piecemoney']) {
  2740 + fp_price = parseFloat(item['piecemoney']);
  2741 + if (goods_piece > item['first_piece']) {
  2742 + var fp = goods_piece - item['first_piece'];
  2743 + var m = Math.ceil(fp / item['second_piece'])
  2744 + fp_price = fp_price + m * parseFloat(item['add_piecemoney']);
  2745 + }
  2746 + }
  2747 + var rspice = parseFloat(price + fw_price + fp_price);
  2748 + return rspice;
  2749 + },
  2750 +
  2751 + //------------循环获取config-----------
  2752 + get_wuliu_config: function (region_id, code, rs) {
  2753 + var item = null, rslist = rs.pageData;
  2754 + for (var i = 0; i < rslist.length; i++) {
  2755 + if (rslist[i].code == code && rslist[i].region_id == region_id) {
  2756 + item = rslist[i];
  2757 + }
  2758 + }
  2759 + return item;
  2760 + },
  2761 + //-------循环获取config,code default-------
  2762 + get_wuliu_default: function (code, rs) {
  2763 + var item = null, rslist = rs.pageData;
  2764 + for (var i = 0; i < rslist.length; i++) {
  2765 + if (rslist[i].shipping_code == code && rslist[i].is_default == 1) {
  2766 + item = rslist[i];
  2767 + }
  2768 + }
  2769 + return item;
  2770 + },
  2771 +
  2772 + //----------立即购买,选择物流-------------
  2773 + bindPickerChange: function (e) {
  2774 + var ind = e.detail.value
  2775 + this.setData({index: ind});
  2776 + this.calculatePrice2();
  2777 + },
  2778 + //----------购物车结算,选择物流-------------
  2779 + bindPickerChange_w: function (e) {
  2780 + var ind = e.detail.value, txt = e.currentTarget.dataset.txt;
  2781 + this.setData({[txt]: ind});
  2782 + this.calculatePrice();
  2783 + },
  2784 +
  2785 + /*----券的所有操作----*/
  2786 + open_coupon_list: function (e) {
  2787 + var th = this;
  2788 + var pickid = e.currentTarget.dataset.pickid;
  2789 + var bn = e.currentTarget.dataset.bn;
  2790 + var cindx = e.currentTarget.dataset.cind;
  2791 + var get_by_quan_list_cart = th.data.get_by_quan_list_cart[pickid];
  2792 +
  2793 +
  2794 + if (bn == 1) {
  2795 + th.setData({open_quan: 1, selected_quan_pick: pickid, disabled: 1});
  2796 + } else {
  2797 + //---多单打开券的时候,就要判断券在其他门店是否有使用---
  2798 + var quanlist = th.data.cartlist[cindx].quan_list;
  2799 + var exp_type = th.data.cartlist[cindx].exp_type;
  2800 +
  2801 +
  2802 + //对于在其他门店已经选择了的券 要判断是否显示到界面
  2803 + var t_user = th.data.using_quan[pickid];
  2804 +
  2805 + for (var i in quanlist) {
  2806 + quanlist[i].is_using = th.check_in_sele(quanlist[i].CashRepNo, pickid);
  2807 + if (t_user && quanlist[i].CashRepNo == t_user.coupon_no)
  2808 + quanlist[i].show_red = 1;
  2809 + else
  2810 + quanlist[i].show_red = 0;
  2811 + }
  2812 +
  2813 + if (get_by_quan_list_cart) {
  2814 + for (var i in get_by_quan_list_cart) {
  2815 + get_by_quan_list_cart[i].is_using = th.check_in_sele(get_by_quan_list_cart[i].no, pickid);
  2816 + if (t_user && get_by_quan_list_cart[i].no == t_user.coupon_no)
  2817 + get_by_quan_list_cart[i].show_red = 1;
  2818 + else
  2819 + get_by_quan_list_cart[i].show_red = 0;
  2820 + }
  2821 + th.setData({by_quan_list_cart: get_by_quan_list_cart});
487 2822 } else {
488   - dis_t = item.distr_type ;
489   - }
490   - switch (dis_t) {
491   - case 0:
492   - e_t = 1;
493   - //-- 系统后台有设置要默认的 --
494   - if(th.data.json_d.pickupway && th.data.json_d.pickupway==1) e_t=0;
495   - break;
496   - case 1: e_t = 1; break;
497   - case 2: e_t = 0; break;
498   - }
499   - //如果是物流的话,全部自提的控制要弄成0
500   - if (e_t == 0) th.setData({ is_all_zt:0});
501   -
502   - var narr = new Array(); narr.push(item);
503   -
504   - //-----------拼装购物车结算的数组,如果有默认物流时要用默认物流编号,计算默认的物流,不管是不是自提都算一下-----------------
505   - var m_wind=0,def_exp_code=getApp().globalData.userInfo.def_exp_code;
506   - if(def_exp_code){
507   - for(var k=0;k<th.data.wu_arr.length;k++){
508   - var item=th.data.wu_arr[k]; if(def_exp_code==item.code){ m_wind=k; }
509   - }
  2823 + th.setData({by_quan_list_cart: null});
510 2824 }
511 2825  
512   - var ie = {
513   - pickup_id: pcid, pname: pikname, goods: narr, wind: m_wind, distr_t: dis_t,card_cut_price:0,exp_type:e_t,
514   - goods_price: 0, shipping_price: 0, user_money: 0, total_amount: 0, order_amount: 0, user_note:0};
515   -
516   - //-- 把等级卡会优惠多少钱装进去 --
517   - if(item.cut_price1) ie.card_cut_price+=item.cut_price1;
518   - arr.push(ie);
519   -
520   - }
521   - }
522   - //-- 如果是回退回来的情况 --
523   - if(th.data.cartlist && th.data.cartlist.length>0) {
524   - for(var kj in th.data.cartlist){
525   - for(var ih in arr){
526   - var ie=arr[ih];
527   - if(ie.pickup_id==th.data.cartlist[kj].pickup_id){
528   - ie.exp_type=parseInt(th.data.cartlist[kj].exp_type);
529   - ie.wind=parseInt(th.data.cartlist[kj].wind);
530   - break;
531   - }
532   - }
533   - }
534   - }
535   -
536   - //-- 循环计算一下线下取价 --
537   - for (var k = 0; k < arr.length; k++) {
538   - var c_item=arr[k];
539   - var item = arr[k].goods;
540   - var offline_price=0;
541   - var offline_num=0;
542   - for (var c = 0; c < item.length; c++) {
543   - //-- 如果这个商品是线下取价的时候 --
544   - if(item[c].offline_price>0){
545   - offline_price+= (item[c].goods_price-item[c].offline_price)*item[c].goods_num;
546   - offline_num+=item[c].goods_num;
547   - }
548   - }
549   - if(offline_price>0){
550   - c_item.offline_price=offline_price;
551   - c_item.offline_num=offline_num;
552   - c_item.is_offline=1;
553   - }
554   - }
555   -
556   - //深拷贝
557   - th.data.old_cartlist= JSON.parse(JSON.stringify(arr));
558   - th.setData({
559   - cartlist: arr,
560   - });
561   - //--- 获取一下看有没有优惠券 ----
562   - setTimeout(function () {
563   - var frozenQuan=null;
564   - var url0="/api/weshop/users/frozenQuan/listFrozenQuan/"+app.globalData.user_id;
565   - app.request.promiseGet(url0,{1:1}).then(res=>{
566   - if(res.data.code==0){ frozenQuan=res.data.data; th.data.frozenQuan=frozenQuan; }
567   - th.calculatePrice();
568   - th.get_cart_quan();
569   - })
  2826 + console.log("2222222券的列表", quanlist);
  2827 + th.setData({
  2828 + sele_cart_ind: cindx,
  2829 + sele_exp_type: exp_type,
  2830 + open_quan: 1,
  2831 + selected_quan_pick: pickid,
  2832 + selected_quan_list: quanlist,
  2833 + disabled: 1
  2834 + });
  2835 + }
  2836 + },
  2837 + close_coupon: function (e) {
  2838 + var th = this;
  2839 + th.setData({open_quan: 0, disabled: 0});
  2840 + },
570 2841  
571   - },500)
572   -
573   - }
574   - });
575   - },
576   -
577   - //-----获取立即购买的商品信息,入口----
578   - get_buy_goods: function (e){
579   - var th=this;
580   - var gg = to.get_b_now();
581   - //--------如果goods_id一样,就是要立即购买-----
582   - if(e==gg.goods_id){
583   - a.get("/api/weshop/goods/get/" + oo.stoid+"/"+e, {
584   - success:async function (t) {
585   - var gd = t.data.data;
586   - if(!gd) return false;
587   -
588   - t.data.data.original_img = oo.imghost + t.data.data.original_img;
589   - t.data.data['buynum'] = gg.goods_num;
590   - var distr_t=0,et=0
591   - if (t.data.data.distr_type==0){
592   - distr_t = gg.pick_dis;
593   - }else{
594   - distr_t = t.data.data.distr_type;
595   - }
596   -
597   - switch (distr_t){
598   - case 0:
599   - et=1;
600   - //-- 系统后台有设置要默认的 --
601   - if(th.data.json_d.pickupway && th.data.json_d.pickupway==1) et=0;
602   - break;
603   - case 1: et = 1; break;
604   - case 2: et = 0; break;
605   - }
606   -
607   -
608   - var m_wind=0,def_exp_code=getApp().globalData.userInfo.def_exp_code;
609   - if(et==0 && def_exp_code){
610   - for(var k=0;k<th.data.wu_arr.length;k++){
611   - var item=th.data.wu_arr[k]; if(def_exp_code==item.code){ m_wind=k; }
612   - }
613   - }
614   -
615   -
616   - if(th.data.bn_goods){
617   - et=th.data.bn_exp_type;
618   - m_wind=th.data.index;
619   - }
620   -
621   - //---是不是购买等级卡成功的返回---等级卡显示的判断---
622   - var is_card_back=getApp().globalData.is_card_back;
623   - if(is_card_back){
624   - th.data.card_name=th.data.userinfo.card_field;
625   - gg.goods_price=gd[th.data.card_name];
626   - getApp().globalData.is_card_back=0;
627   - th.setData({card_cut_price:0});
628   - //如果是秒杀的返回
629   - if(gd.prom_type==1) gd.prom_type=0;
630   - }else{
631   - //--- 商家等级卡开通的情况下, 会员不是等级会员的情况, 商品有设置等级卡价格,同时等级卡价格小于商品的价格
632   - //-- 搭配购的商品也可以单独购买,所以此时搭配购的商品要进行计算优惠 --
633   - if(!gg.collocation_goods && gd['prom_type']!=6 && th.data.card_name && gd[th.data.card_name]>0 && gg.goods_price>gd[th.data.card_name] && !th.data.userinfo.card_field){
634   - var cut_p= (gg.goods_price-gd[th.data.card_name])*gg.goods_num;
635   - th.setData({card_cut_price:cut_p});
636   - }
637   - }
638   -
639   -
640   -
641   - switch (gd.prom_type){
642   - case 0:
643   - case 2:
644   - case 3:
645   - case 4:
646   - case 5:
647   - case 6:
648   - //--此时开始计算商品的使用券相关,如果有等级价还要计算和等级价相关的,
649   - // 如果有优惠促销,还要把促销的部分计算在内,因为促销还有不能使用优惠券--
650   - t.data.data.shop_price=gg.goods_price;
651   - t.data.data.goods_price=gg.goods_price;
652   - t.data.data.goods_num=gg.goods_num;
653   - th.data.ckeck_quan_price=t.data.data.shop_price*gg.goods_num;
654   - th.data.check_quan_price_list=t.data.data.shop_price*gg.goods_num+"";
655   - th.data.check_quan_ware_list=t.data.data.erpwareid+"";
656   -
657   - //-- 如果有线下取价的时候 --
658   - if(gg.offline_price){
659   - t.data.data.offline_price=gg.offline_price;
660   - t.data.data.pricing_type=gg.pricing_type;
661   - t.data.data.is_offline=1;
662   -
663   - th.data.ckeck_quan_price=t.data.data.offline_price*gg.goods_num;
664   - th.data.check_quan_price_list=t.data.data.offline_price*gg.goods_num+"";
665   - th.data.check_quan_ware_list=t.data.data.erpwareid+"";
666   - }
667   -
668   - t.data.data.prom_id = 0;
669   - t.data.data.prom_type = 0;
670   -
671   - //如果立即购买那边过来,就要读取接口,查看活动的优惠内容
672   - if(gg.prom_type==3){
673   - t.data.data.prom_id = gg.prom_id ;
674   - t.data.data.prom_type =3;
675   - //如果是优惠活动,就要调用活动,计算价格
676   - th.buy_now_prom_goods(gg.prom_id, t.data.data,function (data) {
677   - //判断一下购买商品的数量是不是超过
678   - if(data.gift_goods_id){
679   - var num=1;
680   - if(data.is_bz==1){
681   - num=data.bs;
682   - if (num > data.gift_limit_num) num = 0;
683   - }
684   - //如果赠品数量超出礼品库存,就取消
685   - if(num>data['gift_storecount']) num=0;
686   - if(num>0){
687   - var ob={};
688   - ob.is_gift=1;
689   - ob.prom_id=data.prom_id;
690   - ob.goods_id=data.gift_goods_id;
691   - ob.goods_name=data.gift_goods_name;
692   - ob.goods_color=data.gift_goods_color;
693   - ob.goods_spec=data.gift_goods_spec;
694   - ob.original_img=os.imghost+data.gift_original_img;
695   - ob.market_price=data.gift_market_price;
696   - ob.gift_id=data.gift_id;
697   - ob.shop_price=0;
698   - ob.buynum=num;
699   - ob.weight=data.gift_weight; //商品的重量
700   - ob.exp_sum_type=data.gift_exp_sum_type; //商品的物流计算方式
701   - ob.uniform_exp_sum=data.gift_uniform_exp_sum //统一运费的金额
702   -
703   - th.setData({buy_now_gift_goods:ob});
704   - }
705   - }
706   -
707   - th.setData({
708   - bn_goods: data, bn_pickname: gg.pick_name,index:m_wind,
709   - bn_pick: gg.pick_id, bn_t_exp_t: distr_t,bn_exp_type: et
710   - });
711   -
712   - //计算价格
713   - th.calculatePrice2();
714   - //获取优惠券
715   - th.get_buy_now_quan();
716   -
717   - })
718   - }else{
719   - //--看是不是搭配促销--
720   - if(gg.prom_type==5){
721   - t.data.data.prom_id = gg.prom_id ;
722   - t.data.data.prom_type =5;
723   - if(gg.room_id){
724   - t.data.data.room_id=gg.room_id;
725   - }
726   - //--主商品要有导购id和导购类型--
727   - if(gg.guide_id){
728   - t.data.data.guide_id=gg.guide_id;
729   - t.data.data.guide_type=gg.guide_type;
730   - }
731   - th.setData({collocation_goods:gg.collocation_goods});
732   -
733   - var cart_arr=new Array();
734   - //var narr=gg.collocation_goods;
735   - //修改成深拷贝,确保返回是数据正确
736   - var narr=JSON.parse(JSON.stringify(gg.collocation_goods));
737   -
738   - narr.push(t.data.data);
739   -
740   - //-- 搭配促销的门店配送方式的修复 --
741   - et=1;distr_t=0;
742   - for(var hi in narr){
743   - var dis_t=narr[hi].distr_type;
744   - if(dis_t==2){
745   - th.setData({ is_all_zt:0});et=0;
746   - }
747   - if(dis_t>0){
748   - distr_t=dis_t;
749   - }
750   - }
751   -
752   - //自选的时候,系统配置了默认的配送方式是物流的时候
753   - if(distr_t==0 && th.data.json_d.pickupway && th.data.json_d.pickupway==1 ){
754   - et=0;
755   - }
756   -
757   -
758   - var ie = {
759   - pickup_id: gg.pick_id, pname: gg.pick_name, goods: narr, exp_type: et, wind: m_wind, distr_t: distr_t,bn_t_exp_t: distr_t,
760   - goods_price: 0, shipping_price: 0, user_money: 0, total_amount: 0, order_amount: 0, user_note:0};
761   - cart_arr.push(ie);
762   - th.data.old_cartlist=cart_arr;
  2842 + //---判断券时候在已经选择的列表中---
  2843 + check_in_sele: function (no, pick_id) {
  2844 + var th = this;
  2845 + if (th.data.using_quan.length <= 0) return false;
  2846 + for (var i in th.data.using_quan) {
  2847 + //--如果键值等于本身就要跳出--
  2848 + if (parseInt(i) == parseInt(pick_id)) continue;
  2849 + var item = th.data.using_quan[i];
  2850 + if (item.coupon_no == no) {
  2851 + return true;
  2852 + }
  2853 + }
  2854 + return false;
  2855 + },
  2856 +
  2857 + /*--点击选择券--*/
  2858 + sele_quan_item: function (e) {
  2859 +
  2860 + var ind = e.currentTarget.dataset.ind;
  2861 + var quan_item = this.data.selected_quan_list[ind];
  2862 + var pickid = this.data.selected_quan_pick; //现在选择的是哪一个门店
  2863 + //--如果券是单品使用的时候--
  2864 + if (quan_item && quan_item.UseObjectType && quan_item.UseObjectType == "20") {
  2865 + //---只有多件购买的时候才要计算,//购物车购买和搭配勾的时候---
  2866 + var gg = getApp().get_b_now();
  2867 + if (this.data.is_b_now == 0 || gg.prom_type == 5) {
  2868 + var arr = this.data.order_prom_list_cart;
  2869 + var t_pk_item = null;
  2870 + for (var ii in arr) {
  2871 + var ep = arr[ii];
  2872 + if (pickid == ep.pickup_id) {
  2873 + t_pk_item = ep;
  2874 + break;
  2875 + }
  2876 + }
  2877 + //--寻找券指定的商品--
  2878 + var gd = null;
  2879 + if (t_pk_item) {
  2880 + var goods = t_pk_item.goods;
  2881 + for (var gid in goods) {
  2882 + if (quan_item.UseObjectID == goods[gid].erpwareid) {
  2883 + gd = goods[gid];
  2884 + }
  2885 + }
  2886 + }
  2887 + if (!gd) {
  2888 + getApp().my_warnning("未找到指定商品使用", 0, this, 600);
  2889 + return false;
  2890 + }
  2891 + //计算价格,如果有平摊的实收要计算实收的金额
  2892 + var item_price = gd.goods_price * gd.goods_num;
  2893 + //-- 如果有平摊下去,有实收价格的时候,就要用account_fir来计算价格 --
  2894 + if (gd.account_fir != null && gd.account_fir != undefined) {
  2895 + item_price = gd.account_fir * gd.goods_num;
763 2896 }
764   - th.setData({
765   - bn_goods: t.data.data, bn_pickname: gg.pick_name,index:m_wind,
766   - bn_pick: gg.pick_id, bn_t_exp_t: distr_t,bn_exp_type: et
767   - });
768   -
769   -
770   - //--搭配促销也是按照购物车的方式来计算优惠券--
771   - if(gg.prom_type==5){
772   - var frozenQuan=null;
773   - var url0="/api/weshop/users/frozenQuan/listFrozenQuan/"+app.globalData.user_id;
774   - app.request.promiseGet(url0,{1:1}).then(res=> {
775   - if(res.data.code==0){ frozenQuan=res.data.data; th.data.frozenQuan=frozenQuan; }
776   - //计算价格
777   - th.calculatePrice2();
778   - th.get_cart_quan();
779   - });
780   - }else{
781   - //计算价格
782   - th.calculatePrice2();
783   - //获取优惠券,
784   - th.get_buy_now_quan();
785   - }
786   - }
787   -
788   - break;
789   - case 1: //---秒杀-----
790   - var quanlist=null;
791   - getApp().request.get("/api/weshop/activitylist/getSJGoodsPrice/"+gd.store_id
792   - + "/" + gd.goods_id + "/1/" + gd.prom_id,{
793   - success: async function (tt) {
794   - if(tt.data.code==0){
795   - t.data.data.shop_price=tt.data.data.prom_price;
796   - }else{
797   - t.data.data.prom_id = 0; t.data.data.prom_type = 0;
798   -
799   - th.data.ckeck_quan_price=t.data.data.shop_price*gg.goods_num;
800   - th.data.check_quan_price_list=t.data.data.shop_price*gg.goods_num+"";
801   - th.data.check_quan_ware_list=t.data.data.erpwareid+"";
802   - }
803   -
804   - th.setData({
805   - bn_goods: t.data.data, bn_pickname: gg.pick_name, bn_exp_type: et,index:m_wind,
806   - bn_pick: gg.pick_id, bn_t_exp_t: distr_t,bn_exp_type: et
807   - });
808   -
809   - //计算价格
810   - th.calculatePrice2();
811   - //获取优惠券
812   - th.get_buy_now_quan();
813   - }
814   - });
815   -
816   - break;
817   - }
818   - },
819   - });
820   - }
821   - },
822   -
823   - //---------------检查是否有收货地址-------------------
824   - checkAddressList: function() {
825   - var t = this;
826   - return !(!this.data.order || null == this.data.order.userAddress) || (wx.showModal({
827   - title: "请先填写或选择收货地址~",
828   - success: function(a) {
829   - a.confirm ? t.enterAddressPage() : wx.navigateBack();
830   - },
831   - fail: function() {
832   - wx.navigateBack();
833   - }
834   - }), !1);
835   - },
836   - showInvoice: function() {
837   - this.setData({
838   - invoiceToggle: !this.data.invoiceToggle
839   - });
840   - },
841   - keyUpChangePay1: function(t) {
842   - this.setData({
843   - payWithUserMoney: !(t.detail.value.length > 0)
844   - });
845   - },
846   - keyUpChangePay2: function(t) {
847   - this.setData({
848   - payWithPoints: !(t.detail.value.length > 0)
849   - });
850   - },
851   - keyUpChangeNum: function(t) {
852   - this.setData({
853   - maxWord: t.detail.value.length
854   - });
855   - },
856   -
857   - calc_per:async function(c_arr){
858   - var th=this;
859   - //-- 循环处理 --
860   - for(var i in c_arr){
861   - var cart_item=c_arr[i]; //就是每一单的意思
862   - var pickid=cart_item.pickup_id;
863   - var ord_goods=c_arr[i].goods; //就是每一单的从表的意思
864   - var o_price=0,q_conditin=0;
865   - //--------循环计算总价-----------
866   - for(var j=0;j<ord_goods.length;j++){
867   - o_price += ord_goods[j].goods_price * ord_goods[j].goods_num;
868   - }
869   -
870   - //---如果该门店的相关活动,就要算一下减价--
871   - if(th.data.prom_goods_map[pickid]){
872   - var ob=th.data.prom_goods_map[pickid];
873   - for(var ii in ob){
874   - var item_map=ob[ii];
875   - if(item_map.bs==undefined || item_map.bs==null) {
876   - //等待,获取一下优惠活动的信息
877   - await getApp().request.promiseGet("/api/weshop/goods/getDiscount", {
878   - data: {
879   - price: item_map.price, prom_id: item_map.prom_id,
880   - goods_num: item_map.goods_num, user_id: getApp().globalData.user_id,
881   - is_bz: item_map.is_bz
882   - }
883   - }).then(res => {
884   - if (res.data.code == 0 && res.data.data.condition) {
885   - var get_data = res.data.data;
886   - item_map.is_bz = get_data.is_bz; //是不是倍增
887   - item_map.bs = get_data.bs; //是不是倍数
888   - item_map.is_past = get_data.is_past; //是不是包邮
889   - item_map.prom_price = get_data.price>=0?get_data.price:item_map.price;
890   - item_map.s_intValue = get_data.intValue;
891   - item_map.s_coupon_id = get_data.coupon_id;
892   - item_map.s_coupon_num = get_data.coupon_num;
893   - if(get_data.gift_id && get_data.goodsinfo) {
894   - item_map.gift_id = get_data.gift_id;
895   - item_map.gift_goods_id = get_data.goods_id;
896   - item_map.gift_goods_name = get_data.goods_name;
897   - item_map.gift_goods_color = get_data.goodsinfo.goods_color ? get_data.goodsinfo.goods_color : '';
898   - item_map.gift_goods_spec = get_data.goodsinfo.goods_spec ? get_data.goodsinfo.goods_spec : '';
899   - item_map.gift_original_img = get_data.goodsinfo.original_img;
900   - item_map.gift_limit_num = get_data.limit_num;
901   - item_map.gift_storecount = get_data.gift_storecount;
902   - item_map.gift_weight = get_data.goodsinfo.weight;
903   - item_map.gift_exp_sum_type = get_data.goodsinfo.exp_sum_type;
904   - item_map.uniform_exp_sum = get_data.goodsinfo.uniform_exp_sum;
905   -
906   - }
907   - item_map.s_libao = get_data.libao;
908   - item_map.s_lb_num = get_data.lb_num;
909   - }
910   - })
911   - }
912   -
913   - //有活动,且优惠活动并没有限制使用优惠券,且有减价
914   - //--看有没有减价--
915   - //if(item_map.prom_price>=0 && item_map.price-item_map.prom_price){
916   - if(item_map.price-item_map.prom_price && item_map.prom_price!==null){
917   - if(cart_item.prom_pt_json){
918   - cart_item.prom_pt_json.push({"prom_id":item_map.prom_id,"dis":(item_map.price-item_map.prom_price).toFixed(2),"ispt":0})
919   - }else{
920   - cart_item.prom_pt_json=[{"prom_id":item_map.prom_id,"dis":(item_map.price-item_map.prom_price).toFixed(2),"ispt":0}];
921   - }
922   -
923   - //-- 如果系统要平摊到单品 --
924   - //if(!th.data.ispt_goods){
925   - var pt_data={
926   - 'prom_id':item_map.prom_id,
927   - 'dis': parseFloat((item_map.price-item_map.prom_price).toFixed(2)),
928   - 'goods':item_map.goods
929   - }
930   -
931   - var pt_res=null;
932   - await getApp().request.promisePost("/api/weshop/order/getGoodsSplit",{is_json:1,data:pt_data}).then(res=>{
933   - if(res.data.code==0){ pt_res=res.data.data; }
934   - })
935   - if(pt_res){
936   - for (var io in item_map.goods){
937   - //平摊赋值
938   - item_map.goods[io].account_fir=th.arr_get_goods(item_map.goods[io].goods_id,pt_res).fisrt_account;
939   - item_map.goods[io].account_yu_fir=th.arr_get_goods(item_map.goods[io].goods_id,pt_res).fisrt_account_yu;
940   - if(!th.data.ispt_goods){
941   - item_map.goods[io].account=item_map.goods[io].account_fir;
942   - item_map.goods[io].account_yu=item_map.goods[io].account_yu_fir;
943   - }
944   - }
945   - }
946   - // }
947   -
948   - o_price-=(item_map.price-item_map.prom_price);
949   - //如果有限制使用优惠券,就要减掉参与的活动商品的钱
950   - if(!item_map.is_xz_yh) q_conditin=o_price;
951   - }
952   -
953   - //--------循环计算商品是不是包邮,是不是使用优惠券,此时循环是商品从表-----------
954   - for(var j=0;j<ord_goods.length;j++){
955   - if(ord_goods[j].is_gift) continue;
956   - if(ord_goods[j].prom_type==3 && ord_goods[j].prom_id==item_map.prom_id){
957   - ord_goods[j].is_xz_yh= item_map.is_xz_yh;
958   - ord_goods[j].is_past= item_map.is_past;
959   - ord_goods[j].account_fir= th.item_map_get_goods(ord_goods[j].goods_id,item_map).account_fir;
960   - ord_goods[j].account_yu_fir= th.item_map_get_goods(ord_goods[j].goods_id,item_map).account_yu_fir;
961   - ord_goods[j].account= th.item_map_get_goods(ord_goods[j].goods_id,item_map).account;
962   - ord_goods[j].account_yu= th.item_map_get_goods(ord_goods[j].goods_id,item_map).account_yu;
963   - }
964   - }
965   -
966   -
967   - //--优惠多少钱--
968   - if(!cart_item.cut_price) cart_item.cut_price=0;
969   - //-- --
970   - if(item_map.price!=undefined && item_map.price!=null
971   - && item_map.prom_price!=undefined && item_map.prom_price!=null)
972   - cart_item.cut_price+=(item_map.price-item_map.prom_price);
973   - //---如果有送积分---
974   - if(item_map.s_intValue){
975   - if(!cart_item.s_intValue) cart_item.s_intValue=0;
976   - cart_item.s_intValue+=item_map.s_intValue;
977   - }
978   - //-- 如果有送优惠券的情况 --
979   - if(item_map.s_coupon_id){
980   - if(!cart_item.s_coupon_id) {
981   - cart_item.s_coupon_id=item_map.s_coupon_id+"";
982   - cart_item.g_coupon_num=[{'c_id':item_map.s_coupon_id,"num": item_map.s_coupon_num}];
983   - }
984   - else{
985   - cart_item.s_coupon_id+=","+item_map.s_coupon_id;
986   - cart_item.g_coupon_num.push({'c_id':item_map.s_coupon_id,"num": item_map.s_coupon_num})
987   - }
988   - }
989   -
990   - //-- 如果有送优包邮券的情况 --
991   - if(item_map.s_libao){
992   - if(!cart_item.s_libao) {
993   - cart_item.s_libao=item_map.s_libao+"";
994   - cart_item.g_lb_num=[{'l_id':item_map.s_libao,"num": item_map.s_lb_num}];
995   - }
996   - else{
997   - cart_item.s_libao+=","+item_map.s_libao;
998   - cart_item.g_lb_num.push({'l_id':item_map.s_libao,"num": item_map.s_lb_num})
999   - }
1000   - }
1001   - }
1002   - }
1003   - }
1004   - },
1005   -
1006   - //-------------------计算订单价格-------------------
1007   - calculatePrice: function(t, s) {
1008   - var th = this;
1009   - to.getConfig2(function(ee){
1010   - to.getwuliuprice( async function (rs) {
1011   - wx.showLoading({
1012   - title:"处理中."
1013   - })
1014   - var all_price=0; //所有的商品总价
1015   - var all_shipping_m= 0; //所有的物流总价
1016   - var all_total_m = 0; //所有的订单应付总价
1017   - var all_order_m = 0; //所有的订单应付总价
1018   - var all_user_m=0; //所有的订单用户使用金额
1019   - var all_coupon_price_m=0; //所有的订单用户使用优惠券价格
1020   - var all_cutprice=0; //所有的优惠减件
1021   - var all_order_prom=0; //所有的订单优惠
1022   -
1023   - var umoney = th.data.userinfo.user_money - th.data.txmon - (th.data.userinfo.frozen_money?th.data.userinfo.frozen_money:0);
1024   - var freight_free = ee.freight_free; //全场满多少包邮
1025   - var no_ex_id=ee.no_ex_id;
1026   - var no_ex_good=null;
1027   - var by_qc={};
1028   -
1029   - if(no_ex_id && freight_free>0){
1030   - //-----------获取不包邮区域,不包邮商品-------
1031   - await getApp().request.promiseGet("/api/weshop/areaFeemail/getAreaGoods",{
1032   - data:{store_id:os.stoid,id:no_ex_id}
1033   - }).then(res=>{
1034   - if(res.data.code==0 && res.data.data && res.data.data.length>0){
1035   - by_qc=res.data.data[0];
1036   - }
1037   - })
1038   - };
1039   - var c_arr=JSON.parse(JSON.stringify(th.data.old_cartlist));
1040   -
1041   -
1042   - if(th.data.cartlist && th.data.cartlist.length>0){
1043   - for(var i =0;i<c_arr.length;i++){
1044   - c_arr[i].exp_type=th.data.cartlist[i].exp_type;
1045   - c_arr[i].wind=th.data.cartlist[i].wind;
1046   - }
1047   - }
1048   -
1049   - //调用函数计算每件商品的单价
1050   - await th.calc_per(c_arr);
1051   - //调用函数计算,优惠券优惠什么商品价格,优惠券优惠什么商品
1052   - await th.get_cart_quan(c_arr);
1053   - //---循环购物车---
1054   - for(var i in c_arr){
1055   - //因为搭配购买也是再这里计算,搭配购的is_b_now==1
1056   - if(th.data.is_b_now==0) {
1057   - //此时物流的选择方式要用th.data.cartlist;
1058   - c_arr[i].exp_type = th.data.cartlist[i].exp_type;
1059   - c_arr[i].wind = th.data.cartlist[i].wind;
1060   - if(th.data.cartlist[i].check_quan_price_list) c_arr[i].check_quan_price_list= th.data.cartlist[i].check_quan_price_list; //优惠券优惠什么商品价格
1061   - if(th.data.cartlist[i].check_quan_ware_list) c_arr[i].check_quan_ware_list= th.data.cartlist[i].check_quan_ware_list; //优惠券优惠什么商品
1062   - }else{
1063   - c_arr[i].exp_type = th.data.bn_exp_type; //配送方式
1064   - c_arr[i].wind = th.data.index; //立即购买选择的物流
1065   - //c_arr[i].=th.data. //立即购买的使用余额
1066   - if(th.data.cartlist) c_arr[i].check_quan_price_list= th.data.cartlist[i].check_quan_price_list; //优惠券优惠什么商品价格
1067   - if(th.data.cartlist) c_arr[i].check_quan_ware_list= th.data.cartlist[i].check_quan_ware_list; //优惠券优惠什么商品
1068   - }
1069   -
1070   - var cart_item=c_arr[i]; //就是每一单的意思
1071   - var pickid=cart_item.pickup_id;
1072   - var o_price=0;
1073   - var o_shipping_price=0,goods_weight=-1, goods_piece=-1;
1074   - var item=c_arr[i].goods; //就是每一单的从表的意思
1075   -
1076   - //---如果有选择优惠券的情况下---
1077   - var quan_price=0;
1078   - var coupon_price=0;
1079   - var quan_no= null;
1080   -
1081   - if(th.data.using_quan[pickid]!=null && th.data.using_quan[pickid]!=undefined)
1082   - quan_no=th.data.using_quan[pickid].coupon_no;
1083   -
1084   - //普通券的时候
1085   - if(quan_no && th.data.using_quan[pickid].isby!=1){
1086   - //---获取优惠券优惠---
1087   - await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice", {
1088   - data: {
1089   - storeId: oo.stoid,
1090   - CashRepNo: quan_no,
1091   - WaresSum: cart_item.check_quan_price_list,
1092   - WareIds: cart_item.check_quan_ware_list
1093   - }
1094   - }).then(res => {
1095   - if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
1096   - var q_data = res.data.data;
1097   - //--存储商品优惠的内容--
1098   - cart_item.quan_youhui_list = q_data;
1099   - for (var k in q_data)
1100   - quan_price += q_data[k].WareCashSum;
1101   - }
1102   - })
1103   - }
1104   -
1105   -
1106   - //--------循环计算总价-----------
1107   - for(var j=0;j<item.length;j++){
1108   - o_price += item[j].goods_price * item[j].goods_num;
1109   - }
1110   -
1111   - var f_o_price=o_price;
1112   - //如果又优惠的钱,就要减价
1113   - if(c_arr[i].cut_price>0) o_price-=c_arr[i].cut_price;
1114   -
1115   - //-- 计算线下取价的功能 --
1116   - if(cart_item.is_offline==1){
1117   - o_price=o_price-cart_item.offline_price;
1118   - }
1119   -
1120   - //判断包邮券的钱
1121   - var q_conditin=0;
1122   - q_conditin=o_price-quan_price;
1123   -
1124   - cart_item.goods_price = f_o_price.toFixed(2); //商品总费用,用f_o_price来计算
1125   - //计算物流费用
1126   - cart_item.shipping_price = 0;
1127   -
1128   -
1129   -
1130   - //--有不包邮区域,且不免运费,全场的计算,要减到优惠金额 和券的金额--
1131   - if(no_ex_id && freight_free>0 && (o_price-quan_price)>=freight_free && cart_item.exp_type == 0 && (by_qc.region_list || by_qc.goods_list) ){
1132   - //如果有设置不包邮区域的时候
1133   - if(by_qc.region_list!="" && by_qc.region_list!=null && by_qc.region_list!=undefined ){
1134   - if(th.check_by_area(by_qc.region_list)){
1135   - freight_free=0;
1136   - th.data.is_no_by[pickid]=1;
1137   - }
1138   - }
1139   - //如果有设置不包邮区商品
1140   - if(by_qc.goods_list!="" && by_qc.goods_list!=undefined && by_qc!=null && freight_free>0){
1141   - freight_free=0;
1142   - no_ex_good=by_qc.goods_list;
1143   - }
1144   - }
1145   -
1146   - //--如果是物流,且选择了地址,就要开始显示包邮券,且包邮券也已经优惠了优惠活动的金额--
1147   - if (cart_item.exp_type == 0 && th.data.user_addr != null) {
1148   - //看是不是有调用过包邮券
1149   - if(!th.data.isget_by_quan[pickid]){
1150   - //--判断要不要显示包邮券,调用接口,因为有for循环---
1151   - await getApp().request.promiseGet("/api/weshop/userfeemail/pageAndArea",{
1152   - data:{store_id:os.stoid,isuse:0,condition:q_conditin,user_id:getApp().globalData.user_id,pageSize:2000}
1153   - }).then(res=>{
1154   - if(res.data.code==0 && res.data.data.total>0){
1155   - //此时要循环判断包邮的地区,不包邮商品是不是符合
1156   - var arr=[],quanlist=res.data.data.pageData;
1157   - quanlist = th.check_is_frozenQuan(quanlist, th.data.frozenQuan,1);
1158   - for(var i in quanlist){
1159   - var item=quanlist[i];
1160   - var goods=cart_item.goods;
1161   - var g_arr=[];
1162   - for(var ii in goods){
1163   - g_arr.push(goods[ii].goods_id);
1164   - }
1165   - if(item.region_list && th.check_by_area(item.region_list)) continue; //如果是不包邮区域
1166   - if(item.goods_list){
1167   - var no_goods_arr=item.goods_list.split(",");
1168   - if(ut.isContained(no_goods_arr,g_arr)) continue; //如果是不包邮商品
1169   - }
1170   - arr.push(item);
1171   - }
1172   - if(arr){
1173   - th.data.get_by_quan_list_cart[pickid]=arr;
1174   - //th.setData({get_by_quan_list_cart:th.data.get_by_quan_list_cart});
1175   - if(th.data.is_b_now){
1176   - th.setData({get_by_quan_list:arr});
1177   - }
1178   - }
1179   - th.data.isget_by_quan[pickid]=1;
1180   - }
1181   - })
1182   - }
1183   - }
1184   -
1185   - //如果是包邮券的时候,要看看券的情况
1186   - if(quan_no && th.data.using_quan[pickid].isby==1){
1187   - var quan=th.data.using_quan[pickid];
1188   - if(!quan.goods_list){
1189   - th.data.is_quan_by[pickid]=1; //专门给券的判断用的
1190   - }else{
1191   - th.data.is_quan_by[pickid]=0;
1192   - //看有没有模板的包邮
1193   - if(no_ex_good){
1194   - var arr=no_ex_good.split(",");
1195   - var arr2=quan.goods_list.split(",");
1196   - if(ut.isContained(arr,arr2)){
1197   - getApp().my_warnning("全场不包邮商品和包邮券的重复",0,th);
1198   - th.data.using_quan[pickid]={};
1199   - th.setData({using_quan:th.data.using_quan})
1200   - return false;
1201   - }
1202   - var n_arr=ut.mergeArray(arr,arr2);
1203   - no_ex_good=n_arr.join(",");
1204   - }else{
1205   - no_ex_good=quan.goods_list;
1206   - }
1207   - }
1208   - }else{
1209   - th.data.is_quan_by[pickid]=0; //专门给券的判断用的
1210   - }
1211   -
1212   - //--------循环计算总价-----------
1213   - for(var j=0;j<item.length;j++){
1214   - //如果都包邮,都没必要等级数量了
1215   - if(th.data.is_quan_by[pickid]) continue;
1216   - //如果是优惠活动是包邮,就不用计算包邮的费用了
1217   - if(item[j].is_past) continue;
1218   - //是不是不包邮的商品
1219   - var is_good_no_by=0;
1220   - if(no_ex_good){
1221   - is_good_no_by=th.check_by_goods(no_ex_good,item[j].goods_id);
1222   - }
1223   -
1224   - //如果达到全场包邮的条件,同时,没有地区不包邮,或者商品不包邮
1225   - if(o_price-quan_price>=freight_free && freight_free>0 && !is_good_no_by && th.data.is_no_by[pickid]!=1){
1226   - continue;
1227   - }
1228   -
1229   - //--如果是包邮券使用的情况下,如果商品是包邮的,那么就不进行计算--
1230   - if(th.data.using_quan[pickid] && th.data.using_quan[pickid].isby==1 && !is_good_no_by){
1231   - continue;
1232   - }
1233   -
1234   -
1235   - var no_ex_good_arr=null;
1236   - if(no_ex_good) no_ex_good_arr=no_ex_good.split(',');
1237   -
1238   - //----------------如果是选择了物流---------------------
1239   - if(cart_item.exp_type == 0 && item[j].is_free_shipping==0 && (!no_ex_good_arr || no_ex_good_arr.indexOf(item[j].goods_id+'')>-1 )){
1240   -
1241   -
1242   - //如果地址不为空
1243   - if (th.data.user_addr!=null){
1244   - switch (item[j]['exp_sum_type']) {
1245   - case 1:
1246   - //统一运费
1247   - o_shipping_price += item[j]['uniform_exp_sum'];break;
1248   - case 2:+''
1249   - if (goods_weight < 0) goods_weight = 0;
1250   - //累积商品重量 每种商品的重量 * 数量
1251   - goods_weight += item[j]['weight'] * item[j]['goods_num'];
1252   -
1253   - break;
1254   - case 3:
1255   - if (goods_piece < 0) goods_piece = 0;
1256   - //累积商品数量
1257   - goods_piece += item[j]['goods_num'];
1258   - break;
1259   - }
1260   - }
1261   -
1262   - }
1263   - }
1264   -
1265   - //计算物流价格
1266   - if (cart_item.exp_type == 0) {
1267   - //freight_free=0; //后面不在进行判断
1268   - var code = "";
1269   - if(th.data.wu_arr && th.data.wu_arr[cart_item.wind])
1270   - code=th.data.wu_arr[cart_item.wind].code;
1271   - cart_item.shipping_price =
1272   - th.calculatewuliu(code, o_shipping_price, goods_weight,
1273   - goods_piece,th.data.user_addr, freight_free, o_price-quan_price, rs);
1274   -
1275   - if(!th.data.using_quan[pickid] || th.data.using_quan[pickid].isby!=1){
1276   - if( cart_item.shipping_price ==0) th.data.is_by[pickid]=1; //已经全场包邮,就不要选择券了
1277   - }
1278   - }else{
1279   - cart_item.shipping_price=0;
1280   - }
1281   -
1282   - cart_item.shipping_price=cart_item.shipping_price.toFixed(2);
1283   -
1284   - //总价计算,总价不包含运费
1285   - cart_item.order_amount= (o_price -quan_price).toFixed(2);
1286   - cart_item.total_amount= f_o_price.toFixed(2);
1287   -
1288   - var order_prom_amount=0; var order_prom_id=0; var o_condition=cart_item.order_amount;
1289   - var order_m=0;
1290   - //---判断是不是有订单优惠---
1291   - await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion",{
1292   - data:{store_id:os.stoid,orderAmount:cart_item.order_amount}
1293   - }).then(res=>{
1294   - if(res.data.code==0){
1295   - var ord_prom=res.data.data;
1296   - order_prom_id = ord_prom['id'];
1297   - switch (ord_prom['type']) {
1298   - case 0:
1299   - order_m = Math.round(o_condition * ord_prom['expression'])/100;//满额打折
1300   - order_prom_amount=(o_condition -order_m).toFixed(2);
1301   - break;
1302   - case 1:
1303   - //order_m = o_condition - ord_prom['expression'];//满额优惠金额
1304   - order_prom_amount= ord_prom['expression'];
1305   - break;
1306   - }
1307   - }
1308   - })
1309   -
1310   - cart_item.order_prom_amount=0;
1311   - //--订单优惠的显示--
1312   - if(order_prom_id>0){
1313   - cart_item.order_amount= (o_price -quan_price-order_prom_amount).toFixed(2);
1314   - cart_item.order_prom_id=order_prom_id;
1315   - cart_item.order_prom_amount=order_prom_amount;
1316   - }
1317   - coupon_price=quan_price;
1318   - if( cart_item.order_amount<0){
1319   - cart_item.order_amount=0;
1320   - coupon_price=o_price;
1321   - }
1322   -
1323   - cart_item.total_amount= parseFloat(cart_item.total_amount)+parseFloat(cart_item.shipping_price); //总金额
1324   - cart_item.order_amount=parseFloat(cart_item.order_amount)+parseFloat(cart_item.shipping_price); //总金额
1325   - cart_item.total_amount= cart_item.total_amount.toFixed(2);
1326   - cart_item.order_amount=cart_item.order_amount.toFixed(2);
1327   -
1328   - //搭配购在使用余额
1329   - if(th.data.bn_use_money==1 && th.data.is_b_now==1){
1330   -
1331   - if (umoney > cart_item.order_amount) {
1332   - cart_item.user_money = cart_item.order_amount;
1333   - umoney = umoney - cart_item.order_amount;
1334   - }else {
1335   - cart_item.user_money = umoney;
1336   - umoney=0;
1337   - }
1338   -
1339   - }else{
1340   - //--------------如果使用余额,购物车购买---------------------
1341   - if (th.data.js_use_money == 1) {
1342   - if (umoney > cart_item.order_amount) {
1343   - cart_item.user_money = cart_item.order_amount;
1344   - umoney = umoney - cart_item.order_amount;
1345   - }else {
1346   - cart_item.user_money = umoney;
1347   - umoney=0;
1348   - }
1349   - }else{
1350   - cart_item.user_money=0;
1351   - }
1352   - }
1353   -
1354   -
1355   -
1356   - cart_item.user_money = parseFloat(cart_item.user_money).toFixed(2);
1357   -
1358   - if (coupon_price>0) cart_item.coupon_price=coupon_price.toFixed(2);
1359   - else cart_item.coupon_price = coupon_price
1360   - if(quan_no) cart_item.quan_no = quan_no;
1361   -
1362   -
1363   - //cart_item.goods_price = o_price.toFixed(2);
1364   - cart_item.order_amount= cart_item.order_amount- cart_item.user_money; //会员使用余额
1365   -
1366   -
1367   - all_price += parseFloat(f_o_price);
1368   - all_total_m += parseFloat(cart_item.total_amount);
1369   - all_shipping_m += parseFloat(cart_item.shipping_price);
1370   - all_order_m += parseFloat(cart_item.order_amount);
1371   - all_user_m += parseFloat(cart_item.user_money);
1372   - all_coupon_price_m+= parseFloat(cart_item.coupon_price);
1373   - all_cutprice+=parseFloat(cart_item.cut_price);
1374   - all_order_prom+=parseFloat(cart_item.order_prom_amount);
1375   - }
1376   -
1377   - all_shipping_m=parseFloat(all_shipping_m).toFixed(2);
1378   - all_total_m = parseFloat(all_total_m).toFixed(2);
1379   - all_order_m = parseFloat(all_order_m).toFixed(2);
1380   - all_price = parseFloat(all_price).toFixed(2);
1381   - all_user_m = parseFloat(all_user_m).toFixed(2);
1382   - all_total_m = parseFloat(all_total_m).toFixed(2);
1383   - all_coupon_price_m = parseFloat(all_coupon_price_m).toFixed(2);
1384   - all_cutprice=all_cutprice.toFixed(2);
1385   - all_order_prom=all_order_prom.toFixed(2);
1386   -
1387   - var atxt = "formData.total_amount";
1388   - var atxt1 = "formData.order_amount";
1389   - var atxt2 = "formData.all_price";
1390   - var atxt3 = "formData.user_money";
1391   - var atxt4 = "formData.shipping_price";
1392   - var atxt5 = "formData.coupon_price";
1393   - var atxt6 = "formData.cut_price";
1394   - var atxt7 = "formData.order_prom_amount";
1395   -
1396   - th.setData({ [atxt]: all_total_m, [atxt1]: all_order_m,
1397   - [atxt2]: all_price, [atxt3]: all_user_m, [atxt4]: all_shipping_m,
1398   - [atxt5]: all_coupon_price_m,[atxt6]: all_cutprice,
1399   - [atxt7]: all_order_prom, show_submit:1
1400   - })
1401   - th.data.order_prom_list_cart=c_arr;
1402   - th.set_can_num();
1403   - wx.hideLoading();
1404   -
1405   - });
1406   - });
1407   - },
1408   -
1409   - set_can_num:function(){
1410   - var th=this;
1411   - //-- 这个地方,循环计算几张优惠券可用--
1412   - for ( var iter in th.data.cartlist){
1413   - var num=0;
1414   - var c_item=th.data.cartlist[iter];
1415   - var pkid=c_item.pickup_id;
1416   - //-- 普通券 --
1417   - if(c_item.quan_list){
1418   - for (var iter1 in c_item.quan_list){
1419   - //判断是不是其他订单有选用
1420   - var is_other_is_use=th.check_other_use(c_item.quan_list[iter1],pkid);
1421   - if(!is_other_is_use) num++;
1422   - }
1423   - }
1424   - //-- 包邮券 --
1425   - var by_quan=th.data.get_by_quan_list_cart[pkid];
1426   - if(by_quan){
1427   - for (var iter2 in by_quan){
1428   - //判断是不是其他订单有选用
1429   - var is_other_is_use=th.check_other_use_by(by_quan[iter2],pkid);
1430   - if(!is_other_is_use) num++;
1431   - }
1432   - }
1433   - var set_txt="cartlist["+iter+"].can_num";
1434   - th.setData({ [set_txt]: num});
1435   - }
1436   - },
1437   -
1438   -
1439   - //---------计算立即购买----------
1440   - calculatePrice2: function () {
1441   - var th = this, good = this.data.bn_goods;
1442   -
1443   - if(!good) return false;
1444   -
1445   - //搭配的计算要用购物的车计算方法
1446   - if(good.prom_type==5){
1447   - th.calculatePrice();
1448   - return false;
1449   - }
1450   -
1451   - wx.showLoading({
1452   - title:"处理中."
1453   - })
1454   - //-----------计算商品总价--------------
1455   - var allpice = good.shop_price * good.buynum;
1456   - var cut_price=0;
1457   - var allpice1=allpice;
1458   -
1459   -
1460   - if(good.prom_type==3 && good.prom_price!==null){
1461   - cut_price=allpice-good.prom_price;
1462   - }
1463   -
1464   - allpice=parseFloat(allpice).toFixed(2);
1465   - var txt = "formData.all_price";
1466   - th.setData({ [txt]: allpice, });
1467   - if(cut_price){
1468   - var c_txt="formData.cut_price";
1469   - th.setData({ [c_txt]: cut_price, });
1470   -
1471   - }
1472   -
1473   - //如果有线下取价的时候
1474   - if(good.is_offline){
1475   - allpice = good.offline_price * good.buynum;
1476   - }
1477   -
1478   -
1479   - to.getConfig2(function (ee) {
1480   - to.getwuliuprice(async function (rs) {
1481   -
1482   - var o_shipping_price = 0, goods_weight = -1, goods_piece = -1;
1483   -
1484   - //---如果有选择优惠券的情况下---
1485   - var quan_price=0,bn_pick=th.data.bn_pick;
1486   - var quan_no=null;
1487   - if(th.data.using_quan[bn_pick]!=null && th.data.using_quan[bn_pick]!=undefined)
1488   - quan_no=th.data.using_quan[bn_pick].coupon_no;
1489   -
1490   - if(quan_no){
1491   - if(th.data.using_quan[bn_pick].isby!=1){
1492   - //---获取优惠券优惠---
1493   - await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice",{
1494   - data:{storeId:oo.stoid,CashRepNo:quan_no, WaresSum:th.data.ckeck_quan_price, WareIds:th.data.check_quan_ware_list}
1495   - }).then(res=>{
1496   - if(res.data.code==0 && res.data.data && res.data.data.length>0 ){
1497   - quan_price=res.data.data[0].WareCashSum;
1498   - }
1499   - })
1500   - }
1501   - }
1502   -
1503   - //-----------当地址不为空,且是物流时,计算物流费用,并同时商品不是优惠活动的包邮----------
1504   - if (th.data.user_addr != null && th.data.bn_exp_type == 0 && good.is_free_shipping == 0 && good.is_past!=1 ){
1505   - //看是不是有调用过包邮券
1506   - if(!th.data.isget_by_quan[th.data.bn_pick] && good.is_xz_yh!=1){
1507   - var condition=allpice-cut_price-quan_price;
1508   - //--判断要不要显示包邮券,链式调用接口,调取包邮券,已经是减了优惠的金额,见到优惠券的钱---
1509   - getApp().request.promiseGet("/api/weshop/userfeemail/pageAndArea",{
1510   - data:{store_id:os.stoid,isuse:0,condition:condition,user_id:getApp().globalData.user_id,pageSize:2000}
1511   - }).then(res=>{
1512   - if(res.data.code==0 && res.data.data.total>0){
1513   - //此时要循环判断包邮的地区,不包邮商品是不是符合
1514   - var arr=[],quanlist=res.data.data.pageData;
1515   - quanlist = th.check_is_frozenQuan(quanlist, th.data.frozenQuan,1);
1516   - for(var i in quanlist){
1517   - var item=quanlist[i];
1518   - if(item.region_list && th.check_by_area(item.region_list)) continue; //如果是不包邮区域
1519   - if(item.goods_list && th.check_by_goods(item.goods_list)) continue; //如果是不包邮商品
1520   - arr.push(item);
1521   - }
1522   - if(arr){
1523   - th.setData({get_by_quan_list:arr});
1524   - }
1525   - th.data.isget_by_quan[th.data.bn_pick]=1;
1526   - }
1527   - })
1528   - }
1529   -
1530   - switch (good['exp_sum_type']) {
1531   - case 1:
1532   - //统一运费
1533   - o_shipping_price += good['uniform_exp_sum']; break;
1534   - case 2:
1535   - if (goods_weight < 0) goods_weight = 0;
1536   - //累积商品重量 每种商品的重量 * 数量
1537   - goods_weight += good['weight'] * good['buynum'];break;
1538   - case 3:
1539   - if (goods_piece < 0) goods_piece = 0;
1540   - //累积商品数量
1541   - goods_piece += good['buynum']; break;
1542   - }
1543   -
1544   - var code ="";
1545   - if(th.data.wu_arr && th.data.wu_arr[th.data.index]) code=th.data.wu_arr[th.data.index].code;
1546   - var freight_free = ee.freight_free; //全场满多少包邮
1547   - var no_ex_id=ee.no_ex_id;
1548   - th.data.is_no_by[th.data.bn_pick]=0;
1549   -
1550   - var no_by_data=null;
1551   - var gift_freight_free=freight_free;
1552   -
1553   -
1554   - //有不包邮区域,且不免运费
1555   - if(no_ex_id && freight_free>0 && freight_free<= parseFloat(allpice)-cut_price-quan_price){
1556   - //-----------获取不包邮区域,不包邮商品-------
1557   - await getApp().request.promiseGet("/api/weshop/areaFeemail/getAreaGoods",{
1558   - data:{store_id:os.stoid,id:no_ex_id}
1559   - }).then(res=>{
1560   - if(res.data.code==0 && res.data.data && res.data.data.length>0){
1561   - no_by_data=res.data.data[0];
1562   - //如果有设置不包邮区域的时候
1563   - if(res.data.data[0].region_list){
1564   - if(th.check_by_area(res.data.data[0].region_list)){
1565   - freight_free=0;
1566   - th.data.is_no_by[th.data.bn_pick]=1;
1567   - }
1568   - }
1569   - //如果有设置不包邮商品
1570   - if(res.data.data[0].goods_list && freight_free){
1571   - if(th.check_by_goods(res.data.data[0].goods_list)){
1572   - freight_free=0;
1573   - th.data.is_no_by[th.data.bn_pick]=1;
1574   - }
1575   - }
1576   - }
1577   - })
1578   - }
1579   -
1580   - th.data.is_by[th.data.bn_pick]=0;
1581   - //--------------开始计算物流------------------
1582   - var shipping_price=
1583   - th.calculatewuliu(code, o_shipping_price, goods_weight,
1584   - goods_piece, th.data.user_addr, freight_free, parseFloat(allpice)-cut_price-quan_price, rs);
1585   -
1586   - //如果有赠品的时候,也要计算赠品的物流费用
1587   - if(th.data.buy_now_gift_goods){
1588   - shipping_price=th.get_now_gift_goods_wuliu(code, o_shipping_price, th.data.user_addr, gift_freight_free,
1589   - parseFloat(allpice)-cut_price-quan_price, rs,shipping_price,no_by_data,goods_weight,goods_piece);
1590   - }
1591   -
1592   - if(shipping_price<=0){
1593   - th.data.is_by[th.data.bn_pick]=1; //已经是包邮了,就不要选择包邮券
1594   - }
1595   -
1596   - shipping_price = parseFloat(shipping_price).toFixed(2);
1597   - var wl_txt = "formData.shipping_price";
1598   - th.setData({ [wl_txt]: shipping_price, })
1599   -
1600   - }else{
1601   - var wl_txt = "formData.shipping_price";
1602   - th.setData({ [wl_txt]: 0, })
1603   - }
1604   -
1605   - if(quan_no){
1606   - if(th.data.using_quan[bn_pick].isby==1){
1607   - shipping_price=0;
1608   - var wl_txt = "formData.shipping_price";
1609   - th.setData({ [wl_txt]: 0, })
1610   - }
1611   - }
1612   - //-----------------支付价,优惠券不减物流-----------------
1613   - var total_m = (parseFloat(allpice1)).toFixed(2);
1614   - var order_m = (parseFloat(allpice-cut_price)-quan_price).toFixed(2);
1615   - var coupon_price=quan_price; //优惠券优惠了多少钱
1616   - if(order_m<0) {
1617   - order_m=0;coupon_price=parseFloat(order_m).toFixed(2);
1618   - }
1619   - //--看一下有没有订单优惠--
1620   - var o_condition=parseFloat(order_m);
1621   - if(o_condition>0){
1622   - th.check_is_order_prom(o_condition,function () {
1623   - var order_prom_amount=0; var order_prom_id=0;
1624   - if(th.data.order_prom[th.data.bn_pick]){
1625   - var ord_prom=th.data.order_prom[th.data.bn_pick];
1626   - order_prom_id = ord_prom['id'];
1627   - switch (ord_prom['type']) {
1628   - case 0:
1629   - order_m = Math.round(o_condition * ord_prom['expression'])/100;//满额打折
1630   - order_prom_amount=(o_condition -order_m).toFixed(2);
1631   - break;
1632   - case 1:
1633   - order_m = o_condition - ord_prom['expression'];//满额优惠金额
1634   - order_prom_amount= ord_prom['expression'];
1635   - break;
1636   - }
1637   - }
1638   - //--订单优惠的显示--
1639   - if(order_prom_id>0){
1640   - var order_prom_txt1="formData.order_prom_id";
1641   - var order_prom_txt2="formData.order_prom_amount";
1642   - th.setData({ [order_prom_txt1]: order_prom_id,[order_prom_txt2]: order_prom_amount})
1643   - }
1644   -
1645   - total_m= parseFloat( total_m)+ parseFloat( th.data.formData.shipping_price);
1646   - order_m = parseFloat(order_m)+ parseFloat( th.data.formData.shipping_price);
1647   -
1648   - total_m=total_m.toFixed(2);
1649   - order_m=order_m.toFixed(2);
1650   -
1651   - var atxt= "formData.total_amount";
1652   - th.setData({ [atxt]: total_m, })
1653   -
1654   - var txt = "formData.user_money";
1655   - var txt2 = "formData.order_amount";
1656   - var txt3="formData.coupon_price";
1657   - var amoney = parseFloat(th.data.userinfo.user_money - th.data.txmon - th.data.userinfo.frozen_money);
1658   - //--------------如果使用余额---------------------
1659   - if (th.data.bn_use_money == 1) {
1660   - if (amoney> order_m) {
1661   - order_m = parseFloat(order_m).toFixed(2);
1662   - th.setData({ [txt]: order_m, [txt2]:0,[txt3]:coupon_price,show_submit:1 })
1663   - }else{
1664   - order_m =parseFloat(order_m) - parseFloat(amoney);
1665   - order_m = order_m.toFixed(2);
1666   - th.setData({ [txt]: amoney, [txt2]: order_m,[txt3]:coupon_price,show_submit:1 })
1667   - }
1668   - }else{
1669   - th.setData({ [txt]: 0, [txt2]: order_m,[txt3]:coupon_price,show_submit:1})
1670   - }
1671   - //优惠活动送积分
1672   - if(good.s_intValue){
1673   - txt = "formData.give_integral";
1674   - th.setData({ [txt]:good.s_intValue });
1675   - }
1676   - //优惠送券
1677   - if(good.s_coupon_id){
1678   - var i_txt = "formData.give_coupon_id";
1679   - //这个是json格式的
1680   - var i_txt1 = "formData.g_coupon_num";
1681   - var ob=[{"num":good.s_coupon_num,"c_id":good.s_coupon_id}];
1682   - ob=JSON.stringify(ob);
1683   - th.setData({ [i_txt]:good.s_coupon_id,[i_txt1]:ob });
1684   - }
1685   - //优惠礼包
1686   - if(good.s_libao){
1687   - var l_txt = "formData.give_lb_id";
1688   - //这个是json格式的
1689   - var l_txt1 = "formData.g_lb_num";
1690   - var ob=[{"num":good.s_lb_num,"l_id":good.s_libao}];
1691   - ob=JSON.stringify(ob);
1692   - th.setData({ [l_txt]:good.s_libao,[l_txt1]:ob });
1693   - }
1694   - })
1695   - }else{
1696   - total_m= parseFloat( total_m)+ parseFloat( th.data.formData.shipping_price);
1697   - order_m = parseFloat(order_m)+ parseFloat( th.data.formData.shipping_price);
1698   - var atxt= "formData.total_amount";
1699   -
1700   - total_m=total_m.toFixed(2);
1701   - order_m=order_m.toFixed(2);
1702   -
1703   - th.setData({ [atxt]: total_m, })
1704   -
1705   - var txt = "formData.user_money";
1706   - var txt2 = "formData.order_amount";
1707   - var txt3="formData.coupon_price";
1708   - var amoney = parseFloat(th.data.userinfo.user_money - th.data.txmon - th.data.userinfo.frozen_money);
1709   - //--------------如果使用余额---------------------
1710   - if (th.data.bn_use_money == 1) {
1711   - if (amoney> order_m) {
1712   - order_m = parseFloat(order_m).toFixed(2);
1713   - th.setData({ [txt]: order_m, [txt2]:0,[txt3]:coupon_price,show_submit:1 })
1714   - }else{
1715   - order_m =parseFloat(order_m) - parseFloat(amoney);
1716   - order_m = order_m.toFixed(2);
1717   - th.setData({ [txt]: amoney, [txt2]: order_m,[txt3]:coupon_price,show_submit:1 })
1718   - }
1719   - }else{
1720   - th.setData({ [txt]: 0, [txt2]: order_m,[txt3]:coupon_price, show_submit:1 })
1721   - }
1722   - //优惠活动送积分
1723   - if(good.s_intValue){
1724   - txt = "formData.give_integral";
1725   - th.setData({ [txt]:good.s_intValue });
1726   - }
1727   - //优惠送券
1728   - if(good.s_coupon_id){
1729   - var i_txt = "formData.give_coupon_id";
1730   - //这个是json格式的
1731   - var i_txt1 = "formData.g_coupon_num";
1732   - var ob=[{"num":good.s_coupon_num,"c_id":good.s_coupon_id}];
1733   - ob=JSON.stringify(ob);
1734   - th.setData({ [i_txt]:good.s_coupon_id,[i_txt1]:ob });
1735   - }
1736   - //优惠礼包
1737   - if(good.s_libao){
1738   - var l_txt = "formData.give_lb_id";
1739   - //这个是json格式的
1740   - var l_txt1 = "formData.g_lb_num";
1741   - var ob=[{"num":good.s_lb_num,"l_id":good.s_libao}];
1742   - ob=JSON.stringify(ob);
1743   - th.setData({ [l_txt]:good.s_coupon_id,[l_txt1]:ob });
1744   - }
1745   - }
1746   -
1747   - wx.hideLoading();
1748   -
1749   - });
1750   - });
1751   - },
1752   -
1753   - //--------------------提交订单-----------------------
1754   - async submitForm(t){
1755   - var sub_value=t;
1756   -
1757   - if(this.data.is_summit_ing==1) return false; //--提交中退出--
1758   - this.data.is_summit_ing=1;
1759   - var th=this,pdata=new Array();
1760   - var ff=true;
1761   - //------------立即购买-------------
1762   - if (th.data.is_b_now==1 && th.data.bn_goods.prom_type!=5){
1763   -
1764   - if(th.data.bn_exp_type == 0 && th.data.user_addr==null ){
1765   - ff = false; getApp().my_warnning("请选择收货地址",0,th);
1766   - th.data.is_summit_ing = 0;
1767   - }
1768   - if (!ff) return false;
1769   - var addr = th.data.user_addr;
1770   - if (th.data.bn_exp_type == 1) addr=null;
1771   -
1772   - if(th.data.bn_exp_type==0)
1773   - if(th.data.wu_arr==null || th.data.wu_arr.length<=0){
1774   - getApp().my_warnning("读取物流失败",0,th);
1775   - th.data.is_summit_ing = 0;
1776   - return false;
1777   - }
1778   -
1779   - var item={
1780   - 'user_id': to.globalData.user_id,
1781   - 'consignee': addr == null ? "" : addr.consignee,
1782   - 'province': addr == null ? 0 : addr.province,
1783   - 'city': addr == null ? 0 : addr.city,
1784   - 'district': addr == null ? 0 : addr.district,
1785   - 'twon': addr == null ? 0 : addr.twon,
1786   - 'address': addr == null ? "": addr.address,
1787   - 'more_address': addr == null ? "" : addr.more_address,
1788   - //'mobile': th.data.userinfo.mobile,
1789   - 'mobile': addr == null ? th.data.userinfo.mobile : addr.mobile,
1790   - 'email':'',
1791   - 'shipping_code': th.data.bn_exp_type == 1 ? 0 : th.data.wu_arr[th.data.index].code,
1792   - 'shipping_name': th.data.bn_exp_type == 1 ? '' : th.data.wu_arr[th.data.index].name,
1793   - 'invoice_title':'',
1794   - 'goods_price': th.data.formData.all_price, //商品总价
1795   - 'shipping_price': th.data.formData.shipping_price, //物流金额
1796   - 'user_money': th.data.formData.user_money, //使用余额
1797   - 'total_amount': th.data.formData.total_amount, //订单总价
1798   - 'order_amount': th.data.formData.order_amount, //应付
1799   - 'user_note': t.detail.value.user_note, //用户备注
1800   - 'store_id':oo.stoid, //商家
1801   - 'pickup_id': th.data.bn_pick, //门店
1802   - 'exp_type': th.data.bn_exp_type, //配送方式
1803   - 'order_goods':new Array(),
1804   - };
1805   - //是不是重新提交
1806   - if(th.data.is_continue==1) item.is_continue=1;
1807   -
1808   - //获取立即购买的商品的信息
1809   - var gg = to.get_b_now();
1810   - //--商品的房间号--
1811   - if(gg.room_id && gg.room_id>0){
1812   - item.room_ids=gg.room_id;
1813   - }
1814   -
1815   - var order_prom_list={};
1816   - //--判断有没有优惠活动--
1817   - if(th.data.order_prom[item.pickup_id]){
1818   - if(th.data.formData.order_prom_amount>0){
1819   - order_prom_list.order_prom_id=th.data.formData.order_prom_id;
1820   - order_prom_list.order_prom_amount=th.data.formData.order_prom_amount;
1821   - }
1822   - }
1823   -
1824   - //--判断优惠活动的提交--
1825   - if(th.data.formData.cut_price>0){
1826   - order_prom_list.discount_amount=th.data.formData.cut_price.toFixed(2);
1827   - var ob=[{"prom_id":th.data.bn_goods.prom_id,"dis":th.data.formData.cut_price.toFixed(2),"ispt":0}]
1828   - order_prom_list.prom_pt_json=JSON.stringify(ob);
1829   - }
1830   - if(th.data.formData.give_integral>0){
1831   - order_prom_list.give_integral=th.data.formData.give_integral;
1832   - }
1833   - if(th.data.formData.give_coupon_id>0){
1834   - order_prom_list.give_coupon_id=th.data.formData.give_coupon_id;
1835   - order_prom_list.g_coupon_num=th.data.formData.g_coupon_num;
1836   - }
1837   - if(th.data.formData.give_lb_id>0){
1838   - order_prom_list.give_lb_id=th.data.formData.give_lb_id;
1839   - order_prom_list.g_lb_num=th.data.formData.g_lb_num;
1840   - }
1841   - item.order_prom_list=order_prom_list;
1842   -
1843   - //组装优惠券的钱
1844   - if(parseFloat(th.data.formData.coupon_price)>0){
1845   - item.coupon_price=th.data.formData.coupon_price;
1846   - item.coupon_no=th.data.using_quan[th.data.bn_pick].coupon_no;
1847   - }
1848   - if(th.data.using_quan[th.data.bn_pick] && th.data.using_quan[th.data.bn_pick].coupon_no && th.data.using_quan[th.data.bn_pick].isby){
1849   - item.coupon_no=th.data.using_quan[th.data.bn_pick].coupon_no;
1850   - item.coupon_price=0;
1851   - }
1852   -
1853   - //老会员成为分销下线需要的参数
1854   - if(getApp().globalData.first_leader && !getApp().globalData.userInfo.first_leader){
1855   - //判断一下分享人是不是分享商
1856   - await app.request.promiseGet("/api/weshop/users/get/" + os.stoid+"/"+getApp().globalData.first_leader,{}).then(res=>{
1857   - if(res.data.code==0){
1858   - var user= res.data.data;
1859   - if(user.is_distribut==1){
1860   - item.first_leader=parseInt(getApp().globalData.first_leader);
1861   - }
1862   - }
1863   - })
1864   - }
1865   -
1866   - var goods={
1867   - 'goods_id': gg.goods_id,
1868   - 'goods_name': gg.goods_name,
1869   - 'goods_sn': gg.goods_sn,
1870   - 'goods_num': gg.goods_num,
1871   - 'market_price': th.data.bn_goods.market_price,
1872   - 'goods_price': th.data.bn_goods.shop_price,
1873   - 'member_goods_price': th.data.bn_goods.shop_price,
1874   - 'store_id': oo.stoid,
1875   - 'prom_type':th.data.bn_goods.prom_type, //促销活动类型
1876   - 'prom_id': th.data.bn_goods.prom_id, //促销活动id
1877   - };
1878   -
1879   - //-- 把导购的信息填入--
1880   - if(gg.guide_id){
1881   - goods.guide_id=gg.guide_id;
1882   - goods.guide_type=gg.guide_type;
1883   - //调用接口判断是不是会员
1884   - await getApp().request.promiseGet("/api/weshop/shoppingGuide/getId/"+oo.stoid+"/"+gg.guide_id,{}).then(res=>{
1885   - if(res.data.code==0){
1886   - goods.guide_name=res.data.data.salesman;
1887   - goods.guide_sn=res.data.data.salesman_no;
1888   - }
1889   - })
1890   - }
1891   -
1892   - //--商品的房间号--
1893   - if(gg.room_id && gg.room_id>0){
1894   - goods.room_id=gg.room_id;
1895   - }
1896   -
1897   - //积分购,先要带is_integral_normal=1
1898   - if(gg.is_integral_normal) goods.is_integral_normal=1;
1899   -
1900   - //先要带is_pd_normal=1
1901   - if(gg.is_pd_normal) goods.is_pd_normal=1;
1902   -
1903   - //如果不立即购买或者秒杀,如果是线下库存购买的时候
1904   - if(goods.prom_type!=1 && goods.prom_type!=6 && th.data.sales_rules==2){
1905   - var isok=1;
1906   - await th.check_store_num(goods.goods_id,th.data.bn_pick, gg.goods_num,function(res){
1907   - isok=res;
1908   - });
1909   - if(!isok){
1910   - getApp().confirmBox("商品的门店库存不足");
1911   - th.data.is_summit_ing=0;
1912   - return false;
1913   - }
1914   - }
1915   -
1916   - //-- 如果有线下取价的话 --
1917   - if(th.data.bn_goods.is_offline){
1918   - item.sum_offline_cut= (th.data.bn_goods.shop_price- th.data.bn_goods.offline_price).toFixed(2);
1919   - goods.offline_cut=item.sum_offline_cut;
1920   - goods.pricing_type=th.data.bn_goods.pricing_type;
1921   - goods.goods_price=th.data.bn_goods.offline_price;
1922   - goods.member_goods_price=th.data.bn_goods.offline_price;
1923   - }
1924   -
1925   - //--- 如果有优惠促销的金额,要把金额先平摊下去 ---
1926   - if(th.data.formData.cut_price>0 && !th.data.ispt_goods){
1927   - var g_arr=new Array();
1928   - g_arr.push(goods);
1929   - var pt_data={
1930   - 'prom_id':goods.prom_id,
1931   - 'dis': parseFloat(th.data.formData.cut_price),
1932   - 'goods':g_arr,
1933   - }
1934   -
1935   - var pt_res=null;
1936   - await getApp().request.promisePost("/api/weshop/order/getGoodsSplit",{is_json:1,data:pt_data}).then(res=>{
1937   - if(res.data.code==0){ pt_res=res.data.data; }
1938   - })
1939   - if(pt_res){
1940   - //平摊赋值
1941   - goods.account=pt_res[0].fisrt_account;
1942   - goods.account_yu=pt_res[0].fisrt_account_yu;
1943   - item.is_discount_amount=1;
1944   - }
1945   - }
1946   -
1947   - //--组装优惠券的钱--
1948   - if(th.data.formData.coupon_price){
1949   - item.coupon_price=th.data.formData.coupon_price;
1950   - item.coupon_no=th.data.using_quan[th.data.bn_pick].coupon_no;
1951   - goods.quan_num=th.data.formData.coupon_price;
1952   - goods.quan_no= item.coupon_no;
1953   - }
1954   -
1955   - item.order_goods.push(goods);
1956   -
1957   - //--如果有赠品的时候,赠品也要提交---
1958   - if(th.data.buy_now_gift_goods){
1959   - var gift_gg=th.data.buy_now_gift_goods;
1960   - var g_goods={
1961   - 'goods_id': gift_gg.goods_id,
1962   - 'goods_name': gift_gg.goods_name,
1963   - 'goods_sn': gift_gg.goods_sn,
1964   - 'goods_num': gift_gg.buynum,
1965   - 'market_price': gift_gg.market_price,
1966   - 'goods_price': 0,
1967   - 'member_goods_price': 0,
1968   - 'store_id': oo.stoid,
1969   - 'is_gift':1,
1970   - 'gift_id':gift_gg.gift_id,
1971   - 'prom_id':gift_gg.prom_id,
1972   - };
1973   - item.order_goods.push(g_goods);
1974   - }
1975   - pdata.push(item);
1976   -
1977   - console.log(pdata);
1978   - }else{
1979   - //---------购物车的结算---------
1980   - if (th.data.is_all_zt == 0 && th.data.user_addr == null) {
1981   - th.data.is_summit_ing = 0;
1982   - ff = false; getApp().confirmBox("请新建收货地址");}
1983   - if (!ff) return false;
1984   -
1985   - var addr = th.data.user_addr;
1986   - if (th.data.is_all_zt == 1) addr = null;
1987   - var val_arr= t.detail.value;
1988   -
1989   -
1990   - if(th.data.is_all_zt !=1)
1991   - if(th.data.wu_arr==null || th.data.wu_arr.length<=0 ){
1992   - th.data.is_summit_ing = 0;
1993   - getApp().confirmBox("读取物流失败");
1994   - return false;
1995   - }
1996   -
1997   - var order_prom_list_cart=th.data.order_prom_list_cart;
1998   -
1999   - //--组装推送数据--
2000   - for (var i = 0; i < order_prom_list_cart.length;i++){
2001   - var t_item = order_prom_list_cart[i];
2002   - var item = {
2003   - 'user_id': to.globalData.user_id,
2004   - 'consignee': addr == null ? th.data.userinfo.mobile : addr.consignee,
2005   - 'province': addr == null ? 0 : addr.province,
2006   - 'city': addr == null ? 0 : addr.city,
2007   - 'district': addr == null ? 0 : addr.district,
2008   - 'twon': addr == null ? 0 : addr.twon,
2009   - 'address': addr == null ? "" : addr.address,
2010   - 'more_address': addr == null ? "" : addr.more_address,
2011   - 'mobile': addr == null ? th.data.userinfo.mobile : addr.mobile,
2012   - 'email': '',
2013   - 'shipping_code': th.data.is_all_zt == 1 ? 0 : th.data.wu_arr[t_item.wind].code,
2014   - 'shipping_name': th.data.is_all_zt == 1 ? '' : th.data.wu_arr[t_item.wind].name,
2015   - 'invoice_title': '',
2016   - 'goods_price': t_item.goods_price, //商品总价
2017   - 'shipping_price': t_item.shipping_price, //物流金额
2018   - 'user_money': t_item.user_money, //使用余额
2019   - 'total_amount': t_item.total_amount, //订单总价
2020   - 'order_amount': t_item.order_amount, //应付
2021   - 'user_note': val_arr['user_note_' + t_item.pickup_id], //用户备注
2022   - 'store_id': oo.stoid, //商家
2023   - 'pickup_id': t_item.pickup_id, //门店
2024   - 'exp_type': t_item.exp_type, //配送方式
2025   - 'order_goods': new Array(),
2026   - };
2027   - //是不是重新提交
2028   - if(th.data.is_continue==1) item.is_continue=1;
2029   - //----- 如果有线下取价的话 ----
2030   - if(t_item.is_offline==1){
2031   - item.sum_offline_cut=t_item.offline_price.toFixed(2);
2032   - }
2033   -
2034   - //组装优惠券的钱
2035   - if(t_item.coupon_price) {
2036   - item.coupon_price = t_item.coupon_price;
2037   - item.coupon_no = th.data.using_quan[t_item.pickup_id].coupon_no;
2038   - }else if(t_item.quan_no) {
2039   - item.coupon_no = t_item.quan_no;
2040   - item.coupon_price = 0;
2041   - }
2042   -
2043   - var order_prom_list={};
2044   - //--判断有没有优惠活动--
2045   - if(t_item.order_prom_amount>0){
2046   - order_prom_list.order_prom_id=t_item.order_prom_id;
2047   - order_prom_list.order_prom_amount=t_item.order_prom_amount;
2048   - }
2049   - //--判断优惠活动的提交--
2050   - if(t_item.cut_price>0){
2051   - order_prom_list.discount_amount=t_item.cut_price.toFixed(2);
2052   - order_prom_list.prom_pt_json=JSON.stringify(t_item.prom_pt_json);
2053   - }
2054   - if(t_item.s_intValue>0){
2055   - order_prom_list.give_integral=t_item.s_intValue;
2056   - }
2057   - if(t_item.s_coupon_id){
2058   - order_prom_list.give_coupon_id=t_item.s_coupon_id;
2059   - order_prom_list.g_coupon_num= JSON.stringify(t_item.g_coupon_num);
2060   - }
2061   - if(t_item.s_libao){
2062   - order_prom_list.give_lb_id=t_item.s_libao;
2063   - order_prom_list.g_lb_num=JSON.stringify(t_item.g_lb_num);
2064   - }
2065   - if(Object.keys(order_prom_list).length>0)
2066   - item.order_prom_list=order_prom_list;
2067   -
2068   - //老会员成为分销下线需要的参数
2069   - if(getApp().globalData.first_leader && !getApp().globalData.userInfo.first_leader){
2070   - //判断一下分享人是不是分享商
2071   - await app.request.promiseGet("/api/weshop/users/get/" + os.stoid+"/"+getApp().globalData.first_leader,{}).then(res=>{
2072   - if(res.data.code==0){
2073   - var user= res.data.data;
2074   - if(user.is_distribut==1){
2075   - item.first_leader=parseInt(getApp().globalData.first_leader);
2076   - }
2077   - }
2078   - })
2079   - }
2080   -
2081   -
2082   - //房间号的ids
2083   - var room_ids="";
2084   - //-------------让商品添加到商品列表--------------------
2085   - for (var k = 0; k < t_item.goods.length;k++){
2086   - var g_item = t_item.goods[k];
2087   - var goods = {
2088   - 'goods_id': g_item.goods_id,
2089   - 'goods_name': g_item.goods_name,
2090   - 'goods_sn': g_item.goods_sn,
2091   - 'goods_num': g_item.goods_num,
2092   - 'market_price': g_item.market_price,
2093   - 'goods_price': g_item.goods_price,
2094   - 'member_goods_price': g_item.goods_price,
2095   - 'store_id': oo.stoid,
2096   - };
2097   -
2098   - //-- 线下取价也要写入 --
2099   - if(g_item.offline_price && t_item.is_offline==1){
2100   - goods.goods_price=g_item.offline_price;
2101   - goods.member_goods_price=g_item.offline_price;
2102   - goods.offline_cut=(g_item.goods_price-g_item.offline_price).toFixed(2);
2103   - goods.pricing_type=g_item.pricing_type;
2104   - }
2105   -
2106   - //--把券的钱,写入从表---
2107   - if(t_item.quan_youhui_list && t_item.coupon_price ){
2108   - for(var kk in t_item.quan_youhui_list ){
2109   - var you_item=t_item.quan_youhui_list[kk];
2110   - if(g_item.erpwareid==you_item.WareId){
2111   - goods.quan_num=you_item.WareCashSum;
2112   - goods.quan_no=you_item.CashRepNo;
2113   - }
2114   - }
2115   - }
2116   -
2117   - //--判断活动的类型--
2118   - switch (g_item.prom_type) {
2119   - case 1:
2120   - goods.prom_type = g_item.prom_type;
2121   - goods.prom_id = g_item.prom_id;
2122   - break;
2123   - case 3:
2124   - goods.prom_type=3;
2125   - goods.prom_id=g_item.prom_id;
2126   - if(g_item.is_gift){
2127   - goods.is_gift=g_item.is_gift;
2128   - goods.gift_id=g_item.gift_id;
2129   - }
2130   - break;
2131   - case 5:
2132   - goods.prom_type=5;
2133   - goods.prom_id=g_item.prom_id;
2134   - if(g_item.is_collocation){
2135   - goods.is_collocation=g_item.is_collocation;
2136   - }
2137   - break
2138   - default:
2139   - goods.prom_type = 0;goods.prom_id =0;
2140   - }
2141   -
2142   - //如果不立即购买或者秒杀,如果是线下库存购买的时候
2143   - if(goods.prom_type==0 && th.data.sales_rules==2){
2144   - var isok=1;
2145   - await th.check_store_num(goods.goods_id, t_item.pickup_id,goods.goods_num,function(res){
2146   - isok=res;
2147   - });
2148   - if(!isok){
2149   - getApp().confirmBox( goods.goods_name+"的门店库存不足");
2150   - th.data.is_summit_ing=0;
2151   - return false;
2152   - }
2153   - }
2154   -
2155   - //把优惠的平摊结果写进去
2156   - if(g_item.account>=0 || g_item.account_yu!=0){
2157   - if(g_item.account>=0) goods.account=g_item.account;
2158   - if(g_item.account_yu!=0) goods.account_yu=g_item.account_yu;
2159   - item.is_discount_amount=1;
2160   - }
2161   -
2162   - //导购ID
2163   - if(g_item.guide_id){
2164   - goods.guide_id=g_item.guide_id;
2165   - goods.guide_type=g_item.guide_type;
2166   - //调用接口判断是不是会员
2167   - await getApp().request.promiseGet("/api/weshop/shoppingGuide/getId/"+oo.stoid+"/"+g_item.guide_id,{}).then(res=>{
2168   - if(res.data.code==0){
2169   - goods.guide_name=res.data.data.salesman;
2170   - goods.guide_sn=res.data.data.salesman_no;
2171   - }
2172   - })
2173   - }
2174   - //如果房间号不为空的时候
2175   - if(g_item.room_id){
2176   - goods.room_id=g_item.room_id;
2177   - room_ids+=g_item.room_id+",";
2178   - }
2179   - item.order_goods.push(goods);
2180   - }
2181   -
2182   - //如果房间号不为空的时候
2183   - if(room_ids!="") item.room_ids= ut.sub_last(room_ids);
2184   - pdata.push(item);
2185   - }
2186   -
2187   -
2188   - }
2189   -
2190   - if (pdata.length==0) return;
2191   - var str = JSON.stringify(pdata);
2192   -
2193   - wx.showLoading({title: "加载中"});
2194   - wx.request({
2195   - url: oo.url + '/api/weshop/order/createWxdOrder',
2196   - data: str,
2197   - method: 'POST',
2198   - header: {
2199   - 'content-type': 'application/json'
2200   - },// 设置请求的 header
2201   - success: function (res) {
2202   -
2203   -
2204   - wx.hideLoading();
2205   - if (res.statusCode == 200) {
2206   - var data=res.data;
2207   - if(data.code==0){
2208   - console.log(th.data.is_b_now);
2209   - //如果是购物车结算,还要删除购物车
2210   - if (th.data.is_b_now == 0) {
2211   - console.log(th.data.cartlist_y);
2212   - var list = th.data.cartlist_y;
2213   - for (var i = 0; i < list.length; i++) {
2214   - //删除购物车
2215   - a.delete("/api/weshop/cart/del/" + oo.stoid + "/" + list[i].id, {});
2216   - }
2217   - }
2218   - var order_amount = 0;
2219   - pdata.forEach(function (em, ind) {
2220   - order_amount += em.order_amount;
2221   - })
2222   - //要进行判断,如果是用微信支付,就要跳转到支付界面
2223   - if (order_amount > 0) {
2224   - th.setData({ isclose: 0 });
2225   - //void e.jumpToCart4({
2226   - // order_sn: data.data,
2227   - //}, 1);
2228   - util_pay.pay(data.data, function() {
2229   - //app.my_warnning("支付成功",1,th);
2230   - //setTimeout(function () {
2231   - wx.redirectTo({
2232   - url: "/pages/payment/pay_success/pay_success?type=2&order_sn="+data.data
2233   - })
2234   - //},1000)
2235 2897  
2236   - }, function () {
2237   - //支付失败
2238   - setTimeout(function () {
2239   - wx.navigateBack({ delta: 1 })
2240   - },1000)
2241   - },oo.stoid);
  2898 + if (item_price < parseFloat(quan_item.BuySum)) {
  2899 + getApp().my_warnning("该单品金额没有大于等于" + quan_item.BuySum + "元时不能使用优惠券", 0, this, 600);
  2900 + return false;
  2901 + }
  2902 + }
  2903 + }
2242 2904  
2243   - } else {
2244   - var dd = {
2245   - parent_sn: data.data,
2246   - store_id: oo.stoid,
2247   - type: 2,
2248   - };
2249   - a.post("/api/weshop/order/pay/createOrder", {
2250   - data: dd,
2251   - success: function (t) {
2252   - //console.log(t);
2253   - if(t.data.code==0){
2254   - //app.my_warnning("支付成功",1,th);
2255   - //setTimeout(function () {
2256   - th.setData({ isclose: 0 });
2257   - wx.redirectTo({
2258   - url: "/pages/payment/pay_success/pay_success?type=2&order_sn="+data.data,
2259   - })
2260   - //}, 1000)
2261   - }
2262   - },
2263   - fail:function () {
2264   -
2265   - }
2266   - });
2267   - }
2268   -
2269   - }
2270   - else{
2271   - //--内容换行--
2272   - var msg=data.msg;
2273   - //赠品活动已经取消,无法赠送,是否继续买单?
2274   - if(msg.indexOf("是否继续买单")>0){
2275   - wx.showModal({
2276   - title:"提示",
2277   - content: data.msg,
2278   - cancelText:'取消',
2279   - confirmText:'确定',
2280   - showCancel: true,
2281   - success(res){
2282   - if(res.cancel){
2283   - return;
2284   - }else if(res.confirm){
2285   - th.data.is_continue=1;
2286   - th.data.is_summit_ing=0; //是否提交中
2287   - th.submitForm(sub_value);
2288   - }
2289   - }
2290   - })
2291   - return;
2292   - }
2293   - if(msg.length>13){
2294   - msg=msg.slice(0, 13) + "\r\n"+ msg.slice(13);
2295   - }
2296   - getApp().confirmBox(msg);
2297   - th.data.is_summit_ing=0; //是否提交中
2298   - }
2299   - }else{
2300   - th.data.is_summit_ing=0; //是否提交中
2301   - console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode);
2302   - }
2303   - },
2304   - fail: function () {
2305   - th.data.is_summit_ing=0;
2306   - wx.hideLoading();
2307   - console.log("index.js wx.request CheckCallUser fail");
2308   - },
2309   - complete: function () {}
2310   - })
2311   -
2312   - },
2313   - //---确认线下门店的数量足不足---
2314   - async check_store_num(goods_id,pick,goods_num,func){
2315   - var lock=0,pick_no,plist,erpwareid;
2316   - //先读取门店的lock
2317   - await getApp().request.promiseGet("/api/weshop/order/ware/lock/page",{
2318   - data:{store_id:os.stoid,wareId:goods_id,storageId:pick,pageSize:1000}
2319   - }).then(res=>{
2320   - if(res.data.code==0 && res.data.data.total>0){
2321   - for(var i in res.data.data.pageData)
2322   - lock+=res.data.data.pageData[i].outQty;
2323   - }
2324   - })
2325   - //先获取门店的编号
2326   - await getApp().request.promiseGet("/api/weshop/pickup/get/"+os.stoid+"/"+pick,{
2327   - data:{storeId:os.stoid,goodsId:t.goods_id,pickupId:pick}
2328   - }).then(res=>{
2329   - if(res.data.code==0){
2330   - pick_no=res.data.data.pickup_no;
2331   - }
2332   - })
2333   - //先获取商品的线下库存
2334   - await getApp().request.promiseGet("/api/weshop/goods/get/"+os.stoid+"/"+goods_id,{
2335   - data:{storeId:os.stoid,goodsId:t.goods_id,pickupId:pick}
2336   - }).then(res=>{
2337   - if(res.data.code==0){
2338   - erpwareid=res.data.data.erpwareid;
2339   - }
2340   - })
2341   - //读取线下的门店库存
2342   - await getApp().request.promiseGet("/api/weshop/goods/getWareStorages",{
2343   - data:{storageNos:pick_no,wareIds:encodeURIComponent(erpwareid),storeId:os.stoid,pageSize:2000}
2344   - }).then(res=>{
2345   - if(res.data.code==0){
2346   - plist=res.data.data.pageData[0];
2347   - }
2348   - })
2349   - var isok=1;
2350   - if(goods_num>plist.CanOutQty-lock){
2351   - isok=0;
2352   - }
2353   - func(isok);
2354   - },
2355   -
2356   - useCoupon: function() {
2357   - if (this.data.order.couponNum <= 0) {
2358   - getApp().my_warnning("无可用优惠券",0,this);
2359   - return;
2360   - }
2361   -
2362   - var a = {
2363   - lid: this.data.coupon ? this.data.coupon.id : "0"
2364   - };
2365   - wx.navigateTo({
2366   - url: "/pages/user/checkcoupon/checkcoupon?" + s.Obj2Str(a)
2367   - });
2368   - },
2369   - enterAddressPage: function() {
2370   - getApp().globalData.is_cart_old=1;
2371   - this.data.isget_by_quan={};
2372   - this.data.enterAddressPage = !0, wx.navigateTo({
2373   - url: "/pages/user/address_list/address_list"
2374   - });
2375   - },
2376   -
2377   - //--------购物车购买时,选择自提和物流-----------
2378   - setexptype_w:function(t){
2379   -
2380   - var def_exp_code= getApp().globalData.userInfo.def_exp_code,th=this;
2381   - var ty = t.currentTarget.dataset.t, txt = t.currentTarget.dataset.txt,
2382   - wl_txt = t.currentTarget.dataset.wl_txt,
2383   - ont = t.currentTarget.dataset.ont;
2384   -
2385   - th.setData({ [txt]: ty });
2386   - var iszt=1;
2387   -
2388   - if(ty==0){
2389   - th.setData({ is_all_zt: 0 });
2390   - }else{
2391   - for(var i=0;i<th.data.cartlist.length;i++){
2392   - var item = th.data.cartlist[i];
2393   - if (item.exp_type==0){ iszt=0;break;}
2394   - }
2395   -
2396   - th.setData({ is_all_zt: iszt });
2397   -
2398   - var ind=t.currentTarget.dataset.ind;
2399   - var c_item=th.data.cartlist[ind];
2400   - var pickid=c_item.pickup_id;
2401   -
2402   - if(th.data.using_quan[pickid] && th.data.using_quan[pickid].isby==1){
2403   - th.data.using_quan[pickid]={};
2404   - th.setData({using_quan:th.data.using_quan});
2405   - }
2406   -
2407   -
2408   - }
2409   - //判断有没有默认的物流地址值
2410   - if (def_exp_code != "" && def_exp_code != null && def_exp_code !=undefined) {
2411   - var wu_arr=this.data.wu_arr;
2412   - if (wu_arr!= null && wu_arr!=""){
2413   - for(var i=0;i<wu_arr.length;i++){
2414   - if (wu_arr[i].shipping_code == def_exp_code){
2415   - var set_txt="cartlist"
2416   - th.setData({wl_txt:i});
2417   - }
2418   - }
2419   - }
2420   - }
2421   - //----计算此时购物车的价格----
2422   - th.calculatePrice();
2423   - },
2424   -
2425   - //--------立即购买时,选择自提和物流----------
2426   - setexptype:function(t){
2427   - var th=this;
2428   - var ty = t.currentTarget.dataset.t,def_exp_code= getApp().globalData.userInfo.def_exp_code;
2429   - th.setData({ bn_exp_type:ty});
2430   - if(ty==0){
2431   - th.setData({ is_all_zt: 0 });
2432   - }
2433   -
2434   - //当物流为空的时候。
2435   - if (ty == 0 && th.data.wu_arr==null){
2436   - th.data.isget_by_quan={};
2437   - return th.get_wuliu(th.calculatePrice2());
2438   - }
2439   -
2440   - //--自提就要把包邮券清理掉--
2441   - if(ty==1){
2442   - th.data.isget_by_quan={};
2443   - if(th.data.using_quan[th.data.bn_pick] && th.data.using_quan[th.data.bn_pick].isby==1){
2444   - th.setData({using_quan:{}});
2445   - }
2446   - }
2447   -
2448   - //判断有没有默认的物流地址值
2449   - if (def_exp_code != "" && def_exp_code != null && def_exp_code !=undefined) {
2450   - var wu_arr=this.data.wu_arr;
2451   - if (wu_arr!= null && wu_arr!=""){
2452   - for(var i=0;i<wu_arr.length;i++){
2453   - if (wu_arr[i].shipping_code == def_exp_code){
2454   - th.setData({index:i});
2455   - }
2456   - }
2457   - }
2458   - }
2459   - th.calculatePrice2()
2460   -
2461   - },
2462   -
2463   - //--------立即购买时,使用余额--------
2464   - set_bn_useyuer:function(){
2465   - var th=this;
2466   - th.setData({ bn_use_money: !th.data.bn_use_money});
2467   - th.calculatePrice2();
2468   - },
2469   - set_js_useyuer:function(){
2470   - var th = this;
2471   - th.setData({ js_use_money: !th.data.js_use_money });
2472   - th.calculatePrice();
2473   - },
2474   - //-------------------计算物流---------------
2475   - calculatewuliu:function(code, o_shipping_price, goods_weight,
2476   - goods_piece,user_addr, freight_free, o_price, rs){
2477   - var price =0,th=this;
2478   - price +=parseFloat(o_shipping_price);
2479   - //如果是包邮
2480   - if (freight_free > 0 && o_price >= freight_free){ return 0;}
2481   - if (user_addr==null) { return 0; }
2482   - //计算物流的config item;
2483   - var item=null;
2484   - //先根据 镇 县 区找计算的config
2485   - item = th.get_wuliu_config(user_addr.district,code,rs);
2486   - if (item==null) item = th.get_wuliu_config(user_addr.city, code, rs);
2487   - if (item==null) item = th.get_wuliu_config(user_addr.province, code, rs);
2488   - if (item == null) item = th.get_wuliu_default(code,rs);
2489   - if (item == null) return o_shipping_price;
2490   - var fw_price = 0, fp_price=0;
2491   - item=item.config;
2492   - if (item == null) return o_shipping_price;
2493   - //------按重量----------
2494   - if (goods_weight>=0 && item['money']) {
2495   - fw_price =parseFloat(item['money']);
2496   - if (goods_weight > item['first_weight']){
2497   - var fw = goods_weight - item['first_weight'];
2498   - var n = Math.ceil(fw/item['second_weight'])
2499   - fw_price = fw_price + n * parseFloat(item['add_money']);
2500   - }
2501   - }
2502   - //------按件数----------
2503   - if (goods_piece > 0 && item['piecemoney']) {
2504   - fp_price = parseFloat(item['piecemoney']);
2505   - if (goods_piece > item['first_piece']) {
2506   - var fp = goods_piece - item['first_piece'];
2507   - var m = Math.ceil(fp / item['second_piece'])
2508   - fp_price = fp_price + m * parseFloat(item['add_piecemoney']);
2509   - }
2510   - }
2511   - var rspice =parseFloat(price + fw_price + fp_price);
2512   - return rspice;
2513   - },
2514   -
2515   - //------------循环获取config-----------
2516   - get_wuliu_config:function(region_id,code,rs){
2517   - var item=null,rslist = rs.pageData;
2518   - for (var i = 0; i < rslist.length;i++){
2519   - if (rslist[i].code == code && rslist[i].region_id == region_id) { item = rslist[i];}
2520   - }
2521   - return item;
2522   - },
2523   - //-------循环获取config,code default-------
2524   - get_wuliu_default: function (code, rs) {
2525   - var item = null, rslist=rs.pageData;
2526   - for (var i = 0; i < rslist.length; i++) {
2527   - if (rslist[i].shipping_code == code && rslist[i].is_default == 1) { item = rslist[i]; }
2528   - }
2529   - return item;
2530   - },
2531   -
2532   - //----------立即购买,选择物流-------------
2533   - bindPickerChange:function(e){
2534   - var ind = e.detail.value
2535   - this.setData({ index: ind });
2536   - this.calculatePrice2();
2537   - },
2538   - //----------购物车结算,选择物流-------------
2539   - bindPickerChange_w: function (e) {
2540   - var ind=e.detail.value, txt = e.currentTarget.dataset.txt;
2541   - this.setData({ [txt]: ind });
2542   - this.calculatePrice();
2543   - },
2544   -
2545   - /*----券的所有操作----*/
2546   - open_coupon_list:function (e) {
2547   - var th=this;
2548   - var pickid=e.currentTarget.dataset.pickid;
2549   - var bn=e.currentTarget.dataset.bn;
2550   - var cindx=e.currentTarget.dataset.cind;
2551   - var get_by_quan_list_cart=th.data.get_by_quan_list_cart[pickid];
2552   -
2553   -
2554   - if(bn==1){
2555   - th.setData({open_quan:1,selected_quan_pick:pickid, disabled:1});
2556   - }else{
2557   - //---多单打开券的时候,就要判断券在其他门店是否有使用---
2558   - var quanlist=th.data.cartlist[cindx].quan_list;
2559   - var exp_type=th.data.cartlist[cindx].exp_type;
2560   -
2561   -
2562   - //对于在其他门店已经选择了的券 要判断是否显示到界面
2563   - var t_user=th.data.using_quan[pickid];
2564   -
2565   - for(var i in quanlist){
2566   - quanlist[i].is_using= th.check_in_sele(quanlist[i].CashRepNo,pickid);
2567   - if(t_user && quanlist[i].CashRepNo==t_user.coupon_no)
2568   - quanlist[i].show_red=1;
2569   - else
2570   - quanlist[i].show_red=0;
2571   - }
2572   -
2573   - if(get_by_quan_list_cart){
2574   - for(var i in get_by_quan_list_cart){
2575   - get_by_quan_list_cart[i].is_using= th.check_in_sele(get_by_quan_list_cart[i].no,pickid);
2576   - if(t_user && get_by_quan_list_cart[i].no==t_user.coupon_no)
2577   - get_by_quan_list_cart[i].show_red=1;
2578   - else
2579   - get_by_quan_list_cart[i].show_red=0;
2580   - }
2581   - th.setData({by_quan_list_cart:get_by_quan_list_cart});
2582   - }else {
2583   - th.setData({by_quan_list_cart:null});
2584   - }
2585   -
2586   - console.log("2222222券的列表", quanlist);
2587   - th.setData({ sele_cart_ind:cindx,sele_exp_type:exp_type,open_quan:1,selected_quan_pick:pickid,selected_quan_list:quanlist,disabled:1});
2588   - }
2589   - },
2590   - close_coupon:function (e) {
2591   - var th=this;
2592   - th.setData({open_quan:0,disabled:0});
2593   - },
2594   -
2595   - //---判断券时候在已经选择的列表中---
2596   - check_in_sele:function (no,pick_id) {
2597   - var th=this;
2598   - if(th.data.using_quan.length<=0) return false;
2599   - for(var i in th.data.using_quan){
2600   - //--如果键值等于本身就要跳出--
2601   - if(parseInt(i)==parseInt(pick_id)) continue;
2602   - var item=th.data.using_quan[i];
2603   - if(item.coupon_no==no){
2604   - return true;
2605   - }
2606   - }
2607   - return false;
2608   - },
2609   -
2610   - /*--点击选择券--*/
2611   - sele_quan_item:function(e) {
2612   -
2613   - var ind = e.currentTarget.dataset.ind;
2614   - var quan_item=this.data.selected_quan_list[ind];
2615   - var pickid=this.data.selected_quan_pick; //现在选择的是哪一个门店
2616   - //--如果券是单品使用的时候--
2617   - if( quan_item && quan_item.UseObjectType && quan_item.UseObjectType=="20"){
2618   - //---只有多件购买的时候才要计算,//购物车购买和搭配勾的时候---
2619   - var gg=getApp().get_b_now();
2620   - if(this.data.is_b_now==0 || gg.prom_type==5){
2621   - var arr=this.data.order_prom_list_cart;
2622   - var t_pk_item=null;
2623   - for(var ii in arr){
2624   - var ep=arr[ii];
2625   - if(pickid==ep.pickup_id){
2626   - t_pk_item=ep; break;
2627   - }
2628   - }
2629   - //--寻找券指定的商品--
2630   - var gd=null;
2631   - if(t_pk_item){
2632   - var goods=t_pk_item.goods;
2633   - for(var gid in goods){
2634   - if(quan_item.UseObjectID==goods[gid].erpwareid){ gd=goods[gid]; }
2635   - }
2636   - }
2637   - if(!gd){
2638   - getApp().my_warnning("未找到指定商品使用",0,this,600);
2639   - return false;
2640   - }
2641   - //计算价格,如果有平摊的实收要计算实收的金额
2642   - var item_price=gd.goods_price*gd.goods_num;
2643   - //-- 如果有平摊下去,有实收价格的时候,就要用account_fir来计算价格 --
2644   - if(gd.account_fir!=null && gd.account_fir!=undefined){
2645   - item_price=gd.account_fir*gd.goods_num;
2646   - }
2647   -
2648   - if(item_price< parseFloat(quan_item.BuySum)){
2649   - getApp().my_warnning("该单品金额没有大于等于"+quan_item.BuySum+"元时不能使用优惠券",0,this,600);
2650   - return false;
2651   - }
2652   - }
2653   - }
2654   -
2655   - var no_use=e.currentTarget.dataset.no, quanlist=this.data.selected_quan_list;
2656   - //---所有的券的显示红色选择都清理一遍---
2657   - for(var i in quanlist){
2658   - quanlist[i].show_red=0;
2659   - }
2660   - this.setData({selected_quan_list:quanlist});
2661   - var by_quanlist=this.data.get_by_quan_list;
2662   - if(by_quanlist){
2663   - //---所有的券的显示红色选择都清理一遍---
2664   - for(var inb in by_quanlist){
2665   - by_quanlist[inb].show_red=0;
2666   - }
2667   - this.setData({get_by_quan_list:by_quanlist});
2668   - }
2669   -
2670   - var by_cart_list=this.data.by_quan_list_cart;
2671   - if(by_cart_list){
2672   - //---所有的券的显示红色选择都清理一遍---
2673   - for(var inc in by_cart_list){
2674   - by_cart_list[inc].show_red=0;
2675   - }
2676   - this.setData({by_quan_list_cart:by_cart_list});
2677   - }
2678   -
2679   - var using_quan=this.data.using_quan;
2680   - var th=this;
2681   - //---如果是不使用优惠券---
2682   - if(no_use==1){
2683   - console.log("有进来吗券", no_use);
2684   - if(using_quan[th.data.selected_quan_pick]){
2685   - using_quan[th.data.selected_quan_pick].is_nouse_red=1;
2686   - }
2687   - else{
2688   - using_quan[th.data.selected_quan_pick] ={is_nouse_red:1};
2689   - }
2690   - this.setData({ using_quan: using_quan, is_coupon:2222});
2691   - return;
2692   - }
2693   -
2694   -
2695   -
2696   - var txt = "selected_quan_list[" + ind + "].show_red";
2697   - var obj = {};
2698   - obj[txt] = 1;
2699   - if (quan_item.show_red) {
2700   - obj[txt] = 0;
2701   - }
2702   - this.setData(obj);
2703   - console.log(this.data.selected_quan_list, "选中的券的下标", quan_item, "数据都在这里", txt);
2704   - if(using_quan[th.data.selected_quan_pick]){
2705   - using_quan[th.data.selected_quan_pick].is_nouse_red=0;
2706   - }
2707   - else{
2708   - using_quan[th.data.selected_quan_pick] ={is_nouse_red:0};
2709   - }
2710   - this.setData({using_quan:using_quan});
2711   -
2712   - },
2713   -
2714   -
2715   - /*----- 点击选择包邮券 -----*/
2716   - sele_quan_item_by:function(e) {
2717   - var no_use=e.currentTarget.dataset.no;
2718   - //立即购买的包邮券
2719   - var by_quanlist=this.data.get_by_quan_list;
2720   - if(by_quanlist) {
2721   - //---所有的券的显示红色选择都清理一遍---
2722   - for (var ind in by_quanlist) {
2723   - by_quanlist[ind].show_red = 0;
2724   - }
2725   - this.setData({get_by_quan_list: by_quanlist});
2726   - }
2727   -
2728   - //--购物车过来的包邮券--
2729   - var by_cart_list=this.data.by_quan_list_cart;
2730   - if(by_cart_list){
2731   - //---所有的券的显示红色选择都清理一遍---
2732   - for(var ind in by_cart_list){
2733   - by_cart_list[ind].show_red=0;
2734   - }
2735   - this.setData({by_quan_list_cart:by_cart_list});
2736   - }
2737   - //普通券
2738   - var quanlist=this.data.selected_quan_list;
2739   - if(quanlist){
2740   - //---所有的券的显示红色选择都清理一遍---
2741   - for(var ind in quanlist){
2742   - quanlist[ind].show_red=0;
2743   - }
2744   - this.setData({selected_quan_list:quanlist});
2745   - }
2746   -
2747   - var th=this;
2748   - var using_quan=this.data.using_quan;
2749   - //---如果是不使用优惠券---
2750   - if(no_use==1){
2751   - if(using_quan[th.data.selected_quan_pick]){
2752   - using_quan[th.data.selected_quan_pick].is_nouse_red=1;
2753   - }
2754   - else{
2755   - using_quan[th.data.selected_quan_pick] ={is_nouse_red:1};
2756   - }
2757   - this.setData({ using_quan: using_quan, is_coupon:2222});
2758   - return;
2759   - }
2760   -
2761   - var pickid=th.data.selected_quan_pick; //现在选择的是哪一个门店
2762   - var ind = e.currentTarget.dataset.ind;
2763   - //--如果是立即购买的部分--
2764   - var txt="";var txt1=""; var quan_item=null;
2765   - if(th.data.is_b_now){
2766   - quan_item = this.data.get_by_quan_list[ind];
2767   - txt = "get_by_quan_list[" + ind + "].show_red";
2768   - var obj = {}; obj[txt] = 1;
2769   - this.setData(obj);
2770   - }else{
2771   - txt= "by_quan_list_cart[" + ind + "].show_red";
2772   - quan_item = th.data.by_quan_list_cart[ind];
2773   - var obj = {}; obj[txt] = 1;
  2905 + var no_use = e.currentTarget.dataset.no, quanlist = this.data.selected_quan_list;
  2906 + //---所有的券的显示红色选择都清理一遍---
  2907 + for (var i in quanlist) {
  2908 + quanlist[i].show_red = 0;
  2909 + }
  2910 + this.setData({selected_quan_list: quanlist});
  2911 + var by_quanlist = this.data.get_by_quan_list;
  2912 + if (by_quanlist) {
  2913 + //---所有的券的显示红色选择都清理一遍---
  2914 + for (var inb in by_quanlist) {
  2915 + by_quanlist[inb].show_red = 0;
  2916 + }
  2917 + this.setData({get_by_quan_list: by_quanlist});
  2918 + }
  2919 +
  2920 + var by_cart_list = this.data.by_quan_list_cart;
  2921 + if (by_cart_list) {
  2922 + //---所有的券的显示红色选择都清理一遍---
  2923 + for (var inc in by_cart_list) {
  2924 + by_cart_list[inc].show_red = 0;
  2925 + }
  2926 + this.setData({by_quan_list_cart: by_cart_list});
  2927 + }
  2928 +
  2929 + var using_quan = this.data.using_quan;
  2930 + var th = this;
  2931 + //---如果是不使用优惠券---
  2932 + if (no_use == 1) {
  2933 + console.log("有进来吗券", no_use);
  2934 + if (using_quan[th.data.selected_quan_pick]) {
  2935 + using_quan[th.data.selected_quan_pick].is_nouse_red = 1;
  2936 + }
  2937 + else {
  2938 + using_quan[th.data.selected_quan_pick] = {is_nouse_red: 1};
  2939 + }
  2940 + this.setData({using_quan: using_quan, is_coupon: 2222});
  2941 + return;
  2942 + }
  2943 +
  2944 +
  2945 + var txt = "selected_quan_list[" + ind + "].show_red";
  2946 + var obj = {};
  2947 + obj[txt] = 1;
  2948 + if (quan_item.show_red) {
  2949 + obj[txt] = 0;
  2950 + }
2774 2951 this.setData(obj);
2775   - th.data.get_by_quan_list_cart[pickid]=JSON.parse(JSON.stringify(th.data.by_quan_list_cart)); //要把选中的弄回数组
2776   - }
2777   -
2778   - if(using_quan[th.data.selected_quan_pick]){
2779   - using_quan[th.data.selected_quan_pick].is_nouse_red=0;
2780   - }
2781   - else{
2782   - using_quan[th.data.selected_quan_pick] ={is_nouse_red:0};
2783   - }
2784   - this.setData({using_quan:using_quan});
2785   - },
2786   -
2787   - //--确认使用券---
2788   - confirm_quan:function () {
2789   - var using_quan=this.data.using_quan; //正在使用中的券列表
2790   - var pickid=this.data.selected_quan_pick; //选中的门店ID
2791   - var th=this;
2792   - var selected_quan_list=this.data.selected_quan_list; //选择了那个门店的券列表
2793   - var get_by_quan_list=this.data.get_by_quan_list; //立即购买的包邮券列表
2794   - var by_quan_list_cart=this.data.by_quan_list_cart; //购物车购买的包邮券列表
2795   - //选择了的券
2796   - var sele_quan=null;
2797   -
2798   - //循环普通的券
2799   - for(var i in selected_quan_list){
2800   - var item=selected_quan_list[i];
2801   - if(item.show_red) {
2802   - th.insert_into_using_quan(item,using_quan,pickid);
2803   - return;
2804   - }
2805   - }
2806   - //循环包邮的券,立即购买的
2807   - for(var i in get_by_quan_list){
2808   - var item=get_by_quan_list[i];
2809   - if(item.show_red) {
2810   - if(th.data.is_no_by[pickid]==1){
2811   - getApp().my_warnning("已全场不能包邮,不能选择包邮券",0,th);return false;
2812   - }
2813   - if(th.data.is_by[pickid]==1){
2814   - getApp().my_warnning("已全场包邮,不能选择包邮券",0,th);return false;
2815   - }
2816   -
2817   - th.insert_into_using_quan(item,using_quan,pickid,1);
2818   - return;
2819   - }
2820   - }
2821   -
2822   - //循环包邮的券
2823   - for(var i in by_quan_list_cart){
2824   - var item=by_quan_list_cart[i];
2825   - if(item.show_red) {
2826   - if(th.data.is_no_by[pickid]==1){
2827   - getApp().my_warnning("已全场不能包邮,不能选择包邮券",0,th);return false;
2828   - }
2829   - if(th.data.is_by[pickid]==1){
2830   - getApp().my_warnning("已全场包邮,不能选择包邮券",0,th);return false;
2831   - }
2832   - th.insert_into_using_quan(item,using_quan,pickid,1);
2833   - return;
2834   - }
2835   - }
2836   -
2837   - //选择了的券,看是不是点击了不使用券,点击了不使用优惠券
2838   - if(using_quan[pickid]){
2839   - if(using_quan[pickid].is_nouse_red==1){
2840   - using_quan[pickid] ={is_nouse_red:1};
2841   - th.setData({using_quan:using_quan});
2842   - if(th.data.is_b_now==1){
  2952 + console.log(this.data.selected_quan_list, "选中的券的下标", quan_item, "数据都在这里", txt);
  2953 + if (using_quan[th.data.selected_quan_pick]) {
  2954 + using_quan[th.data.selected_quan_pick].is_nouse_red = 0;
  2955 + }
  2956 + else {
  2957 + using_quan[th.data.selected_quan_pick] = {is_nouse_red: 0};
  2958 + }
  2959 + this.setData({using_quan: using_quan});
  2960 +
  2961 + },
  2962 +
  2963 +
  2964 + /*----- 点击选择包邮券 -----*/
  2965 + sele_quan_item_by: function (e) {
  2966 + var no_use = e.currentTarget.dataset.no;
  2967 + //立即购买的包邮券
  2968 + var by_quanlist = this.data.get_by_quan_list;
  2969 + if (by_quanlist) {
  2970 + //---所有的券的显示红色选择都清理一遍---
  2971 + for (var ind in by_quanlist) {
  2972 + by_quanlist[ind].show_red = 0;
  2973 + }
  2974 + this.setData({get_by_quan_list: by_quanlist});
  2975 + }
  2976 +
  2977 + //--购物车过来的包邮券--
  2978 + var by_cart_list = this.data.by_quan_list_cart;
  2979 + if (by_cart_list) {
  2980 + //---所有的券的显示红色选择都清理一遍---
  2981 + for (var ind in by_cart_list) {
  2982 + by_cart_list[ind].show_red = 0;
  2983 + }
  2984 + this.setData({by_quan_list_cart: by_cart_list});
  2985 + }
  2986 + //普通券
  2987 + var quanlist = this.data.selected_quan_list;
  2988 + if (quanlist) {
  2989 + //---所有的券的显示红色选择都清理一遍---
  2990 + for (var ind in quanlist) {
  2991 + quanlist[ind].show_red = 0;
  2992 + }
  2993 + this.setData({selected_quan_list: quanlist});
  2994 + }
  2995 +
  2996 + var th = this;
  2997 + var using_quan = this.data.using_quan;
  2998 + //---如果是不使用优惠券---
  2999 + if (no_use == 1) {
  3000 + if (using_quan[th.data.selected_quan_pick]) {
  3001 + using_quan[th.data.selected_quan_pick].is_nouse_red = 1;
  3002 + }
  3003 + else {
  3004 + using_quan[th.data.selected_quan_pick] = {is_nouse_red: 1};
  3005 + }
  3006 + this.setData({using_quan: using_quan, is_coupon: 2222});
  3007 + return;
  3008 + }
  3009 +
  3010 + var pickid = th.data.selected_quan_pick; //现在选择的是哪一个门店
  3011 + var ind = e.currentTarget.dataset.ind;
  3012 + //--如果是立即购买的部分--
  3013 + var txt = "";
  3014 + var txt1 = "";
  3015 + var quan_item = null;
  3016 + if (th.data.is_b_now) {
  3017 + quan_item = this.data.get_by_quan_list[ind];
  3018 + txt = "get_by_quan_list[" + ind + "].show_red";
  3019 + var obj = {};
  3020 + obj[txt] = 1;
  3021 + this.setData(obj);
  3022 + } else {
  3023 + txt = "by_quan_list_cart[" + ind + "].show_red";
  3024 + quan_item = th.data.by_quan_list_cart[ind];
  3025 + var obj = {};
  3026 + obj[txt] = 1;
  3027 + this.setData(obj);
  3028 + th.data.get_by_quan_list_cart[pickid] = JSON.parse(JSON.stringify(th.data.by_quan_list_cart)); //要把选中的弄回数组
  3029 + }
  3030 +
  3031 + if (using_quan[th.data.selected_quan_pick]) {
  3032 + using_quan[th.data.selected_quan_pick].is_nouse_red = 0;
  3033 + }
  3034 + else {
  3035 + using_quan[th.data.selected_quan_pick] = {is_nouse_red: 0};
  3036 + }
  3037 + this.setData({using_quan: using_quan});
  3038 + },
  3039 +
  3040 + //--确认使用券---
  3041 + confirm_quan: function () {
  3042 + var using_quan = this.data.using_quan; //正在使用中的券列表
  3043 + var pickid = this.data.selected_quan_pick; //选中的门店ID
  3044 + var th = this;
  3045 + var selected_quan_list = this.data.selected_quan_list; //选择了那个门店的券列表
  3046 + var get_by_quan_list = this.data.get_by_quan_list; //立即购买的包邮券列表
  3047 + var by_quan_list_cart = this.data.by_quan_list_cart; //购物车购买的包邮券列表
  3048 + //选择了的券
  3049 + var sele_quan = null;
  3050 +
  3051 + //循环普通的券
  3052 + for (var i in selected_quan_list) {
  3053 + var item = selected_quan_list[i];
  3054 + if (item.show_red) {
  3055 + th.insert_into_using_quan(item, using_quan, pickid);
  3056 + return;
  3057 + }
  3058 + }
  3059 + //循环包邮的券,立即购买的
  3060 + for (var i in get_by_quan_list) {
  3061 + var item = get_by_quan_list[i];
  3062 + if (item.show_red) {
  3063 + if (th.data.is_no_by[pickid] == 1) {
  3064 + getApp().my_warnning("已全场不能包邮,不能选择包邮券", 0, th);
  3065 + return false;
  3066 + }
  3067 + if (th.data.is_by[pickid] == 1) {
  3068 + getApp().my_warnning("已全场包邮,不能选择包邮券", 0, th);
  3069 + return false;
  3070 + }
  3071 +
  3072 + th.insert_into_using_quan(item, using_quan, pickid, 1);
  3073 + return;
  3074 + }
  3075 + }
  3076 +
  3077 + //循环包邮的券
  3078 + for (var i in by_quan_list_cart) {
  3079 + var item = by_quan_list_cart[i];
  3080 + if (item.show_red) {
  3081 + if (th.data.is_no_by[pickid] == 1) {
  3082 + getApp().my_warnning("已全场不能包邮,不能选择包邮券", 0, th);
  3083 + return false;
  3084 + }
  3085 + if (th.data.is_by[pickid] == 1) {
  3086 + getApp().my_warnning("已全场包邮,不能选择包邮券", 0, th);
  3087 + return false;
  3088 + }
  3089 + th.insert_into_using_quan(item, using_quan, pickid, 1);
  3090 + return;
  3091 + }
  3092 + }
  3093 +
  3094 + //选择了的券,看是不是点击了不使用券,点击了不使用优惠券
  3095 + if (using_quan[pickid]) {
  3096 + if (using_quan[pickid].is_nouse_red == 1) {
  3097 + using_quan[pickid] = {is_nouse_red: 1};
  3098 + th.setData({using_quan: using_quan});
  3099 + if (th.data.is_b_now == 1) {
2843 3100 th.calculatePrice2();
2844   - }else{
2845   - th.calculatePrice();
  3101 + } else {
  3102 + th.calculatePrice();
2846 3103 }
2847   - th.setData({open_quan:0});
  3104 + th.setData({open_quan: 0});
2848 3105 return;
2849   - }
2850   - }
2851   - },
2852   -
2853   - //----把券插入之后的操作,同时还要重新计算价格----
2854   - insert_into_using_quan:function (item,using_quan,pickid,isby) {
2855   - var th=this;
2856   - if(isby==1){
2857   - using_quan[pickid]={coupon_no:item.no,money:0,is_nouse_red:0,region_list:item.region_list,goods_list:item.goods_list};
2858   - using_quan[pickid].isby=1;
2859   - }else{
2860   - using_quan[pickid]={coupon_no:item.CashRepNo,money:item.Sum,is_nouse_red:0};
2861   - using_quan[pickid].isby=0;
2862   - }
2863   - this.setData({using_quan:using_quan});
2864   - if(th.data.is_b_now==1){
2865   - th.calculatePrice2();
2866   - }else{
2867   - th.calculatePrice();
2868   - }
2869   - th.setData({open_quan:0});
2870   - },
2871   -
2872   - cart_set_err:function(e){
2873   - var txt = e.currentTarget.dataset.err;
2874   - var ob={};
2875   - ob[txt] = this.data.imgUrl + "/miniapp/images/default_g_img.gif";
2876   - this.setData(ob);
2877   - },
2878   - //--验证是否已经冻结--
2879   - check_is_frozenQuan:function(quanlist,frozenQuan,isby){
2880   - console.log("券列表",quanlist);
2881   - if(!quanlist) return null;
2882   - if(!frozenQuan) return quanlist;
2883   - var arr=[];
2884   - for(var i=0;i<quanlist.length;i++){
2885   - var item=quanlist[i];
2886   - var is_find=0;
2887   - var Q_no=quanlist[i].CashRepNo;
2888   - if(isby) Q_no=quanlist[i].no;
2889   - for(var j=0;j<frozenQuan.length;j++){
2890   - var q_no=frozenQuan[j].cashRepNo;
2891   - if(Q_no==q_no){
2892   - is_find=1; break;
2893   - }
2894 3106 }
2895   - if(!is_find) arr.push(item);
  3107 + }
  3108 + },
  3109 +
  3110 + //----把券插入之后的操作,同时还要重新计算价格----
  3111 + insert_into_using_quan: function (item, using_quan, pickid, isby) {
  3112 + var th = this;
  3113 + if (isby == 1) {
  3114 + using_quan[pickid] = {
  3115 + coupon_no: item.no,
  3116 + money: 0,
  3117 + is_nouse_red: 0,
  3118 + region_list: item.region_list,
  3119 + goods_list: item.goods_list
  3120 + };
  3121 + using_quan[pickid].isby = 1;
  3122 + } else {
  3123 + using_quan[pickid] = {coupon_no: item.CashRepNo, money: item.Sum, is_nouse_red: 0};
  3124 + using_quan[pickid].isby = 0;
  3125 + }
  3126 + this.setData({using_quan: using_quan});
  3127 + if (th.data.is_b_now == 1) {
  3128 + th.calculatePrice2();
  3129 + } else {
  3130 + th.calculatePrice();
  3131 + }
  3132 + th.setData({open_quan: 0});
  3133 + },
  3134 +
  3135 + cart_set_err: function (e) {
  3136 + var txt = e.currentTarget.dataset.err;
  3137 + var ob = {};
  3138 + ob[txt] = this.data.imgUrl + "/miniapp/images/default_g_img.gif";
  3139 + this.setData(ob);
  3140 + },
  3141 + //--验证是否已经冻结--
  3142 + check_is_frozenQuan: function (quanlist, frozenQuan, isby) {
  3143 + console.log("券列表", quanlist);
  3144 + if (!quanlist) return null;
  3145 + if (!frozenQuan) return quanlist;
  3146 + var arr = [];
  3147 + for (var i = 0; i < quanlist.length; i++) {
  3148 + var item = quanlist[i];
  3149 + var is_find = 0;
  3150 + var Q_no = quanlist[i].CashRepNo;
  3151 + if (isby) Q_no = quanlist[i].no;
  3152 + for (var j = 0; j < frozenQuan.length; j++) {
  3153 + var q_no = frozenQuan[j].cashRepNo;
  3154 + if (Q_no == q_no) {
  3155 + is_find = 1;
  3156 + break;
  3157 + }
  3158 + }
  3159 + if (!is_find) arr.push(item);
2896 3160 }
2897 3161 return arr;
2898   - },
2899   -
2900   - //// 开启物流的弹窗
2901   - show_wu_arr:function(e){
2902   - var wu_arr_txt=e.currentTarget.dataset.txt;
2903   - var w_sele_index=e.currentTarget.dataset.w_sele_index;
2904   - var is_express=null;
2905   - var ob={open_express: 1,wu_arr_txt:wu_arr_txt,disabled:1};
2906   -
2907   - //--如果是多个门店的时候--
2908   - if(w_sele_index!=undefined){
2909   - is_express=this.data.cartlist[w_sele_index].wind;
2910   - ob['is_express']=is_express;
2911   - }
2912   - this.setData(ob);
2913   - },
  3162 + },
  3163 +
  3164 + //// 开启物流的弹窗
  3165 + show_wu_arr: function (e) {
  3166 + var wu_arr_txt = e.currentTarget.dataset.txt;
  3167 + var w_sele_index = e.currentTarget.dataset.w_sele_index;
  3168 + var is_express = null;
  3169 + var ob = {open_express: 1, wu_arr_txt: wu_arr_txt, disabled: 1};
  3170 +
  3171 + //--如果是多个门店的时候--
  3172 + if (w_sele_index != undefined) {
  3173 + is_express = this.data.cartlist[w_sele_index].wind;
  3174 + ob['is_express'] = is_express;
  3175 + }
  3176 + this.setData(ob);
  3177 + },
2914 3178 // 关闭物流的弹窗
2915   - close_express:function(){
2916   - this.setData({ open_express:0,disabled:0 });
2917   - },
  3179 + close_express: function () {
  3180 + this.setData({open_express: 0, disabled: 0});
  3181 + },
2918 3182 // 选择物流
2919   - click_express_name:function(e){
2920   - var express_name = e.currentTarget.dataset.name, shippingcode = e.currentTarget.dataset.shippingcode;
2921   - var index=e.currentTarget.dataset.idxe;
2922   - var ob={ is_express: index, is_shipping_code: shippingcode,disabled:0};
2923   - ob[this.data.wu_arr_txt]=index;
2924   - this.setData(ob);
  3183 + click_express_name: function (e) {
  3184 + var express_name = e.currentTarget.dataset.name, shippingcode = e.currentTarget.dataset.shippingcode;
  3185 + var index = e.currentTarget.dataset.idxe;
  3186 + var ob = {is_express: index, is_shipping_code: shippingcode, disabled: 0};
  3187 + ob[this.data.wu_arr_txt] = index;
  3188 + this.setData(ob);
2925 3189 },
2926 3190  
2927 3191 //点击确定物流
2928   - determine_expres:function(e){
2929   - this.setData({ open_express: 0});
2930   - if(this.data.is_b_now==1)
2931   - this.calculatePrice2();
2932   - else
2933   - this.calculatePrice();
2934   - },
2935   -
2936   - //点击打开优惠券使用说明
2937   - clik_coupons:function(e){
2938   - var ind = e.currentTarget.dataset.idx;
2939   - var is_open = this.data.selected_quan_list[ind].is_open;
2940   -
2941   - if (is_open == 1) is_open = 0;
2942   - else is_open = 1;
2943   -
2944   - var txt = "selected_quan_list[" + ind + "].is_open"
2945   - var obj = {}; obj[txt] = is_open;
2946   -
2947   - this.setData(obj);
2948   - this.setData({disabled:1})
2949   - },
2950   -
2951   - clik_coupons2:function(e){
2952   - var ind = e.currentTarget.dataset.idx;
2953   - var is_open = this.data.get_by_quan_list[ind].is_open;
2954   -
2955   - if (is_open == 1) is_open = 0;
2956   - else is_open = 1;
2957   -
2958   - var txt = "get_by_quan_list[" + ind + "].is_open"
2959   - var obj = {}; obj[txt] = is_open;
2960   -
2961   - this.setData(obj);
2962   - this.setData({disabled:1})
2963   - },
2964   -
2965   -
2966   - //设置默认物流
2967   - select_default_logistics: function () {
2968   - var th=this;
2969   - var is_shipping_code=this.data.is_shipping_code
2970   - getApp().request.put("/api/weshop/users/update",{
2971   - data: { user_id: getApp().globalData.user_id, store_id: oo.stoid, def_exp_code: is_shipping_code},
2972   - success:function(rse){
2973   - if (rse.data.code==0){
2974   - getApp().globalData.userInfo.def_exp_code=is_shipping_code;
2975   - th.setData({ open_express: 0 });
2976   - //----计算此时购物车的价格----
2977   - if(th.data.is_b_now==1) th.calculatePrice2();
2978   - else th.calculatePrice();
2979   - }
2980   - }
2981   - })
2982   - },
2983   -
2984   - //更新下默认,在onshow里面
2985   - update_code(){
2986   - var th=this,m_wind=0,def_exp_code=getApp().globalData.userInfo.def_exp_code;
2987   - //--定时器,判断wu_arr不未空--
2988   - var uii=setInterval(function () {
2989   - if(th.data.wu_arr)
2990   - {
2991   - clearInterval(uii);
2992   - for (var k = 0; k < th.data.wu_arr.length; k++) {
2993   - var item = th.data.wu_arr[k];
2994   - if (def_exp_code == item.code) { m_wind = k; }
2995   - }
2996   - //--如果是立即购买--
2997   - if (th.data.is_b_now == 1) {
2998   - th.setData({index: m_wind,is_express:m_wind});
2999   - } else {
3000   - var ui = setInterval(function () {
3001   - if (th.data.cartlist) {
3002   - var c_arr = th.data.cartlist;
3003   - for (var i in c_arr) {
3004   - c_arr[i].wind = m_wind;
3005   - }
3006   - th.setData({cartlist: c_arr,is_express:m_wind})
3007   - clearInterval(ui);
3008   - }
3009   - }, 500)
3010   - }
3011   - }
3012   - },500);
3013   - },
3014   - //-----获取购物车进来的劵-------
3015   - get_cart_quan:async function (order_prom_list_cart) {
3016   - var th=this;
3017   - var is_xz_yh=1;
3018   - //等待值的出现
3019   - //getApp().waitfor2(this,"g_cart_q_time","order_prom_list_cart",async function () {
3020   - //var arr=th.data.order_prom_list_cart;
3021   - var arr=order_prom_list_cart;
3022   - if(!arr) arr=[];
3023   - //如果系统有限制使用优惠券
3024   - if(th.data.is_close_quan) return false;
3025   -
3026   - //------------开始计算使用优惠券相关------------
3027   - for(var ind in arr){
3028   - var ep=arr[ind];
3029   - var goodlist=ep.goods;
3030   - var pickup_id=ep.pickup_id;
3031   - //--更优惠券抵用有关,立即购买的,如果是购物车,如果有等级价还有考虑等级价的东西
3032   - //就要把相应的值,写入cartlist数组中--
3033   - var ckeck_quan_price=0,
3034   - check_quan_price_list='',
3035   - check_quan_ware_list='';
3036   -
3037   - for(var i in goodlist){
3038   - var gd=goodlist[i];
3039   - //--如果是秒杀就跳出,如果是赠品,如果是限制使用优惠券--
3040   - if(gd.prom_type==1 || gd.is_gift ){ continue; }
3041   - //如果有限制使用优惠券,就要返回
3042   - if(gd.prom_type==3){
3043   - if(th.data.prom_goods_map[pickup_id][gd.prom_id].is_xz_yh) continue;
3044   - th.data.prom_goods_map[pickup_id][gd.prom_id].coupon_sele=1;
3045   - }
3046   - is_xz_yh=0;
3047   - var item_price=gd.goods_price*gd.goods_num;
3048   - //-- 如果有平摊下去,有实收价格的时候,就要用account来计算价格 --
3049   - if(gd.account_fir!=null && gd.account_fir!=undefined){
3050   - item_price=gd.account_fir*gd.goods_num;
3051   - }
3052   - ckeck_quan_price+=item_price;
3053   -
3054   - //--组装价格list--
3055   - if (check_quan_price_list) {
3056   - check_quan_price_list += "," +item_price;
3057   - } else {
3058   - check_quan_price_list = item_price;
3059   - }
3060   - //--组装商品的线下erpwareid--
3061   - if (check_quan_ware_list) {
3062   - check_quan_ware_list += "," + encodeURIComponent(gd['erpwareid']);
3063   - } else {
3064   - check_quan_ware_list = encodeURIComponent(gd['erpwareid']);
3065   - }
3066   - }
3067   - //优惠券优惠的金额要控制到优惠券的选择条件
3068   - var cut_price=0;
3069   - for(var i in th.data.prom_goods_map[pickup_id]){
3070   - var obj=th.data.prom_goods_map[pickup_id][i];
3071   - if(obj.coupon_sele){
3072   - cut_price+=obj.price-obj.prom_price;
3073   - }
3074   - }
3075   -
3076   - arr[ind].ckeck_quan_price=ckeck_quan_price-cut_price;
3077   - arr[ind].check_quan_ware_list=check_quan_ware_list;
3078   - arr[ind].check_quan_price_list=check_quan_price_list;
3079   -
3080   - //是否关闭使用优惠券
3081   - if (th.data.is_close_quan != 1 && !is_xz_yh) {
3082   - //--调用接口,获取优惠券的列表,3秒钟内控制接口请求--
3083   - var url="/api/weshop/couponList/getUseCouponList";
3084   - await app.request.promiseGet(url,{ data:{storeId:oo.stoid,userId:app.globalData.user_id,BuySum:ckeck_quan_price,WareIds:check_quan_ware_list,pageSize:100}}).then(res=>{
3085   - if (res.data.code == 0) {
3086   - var quan_list = res.data.data.pageData;
3087   - arr[ind].quan_list = th.check_is_frozenQuan(quan_list, th.data.frozenQuan);
3088   - }
3089   - })
3090   - }
3091   - }
3092   -
3093   - //如果是搭配购的立即购买的时候
3094   - if(th.data.is_b_now){
3095   - if(arr && arr.length>0){
3096   - var quanlist=arr[0].quan_list;
3097   - th.setData({selected_quan_list:quanlist,cartlist:arr})
3098   - }
3099   - }else{
3100   - th.setData({cartlist:arr })
3101   - th.set_can_num();
3102   - }
3103   -
3104   - //})
3105   - },
3106   -
3107   - //------ 获取立即购买的购物车的劵 --------
3108   - get_buy_now_quan:function () {
3109   - var quanlist=null,th=this,frozenQuan = null;
3110   - var good = this.data.bn_goods;
3111   - if(good.prom_price){
3112   - th.data.ckeck_quan_price=good.prom_price; //如果有优惠价,就用优惠价
3113   - }else if(good.is_offline){
3114   - th.data.ckeck_quan_price=good.offline_price; //如果有线下取价,就用线下价
3115   - }
3116   - //--如果商家后台没有限制使用优惠券,同时商品的优惠活动没有限制使用优惠券--
3117   - if(th.data.is_close_quan != 1 && th.data.bn_goods.is_xz_yh!=1)
3118   - {
3119   - var url0 = "/api/weshop/users/frozenQuan/listFrozenQuan/" + app.globalData.user_id;
3120   - var url="/api/weshop/couponList/getUseCouponList";
3121   - app.request.promiseGet(url0, {1: 1}).then(res => {
3122   - if (res.data.code == 0) {
3123   - frozenQuan = res.data.data;th.data.frozenQuan=frozenQuan;
3124   - }
3125   - app.request.time_limit_get(6, url, {
3126   - data: {
3127   - storeId: oo.stoid,
3128   - userId: app.globalData.user_id,
3129   - BuySum: th.data.ckeck_quan_price,
3130   - WareIds: encodeURIComponent(th.data.check_quan_ware_list),
3131   - pageSize: 100
3132   - },
3133   - success: function (res) {
3134   - if (res.data.code == 0) {
3135   - quanlist = res.data.data.pageData;
3136   - if (quanlist) {
3137   - quanlist = th.check_is_frozenQuan(quanlist, frozenQuan);
3138   - th.setData({selected_quan_list:quanlist })
3139   - }
3140   - }
3141   - }
3142   - })
3143   - })
3144   - }
3145   - },
3146   -
3147   - //检查区域是不是包邮
3148   - check_area:function(arr){
3149   - var user_addr=this.data.user_addr;
3150   - if(!user_addr) return 0;
3151   - for(var i in arr){
3152   - var item=arr[i];
3153   - if(user_addr.twon==item || user_addr.district==item
3154   - || user_addr.city==item|| user_addr.province==item ){
3155   - return 0;
3156   - }
3157   - }
3158   - return 1;
3159   - },
3160   -
3161   - //检查立即购买的商品是不是不包邮
3162   - check_good:function(arr,goods_id){
3163   - if(!goods_id) goods_id=this.data.bn_goods.goods_id;
3164   - for(var i in arr){
3165   - var item=arr[i];
3166   - if(goods_id==item) return 0;
3167   - }
3168   - return 1;
3169   - },
3170   - check_by_area:function(region_list){
3171   - var arr=region_list.split(",");
3172   - var check=this.check_area(arr);
3173   - return !check;
3174   - },
3175   - check_by_goods:function(goods_list,goods_id){
3176   - var arr=goods_list.split(",");
3177   - var check=this.check_good(arr,goods_id);
3178   - return !check;
3179   - },
3180   - //立即购买获取优惠活动的内容
3181   - buy_now_prom_goods:function (prom_id,arr,func) {
3182   - var price=arr.shop_price*arr.goods_num;
3183   - var prom=null;
3184   - getApp().request.promiseGet("/api/weshop/promgoods/get/"+os.stoid+"/"+prom_id,{}).then(res=>{
3185   - if(res.data.code==0){
3186   - prom=res.data.data;
3187   - return getApp().request.promiseGet("/api/weshop/goods/getDiscount", {
3188   - data: {
3189   - price: price,
3190   - prom_id: prom_id,
3191   - goods_num: arr.goods_num,
3192   - user_id: getApp().globalData.user_id,
3193   - is_bz: prom.is_bz
3194   - }
3195   - })
3196   - }else {
3197   - func(arr);
3198   - }
3199   - }).then(res=>{
3200   - if(res.data.code==0){
3201   - var get_data=res.data.data;
3202   - arr.is_bz=prom.is_bz; //是不是倍增
3203   - arr.is_xz_yh=prom.is_xz_yh; //是不是优惠
3204   - arr.bs=get_data.bs; //是不是倍数
3205   - arr.is_past=get_data.is_past; //是不是包邮
3206   - arr.prom_price=get_data.price>=0?get_data.price:price;
3207   - arr.s_intValue=get_data.intValue;
3208   - arr.s_coupon_id=get_data.coupon_id;
3209   - arr.s_coupon_num=get_data.coupon_num;
3210   - //-- 看是不是有赠品 --
3211   - if(get_data.gift_id) {
3212   - arr.gift_id = get_data.gift_id;
3213   - arr.gift_goods_id = get_data.goods_id;
3214   - arr.gift_goods_name = get_data.goods_name;
3215   - arr.gift_goods_color = get_data.goodsinfo.goods_color;
3216   - arr.gift_goods_spec = get_data.goodsinfo.goods_spec;
3217   - arr.gift_original_img = get_data.goodsinfo.original_img;
3218   - arr.gift_weight = get_data.goodsinfo.weight;
3219   - arr.gift_exp_sum_type = get_data.goodsinfo.exp_sum_type;
3220   - arr.gift_uniform_exp_sum = get_data.goodsinfo.uniform_exp_sum;
3221   - arr.gift_limit_num = get_data.limit_num;
3222   - arr.gift_storecount = get_data.gift_storecount;
3223   - }
3224   - arr.s_libao=get_data.libao;
3225   - arr.s_lb_num=get_data.lb_num;
3226   - arr.prom_id=prom_id;
3227   - }
3228   - func(arr);
3229   - })
3230   - },
3231   - //--检查订单优惠--
3232   - check_is_order_prom:function (condition,func,pick) {
3233   - var th=this;
3234   - if(this.data.is_b_now==1) pick=this.data.bn_pick;
3235   - //---获取订单优惠---
3236   - getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion",{
3237   - data:{store_id:os.stoid,orderAmount:condition}
3238   - }).then(res=>{
3239   - if(res.data.code==0) {
3240   - var data = res.data.data;
3241   - th.data.order_prom[pick]=data;
3242   - }
3243   - func();
3244   - })
3245   - },
3246   -
3247   - //--- 加入优惠活动的映射中,同时要有一个good列表 ---
3248   - add_prom_goods_map:async function (item) {
3249   - var th=this;
3250   - var pickid=item.pick_id;
3251   - var map=th.data.prom_goods_map;
3252   - var obj=map[pickid];
3253   -
3254   - if(map[pickid]){
3255   - if(map[pickid][item.prom_id]){
3256   - var ob=map[pickid][item.prom_id];
3257   - ob.price+=item.goods_price*item.goods_num;
3258   - ob.goods_num+=item.goods_num;
3259   - ob.goods.push({goods_id:item.goods_id,goods_price:item.goods_price,goods_num:item.goods_num});
3260   -
3261   - }else{
3262   - var prom=null;
3263   - await getApp().request.promiseGet("/api/weshop/promgoods/get/"+os.stoid+"/"+item.prom_id,{}).then(res=>{
3264   - if(res.data.code==0){ prom=res.data.data; }
  3192 + determine_expres: function (e) {
  3193 + this.setData({open_express: 0});
  3194 + if (this.data.is_b_now == 1)
  3195 + this.calculatePrice2();
  3196 + else
  3197 + this.calculatePrice();
  3198 + },
  3199 +
  3200 + //点击打开优惠券使用说明
  3201 + clik_coupons: function (e) {
  3202 + var ind = e.currentTarget.dataset.idx;
  3203 + var is_open = this.data.selected_quan_list[ind].is_open;
  3204 +
  3205 + if (is_open == 1) is_open = 0;
  3206 + else is_open = 1;
  3207 +
  3208 + var txt = "selected_quan_list[" + ind + "].is_open"
  3209 + var obj = {};
  3210 + obj[txt] = is_open;
  3211 +
  3212 + this.setData(obj);
  3213 + this.setData({disabled: 1})
  3214 + },
  3215 +
  3216 + clik_coupons2: function (e) {
  3217 + var ind = e.currentTarget.dataset.idx;
  3218 + var is_open = this.data.get_by_quan_list[ind].is_open;
  3219 +
  3220 + if (is_open == 1) is_open = 0;
  3221 + else is_open = 1;
  3222 +
  3223 + var txt = "get_by_quan_list[" + ind + "].is_open"
  3224 + var obj = {};
  3225 + obj[txt] = is_open;
  3226 +
  3227 + this.setData(obj);
  3228 + this.setData({disabled: 1})
  3229 + },
  3230 +
  3231 +
  3232 + //设置默认物流
  3233 + select_default_logistics: function () {
  3234 + var th = this;
  3235 + var is_shipping_code = this.data.is_shipping_code
  3236 + getApp().request.put("/api/weshop/users/update", {
  3237 + data: {user_id: getApp().globalData.user_id, store_id: oo.stoid, def_exp_code: is_shipping_code},
  3238 + success: function (rse) {
  3239 + if (rse.data.code == 0) {
  3240 + getApp().globalData.userInfo.def_exp_code = is_shipping_code;
  3241 + th.setData({open_express: 0});
  3242 + //----计算此时购物车的价格----
  3243 + if (th.data.is_b_now == 1) th.calculatePrice2();
  3244 + else th.calculatePrice();
  3245 + }
  3246 + }
  3247 + })
  3248 + },
  3249 +
  3250 + //更新下默认,在onshow里面
  3251 + update_code(){
  3252 + var th = this, m_wind = 0, def_exp_code = getApp().globalData.userInfo.def_exp_code;
  3253 + //--定时器,判断wu_arr不未空--
  3254 + var uii = setInterval(function () {
  3255 + if (th.data.wu_arr) {
  3256 + clearInterval(uii);
  3257 + for (var k = 0; k < th.data.wu_arr.length; k++) {
  3258 + var item = th.data.wu_arr[k];
  3259 + if (def_exp_code == item.code) {
  3260 + m_wind = k;
  3261 + }
  3262 + }
  3263 + //--如果是立即购买--
  3264 + if (th.data.is_b_now == 1) {
  3265 + th.setData({index: m_wind, is_express: m_wind});
  3266 + } else {
  3267 + var ui = setInterval(function () {
  3268 + if (th.data.cartlist) {
  3269 + var c_arr = th.data.cartlist;
  3270 + for (var i in c_arr) {
  3271 + c_arr[i].wind = m_wind;
  3272 + }
  3273 + th.setData({cartlist: c_arr, is_express: m_wind})
  3274 + clearInterval(ui);
  3275 + }
  3276 + }, 500)
  3277 + }
  3278 + }
  3279 + }, 500);
  3280 + },
  3281 + //-----获取购物车进来的劵-------
  3282 + get_cart_quan: async function (order_prom_list_cart) {
  3283 + var th = this;
  3284 + var is_xz_yh = 1;
  3285 + //等待值的出现
  3286 + //getApp().waitfor2(this,"g_cart_q_time","order_prom_list_cart",async function () {
  3287 + //var arr=th.data.order_prom_list_cart;
  3288 + var arr = order_prom_list_cart;
  3289 + if (!arr) arr = [];
  3290 + //如果系统有限制使用优惠券
  3291 + if (th.data.is_close_quan) return false;
  3292 +
  3293 + //------------开始计算使用优惠券相关------------
  3294 + for (var ind in arr) {
  3295 + var ep = arr[ind];
  3296 + var goodlist = ep.goods;
  3297 + var pickup_id = ep.pickup_id;
  3298 + //--更优惠券抵用有关,立即购买的,如果是购物车,如果有等级价还有考虑等级价的东西
  3299 + //就要把相应的值,写入cartlist数组中--
  3300 + var ckeck_quan_price = 0,
  3301 + check_quan_price_list = '',
  3302 + check_quan_ware_list = '';
  3303 +
  3304 + for (var i in goodlist) {
  3305 + var gd = goodlist[i];
  3306 + //--如果是秒杀就跳出,如果是赠品,如果是组合购,如果是限制使用优惠券--
  3307 + if (gd.prom_type == 1 || gd.is_gift || gd.prom_type == 7) {
  3308 + continue;
  3309 + }
  3310 + //如果有限制使用优惠券,就要返回
  3311 + if (gd.prom_type == 3) {
  3312 + if (th.data.prom_goods_map[pickup_id][gd.prom_id].is_xz_yh) continue;
  3313 + th.data.prom_goods_map[pickup_id][gd.prom_id].coupon_sele = 1;
  3314 + }
  3315 + is_xz_yh = 0;
  3316 + var item_price = gd.goods_price * gd.goods_num;
  3317 + //-- 如果有平摊下去,有实收价格的时候,就要用account来计算价格 --
  3318 + if (gd.account_fir != null && gd.account_fir != undefined) {
  3319 + item_price = gd.account_fir * gd.goods_num;
  3320 + }
  3321 + ckeck_quan_price += item_price;
  3322 +
  3323 + //--组装价格list--
  3324 + if (check_quan_price_list) {
  3325 + check_quan_price_list += "," + item_price;
  3326 + } else {
  3327 + check_quan_price_list = item_price;
  3328 + }
  3329 + //--组装商品的线下erpwareid--
  3330 + if (check_quan_ware_list) {
  3331 + check_quan_ware_list += "," + encodeURIComponent(gd['erpwareid']);
  3332 + } else {
  3333 + check_quan_ware_list = encodeURIComponent(gd['erpwareid']);
  3334 + }
  3335 + }
  3336 + //优惠券优惠的金额要控制到优惠券的选择条件
  3337 + var cut_price = 0;
  3338 + for (var i in th.data.prom_goods_map[pickup_id]) {
  3339 + var obj = th.data.prom_goods_map[pickup_id][i];
  3340 + if (obj.coupon_sele) {
  3341 + cut_price += obj.price - obj.prom_price;
  3342 + }
  3343 + }
  3344 +
  3345 + arr[ind].ckeck_quan_price = ckeck_quan_price - cut_price;
  3346 + arr[ind].check_quan_ware_list = check_quan_ware_list;
  3347 + arr[ind].check_quan_price_list = check_quan_price_list;
  3348 +
  3349 + //是否关闭使用优惠券
  3350 + if (th.data.is_close_quan != 1 && !is_xz_yh) {
  3351 + //--调用接口,获取优惠券的列表,3秒钟内控制接口请求--
  3352 + var url = "/api/weshop/couponList/getUseCouponList";
  3353 + await app.request.promiseGet(url, {
  3354 + data: {
  3355 + storeId: oo.stoid,
  3356 + userId: app.globalData.user_id,
  3357 + BuySum: ckeck_quan_price,
  3358 + WareIds: check_quan_ware_list,
  3359 + pageSize: 100
  3360 + }
  3361 + }).then(res => {
  3362 + if (res.data.code == 0) {
  3363 + var quan_list = res.data.data.pageData;
  3364 + arr[ind].quan_list = th.check_is_frozenQuan(quan_list, th.data.frozenQuan);
  3365 + }
  3366 + })
  3367 + }
  3368 + }
  3369 +
  3370 + //如果是搭配购的立即购买的时候
  3371 + if (th.data.is_b_now) {
  3372 + if (arr && arr.length > 0) {
  3373 + var quanlist = arr[0].quan_list;
  3374 + th.setData({selected_quan_list: quanlist, cartlist: arr})
  3375 + }
  3376 + } else {
  3377 + th.setData({cartlist: arr})
  3378 + th.set_can_num();
  3379 + }
  3380 +
  3381 + //})
  3382 + },
  3383 +
  3384 + //------ 获取立即购买的购物车的劵 --------
  3385 + get_buy_now_quan: function () {
  3386 + var quanlist = null, th = this, frozenQuan = null;
  3387 + var good = this.data.bn_goods;
  3388 + if (good.prom_price) {
  3389 + th.data.ckeck_quan_price = good.prom_price; //如果有优惠价,就用优惠价
  3390 + } else if (good.is_offline) {
  3391 + th.data.ckeck_quan_price = good.offline_price; //如果有线下取价,就用线下价
  3392 + }
  3393 + //--如果商家后台没有限制使用优惠券,同时商品的优惠活动没有限制使用优惠券--
  3394 + if (th.data.is_close_quan != 1 && th.data.bn_goods.is_xz_yh != 1) {
  3395 + var url0 = "/api/weshop/users/frozenQuan/listFrozenQuan/" + app.globalData.user_id;
  3396 + var url = "/api/weshop/couponList/getUseCouponList";
  3397 + app.request.promiseGet(url0, {1: 1}).then(res => {
  3398 + if (res.data.code == 0) {
  3399 + frozenQuan = res.data.data;
  3400 + th.data.frozenQuan = frozenQuan;
  3401 + }
  3402 + app.request.time_limit_get(6, url, {
  3403 + data: {
  3404 + storeId: oo.stoid,
  3405 + userId: app.globalData.user_id,
  3406 + BuySum: th.data.ckeck_quan_price,
  3407 + WareIds: encodeURIComponent(th.data.check_quan_ware_list),
  3408 + pageSize: 100
  3409 + },
  3410 + success: function (res) {
  3411 + if (res.data.code == 0) {
  3412 + quanlist = res.data.data.pageData;
  3413 + if (quanlist) {
  3414 + quanlist = th.check_is_frozenQuan(quanlist, frozenQuan);
  3415 + th.setData({selected_quan_list: quanlist})
  3416 + }
  3417 + }
  3418 + }
3265 3419 })
3266   - var ob={};
3267   - ob.prom_id=item.prom_id;
3268   - ob.price=item.goods_price*item.goods_num;
3269   - ob.goods_num=item.goods_num;
3270   - ob.is_bz=prom.is_bz;
3271   - ob.is_xz_yh=prom.is_xz_yh;
3272   - ob.goods=new Array();
3273   - ob.goods.push({goods_id:item.goods_id,goods_price:item.goods_price,goods_num:item.goods_num});
3274   - map[pickid][item.prom_id]=ob;
3275   - }
3276   - }else{
3277   - var ob={};
3278   - var prom=null;
3279   - await getApp().request.promiseGet("/api/weshop/promgoods/get/"+os.stoid+"/"+item.prom_id,{}).then(res=>{
3280   - if(res.data.code==0){ prom=res.data.data; }
3281 3420 })
3282   - ob.prom_id=item.prom_id;
3283   - ob.price=item.goods_price*item.goods_num;
3284   - ob.goods_num=item.goods_num;
3285   - ob.is_bz=prom.is_bz;
3286   - ob.is_xz_yh=prom.is_xz_yh;
3287   - ob.goods=new Array();
3288   - ob.goods.push({goods_id:item.goods_id,goods_price:item.goods_price,goods_num:item.goods_num});
  3421 + }
  3422 + },
  3423 +
  3424 + //检查区域是不是包邮
  3425 + check_area: function (arr) {
  3426 + var user_addr = this.data.user_addr;
  3427 + if (!user_addr) return 0;
  3428 + for (var i in arr) {
  3429 + var item = arr[i];
  3430 + if (user_addr.twon == item || user_addr.district == item
  3431 + || user_addr.city == item || user_addr.province == item) {
  3432 + return 0;
  3433 + }
  3434 + }
  3435 + return 1;
  3436 + },
  3437 +
  3438 + //检查立即购买的商品是不是不包邮
  3439 + check_good: function (arr, goods_id) {
  3440 + if (!goods_id) goods_id = this.data.bn_goods.goods_id;
  3441 + for (var i in arr) {
  3442 + var item = arr[i];
  3443 + if (goods_id == item) return 0;
  3444 + }
  3445 + return 1;
  3446 + },
  3447 + check_by_area: function (region_list) {
  3448 + var arr = region_list.split(",");
  3449 + var check = this.check_area(arr);
  3450 + return !check;
  3451 + },
  3452 + check_by_goods: function (goods_list, goods_id) {
  3453 + var arr = goods_list.split(",");
  3454 + var check = this.check_good(arr, goods_id);
  3455 + return !check;
  3456 + },
  3457 + //立即购买获取优惠活动的内容
  3458 + buy_now_prom_goods: function (prom_id, arr, func) {
  3459 + var price = arr.shop_price * arr.goods_num;
  3460 + var prom = null;
  3461 + getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + prom_id, {}).then(res => {
  3462 + if (res.data.code == 0) {
  3463 + prom = res.data.data;
  3464 + return getApp().request.promiseGet("/api/weshop/goods/getDiscount", {
  3465 + data: {
  3466 + price: price,
  3467 + prom_id: prom_id,
  3468 + goods_num: arr.goods_num,
  3469 + user_id: getApp().globalData.user_id,
  3470 + is_bz: prom.is_bz
  3471 + }
  3472 + })
  3473 + } else {
  3474 + func(arr);
  3475 + }
  3476 + }).then(res => {
  3477 + if (res.data.code == 0) {
  3478 + var get_data = res.data.data;
  3479 + arr.is_bz = prom.is_bz; //是不是倍增
  3480 + arr.is_xz_yh = prom.is_xz_yh; //是不是优惠
  3481 + arr.bs = get_data.bs; //是不是倍数
  3482 + arr.is_past = get_data.is_past; //是不是包邮
  3483 + arr.prom_price = get_data.price >= 0 ? get_data.price : price;
  3484 + arr.s_intValue = get_data.intValue;
  3485 + arr.s_coupon_id = get_data.coupon_id;
  3486 + arr.s_coupon_num = get_data.coupon_num;
  3487 + //-- 看是不是有赠品 --
  3488 + if (get_data.gift_id) {
  3489 + arr.gift_id = get_data.gift_id;
  3490 + arr.gift_goods_id = get_data.goods_id;
  3491 + arr.gift_goods_name = get_data.goods_name;
  3492 + arr.gift_goods_color = get_data.goodsinfo.goods_color;
  3493 + arr.gift_goods_spec = get_data.goodsinfo.goods_spec;
  3494 + arr.gift_original_img = get_data.goodsinfo.original_img;
  3495 + arr.gift_weight = get_data.goodsinfo.weight;
  3496 + arr.gift_exp_sum_type = get_data.goodsinfo.exp_sum_type;
  3497 + arr.gift_uniform_exp_sum = get_data.goodsinfo.uniform_exp_sum;
  3498 + arr.gift_limit_num = get_data.limit_num;
  3499 + arr.gift_storecount = get_data.gift_storecount;
  3500 + }
  3501 + arr.s_libao = get_data.libao;
  3502 + arr.s_lb_num = get_data.lb_num;
  3503 + arr.prom_id = prom_id;
  3504 + }
  3505 + func(arr);
  3506 + })
  3507 + },
  3508 + //--检查订单优惠--
  3509 + check_is_order_prom: function (condition, func, pick) {
  3510 + var th = this;
  3511 + if (this.data.is_b_now == 1) pick = this.data.bn_pick;
  3512 + //---获取订单优惠---
  3513 + getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", {
  3514 + data: {store_id: os.stoid, orderAmount: condition}
  3515 + }).then(res => {
  3516 + if (res.data.code == 0) {
  3517 + var data = res.data.data;
  3518 + th.data.order_prom[pick] = data;
  3519 + }
  3520 + func();
  3521 + })
  3522 + },
  3523 +
  3524 + //--- 加入优惠活动的映射中,同时要有一个good列表 ---
  3525 + add_prom_goods_map: async function (item) {
  3526 + var th = this;
  3527 + var pickid = item.pick_id;
  3528 + var map = th.data.prom_goods_map;
  3529 + var obj = map[pickid];
  3530 +
  3531 + if (map[pickid]) {
  3532 + if (map[pickid][item.prom_id]) {
  3533 + var ob = map[pickid][item.prom_id];
  3534 + ob.price += item.goods_price * item.goods_num;
  3535 + ob.goods_num += item.goods_num;
  3536 + ob.goods.push({goods_id: item.goods_id, goods_price: item.goods_price, goods_num: item.goods_num});
3289 3537  
3290   - var obj={};
3291   - obj[item.prom_id]=ob;
3292   - map[pickid]=obj;
  3538 + } else {
  3539 + var prom = null;
  3540 + await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + item.prom_id, {}).then(res => {
  3541 + if (res.data.code == 0) {
  3542 + prom = res.data.data;
  3543 + }
  3544 + })
  3545 + var ob = {};
  3546 + ob.prom_id = item.prom_id;
  3547 + ob.price = item.goods_price * item.goods_num;
  3548 + ob.goods_num = item.goods_num;
  3549 + ob.is_bz = prom.is_bz;
  3550 + ob.is_xz_yh = prom.is_xz_yh;
  3551 + ob.goods = new Array();
  3552 + ob.goods.push({goods_id: item.goods_id, goods_price: item.goods_price, goods_num: item.goods_num});
  3553 + map[pickid][item.prom_id] = ob;
  3554 + }
  3555 + } else {
  3556 + var ob = {};
  3557 + var prom = null;
  3558 + await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + item.prom_id, {}).then(res => {
  3559 + if (res.data.code == 0) {
  3560 + prom = res.data.data;
  3561 + }
  3562 + })
  3563 + ob.prom_id = item.prom_id;
  3564 + ob.price = item.goods_price * item.goods_num;
  3565 + ob.goods_num = item.goods_num;
  3566 + ob.is_bz = prom.is_bz;
  3567 + ob.is_xz_yh = prom.is_xz_yh;
  3568 + ob.goods = new Array();
  3569 + ob.goods.push({goods_id: item.goods_id, goods_price: item.goods_price, goods_num: item.goods_num});
  3570 +
  3571 + var obj = {};
  3572 + obj[item.prom_id] = ob;
  3573 + map[pickid] = obj;
3293 3574  
3294 3575 }
3295 3576 },
3296 3577  
3297   - //计算立即购买赠品的物流费用
3298   - get_now_gift_goods_wuliu:function (code, o_shipping_price, user_addr, gift_freight_free,allpice, rs,shipping_price,no_by_data,goods_weight1,goods_piece1) {
3299   - var good=this.data.buy_now_gift_goods;
3300   - var goods_weight=-1, goods_piece=-1;
3301   - var gift_shipping_price=0;
3302   - var th=this;
  3578 + //计算立即购买赠品的物流费用
  3579 + get_now_gift_goods_wuliu: function (code, o_shipping_price, user_addr, gift_freight_free, allpice, rs, shipping_price, no_by_data, goods_weight1, goods_piece1) {
  3580 + var good = this.data.buy_now_gift_goods;
  3581 + var goods_weight = -1, goods_piece = -1;
  3582 + var gift_shipping_price = 0;
  3583 + var th = this;
3303 3584 switch (good['exp_sum_type']) {
3304 3585 case 1:
3305 3586 //统一运费
3306   - gift_shipping_price += good['uniform_exp_sum'];
3307   - gift_shipping_price+=o_shipping_price;
3308   - break;
  3587 + gift_shipping_price += good['uniform_exp_sum'];
  3588 + gift_shipping_price += o_shipping_price;
  3589 + break;
3309 3590 case 2:
3310 3591 if (goods_weight < 0) goods_weight = 0;
3311 3592 //累积商品重量 每种商品的重量 * 数量
3312 3593 goods_weight += good['weight'] * good['buynum'];
3313   - if(goods_weight1>0){
3314   - goods_weight+=goods_weight1;
3315   - }
3316   - break;
  3594 + if (goods_weight1 > 0) {
  3595 + goods_weight += goods_weight1;
  3596 + }
  3597 + break;
3317 3598 case 3:
3318 3599 if (goods_piece < 0) goods_piece = 0;
3319 3600 //累积商品数量
3320   - goods_piece += good['buynum'];
3321   - if(goods_piece1){
3322   - goods_piece+=goods_piece1;
3323   - }
3324   - break;
3325   - }
3326   -
3327   -
  3601 + goods_piece += good['buynum'];
  3602 + if (goods_piece1) {
  3603 + goods_piece += goods_piece1;
  3604 + }
  3605 + break;
  3606 + }
  3607 +
  3608 +
3328 3609 //如果有设置不包邮区域的时候
3329   - if(no_by_data && no_by_data.region_list){
3330   - if(th.check_by_area(no_by_data.region_list)){
3331   - gift_freight_free=0;
3332   - th.data.is_no_by[th.data.bn_pick]=1;
  3610 + if (no_by_data && no_by_data.region_list) {
  3611 + if (th.check_by_area(no_by_data.region_list)) {
  3612 + gift_freight_free = 0;
  3613 + th.data.is_no_by[th.data.bn_pick] = 1;
3333 3614 }
3334 3615 }
3335 3616 //如果有设置不包邮商品
3336   - if(no_by_data && no_by_data.goods_list && gift_freight_free){
3337   - if(th.check_by_goods(no_by_data.goods_list,good.goods_id)){
3338   - gift_freight_free=0;
  3617 + if (no_by_data && no_by_data.goods_list && gift_freight_free) {
  3618 + if (th.check_by_goods(no_by_data.goods_list, good.goods_id)) {
  3619 + gift_freight_free = 0;
3339 3620 //th.data.is_no_by[th.data.bn_pick]=1;
3340 3621 }
3341 3622 }
3342   -
3343   - var t_shipping_price=
  3623 +
  3624 + var t_shipping_price =
3344 3625 this.calculatewuliu(code, gift_shipping_price, goods_weight,
3345 3626 goods_piece, user_addr, gift_freight_free, allpice, rs);
3346 3627 return t_shipping_price;
3347 3628  
3348 3629 },
3349 3630  
3350   - //从优惠的映射中拿出商品从表的item
3351   - item_map_get_goods:function(goods_id,map){
3352   - for(var i in map.goods){
3353   - if(map.goods[i].goods_id==goods_id) return map.goods[i];
  3631 + //从优惠的映射中拿出商品从表的item
  3632 + item_map_get_goods: function (goods_id, map) {
  3633 + for (var i in map.goods) {
  3634 + if (map.goods[i].goods_id == goods_id) return map.goods[i];
3354 3635 }
3355 3636 },
3356 3637 //从优惠的映射中拿出商品从表的item
3357   - arr_get_goods:function(goods_id,arr){
3358   - for(var i in arr){
3359   - if(arr[i].goods_id==goods_id) return arr[i];
  3638 + arr_get_goods: function (goods_id, arr) {
  3639 + for (var i in arr) {
  3640 + if (arr[i].goods_id == goods_id) return arr[i];
3360 3641 }
3361 3642 },
3362   -
  3643 +
3363 3644 //检查是不是有其他门店的订单在选择了券
3364   - check_other_use:function (iter,pkid) {
3365   - var using=this.data.using_quan;
3366   - var is_use=0;
3367   - if(using){
3368   - for(var i in using){
3369   - if(i==pkid) continue;
3370   - if(iter.CashRepNo==using[i].coupon_no){
3371   - is_use=1; break;
  3645 + check_other_use: function (iter, pkid) {
  3646 + var using = this.data.using_quan;
  3647 + var is_use = 0;
  3648 + if (using) {
  3649 + for (var i in using) {
  3650 + if (i == pkid) continue;
  3651 + if (iter.CashRepNo == using[i].coupon_no) {
  3652 + is_use = 1;
  3653 + break;
3372 3654 }
3373 3655 }
3374 3656 }
3375 3657 return is_use;
3376 3658 },
3377 3659 //检查是不是有其他门店的订单在选择了包邮券
3378   - check_other_use_by:function (iter,pkid) {
3379   - var using=this.data.using_quan;
3380   - var is_use=0;
3381   - if(using){
3382   - for(var i in using){
3383   - if(i==pkid) continue;
3384   - if(iter.no==using[i].coupon_no){
3385   - is_use=1; break;
  3660 + check_other_use_by: function (iter, pkid) {
  3661 + var using = this.data.using_quan;
  3662 + var is_use = 0;
  3663 + if (using) {
  3664 + for (var i in using) {
  3665 + if (i == pkid) continue;
  3666 + if (iter.no == using[i].coupon_no) {
  3667 + is_use = 1;
  3668 + break;
3386 3669 }
3387 3670 }
3388 3671 }
3389 3672 return is_use;
3390 3673 },
3391   -
3392   - //跳转到购买卡
3393   - buycard:function(){
3394   - getApp().goto("/pages/user/plus/plus");
3395   - getApp().globalData.plus_buy_back=1;
3396   - },
  3674 +
  3675 + //跳转到购买卡
  3676 + buycard: function () {
  3677 + getApp().goto("/pages/user/plus/plus");
  3678 + getApp().globalData.plus_buy_back = 1;
  3679 + },
3397 3680  
3398 3681 //跳转关闭弹出框的显示
3399   - close_offline:function(){
3400   - this.setData({is_offline_show:0});
3401   - },
3402   -
3403   - //立即购买显示弹出框
3404   - bn_pop_offline:function(){
3405   - var off_price=this.data.bn_goods.shop_price-this.data.bn_goods.offline_price;
3406   - //是不是线下
3407   - var is_get_offline=this.data.bn_goods.is_offline;
3408   - this.setData({is_offline_show:1,show_off_price:off_price.toFixed(2),is_get_offline:is_get_offline});
3409   - },
3410   -
3411   - //确定使用线下取价
3412   - sure_offline:function(){
3413   - var bn_goods=this.data.bn_goods;
3414   - if(bn_goods && bn_goods.prom_type==0){
3415   - bn_goods.is_offline=1;
3416   - this.setData({is_offline_show:0,bn_goods:bn_goods});
3417   - this.calculatePrice2();
3418   - }
3419   - //就是购物车结算时的
3420   - else{
3421   - var index=this.data.pop_offline_index;
3422   - var txt="cartlist["+index+"].is_offline";
3423   - this.setData({[txt]:1,is_offline_show:0,});
3424   - this.data.old_cartlist[index].is_offline=1;
3425   - this.calculatePrice();
3426   - }
3427   - },
3428   -
3429   -
3430   - //取消使用线下取价
3431   - cancle_offline:function(){
3432   - //判断是不是立即购买
3433   - var bn_goods=this.data.bn_goods;
3434   - if(bn_goods && bn_goods.prom_type==0){
3435   - bn_goods.is_offline=0;
3436   - this.setData({is_offline_show:0,bn_goods:bn_goods});
3437   - this.calculatePrice2();
3438   - }
3439   - //就是购物车结算时的
3440   - else{
3441   - var index=this.data.pop_offline_index;
3442   - var txt="cartlist["+index+"].is_offline";
3443   - this.setData({[txt]:0,is_offline_show:0,})
3444   - this.data.old_cartlist[index].is_offline=0;
  3682 + close_offline: function () {
  3683 + this.setData({is_offline_show: 0});
  3684 + },
  3685 +
  3686 + //立即购买显示弹出框
  3687 + bn_pop_offline: function () {
  3688 + var off_price = this.data.bn_goods.shop_price - this.data.bn_goods.offline_price;
  3689 + //是不是线下
  3690 + var is_get_offline = this.data.bn_goods.is_offline;
  3691 + this.setData({is_offline_show: 1, show_off_price: off_price.toFixed(2), is_get_offline: is_get_offline});
  3692 + },
  3693 +
  3694 + //确定使用线下取价
  3695 + sure_offline: function () {
  3696 + var bn_goods = this.data.bn_goods;
  3697 + if (bn_goods && bn_goods.prom_type == 0) {
  3698 + bn_goods.is_offline = 1;
  3699 + this.setData({is_offline_show: 0, bn_goods: bn_goods});
  3700 + this.calculatePrice2();
  3701 + }
  3702 + //就是购物车结算时的
  3703 + else {
  3704 + var index = this.data.pop_offline_index;
  3705 + var txt = "cartlist[" + index + "].is_offline";
  3706 + this.setData({[txt]: 1, is_offline_show: 0,});
  3707 + this.data.old_cartlist[index].is_offline = 1;
  3708 + this.calculatePrice();
  3709 + }
  3710 + },
  3711 +
  3712 +
  3713 + //取消使用线下取价
  3714 + cancle_offline: function () {
  3715 + //判断是不是立即购买
  3716 + var bn_goods = this.data.bn_goods;
  3717 + if (bn_goods && bn_goods.prom_type == 0) {
  3718 + bn_goods.is_offline = 0;
  3719 + this.setData({is_offline_show: 0, bn_goods: bn_goods});
  3720 + this.calculatePrice2();
  3721 + }
  3722 + //就是购物车结算时的
  3723 + else {
  3724 + var index = this.data.pop_offline_index;
  3725 + var txt = "cartlist[" + index + "].is_offline";
  3726 + this.setData({[txt]: 0, is_offline_show: 0,})
  3727 + this.data.old_cartlist[index].is_offline = 0;
3445 3728 this.calculatePrice();
3446   - }
3447   - },
  3729 + }
  3730 + },
3448 3731  
3449 3732 //-- 弹出购物车选择是不是要店铺优惠 --
3450   - cart_pop_offline:function (e){
3451   - var index=e.currentTarget.dataset.index;
3452   - var item=this.data.cartlist[index];
3453   - var off_price=item.offline_price;
  3733 + cart_pop_offline: function (e) {
  3734 + var index = e.currentTarget.dataset.index;
  3735 + var item = this.data.cartlist[index];
  3736 + var off_price = item.offline_price;
3454 3737 //是不是线下
3455   - var is_get_offline=item.is_offline;
3456   - this.setData({pop_offline_index:index,is_offline_show:1,show_off_price:off_price.toFixed(2),is_get_offline:is_get_offline});
  3738 + var is_get_offline = item.is_offline;
  3739 + this.setData({
  3740 + pop_offline_index: index,
  3741 + is_offline_show: 1,
  3742 + show_off_price: off_price.toFixed(2),
  3743 + is_get_offline: is_get_offline
  3744 + });
3457 3745 },
3458   -
3459   -
3460   -
3461 3746  
3462 3747  
3463 3748 });
... ...
pages/cart/cart2/cart2.wxml
... ... @@ -427,6 +427,12 @@
427 427 <view>优惠活动</view>
428 428 <view class="co-red">- ¥ {{filters.toFix(formData.cut_price,2)}}元</view>
429 429 </view>
  430 + <!-- 组合购优惠金额 -->
  431 + <view class="item" wx:if="{{formData.zh_cut_price>0}}">
  432 + <view>优惠活动</view>
  433 + <view class="co-red">- ¥ {{filters.toFix(formData.zh_cut_price,2)}}元</view>
  434 + </view>
  435 +
430 436 <!-- 订单优惠优惠金额 -->
431 437 <view class="item" wx:if="{{formData.order_prom_amount>0}}">
432 438 <view>订单优惠</view>
... ...
pages/cart/cart2/zh_calculate.js 0 → 100644
  1 +var regeneratorRuntime = require('../../../utils/runtime.js');
  2 +module.exports = {
  3 + //主要的作用,就是把组合购多余的商品进行拆分,
  4 + //如果没有达成组合购的要求,所有的商品都打回原价购买
  5 + fir_set_arr: function (c_item) {
  6 + //组合活动,以及组合活动从表的商品
  7 + let zh_prom_goods = c_item.zh_prom_goods;
  8 + let goods = c_item.goods; //一个门店中所有的商品
  9 + let tfeel = 0,cut_price=0, offline_price = 0, offline_num = 0;
  10 + let txt_ite = c_item.need_list;
  11 + //多个活动要拿来循环一下
  12 + for (let i in zh_prom_goods) {
  13 + let title = ""; //提示语;
  14 + //其中的一个活动
  15 + let act_item = zh_prom_goods[i];
  16 + let act_goos = act_item.gdlist;
  17 + let act = act_item.act;
  18 +
  19 + let all_num = 0; //商品数量之和
  20 + let all_price0 = 0; //商品数量之和
  21 + let aprice=0; //达到活动条件的购买价格
  22 + let need_to_buy = 0;
  23 + let all_zhqty = 0; //所有商品要求起购数之和
  24 + let no_in_arr = []; //剩余的未加入组合购
  25 +
  26 + for (let j in act_goos) {
  27 + let item_j = goods.find(function (ele) {
  28 + return ele.goods_id == act_goos[j].goods_id;
  29 + })
  30 + if(!item_j) continue;
  31 + act_goos[j].num = item_j.goods_num;
  32 + act_goos[j].goods_price = item_j.goods_price;
  33 + let item = act_goos[j];
  34 + if (item.num) {
  35 + all_num += item.num;
  36 + //当有起购数的控制的时候
  37 + if (item.zhqty) {
  38 + all_zhqty += item.zhqty;
  39 + if (item.num < item.zhqty) {
  40 + need_to_buy += item.zhqty - item.num;
  41 + }
  42 + if (item.num > item.zhqty) {
  43 + for (let i = 0; i < item.num - item.zhqty; i++) {
  44 + no_in_arr.push({
  45 + price: item.goods_price, goods_id: item.goods_id, offline_price: item.offline_price
  46 + })
  47 + }
  48 + }
  49 + } else {
  50 + for (let j = 0; j < item.num; j++) {
  51 + no_in_arr.push({
  52 + price: item.goods_price, goods_id: item.goods_id, offline_price: item.offline_price
  53 + })
  54 + }
  55 + }
  56 + } else {
  57 + if (item.zhqty) {
  58 + title = "必买商品未加购,下单立享【" + act.zhprice + "元任选" + act.zhbuyqty + "件】";
  59 + need_to_buy += item.zhqty;
  60 + }
  61 + }
  62 +
  63 + }
  64 +
  65 + //当满足组合的要求:总数要满足,起购数要满足
  66 + if (all_num >= act.zhbuyqty && !need_to_buy) {
  67 + function sortData(a, b) {
  68 + return a.price - b.price
  69 + }
  70 + no_in_arr.sort(sortData);
  71 + aprice = act.zhprice;
  72 + if (act.zhbuyqty > all_zhqty) {
  73 + for (let n = 0; n < act.zhbuyqty; n++) {
  74 + no_in_arr.pop();
  75 + }
  76 + }
  77 + //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增
  78 + if (act.is_bz && no_in_arr.length > act.zhbuyqty) {
  79 + //看一下是几倍
  80 + let be = parseInt(no_in_arr / act.zhbuyqty);
  81 + aprice += be * act.zhprice;
  82 + for (let m = 0; m < be * act.zhbuyqty; m++) {
  83 + no_in_arr.pop();
  84 + }
  85 + }
  86 +
  87 + //算一下剩余的商品
  88 + if (no_in_arr.length) {
  89 + let goods_map = {};
  90 + for (let ii in no_in_arr) {
  91 + let item = no_in_arr[ii];
  92 + if (item.offline_price) {
  93 + offline_price += item.goods_price - item.offline_price;
  94 + offline_num += 1;
  95 + }
  96 + if (goods_map[item.goods_id]) {
  97 + var num = goods_map[item.goods_id];
  98 + goods_map[item.goods_id] = ++num;
  99 + } else {
  100 + goods_map[item.goods_id] = 1;
  101 + }
  102 + }
  103 + //这里就开始拆分提交订单时的列表
  104 + for (let j in goods_map) {
  105 + //map中存的就是商品的数量
  106 + let num = goods_map[j];
  107 + //找到相应的商品
  108 + let idx = goods.findIndex(function (ele) {
  109 + return ele.goods_id == j;
  110 + })
  111 + goods[idx].goods_num -= num;
  112 + let new_g = JSON.parse(JSON.stringify(goods[idx]));
  113 + new_g.goods_num = num;
  114 + new_g.prom_type = 0;
  115 + new_g.prom_id = 0;
  116 + goods.push(new_g);
  117 + }
  118 + }
  119 + //-- 只统计是参与活动的商品 --
  120 + for(var ij in goods){
  121 + var iter=goods[ij];
  122 + if(iter.prom_type!=7 || iter.prom_id!=act.id){ continue; }
  123 + all_price0+=iter.goods_num*iter.goods_price;
  124 + }
  125 + //-- 活动的条件已经满足 --
  126 + c_item.zh_prom_goods[act.id].is_has_zh = 1;
  127 + c_item.is_has_zh = 1;
  128 + c_item.zh_prom_goods[act.id].actual_price = aprice;
  129 + c_item.zh_prom_goods[act.id].cut_price =all_price0-aprice;
  130 +
  131 + //-- 设置还需要购买多少件,享受活动,前段显示 --
  132 + let need_to = c_item.need_list;
  133 + let index = this.find_need_to(need_to, act);
  134 + if (index > -1) {
  135 + need_to.splice(index, 1);
  136 + txt_ite = need_to
  137 + }
  138 +
  139 +
  140 + } else {
  141 + for (let ii in goods) {
  142 + let item = goods[ii];
  143 + if (item.prom_type != 7) continue;
  144 + if (item.prom_id != act.id) continue;
  145 + if (item.offline_price) {
  146 + offline_price += item.goods_price - item.offline_price;
  147 + offline_num += 1;
  148 + }
  149 + item.prom_type = 0;
  150 + item.prom_id = 0;
  151 + }
  152 + if (act.zhbuyqty - all_num > need_to_buy) {
  153 + need_to_buy = act.zhbuyqty - all_num;
  154 + }
  155 + //-- 设置还需要购买多少件享受活动,前端显示 --
  156 + let need_to = c_item.need_list;
  157 + let index = this.find_need_to(need_to, act);
  158 + if (title == '') title = "再买" + need_to_buy + "件,下单立享【" + act.zhprice + "元任选" + act.zhbuyqty + "件】";
  159 + if (index != -1) {
  160 + need_to[index].title = title;
  161 + } else {
  162 + if (!need_to) need_to = [];
  163 + let it = {
  164 + id: act.id,
  165 + pickup_id: c_item.pickup_id,
  166 + title: title
  167 + };
  168 + need_to.push(it);
  169 + }
  170 + txt_ite = need_to;
  171 + }
  172 + tfeel += aprice;
  173 + cut_price+=all_price0-aprice;;
  174 + }
  175 +
  176 + c_item.zh_all_price = tfeel;
  177 + c_item.zh_cut_price = cut_price;
  178 +
  179 + if (c_item.is_offline == 1) {
  180 + c_item.offline_price += offline_price;
  181 + c_item.offline_num += offline_num;
  182 + } else {
  183 + c_item.is_offline == 1;
  184 + c_item.offline_price = offline_price;
  185 + c_item.offline_num = offline_num;
  186 + }
  187 +
  188 + },
  189 + //筛选组合购,纯粹的数组按活动id分组
  190 + find_split: function (arr) {
  191 + //过滤只有团购的商品
  192 + let oarr = arr.goods.filter(function (ele) {
  193 + return ele.prom_type == 7
  194 + })
  195 + if (!oarr || oarr.length == 0) return null;
  196 + //看一下有多少个不同的团购
  197 + let map = {},
  198 + dest = [];
  199 + for (let i = 0; i < oarr.length; i++) {
  200 + let ai = oarr[i];
  201 + let index = map[ai.prom_id]
  202 + if (!index) {
  203 + dest.push({
  204 + prom_id: ai.prom_id,
  205 + act: ai.act,
  206 + data: [ai]
  207 + });
  208 + map[ai.prom_id] = dest.length; //存储下标
  209 + } else {
  210 + let dj = dest[index - 1];
  211 + dj.data.push(ai);
  212 + }
  213 + }
  214 + return dest;
  215 + },
  216 +
  217 + find_need_to: function (list, iter) {
  218 + if (!list || list.length <= 0) return -1;
  219 + for (var i in list) {
  220 + var item = list[i];
  221 + if (item.id == iter.id) {
  222 + return i;
  223 + }
  224 + }
  225 + return -1;
  226 + },
  227 + //-- 平摊组合购的价格 --
  228 + calc_zh_split_price: async function (c_arr, th) {
  229 + //-- 循环处理 --
  230 + for (var k in c_arr) {
  231 + var cart_item = c_arr[k]; //就是每一单的意思
  232 + var ord_goods = c_arr[k].goods; //就是每一单的从表的意思
  233 +
  234 + var zh_prom_goods = cart_item.zh_prom_goods; //一单中所有的组合购的集合
  235 + var item_map = {};
  236 + for (let i in zh_prom_goods) {
  237 + let item = zh_prom_goods[i];
  238 + let prom_id = i;
  239 + //如果这个活动还没有达到要求,继续下一个计算
  240 + if (!item.is_has_zh) continue;
  241 + //过滤出相应组合购活动的商品
  242 + let glist = ord_goods.filter(function (ele) {
  243 + return ele.prom_type == 7 && ele.prom_id == i;
  244 + })
  245 + var all_good_price = 0;
  246 + var post_gd=[];
  247 + for (let j in glist) {
  248 + let item = glist[j];
  249 + all_good_price += item.goods_price * item.goods_num;
  250 + var gitem={
  251 + goods_id:item.goods_id,
  252 + goods_num:item.goods_num,
  253 + goods_price:item.goods_price
  254 + }
  255 + post_gd.push(gitem);
  256 + }
  257 + //要进行优惠的计算
  258 + if (all_good_price - item.actual_price) {
  259 + if (cart_item.prom_pt_json) {
  260 + cart_item.prom_pt_json.push({
  261 + "zhprom_id": prom_id,
  262 + "dis": (all_good_price - item.actual_price).toFixed(2),
  263 + "ispt": 0
  264 + })
  265 + } else {
  266 + cart_item.prom_pt_json = [{
  267 + "zhprom_id": prom_id,
  268 + "dis": (all_good_price - item.actual_price).toFixed(2),
  269 + "ispt": 0
  270 + }];
  271 + }
  272 + }
  273 +
  274 + //-- 如果系统要平摊到单品 --
  275 + var pt_data = {
  276 + 'prom_id': prom_id,
  277 + 'dis': parseFloat(all_good_price - item.actual_price).toFixed(2),
  278 + 'goods': post_gd
  279 + }
  280 + var pt_res = null;
  281 + await getApp().request.promisePost("/api/weshop/order/getGoodsSplit", {
  282 + is_json: 1,
  283 + data: pt_data
  284 + }).then(res => {
  285 + if (res.data.code == 0) {
  286 + pt_res = res.data.data;
  287 + }
  288 + })
  289 + if (pt_res) {
  290 + for (var io in glist) {
  291 + var goods_id = glist[io].goods_id;
  292 + item_map[goods_id]={};
  293 + //平摊赋值
  294 + item_map[goods_id].account_fir = th.arr_get_goods(goods_id, pt_res).fisrt_account;
  295 + item_map[goods_id].account_yu_fir = th.arr_get_goods(goods_id, pt_res).fisrt_account_yu;
  296 + if (!th.data.ispt_goods) {
  297 + item_map[goods_id].account = item_map[goods_id].account_fir;
  298 + item_map[goods_id].account_yu = item_map[goods_id].account_yu_fir;
  299 + }
  300 + }
  301 + }
  302 + }
  303 +
  304 + //--------循环计算商品是不是包邮,是不是使用优惠券,此时循环是商品从表-----------
  305 + for (var jj = 0; jj < ord_goods.length; jj++) {
  306 + if (ord_goods[jj].is_gift) continue;
  307 + if (ord_goods[jj].prom_type == 7 && item_map[ord_goods[jj].goods_id]) {
  308 + ord_goods[jj].account_fir = item_map[ord_goods[jj].goods_id].account_fir;
  309 + ord_goods[jj].account_yu_fir = item_map[ord_goods[jj].goods_id].account_yu_fir;
  310 + ord_goods[jj].account = item_map[ord_goods[jj].goods_id].account;
  311 + ord_goods[jj].account_yu = item_map[ord_goods[jj].goods_id].account_yu;
  312 + }
  313 + }
  314 + }
  315 +
  316 +
  317 + }
  318 +
  319 +
  320 +}
... ...
pages/goods/goodsInfo/goodsInfo.js
... ... @@ -776,7 +776,28 @@ Page({
776 776 //动态获取商品名称
777 777 wx.setNavigationBarTitle({
778 778 title: t.data.data.goods_name,
779   - })
  779 + });
  780 +
  781 + //-- 判断是不是组合购活动,必须要登录后才能判断 --
  782 + if(getApp().globalData.userInfo && t.data.data.prom_type==7 ){
  783 + //获取活动信息
  784 + var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" +
  785 + t.data.data.prom_id+"/"+getApp().globalData.userInfo.user_id;
  786 + getApp().request.get(url, {
  787 + success:function (e) {
  788 + if (e.data.code == 0 && e.data.data) {
  789 + if(ut.gettimestamp()<e.data.data.start_time){
  790 + return false;
  791 + }
  792 + if (e.data.data.is_end == 0 && ut.gettimestamp()<e.data.data.end_time ) {
  793 + //-- 获取商品列表 --
  794 + th.setData({zh_act:e.data.data });
  795 + }
  796 +
  797 + }
  798 + }
  799 + });
  800 + }
780 801  
781 802 //-- 把商品的赋值 --
782 803 ee.data.fir_goods=JSON.parse(JSON.stringify(t.data.data));
... ... @@ -814,7 +835,7 @@ Page({
814 835  
815 836  
816 837 //获取统一条形码,普通商品和优惠促销的商品
817   - if (ee.data.data.prom_type == 0 || ee.data.data.prom_type == 2 || ee.data.data.prom_type == 3 || ee.data.data.prom_type == 5){
  838 + if (ee.data.data.prom_type == 0 || ee.data.data.prom_type == 2 || ee.data.data.prom_type == 3 || ee.data.data.prom_type == 5 || ee.data.data.prom_type == 7){
818 839 //默认门店要拿下门店库存
819 840 if(that.data.sales_rules==2 && that.data.is_newsales_rules){
820 841 //获取门店
... ... @@ -1749,6 +1770,12 @@ Page({
1749 1770  
1750 1771 var ind = t.currentTarget.dataset.ind;
1751 1772  
  1773 + if(th.data.zh_act && ind==1){
  1774 + getApp().goto("/packageB/pages/zuhegou/index/index?id="+th.data.zh_act.id);
  1775 + return false;
  1776 + }
  1777 +
  1778 +
1752 1779 //回调。判断是不是优惠促销
1753 1780 th.check_is_prom_goods(function (){
1754 1781 th.setData({
... ... @@ -2820,7 +2847,7 @@ Page({
2820 2847 async check_prom(gid, prom_type, prom_id) {
2821 2848 var ee = this,
2822 2849 th = ee;
2823   - if (prom_type == 3 || prom_type == 0 || prom_type == 2 || prom_type == 5) {
  2850 + if (prom_type == 3 || prom_type == 0 || prom_type == 2 || prom_type == 5 || prom_type == 7) {
2824 2851 this.setData({
2825 2852 prom_type: 0,
2826 2853 isshow: 1,
... ... @@ -4439,6 +4466,11 @@ Page({
4439 4466  
4440 4467 });
4441 4468 });
  4469 + },
  4470 + fail: function(res) {
  4471 + console.log(res);
  4472 + wx.hideLoading();
  4473 +
4442 4474 }
4443 4475 });
4444 4476 },
... ... @@ -5429,5 +5461,10 @@ Page({
5429 5461 }
5430 5462 }
5431 5463 })
  5464 + },
  5465 +
  5466 + go_zh:function (e) {
  5467 + var id=e.currentTarget.dataset.id;
  5468 + getApp().goto("/packageB/pages/zuhegou/index/index?id="+id);
5432 5469 }
5433 5470 });
... ...
pages/goods/goodsInfo/goodsInfo.wxml
... ... @@ -465,25 +465,28 @@
465 465 </view>
466 466 </view>
467 467  
  468 +
  469 +
  470 +
468 471 <!-- 要判断是不是有促销活动 -->
469 472 <block wx:if="{{prom_goods}}">
470 473 <view class="cx-frame flex" style="position: relative; height: auto" >
471 474 <view class="cx-sizs fs30">促销</view>
472 475 <!-- 中间显示层 -->
473 476 <view class="f1 pdh20">
474   - <view class="cx_show_view flex fs28" wx:for="{{prom_goods}}">
475   - <view class="prom_condition">消费满{{item.condition}}<text wx:if="{{item.prom_type==1}}">件</text><text wx:else>元</text></view>
476   - <view class="word {{is_more_cx?'':'ellipsis-1'}}">
477   - <text wx:if="{{item.money>0}}">减价{{item.money}}元;</text>
478   - <text wx:if="{{item.sale>0}}">打{{item.sale}}折;</text>
479   - <text wx:if="{{item.past==1}}">包邮;</text>
480   - <text wx:if="{{item.intValue>0}}">送{{tem.intValue}}积分;</text>
481   - <text wx:if="{{item.couponId>0}}">送{{item.couponMoney}}元优惠券;</text>
482   - <text wx:if="{{item.gift_id>0}}">送商品{{item.goods_name}};</text>
483   - <text wx:if="{{item.lb_id>0}}">送{{item.lbtitle}};</text>
484   - </view>
485   - </view>
486 477  
  478 + <view class="cx_show_view flex fs28" wx:for="{{prom_goods}}">
  479 + <view class="prom_condition">消费满{{item.condition}}<text wx:if="{{item.prom_type==1}}">件</text><text wx:else>元</text></view>
  480 + <view class="word {{is_more_cx?'':'ellipsis-1'}}">
  481 + <text wx:if="{{item.money>0}}">减价{{item.money}}元;</text>
  482 + <text wx:if="{{item.sale>0}}">打{{item.sale}}折;</text>
  483 + <text wx:if="{{item.past==1}}">包邮;</text>
  484 + <text wx:if="{{item.intValue>0}}">送{{tem.intValue}}积分;</text>
  485 + <text wx:if="{{item.couponId>0}}">送{{item.couponMoney}}元优惠券;</text>
  486 + <text wx:if="{{item.gift_id>0}}">送商品{{item.goods_name}};</text>
  487 + <text wx:if="{{item.lb_id>0}}">送{{item.lbtitle}};</text>
  488 + </view>
  489 + </view>
487 490 </view>
488 491 <view data-coupon="1" bindtap="show_more_cx" class="cx-obtain-coupon wsize">
489 492 <text class="bg_jj {{is_more_cx?'down1':''}}"></text>
... ... @@ -507,6 +510,25 @@
507 510 </block>
508 511  
509 512  
  513 + <!-- 要判断是不是有组合优惠 -->
  514 + <block wx:if="{{zh_act}}">
  515 + <view class="cx-frame flex" style="position: relative; height: auto" >
  516 + <view class="cx-sizs wsize" style="width: 144rpx">组合购</view>
  517 + <!-- 中间显示层 -->
  518 + <view class="flex ai-center jc_sb" style="width: 570rpx" bindtap="go_zh" data-id="{{zh_act.id}}" >
  519 + <view class="flex">
  520 + <image class="hui_img" src="{{iurl}}/miniapp//images/hui.png"></image>
  521 + <view class="order_hui">
  522 + <view class="fs28 ellipsis-1">{{order_prom.name}}</view>
  523 + <view class="fs26" >(活动时间:{{tool.format_tt(zh_act.start_time)}} - {{tool.format_tt(zh_act.end_time)}})</view>
  524 + </view>
  525 + </view>
  526 + <view><text class="bg_jj is_more_cx" style="position: relative;top:-10rpx"></text></view>
  527 + </view>
  528 + </view>
  529 + </block>
  530 +
  531 +
510 532 <view class="bz_view flex bdt16" wx:if="{{bconfig}}" style="">
511 533 <image class="bzfu_img" src="{{iurl}}/miniapp/images/bzfu_w.png"></image>
512 534 <view class="flex f1 ai_c rel">
... ...