method.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <!-- 收银台 -->
  2. <template>
  3. <view class="pay-method-wrap">
  4. <view class="u-flex-col u-col-center money-box" v-if="orderDetail.total_fee">
  5. <text class="time" v-show="isCountDown">{{ timeText }}</text>
  6. <view class="money">{{ orderDetail.total_fee }}</view>
  7. </view>
  8. <!-- 支付方式单选项 -->
  9. <u-radio-group v-if="paymentList && paymentList.length" class="pay-box" v-model="payType"
  10. active-color="#f0c785">
  11. <!-- 微信支付 -->
  12. <view class="u-flex u-row-between pay-item" v-show="paymentList.includes('wechat')"
  13. @tap="payType = 'wechat'">
  14. <view class="u-flex">
  15. <image class="pay-img" :src="$IMG_URL + '/imgs/order/order_wx_pay.png'" mode=""></image>
  16. <text>微信支付</text>
  17. </view>
  18. <u-radio shape="circle" name="wechat"></u-radio>
  19. </view>
  20. <!-- 支付宝支付 -->
  21. <view class="u-flex u-row-between pay-item" v-show="paymentList.includes('alipay')"
  22. @tap="payType = 'alipay'">
  23. <view class="u-flex">
  24. <image class="pay-img" :src="$IMG_URL + '/imgs/order/order_ali_pay.png'" mode=""></image>
  25. <text>支付宝支付</text>
  26. </view>
  27. <u-radio shape="circle" name="alipay"></u-radio>
  28. </view>
  29. <!-- 苹果支付 -->
  30. <view class="u-flex u-row-between pay-item" v-show="paymentList.includes('iospay') && appPlatfrom === 'ios'"
  31. @tap="payType = 'iospay'">
  32. <view class="u-flex">
  33. <image class="pay-img" :src="$IMG_URL + '/imgs/order/order_apple_pay.png'" mode=""></image>
  34. <text>ApplePay</text>
  35. </view>
  36. <u-radio shape="circle" name="iospay"></u-radio>
  37. </view>
  38. <!-- 余额支付 -->
  39. <view class="u-flex u-row-between pay-item" v-show="paymentList.includes('wallet')"
  40. @tap="payType = 'wallet'">
  41. <view class="u-flex">
  42. <image class="pay-img" :src="$IMG_URL + '/imgs/order/order_wallet_pay.png'" mode=""></image>
  43. <text>余额支付</text>
  44. </view>
  45. <u-radio shape="circle" name="wallet"></u-radio>
  46. </view>
  47. </u-radio-group>
  48. <button class="u-reset-button pay-btn" @tap="confirmPay">确认支付 ¥{{ orderDetail.total_fee || '0.00' }}</button>
  49. </view>
  50. </template>
  51. <script>
  52. /**
  53. * 接收商品订单orderType:goods,充值订单orderType:recharge
  54. */
  55. import Pay from '@/shopro/pay';
  56. import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
  57. let timer;
  58. export default {
  59. components: {},
  60. data() {
  61. return {
  62. payType: '', //支付方式
  63. isCountDown: true, //是否显示订单倒计时。
  64. orderDetail: {},
  65. timeText: '', //倒计时文本
  66. platform: this.$platform.get(),
  67. appPlatfrom: '',
  68. orderType: ''
  69. };
  70. },
  71. computed: {
  72. ...mapGetters(['initPayment', 'initRecharge']),
  73. paymentList() {
  74. let list = []
  75. switch (this.orderType) {
  76. case 'goods':
  77. list = this.initPayment
  78. break;
  79. case 'recharge':
  80. list = this.initPayment?.length && this.initPayment.filter(item => {
  81. if (this.initRecharge.methods.includes(item)) return item
  82. })
  83. break;
  84. default:
  85. list = this.initPayment
  86. break;
  87. }
  88. this.payType = list?. [0];
  89. return list
  90. },
  91. },
  92. onShow() {
  93. this.orderDetail.id && this.countDown();
  94. },
  95. onLoad() {
  96. this.orderType = this.$Route.query.orderType
  97. if (this.$platform.get() === 'wxOfficialAccount' && this.$platform.device() === 'ios' && this.$platform
  98. .entry() !== location.href) location.reload();
  99. // 获取订单详情
  100. this.getOrderDetail()
  101. },
  102. onHide() {
  103. clearInterval(timer);
  104. timer = null;
  105. },
  106. methods: {
  107. // 获取订单详情
  108. getOrderDetail() {
  109. switch (this.$Route.query.orderType) {
  110. case 'goods':
  111. this.getGoodsOrderDetail()
  112. break;
  113. case 'recharge':
  114. this.getRechargeOrderDetail()
  115. break;
  116. default:
  117. this.getGoodsOrderDetail()
  118. break;
  119. }
  120. },
  121. // 倒计时
  122. countDown() {
  123. let that = this;
  124. let t = parseInt(that.orderDetail.ext_arr.expired_time * 1000) - parseInt(new Date().getTime());
  125. t = t / 1000;
  126. timer = setInterval(() => {
  127. if (t > 0) {
  128. let time = that.$tools.format(t);
  129. that.timeText = `支付剩余时间 ${time.m}:${time.s}`;
  130. t--;
  131. } else {
  132. clearInterval(timer);
  133. that.timeText = '订单已过期!';
  134. }
  135. }, 1000);
  136. },
  137. // 发起支付
  138. confirmPay() {
  139. let that = this;
  140. let pay = null;
  141. if (!that.payType) {
  142. this.$u.toast('请选择支付方式');
  143. return;
  144. }
  145. if (that.payType === 'wallet') {
  146. uni.showModal({
  147. title: '支付提示',
  148. confirmColor: '#f0c785',
  149. content: `是否确认使用余额支付:${that.orderDetail.total_fee || '0.00'}元?`,
  150. success: res => {
  151. if (res.confirm) {
  152. pay = new Pay(that.payType, that.orderDetail, that.$Route.query.orderType);
  153. }
  154. }
  155. });
  156. } else {
  157. pay = new Pay(that.payType, that.orderDetail, that.$Route.query.orderType);
  158. }
  159. },
  160. // 支付商品订单信息
  161. getGoodsOrderDetail() {
  162. let that = this;
  163. that.$http('order.detail', {
  164. id: that.$Route.query.orderId
  165. }).then(res => {
  166. if (res.code === 1) {
  167. that.orderDetail = res.data;
  168. if (res.data.ext_arr !== null) {
  169. that.countDown();
  170. } else {
  171. that.isCountDown = false;
  172. }
  173. }
  174. });
  175. },
  176. // 充值订单信息
  177. getRechargeOrderDetail() {
  178. let that = this;
  179. that.$http('money.rechargeDetail', {
  180. id: that.$Route.query.orderId
  181. }).then(res => {
  182. if (res.code === 1) {
  183. that.orderDetail = res.data;
  184. if (res.data.ext_arr !== null) {
  185. that.countDown();
  186. } else {
  187. that.isCountDown = false;
  188. }
  189. }
  190. });
  191. }
  192. }
  193. };
  194. </script>
  195. <style lang="scss">
  196. .money-box {
  197. background: #fff;
  198. height: 250rpx;
  199. margin-bottom: 20rpx;
  200. padding-top: 30rpx;
  201. .time {
  202. font-size: 28rpx;
  203. color: #c4c4c4;
  204. }
  205. .money {
  206. color: #e1212b;
  207. font-size: 60rpx;
  208. margin-top: 60rpx;
  209. &::before {
  210. content: '¥';
  211. font-size: 46rpx;
  212. }
  213. }
  214. }
  215. .pay-box {
  216. .pay-item {
  217. height: 90rpx;
  218. padding: 0 30rpx;
  219. font-size: 26rpx;
  220. background: #fff;
  221. width: 750rpx;
  222. border-bottom: 1rpx solid #eeeeee;
  223. &:last-child {
  224. border-bottom: none;
  225. }
  226. .pay-img {
  227. width: 40rpx;
  228. height: 40rpx;
  229. margin-right: 25rpx;
  230. }
  231. }
  232. }
  233. .pay-btn {
  234. width: 690rpx;
  235. line-height: 80rpx;
  236. background: linear-gradient(90deg, rgba(240, 199, 133, 1), rgba(246, 214, 157, 1));
  237. border-radius: 40rpx;
  238. color: rgba(#fff, 0.9);
  239. margin: 100rpx auto 0;
  240. }
  241. </style>