const app = getApp(); 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() { this.setData({ shopInfo: app.shopInfo }); }, onShow: function() { var _this = this; _this.jsjg(); //获取收货地址 _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.msActivitInfo.siPrice, cartNumber: orderMsg.cartNumber, }], orderMsg: orderMsg, }); //调用接口计算价格 var goods = this.data.goodsList[0]; let actId = _this.data.orderMsg.msActivitInfo.id; var sendData = { id: actId,//活动id addressId: _this.data.address.addrId, //收货地址ID count: goods.cartNumber, shopId: app.shopInfo.id, shippingMethod: this.data.deliverySelect, } util.request({ api: api.seckill.calSecKillPrice, data: sendData, callback: function (data) { _this.setData({ discountExplain: { billPrice: data.mapInfo.totalPrice, postage: data.mapInfo.postage, payPrice:data.mapInfo.postage + 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() { 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]; let actId = _this.data.orderMsg.msActivitInfo.id; var sendData = { id: actId,//活动id addressId: _this.data.address.addrId, //收货地址ID count: goods.cartNumber, shopId: app.shopInfo.id, shippingMethod: this.data.deliverySelect, } util.request({ api: api.seckill.createSecKill, 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) { if (payRes.mapInfo.status == 'success') { wx.redirectTo({ url: '../payOrder/paySuccess', }); } 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() { wx.redirectTo({ url: '../order/order?status=1', }) } }); } }); }, // 进入收货地址列表 goAddress() { wx.navigateTo({ url: '../editAddress/editAddress?pageScen=2', }) }, // 进入添加收货地址 addAddress() { wx.navigateTo({ url: '../editAddress/editAddress?pageScen=2', }) }, //设置地址 setAddress(address) { this.setData({ "address": address, hasAddress: true }); }, //隐藏弹窗 popupTap() { this.setData({ couponsShow: false, isShow: false }) }, total() { 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 }) } } }); }, // 不使用优惠券按钮 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() { this.setData({ couponsShow: true, isShow: true }) }, //优惠券 radioCouponsChange(e) { }, //优惠券选择 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(); }, })