result.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <!-- 支付结果页 -->
  2. <template>
  3. <view class="success-page">
  4. <!-- 商品结果页 -->
  5. <template v-if="orderType==='goods'">
  6. <view class="success-box u-flex-col u-row-center u-col-center">
  7. <image class="pay-img" :src="payImg[payState]" mode=""></image>
  8. <text class="notice">{{ payText[payState] }}</text>
  9. <text class="pay-money"
  10. v-if="payState === 'success' && orderDetail.total_fee">¥{{ orderDetail.total_fee }}</text>
  11. <view class="btn-box u-flex u-row-between">
  12. <block
  13. v-if="payState === 'success' && orderDetail.activity_type === 'groupon' && orderDetail.ext_arr.buy_type === 'groupon'">
  14. <button class="u-reset-button base-btn" v-if="orderDetail.ext_arr.groupon_id > 0"
  15. @tap="$Router.replace({ path: '/pages/activity/groupon/detail', query: { id: orderDetail.ext_arr.groupon_id } })">
  16. 拼团详情
  17. </button>
  18. <button class="u-reset-button base-btn" v-else
  19. @tap="$Router.push('/pages/activity/groupon/my-groupon')">我的拼团</button>
  20. </block>
  21. <button class="u-reset-button base-btn" v-else
  22. @tap="$Router.pushTab('/pages/index/index')">返回首页</button>
  23. <button class="u-reset-button base-btn u-m-l-10 u-m-r-10"
  24. @tap="$Router.replace({ path: '/pages/order/detail', query: { id: orderDetail.id } })">查看订单</button>
  25. <button class="u-reset-button again-pay " v-show="payState === 'fail'" @tap="onPay">重新支付</button>
  26. </view>
  27. </view>
  28. <!-- modal -->
  29. <!-- #ifdef MP-WEIXIN -->
  30. <u-modal v-if="payState === 'success'" ref="uModal" v-model="showModal" :show-cancel-button="true"
  31. confirm-color="#e9b461" cancel-color="#666666" @confirm="onConfirm" confirm-text="订阅消息" cancel-text="取消"
  32. content="是否订阅消息,追踪订单信息?" title="提示"></u-modal>
  33. <!-- #endif -->
  34. </template>
  35. <template v-if="orderType==='recharge'">
  36. <view class="success-box u-flex-col u-row-center u-col-center">
  37. <image class="pay-img" :src="payImg[payState]" mode=""></image>
  38. <text class="notice">{{ payText[payState] }}</text>
  39. <text class="pay-money"
  40. v-if="payState === 'success' && orderDetail.total_fee">¥{{ orderDetail.total_fee }}</text>
  41. <view class="btn-box u-flex u-row-between">
  42. <button class="u-reset-button base-btn" @tap="$Router.pushTab('/pages/index/index')">返回首页</button>
  43. <button v-if="payState === 'fail'" class="u-reset-button again-pay" @tap="onPay">重新支付</button>
  44. <button v-else class="u-reset-button base-btn"
  45. @tap="$Router.pushTab('/pages/index/user')">个人中心</button>
  46. </view>
  47. </view>
  48. </template>
  49. </view>
  50. </template>
  51. <script>
  52. import Pay from '@/shopro/pay';
  53. import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
  54. let payTimer = null;
  55. const payCount = 5;
  56. export default {
  57. components: {},
  58. data() {
  59. return {
  60. showModal: false,
  61. messageType: '',
  62. templateIds: [],
  63. wxOpenTags: '',
  64. orderDetail: {}, //订单详情
  65. orderType: '', //订单类型
  66. payText: {
  67. fail: '支付失败',
  68. success: '支付成功',
  69. paying: '查询中...'
  70. },
  71. payImg: {
  72. fail: this.$IMG_URL + '/imgs/order/order_pay_fail.gif',
  73. success: this.$IMG_URL + '/imgs/order/order_pay_success.gif',
  74. paying: this.$IMG_URL + '/imgs/order/order_paying.gif'
  75. },
  76. payState: '' //支付状态
  77. };
  78. },
  79. computed: {
  80. ...mapGetters(['subscribeMessageIdsMap'])
  81. },
  82. onLoad() {
  83. this.payState = this.$Route.query.payState ? this.$Route.query.payState : 'paying';
  84. this.orderType = this.$Route.query.orderType
  85. this.$Route.query.orderId && this.getOrderDetail();
  86. switch (this.payState) {
  87. case 'success':
  88. this.getCartList();
  89. break;
  90. case 'fail':
  91. break;
  92. case 'paying':
  93. this.checkTimer();
  94. break;
  95. default:
  96. break;
  97. }
  98. },
  99. onHide() {
  100. clearInterval(payTimer);
  101. payTimer = null;
  102. },
  103. methods: {
  104. ...mapActions(['getCartList']),
  105. // 订阅消息
  106. onConfirm() {
  107. // #ifdef MP-WEIXIN
  108. this.templateIds.length && this.$store.commit('subscribeMessage', this.messageType);
  109. // #endif
  110. },
  111. // 获取订单详情
  112. getOrderDetail() {
  113. switch (this.$Route.query.orderType) {
  114. case 'goods':
  115. this.getGoodsOrderDetail()
  116. break;
  117. case 'recharge':
  118. this.getRechargeOrderDetail()
  119. break;
  120. default:
  121. break;
  122. }
  123. },
  124. // 支付订单信息
  125. getGoodsOrderDetail() {
  126. let that = this;
  127. that.$http('order.detail', {
  128. id: that.$Route.query.orderId
  129. }).then(async res => {
  130. if (res.code === 1) {
  131. that.orderDetail = res.data;
  132. if (res.data.status > 0) {
  133. this.messageType = this.orderDetail.activity_type == 'groupon' ? 'grouponResult' :
  134. 'result';
  135. // #ifdef MP-WEIXIN
  136. this.templateIds = this.subscribeMessageIdsMap[this.messageType];
  137. this.showModal = this.templateIds.length;
  138. // #endif
  139. }
  140. }
  141. });
  142. },
  143. // 充值订单信息
  144. getRechargeOrderDetail() {
  145. let that = this;
  146. that.$http('money.rechargeDetail', {
  147. id: that.$Route.query.orderId
  148. }).then(res => {
  149. if (res.code === 1) {
  150. that.orderDetail = res.data;
  151. if (res.data.status > 0) {
  152. this.messageType = 'result';
  153. }
  154. }
  155. });
  156. },
  157. // 支付倒计时
  158. checkTimer() {
  159. let that = this;
  160. let count = 0;
  161. that.payState = 'paying';
  162. payTimer = setInterval(() => {
  163. count++;
  164. if (count < payCount) {
  165. that.checkPay();
  166. } else {
  167. clearInterval(payTimer);
  168. that.payState = 'fail';
  169. }
  170. }, 800);
  171. },
  172. // 检测支付
  173. async checkPay() {
  174. let that = this;
  175. let paiMap = {
  176. 'goods': 'order.detail',
  177. 'recharge': 'money.rechargeDetail'
  178. }
  179. let res = await that.$http(
  180. paiMap[that.orderType], {
  181. id: that.$Route.query.orderId
  182. },
  183. false
  184. );
  185. if (res.code === 1 && res.data.status > 0) {
  186. that.payState = 'success';
  187. clearInterval(payTimer);
  188. }
  189. },
  190. // 重新支付
  191. onPay() {
  192. let that = this;
  193. let pay = new Pay(that.$Route.query.type, that.orderDetail, that.orderType);
  194. }
  195. }
  196. };
  197. </script>
  198. <style lang="scss" scopeds>
  199. .success-box {
  200. background: #fff;
  201. width: 750rpx;
  202. padding: 40rpx 0;
  203. .pay-img {
  204. width: 130rpx;
  205. height: 130rpx;
  206. }
  207. .notice {
  208. font-size: 30rpx;
  209. font-weight: bold;
  210. color: rgba(51, 51, 51, 1);
  211. line-height: 30rpx;
  212. margin-top: 30rpx;
  213. }
  214. .pay-money {
  215. font-size: 36rpx;
  216. color: #ff3000;
  217. font-weight: 600;
  218. margin-top: 20rpx;
  219. }
  220. .btn-box {
  221. margin-top: 30rpx;
  222. width: 660rpx;
  223. .base-btn {
  224. width: 320rpx;
  225. line-height: 70rpx;
  226. background: rgba(255, 255, 255, 1);
  227. border: 1rpx solid rgba(223, 223, 223, 0.5);
  228. border-radius: 35rpx;
  229. font-size: 28rpx;
  230. font-weight: 400;
  231. color: rgba(153, 153, 153, 1);
  232. padding: 0;
  233. }
  234. .again-pay {
  235. width: 320rpx;
  236. line-height: 70rpx;
  237. background: linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1));
  238. box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
  239. border-radius: 35rpx;
  240. font-size: 28rpx;
  241. font-weight: 400;
  242. color: rgba(255, 255, 255, 0.8);
  243. padding: 0;
  244. }
  245. }
  246. }
  247. .hot-box {
  248. background: #fff;
  249. padding: 20rpx;
  250. margin-top: 20rpx;
  251. .hot-title {
  252. font-size: 30rpx;
  253. font-weight: 500;
  254. color: rgba(51, 51, 51, 1);
  255. height: 80rpx;
  256. }
  257. }
  258. </style>