result.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <!-- 支付结果页面 -->
  2. <template>
  3. <s-layout title="支付结果" :bgStyle="{ color: '#FFF' }">
  4. <view class="pay-result-box ss-flex-col ss-row-center ss-col-center">
  5. <view class="pay-waiting ss-m-b-30" v-if="payResult === 'waiting'"> </view>
  6. <image
  7. class="pay-img ss-m-b-30"
  8. v-if="payResult === 'success'"
  9. :src="sheep.$url.static('/static/img/shop/order/order_pay_success.gif')"
  10. ></image>
  11. <image
  12. class="pay-img ss-m-b-30"
  13. v-if="['failed', 'closed'].includes(payResult)"
  14. :src="sheep.$url.static('/static/img/shop/order/order_paty_fail.gif')"
  15. ></image>
  16. <view class="tip-text ss-m-b-30" v-if="payResult == 'success'">支付成功</view>
  17. <view class="tip-text ss-m-b-30" v-if="payResult == 'failed'">支付失败</view>
  18. <view class="tip-text ss-m-b-30" v-if="payResult == 'closed'">该订单已关闭</view>
  19. <view class="tip-text ss-m-b-30" v-if="payResult == 'waiting'">检测支付结果...</view>
  20. <view class="pay-total-num ss-flex" v-if="payResult === 'success'">
  21. <view v-if="Number(state.orderInfo.pay_fee) > 0">¥{{ state.orderInfo.pay_fee }}</view>
  22. <view v-if="state.orderInfo.score_amount && Number(state.orderInfo.pay_fee) > 0">+</view>
  23. <view class="price-text ss-flex ss-col-center" v-if="state.orderInfo.score_amount">
  24. <image
  25. :src="sheep.$url.static('/static/img/shop/goods/score1.svg')"
  26. class="score-img"
  27. ></image>
  28. <view>{{ state.orderInfo.score_amount }}</view>
  29. </view>
  30. </view>
  31. <view class="btn-box ss-flex ss-row-center ss-m-t-50">
  32. <button class="back-btn ss-reset-button" @tap="sheep.$router.go('/pages/index/index')">
  33. 返回首页
  34. </button>
  35. <button
  36. class="check-btn ss-reset-button"
  37. v-if="payResult === 'failed'"
  38. @tap="sheep.$router.redirect('/pages/pay/index', { orderSN: state.orderId })"
  39. >
  40. 重新支付
  41. </button>
  42. <button
  43. class="check-btn ss-reset-button"
  44. v-if="payResult === 'success'"
  45. @tap="sheep.$router.redirect('/pages/order/list')"
  46. >
  47. 查看订单
  48. </button>
  49. <button
  50. class="check-btn ss-reset-button"
  51. v-if="
  52. payResult === 'success' &&
  53. ['groupon', 'groupon_ladder'].includes(state.orderInfo.activity_type)
  54. "
  55. @tap="sheep.$router.redirect('/pages/activity/groupon/order')"
  56. >
  57. 我的拼团
  58. </button>
  59. </view>
  60. <!-- #ifdef MP -->
  61. <view class="subscribe-box ss-flex ss-m-t-44">
  62. <image
  63. class="subscribe-img"
  64. :src="sheep.$url.static('/static/img/shop/order/cargo.png')"
  65. ></image>
  66. <view class="subscribe-title ss-m-r-48 ss-m-l-16">获取实时发货信息与订单状态</view>
  67. <view class="subscribe-start" @tap="subscribeMessage">立即订阅</view>
  68. </view>
  69. <!-- #endif -->
  70. </view>
  71. </s-layout>
  72. </template>
  73. <script setup>
  74. import { onLoad } from '@dcloudio/uni-app';
  75. import { reactive, computed } from 'vue';
  76. import sheep from '@/sheep';
  77. const state = reactive({
  78. orderId: 0,
  79. orderType: 'goods',
  80. result: 'unpaid', // 支付状态
  81. orderInfo: {}, // 订单详情
  82. counter: 0, // 获取结果次数
  83. });
  84. const payResult = computed(() => {
  85. if (state.result === 'unpaid') {
  86. return 'waiting';
  87. }
  88. if (state.result === 'paid') {
  89. return 'success';
  90. }
  91. if (state.result === 'failed') {
  92. return 'failed';
  93. }
  94. if (state.result === 'closed') {
  95. return 'closed';
  96. }
  97. });
  98. async function getOrderInfo(orderId) {
  99. let checkPayResult;
  100. state.counter++;
  101. if (state.orderType === 'recharge') {
  102. checkPayResult = sheep.$api.trade.order;
  103. } else {
  104. checkPayResult = sheep.$api.order.detail;
  105. }
  106. const { data, error } = await checkPayResult(orderId);
  107. if (error === 0) {
  108. state.orderInfo = data;
  109. if (state.orderInfo.status === 'closed') {
  110. state.result = 'closed';
  111. return;
  112. }
  113. if (state.orderInfo.status !== 'unpaid') {
  114. state.result = 'paid';
  115. // #ifdef MP
  116. subscribeMessage();
  117. // #endif
  118. return;
  119. }
  120. }
  121. if (state.counter < 3 && state.result === 'unpaid') {
  122. setTimeout(() => {
  123. getOrderInfo(orderId);
  124. }, 1000);
  125. }
  126. // 超过三次检测才判断为支付失败
  127. if (state.counter >= 3) {
  128. state.result = 'failed';
  129. }
  130. }
  131. // #ifdef MP
  132. function subscribeMessage() {
  133. let event = ['order_dispatched'];
  134. if (['groupon', 'groupon_ladder'].includes(state.orderInfo.activity_type)) {
  135. event.push('groupon_finish');
  136. event.push('groupon_fail');
  137. }
  138. sheep.$platform.useProvider('wechat').subscribeMessage(event);
  139. }
  140. // #endif
  141. onLoad(async (options) => {
  142. let id = '';
  143. // 支付订单号
  144. if (options.orderSN) {
  145. id = options.orderSN;
  146. }
  147. if (options.orderType === 'recharge') {
  148. state.orderType = 'recharge';
  149. }
  150. if (options.id) {
  151. id = options.id;
  152. }
  153. state.orderId = id;
  154. // 支付结果传值过来是失败,则直接显示失败界面
  155. if (options.payState === 'fail') {
  156. state.result = 'failed';
  157. } else {
  158. // 轮询三次检测订单支付结果
  159. getOrderInfo(id);
  160. }
  161. });
  162. </script>
  163. <style lang="scss" scoped>
  164. @keyframes rotation {
  165. 0% {
  166. transform: rotate(0deg);
  167. }
  168. 100% {
  169. transform: rotate(360deg);
  170. }
  171. }
  172. .score-img {
  173. width: 36rpx;
  174. height: 36rpx;
  175. margin: 0 4rpx;
  176. }
  177. .pay-result-box {
  178. padding: 60rpx 0;
  179. .pay-waiting {
  180. margin-top: 20rpx;
  181. width: 60rpx;
  182. height: 60rpx;
  183. border: 10rpx solid rgb(233, 231, 231);
  184. border-bottom-color: rgb(204, 204, 204);
  185. border-radius: 50%;
  186. display: inline-block;
  187. // -webkit-animation: rotation 1s linear infinite;
  188. animation: rotation 1s linear infinite;
  189. }
  190. .pay-img {
  191. width: 130rpx;
  192. height: 130rpx;
  193. }
  194. .tip-text {
  195. font-size: 30rpx;
  196. font-weight: bold;
  197. color: #333333;
  198. }
  199. .pay-total-num {
  200. font-size: 36rpx;
  201. font-weight: 500;
  202. color: #333333;
  203. font-family: OPPOSANS;
  204. }
  205. .btn-box {
  206. width: 100%;
  207. .back-btn {
  208. width: 190rpx;
  209. height: 70rpx;
  210. font-size: 28rpx;
  211. border: 2rpx solid #dfdfdf;
  212. border-radius: 35rpx;
  213. font-weight: 400;
  214. color: #595959;
  215. }
  216. .check-btn {
  217. width: 190rpx;
  218. height: 70rpx;
  219. font-size: 28rpx;
  220. border: 2rpx solid #dfdfdf;
  221. border-radius: 35rpx;
  222. font-weight: 400;
  223. color: #595959;
  224. margin-left: 32rpx;
  225. }
  226. }
  227. .subscribe-box {
  228. .subscribe-img {
  229. width: 44rpx;
  230. height: 44rpx;
  231. }
  232. .subscribe-title {
  233. font-weight: 500;
  234. font-size: 32rpx;
  235. line-height: 36rpx;
  236. color: #434343;
  237. }
  238. .subscribe-start {
  239. color: var(--ui-BG-Main);
  240. font-weight: 700;
  241. font-size: 32rpx;
  242. line-height: 36rpx;
  243. }
  244. }
  245. }
  246. </style>