const app = getApp(); 
 | 
  
 | 
//拼团订单 
 | 
const SHOW_MODEL_GROUP = 2; 
 | 
//拼团订单结束 
 | 
const SHOW_MODEL_GROUP_END = 3; 
 | 
  
 | 
var util = require('../../utils/util.js'); 
 | 
var api = require('../../utils/service-api.js'); 
 | 
Page({ 
 | 
  
 | 
  data: { 
 | 
    address: {}, 
 | 
    addrDefault: "", 
 | 
    hasAddress: false, 
 | 
    total: 0, 
 | 
    couponsShow: false, //优惠券 
 | 
    delivery: [], 
 | 
    key: 0, 
 | 
    keydelivery: 0, 
 | 
    isShow: true, 
 | 
    selected: "", 
 | 
    hidden: false, 
 | 
    goodsList: [], 
 | 
    skuList: [], 
 | 
    usefulCoupon: [], 
 | 
    coupons: '暂无可用优惠券', // 优惠券金额 
 | 
    couponReceiveId: null, // 优惠券Id 
 | 
    postage: '', //邮费 
 | 
    showCoupon: false, //是否存在优惠券 
 | 
    carId: '', //购物车id 
 | 
    buttonClicked: false, 
 | 
    checkedValue: false, 
 | 
    deliverySelect: "物流配送", 
 | 
    qsfy: "", 
 | 
    pageScen: "", 
 | 
    discountExplain: {}, 
 | 
    shopInfo: {}, 
 | 
  }, 
 | 
  
 | 
  onLoad(options) { 
 | 
    var _this = this; 
 | 
  
 | 
    this.setData({ 
 | 
      shopInfo: app.shopInfo 
 | 
    }); 
 | 
  
 | 
  }, 
 | 
  
 | 
  onShow: function() { 
 | 
    var _this = this; 
 | 
     
 | 
  
 | 
    //获取收货地址 
 | 
    _this.getAddress(); 
 | 
  
 | 
  }, 
 | 
  
 | 
  
 | 
  //计算订单价格 
 | 
  jsjg() { 
 | 
    var _this = this; 
 | 
    let orderMsg = util.getOutStorage("orderMsg"); 
 | 
    let goodsInfo = orderMsg.goodsInfo;  
 | 
  
 | 
     
 | 
    _this.setData({ 
 | 
      goodsList: [{ 
 | 
        imgMobile: goodsInfo.imgMobile, 
 | 
        title: goodsInfo.title, 
 | 
        name: orderMsg.specification, 
 | 
        price: orderMsg.currentGrooupPrice.gpPrice, 
 | 
        gpHeadPrice:orderMsg.currentGrooupPrice.gpHeadPrice, 
 | 
        cartNumber: orderMsg.cartNumber, 
 | 
      }], 
 | 
      orderMsg: orderMsg, 
 | 
    }); 
 | 
  
 | 
  
 | 
    //调用接口计算价格 
 | 
    var goods = this.data.goodsList[0]; 
 | 
    var couponReceiveId = _this.data.couponReceiveId; 
 | 
  
 | 
    let gpId = _this.data.orderMsg.currentGrooupPrice.id; 
 | 
    let actId = _this.data.orderMsg.currentGrooupPrice.actId; 
 | 
  
 | 
  
 | 
  
 | 
    var sendData = { 
 | 
      actId: actId,//活动id 
 | 
      gpId: gpId,//几人团 
 | 
      addressId: _this.data.address.addrId, //收货地址ID  
 | 
      remarks: _this.data.txtContent, 
 | 
      skuId: goods.cartSkuId, 
 | 
      productId: goods.cartProductId, 
 | 
      count: goods.cartNumber, 
 | 
      shopId: app.shopInfo.id, 
 | 
      shippingMethod: this.data.deliverySelect, 
 | 
    } 
 | 
    if (_this.data.orderMsg.gjId) {  
 | 
      sendData.gjId = _this.data.orderMsg.gjId; 
 | 
    } 
 | 
  
 | 
  
 | 
    util.request({ 
 | 
      api: api.groupBuy.calPrice, 
 | 
      data: sendData, 
 | 
      callback: function (data) { 
 | 
        console.log(data); 
 | 
  
 | 
        
 | 
  
 | 
       _this.setData({ 
 | 
         discountExplain: { 
 | 
           billPrice: data.mapInfo.billPrice, 
 | 
           postage: data.mapInfo.postage,  
 | 
           payPrice:data.mapInfo.totalPrice 
 | 
         }, 
 | 
       }); 
 | 
  
 | 
  
 | 
  
 | 
      } 
 | 
    }); 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  }, 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  mySelect(e) { 
 | 
    var name = e.currentTarget.dataset.name 
 | 
    this.setData({ 
 | 
      tihuoWay: name, 
 | 
      select: false 
 | 
    }) 
 | 
  }, 
 | 
  
 | 
  //获取textarea里的值 
 | 
  txtInput(e) { 
 | 
    this.setData({ 
 | 
      txtContent: e.detail.value 
 | 
    }) 
 | 
  }, 
 | 
  
 | 
  
 | 
  onShowText(e) { 
 | 
    this.setData({ 
 | 
      isShow: true, 
 | 
    }) 
 | 
  }, 
 | 
  
 | 
  
 | 
  onReady() { 
 | 
    this.getTotalPrice(); 
 | 
  }, 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  /** 
 | 
   * 计算总价 
 | 
   */ 
 | 
  getTotalPrice() { 
 | 
  
 | 
  }, 
 | 
  
 | 
  
 | 
  bindTextAreaBlur(event) { 
 | 
    var value = event.detail.value; 
 | 
    this.setData({ 
 | 
      txtContent: value, 
 | 
    }); 
 | 
  }, 
 | 
  
 | 
  
 | 
  // 支付 
 | 
  startPayment() { 
 | 
  
 | 
  
 | 
    var _this = this; 
 | 
    if (!_this.data.address) { 
 | 
      wx.showToast({ 
 | 
        title: "请选择收货地址", 
 | 
        icon: "none" 
 | 
      }); 
 | 
      return; 
 | 
    } 
 | 
  
 | 
  
 | 
    wx.showLoading({ 
 | 
      title: '加载中', 
 | 
      mask: true, 
 | 
      duration: 2000 
 | 
    }); 
 | 
  
 | 
    util.buttonClicked(this); 
 | 
  
 | 
    var goods = this.data.goodsList[0]; 
 | 
    var couponReceiveId = _this.data.couponReceiveId; 
 | 
  
 | 
    let gpId = _this.data.orderMsg.currentGrooupPrice.id; 
 | 
    let actId = _this.data.orderMsg.currentGrooupPrice.actId; 
 | 
  
 | 
  
 | 
  
 | 
    var sendData = { 
 | 
      actId: actId, //活动id 
 | 
      gpId: gpId, //几人团 
 | 
      addressId: _this.data.address.addrId, //收货地址ID  
 | 
      remarks: _this.data.txtContent, 
 | 
      skuId: goods.cartSkuId, 
 | 
      productId: goods.cartProductId, 
 | 
      count: goods.cartNumber, 
 | 
      shopId: app.shopInfo.id, 
 | 
      shippingMethod: this.data.deliverySelect, 
 | 
    } 
 | 
  
 | 
    console.log("订单请求参数", sendData) 
 | 
    var url = api.groupBuy.createGroupBuy; 
 | 
    if (_this.data.orderMsg.gjId) { 
 | 
  
 | 
      //存在指定团队,则调用加入该团的接口 
 | 
      url = api.groupBuy.joinGroupBuy; 
 | 
  
 | 
      sendData.gjId = _this.data.orderMsg.gjId; 
 | 
    } 
 | 
  
 | 
    util.request({ 
 | 
      api: url, 
 | 
      data: sendData, 
 | 
      callback: function(data) { 
 | 
        wx.requestPayment({ 
 | 
          'timeStamp': data.rows[0].timeStamp, 
 | 
          'nonceStr': data.rows[0].nonceStr, 
 | 
          'package': data.rows[0].prepay_id, 
 | 
          'signType': 'MD5', 
 | 
          'paySign': data.rows[0].paySign, 
 | 
          'success': function(res) { 
 | 
            // console.log(res.errMsg) 
 | 
            console.log("成功后的回调") 
 | 
            console.log(res) 
 | 
            if (res.errMsg == 'requestPayment:ok') { 
 | 
              // console.log(data.mapInfo.orderId); 
 | 
              //成功后的回调; 
 | 
              util.request({ 
 | 
                method: "GET", 
 | 
                api: '/wxapi/shopOrder/findOrderPayStatus/' + data.mapInfo.orderId, 
 | 
                mask: true, 
 | 
                callback: function(payRes) { 
 | 
                  debugger 
 | 
                  if (payRes.mapInfo.status == 'success') { 
 | 
  
 | 
                    //传输分享数据到订单成功页面 
 | 
                    var shareData = { 
 | 
                      id: actId, //活动id 
 | 
                      gpId: gpId, //几人团 
 | 
                      shopId: app.shopInfo.id, 
 | 
                      actId: actId, //活动id 
 | 
                      title: "[拼团]" + _this.data.goodsList[0].title, 
 | 
                      imageUrl: _this.data.goodsList[0].imgMobile, 
 | 
                      gjId:payRes.mapInfo.gjId, 
 | 
  
 | 
                    }; 
 | 
  
 | 
                    wx.setStorageSync("shareData", shareData); 
 | 
  
 | 
  
 | 
                    wx.redirectTo({ 
 | 
                      url: '../payOrder/paySuccess?showModel=' + payRes.mapInfo.groupBuyStatus, 
 | 
                    }); 
 | 
                    wx.showToast({ 
 | 
                      title: payRes.mapInfo.msg, 
 | 
                      icon: 'success' 
 | 
                    }) 
 | 
                  } else { 
 | 
                    wx.showToast({ 
 | 
                      title: payRes.mapInfo.msg, 
 | 
                      duration: 2000, 
 | 
                      image: "/image/fail.png" 
 | 
                    }) 
 | 
                    wx.redirectTo({ 
 | 
                      url: '../payOrder/payError', 
 | 
                    }) 
 | 
                  } 
 | 
                } 
 | 
              }); 
 | 
            } else { 
 | 
              // console.log("支付失败"); 
 | 
              wx.redirectTo({ 
 | 
                url: '../order/order', 
 | 
              }) 
 | 
            } 
 | 
            //{errMsg: "requestPayment:ok"} 
 | 
          }, 
 | 
  
 | 
          'fail': function(res) { 
 | 
            wx.redirectTo({ 
 | 
              url: '../order/order?status=1', 
 | 
            }) 
 | 
          } 
 | 
        }); 
 | 
  
 | 
  
 | 
  
 | 
      } 
 | 
    }); 
 | 
  }, 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  // 进入收货地址列表 
 | 
  goAddress(e) { 
 | 
    wx.navigateTo({ 
 | 
      url: '../editAddress/editAddress?pageScen=2', 
 | 
    }) 
 | 
  }, 
 | 
  
 | 
  
 | 
  
 | 
  // 进入添加收货地址 
 | 
  addAddress() { 
 | 
    wx.navigateTo({ 
 | 
      url: '../editAddress/editAddress?pageScen=2', 
 | 
    }) 
 | 
  }, 
 | 
  
 | 
  //设置地址 
 | 
  setAddress(address) { 
 | 
    debugger 
 | 
    this.setData({ 
 | 
      "address": address, 
 | 
      hasAddress: true 
 | 
    }); 
 | 
  }, 
 | 
  
 | 
  //隐藏弹窗 
 | 
  popupTap(e) { 
 | 
    this.setData({ 
 | 
      couponsShow: false, 
 | 
      isShow: false 
 | 
    }) 
 | 
  }, 
 | 
  total(e) { 
 | 
    this.setData({ 
 | 
      isShow: true 
 | 
    }) 
 | 
  }, 
 | 
  
 | 
  
 | 
  // 获取默认地址 
 | 
  getAddress() { 
 | 
    var _this = this; 
 | 
    util.request({ 
 | 
      api: api.address.queryaddress, 
 | 
      callback: function(data) { 
 | 
        if (data.rows.length != 0) { 
 | 
          _this.setData({ 
 | 
            address: data.rows[0], 
 | 
            hasAddress: true 
 | 
          }); 
 | 
        } else { 
 | 
          _this.setData({ 
 | 
            hasAddress: false 
 | 
          }) 
 | 
        } 
 | 
        _this.jsjg(); 
 | 
  
 | 
      } 
 | 
    }); 
 | 
  }, 
 | 
  
 | 
  // 不使用优惠券按钮 
 | 
  checkedTap: function() { 
 | 
    var checked = this.data.checkedValue; 
 | 
    var couponReceiveId = this.data.couponReceiveId; 
 | 
    if (!checked) { 
 | 
      couponReceiveId = 1 
 | 
      this.setData({ 
 | 
        coupons: '不使用优惠券', 
 | 
        couponReceiveId: couponReceiveId 
 | 
      }) 
 | 
    } 
 | 
    this.setData({ 
 | 
      checkedValue: !checked, 
 | 
      couponsShow: false 
 | 
    }) 
 | 
    this.jsjg(); 
 | 
  
 | 
  
 | 
  }, 
 | 
  
 | 
  //优惠券 
 | 
  couponsChoice(e) { 
 | 
    this.setData({ 
 | 
      couponsShow: true, 
 | 
      isShow: true 
 | 
    }) 
 | 
  }, 
 | 
  
 | 
  
 | 
  //优惠券 
 | 
  radioCouponsChange(e) { 
 | 
    var checked = e.detail.value; 
 | 
    var changed = {} 
 | 
  
 | 
  }, 
 | 
  //优惠券选择 
 | 
  couponsEvent(e) { 
 | 
    var _this = this; 
 | 
    var coupon = e.currentTarget.dataset.coupon; 
 | 
    var index = e.currentTarget.dataset.index; 
 | 
    var id = e.currentTarget.dataset.id; 
 | 
    var usefulCoupon = _this.data.usefulCoupon; 
 | 
    var changed = {}; 
 | 
    for (var i = 0; i < usefulCoupon.length; i++) { 
 | 
      if (i == index) { 
 | 
        changed['usefulCoupon[' + i + '].checked'] = true; 
 | 
  
 | 
      } else { 
 | 
        changed['usefulCoupon[' + i + '].checked'] = false 
 | 
      } 
 | 
    } 
 | 
    _this.setData(changed) 
 | 
    _this.setData({ 
 | 
      coupons: coupon.cName, 
 | 
      couponsShow: false, 
 | 
      isShow: false, 
 | 
      couponReceiveId: id, 
 | 
      checkedValue: false 
 | 
    }) 
 | 
  
 | 
    this.jsjg(); 
 | 
  }, 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
}) 
 |