Няма описание

order.js 3.7KB

    const app = getApp() app.routerInterceptor.checkLoginStatus({ /** * Page initial data */ data: { hasAddress: false, goodsInfo: {}, address: {}, order_id: '', prepay_id: '', total: 0, amount: 1, isLoading: false }, onLoad(options) { wx.hideHomeButton() const that = this const { userInfo } = app.globalData this.getGoods(options) console.log(app) if (userInfo.consignee_name !== '' && userInfo.consignee_name !== null) { that.setData({ address: { userName: userInfo.consignee_name, telNumber: userInfo.consignee_phone, provinceName: userInfo.consignee_province, cityName: userInfo.consignee_city, countyName: userInfo.consignee_county, detailInfo: userInfo.consignee_address, combination: userInfo.consignee_province + userInfo.consignee_city + userInfo.consignee_county + userInfo.consignee_address }, hasAddress: true }) } }, getGoods(options) { const { room_id, goods_id, share_openid } = options const _self = this app.network.post({ url: app.urls.LIVE.GOODS_DETAIL, data: { goods_id, room_id }, success(res) { const { goods_info } = res.data if (goods_info.price_type === 3) { const tmp = goods_info.price goods_info.price = goods_info.price2 goods_info.price2 = tmp } _self.setData({ goodsInfo: goods_info, anchor_id: res.data.anchor_id, room_id, share_openid, goods_id, total: res.data.goods_info.price, isLoading: true }) } }) }, bindstepperChanged(e) { this.setData({ amount: e.detail, total: this.data.goodsInfo.price * e.detail }) }, navigateToAddress() { const that = this wx.chooseAddress({ success: res => { res.combination = res.provinceName + res.cityName + res.countyName + res.detailInfo that.setData({ address: res, hasAddress: true }) } }) }, confirm() { const that = this app.network.post({ url: app.urls.LIVE.ORDER_CREATE, data: { anchor_id: this.data.anchor_id, room_id: this.data.room_id, share_openid: this.data.share_openid, goods_id: this.data.goods_id, total_fee: this.data.total, amount: this.data.amount, name: this.data.address.userName || '', phone: this.data.address.telNumber || '', province: this.data.address.provinceName, city: this.data.address.cityName, county: this.data.address.countyName, address: this.data.address.detailInfo, body: '尖货接龙' }, success(res1) { const { wxpay_params } = res1.data that.setData({ order_id: res1.data.order_id, prepay_id: res1.data.prepay_id }) wx.requestPayment({ timeStamp: wxpay_params.timeStamp, nonceStr: wxpay_params.nonceStr, package: wxpay_params.package, signType: wxpay_params.signType, paySign: wxpay_params.paySign, success: _ => { wx.redirectTo({ url: '/template/resultView/resultView' }) }, fail: res2 => { if (res2.errMsg === 'requestPayment:fail cancel') { app.network.post({ url: app.urls.LIVE.ORDER_CANCEL, data: { order_id: that.data.order_id, prepay_id: that.data.prepay_id } }) } } }) } }) } })