result.vue 7.2 KB

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