1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
| <template> <view class="my-settle-container"> <!-- 全选 --> <label class="radio" @click="changeAllState"> <radio color="#FF0000" :checked="isFullCheck" /><text>全选</text> </label> <!-- 合计 --> <view class="amount-box"> 合计:<text class = "amount">${{checkedGoodsAmount}}</text> </view> <!-- 结算 --> <view class="btn-settle" @click="settlement"> 结算({{checkedCount}}) </view> </view> </template>
<script> import { mapGetters,mapMutations,mapState } from 'vuex' export default { computed:{ ...mapGetters('m_cart',['checkedCount','total','checkedGoodsAmount']), ...mapGetters('m_user',['addstr']), ...mapState('m_user',['token']), ...mapState('m_cart',['cart']), isFullCheck(){ return this.total === this.checkedCount } }, name:"my-settle", data() { return { seconds:3, timer:null }; }, methods:{ ...mapMutations('m_cart',['updateAllGoodsState']), ...mapMutations('m_user',['updateRedirectInfo']), changeAllState(){ this.updateAllGoodsState(!this.isFullCheck) }, // 三重判断 当用户点击了结算按钮 settlement(){ if(!this.checkedCount) return uni.$showMsg('请选择要结算的商品') if(!this.addstr) return uni.$showMsg('请选择收货地址') // if(!this.token) return uni.$showMsg('请先登录') if(!this.token) return this.delayNavigate() //实现微信支付功能 this.payOrder() }, async payOrder(){ const orderInfo = { order_price: 0.01,//写死总价格为0.01 checkedGoodsAmount真实总价格 consignee_addr: this.addstr, goods:this.cart.filter(x => x.goods_state).map(x=>({ goods_id: x.goods_id, goods_number: x.goods_count, goods_price: x.goods_price })), } const {data: res} = await uni.$http.post('/api/public/v1/my/orders/create',orderInfo) //if(res.meta.status !== 200)return uni.$showMsg('创建订单失败') //const orderNumber = res.message.order_number//获取订单编号 console.log(res) //console.log(orderNumber) //token有问题所以获取不到订单编号 代码思路没问题 //const orderNumber = 'GD20180504000000000045' const {data: res2} = await uni.$http.post('/api/public/v1/my/orders/req_unifiedorder',orderNumber) //if(res2.data.status !== 200)return uni.$showError('预付订单生成失败') console.log('------------------------') console.log(res2) //拿到订单预支付相关属性 //const payInfo = res2.message.pay const mes = await uni.requestPayment(payInfo) //错误检测······ if(err) return uni.$showMsg('error') const {data: res3} = await uni.$http.post('/api/public/v1/my/orders/chkOrder',{order_number: orederNumber}) //if(res3.data.status !== 200)return uni.$showError('订单未支付') uni.showToast({ title:'finish', icon:'success' }) //微信支付分三大步 // 1.生成订单基本信息发送服务器获取订单编号 token-->订单编号orderNumber // 2.订单预支付通过订单编号发送给服务器获取订单相关参数 订单编号-->订单相关参数payInfo // 3.通过订单相关参数发起支付请求 订单相关参数payInfo--->uni.requestPayment(payInfo) // 注意每一步应该做好错误检测 }, // 展示倒计时提示消息 showTips(n){ uni.showToast({ icon:'none', title:'请登陆后结算'+n+'秒后自动跳转到登录页面', // 为页面贴加透明遮罩 防止点击穿透 mask:true, // 1.5s后自动消失 duration:1500 }) }, delayNavigate(){ this.seconds = 3 this.showTips(this.seconds) // 创建定时器 每隔一秒执行一次 this.timer = setInterval(()=>{ this.seconds-- if(this.seconds <= 0){ //清除计时器 clearInterval(this.timer) uni.switchTab({ url:'/pages/my/my', success:()=>{ this.updateRedirectInfo({ openType:'switchTab', from:'/pages/cart/cart' }) } }) // 秒数为0 不再展示计时器提示信息 return } this.showTips(this.seconds) },1000) } } } </script>
<style lang="scss"> .my-settle-container{ position: fixed; bottom:0; left:0; width: 100%; height: 50px; background-color: white; display: flex; justify-content: space-between; align-items: center; font-size: 14px; padding-left: 5px; .radio{ display: flex; align-items: center; } .amount-box{ .amount{ color: #FF0000; font-weight: bold; } } .btn-settle{ background-color: #FF0000; height:50px; color:white; line-height: 50px; padding:0 10px; min-width: 100px; text-align: center; } } </style>
|