/* * 手太欠 * 愿这世界都如故事里一样 美好而动人~ */ Page({ /** * 页面的初始数据 */ data: { listType : 'unpay', //unpay待付款, paid待发货,delivered已发货,signed已签收 completed已完成 orderArr : [], //订单列表 disabled : false, surplus : '', // 水滴数量 orderNo : '', // 订单编号 payEject : false, // 支付弹出 payType : 'wechat' //支付类型 wechat微信 water水滴兑换 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ listType: options.listType }) }, /** * 生命周期函数--监听页面显示 */ onShow() { // 获取订单列表 this.ordersInfo(); // 获取用户信息 this.userInfo(); }, /** * 用户信息 */ userInfo() { wx.$api.user.home().then(res => { this.setData({ surplus : res.data.account.score.surplus }) }).catch(err => {}) }, /** * 订单列表 */ ordersInfo(page) { wx.$api.user.orders({ state: this.data.listType, page : page }).then(res => { let listArr = this.data.orderArr, newData = [] if(page == 1 || page == undefined) listArr = [] newData = listArr.concat(res.data.data) this.setData({ orderArr : newData, page : res.data.page, lodingStats : false }) wx.stopPullDownRefresh() }).catch(err => {}) }, /** * 状态筛选 */ onTabs(val){ if(this.data.listType === val) return this.setData({ listType: val.currentTarget.dataset.type }) // 商品详情数据 this.ordersInfo(); }, /** * 选择支付方式 */ radioChange(e) { this.setData({ payType : e.detail.value }) }, /** * 立即付款 */ payTap(e) { this.setData({ orderNo: e.currentTarget.dataset.no, payEject: true }) }, /** * 立即付款-弹出关闭 */ payClose() { this.setData({ payEject: false }) }, // 支付提交 paySubmit() { this.setData({ payEject: false }) if(this.data.payType == 'wechat') { this.wxPay() return } // this.data.payType == water 为水滴兑换 this.waterPay() }, // 微信支付 wxPay() { wx.showLoading({ title: '支付中...', mask : true }) let that = this wx.login({ success: res => { wx.$api.member.openid(res).then(openidRes => { wx.$api.member.wechatPay(this.data.orderNo, { type : 'miniapp', openid : openidRes.data }).then(PayRes => { wx.hideLoading() this.setData({ disabled : true }) let payInfo = JSON.parse(PayRes.data.wechat) wx.requestPayment({ timeStamp: payInfo.timeStamp, nonceStr : payInfo.nonceStr, package : payInfo.package, paySign : payInfo.paySign, signType : payInfo.signType, success : payInfoRes=>{ if(payInfoRes.errMsg == "requestPayment:ok"){ wx.showToast({ title: '支付成功', icon: 'none', duration: 2000, //显示透明蒙层,防止触摸穿透 mask:true, success: function () { // 获取订单列表 that.ordersInfo(); } }) } }, fail : res=>{ wx.showToast({ title: '支付失败', icon: 'none', duration: 500, //显示透明蒙层,防止触摸穿透 mask:true, success: function () { // 获取订单列表 that.ordersInfo(); that.setData({ listType: 'unpay' }) } }) } }) }).catch(err => {}) }).catch(err => {}) } }) }, // 水滴兑换 waterPay() { wx.showLoading({ title: '水滴兑换中...', mask : true }) let that = this wx.$api.mall.affirmPay(this.data.orderNo, {gateway: 'miniapp'}).then(res => { wx.hideLoading() this.setData({ disabled : true }) wx.showToast({ title: '兑换成功', icon: 'none', duration: 2000, //显示透明蒙层,防止触摸穿透 mask:true, success: function () { // 获取订单列表 that.ordersInfo(); that.setData({ listType: 'unpay' }) } }) }).catch(err => {}) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { // 获取订单列表 this.ordersInfo(); }, /** * 上拉加载 */ onReachBottom(){ this.setData({ lodingStats: true }) let pageNumber = this.data.page.current if(this.data.page.has_more){ pageNumber++ // 获取订单列表 this.ordersInfo(pageNumber); } } })