result.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <!-- 支付结果页面 -->
  2. <template>
  3. <s-layout :title="$t('pay.payresult.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('/assets/addons/shopro/uniapp/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('/assets/addons/shopro/uniapp/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' ? $t('pay.payresult.orderSuccess') : $t('pay.payresult.paySuccess')
  18. }}</view>
  19. <view class="tip-text ss-m-b-30" v-if="payResult == 'failed'">{{$t('pay.payresult.payFailed')}}</view>
  20. <view class="tip-text ss-m-b-30" v-if="payResult == 'closed'">{{$t('pay.payresult.orderClosed')}}</view>
  21. <view class="tip-text ss-m-b-30" v-if="payResult == 'waiting'">{{$t('pay.payresult.checkPay')}}</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('/assets/addons/shopro/uniapp/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. {{$t('pay.payresult.backHome')}}
  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. {{$t('pay.payresult.repay')}}
  43. </button>
  44. <button
  45. class="check-btn ss-reset-button"
  46. v-if="payResult === 'success'"
  47. @tap="onOrder"
  48. >
  49. {{$t('pay.payresult.viewOrder')}}
  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. {{$t('pay.payresult.myGroup')}}
  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('/assets/addons/shopro/uniapp/order/cargo.png')"
  67. ></image>
  68. <view class="subscribe-title ss-m-r-48 ss-m-l-16">{{$t('pay.payresult.getInfo')}}</view>
  69. <view class="subscribe-start" @tap="subscribeMessage">{{$t('pay.payresult.subscribe')}}</view>
  70. </view>
  71. <!-- #endif -->
  72. </view>
  73. </s-layout>
  74. </template>
  75. <script setup>
  76. import { onLoad, onHide, onShow } from '@dcloudio/uni-app';
  77. import { reactive, computed } from 'vue';
  78. import { isEmpty } from 'lodash';
  79. import sheep from '@/sheep';
  80. const state = reactive({
  81. orderId: 0,
  82. orderType: 'goods',
  83. result: 'unpaid', // 支付状态
  84. orderInfo: {}, // 订单详情
  85. counter: 0, // 获取结果次数
  86. });
  87. const payResult = computed(() => {
  88. if (state.result === 'unpaid') {
  89. return 'waiting';
  90. }
  91. if (state.result === 'paid') {
  92. return 'success';
  93. }
  94. if (state.result === 'failed') {
  95. return 'failed';
  96. }
  97. if (state.result === 'closed') {
  98. return 'closed';
  99. }
  100. });
  101. async function getOrderInfo(orderId) {
  102. let checkPayResult;
  103. state.counter++;
  104. if (state.orderType === 'recharge') {
  105. checkPayResult = sheep.$api.trade.order;
  106. } else {
  107. checkPayResult = sheep.$api.order.detail;
  108. }
  109. const { data, code } = await checkPayResult(orderId);
  110. if (code === 1) {
  111. state.orderInfo = data;
  112. if (state.orderInfo.status === 'closed') {
  113. state.result = 'closed';
  114. return;
  115. }
  116. if (state.orderInfo.status !== 'unpaid') {
  117. state.result = 'paid';
  118. // #ifdef MP
  119. subscribeMessage();
  120. // #endif
  121. return;
  122. }
  123. }
  124. if (state.counter < 3 && state.result === 'unpaid') {
  125. setTimeout(() => {
  126. getOrderInfo(orderId);
  127. }, 1500);
  128. }
  129. // 超过三次检测才判断为支付失败
  130. if (state.counter >= 3) {
  131. state.result = 'failed';
  132. }
  133. }
  134. function onOrder() {
  135. if(state.orderType === 'recharge') {
  136. sheep.$router.redirect('/pages/pay/recharge-log');
  137. }else {
  138. sheep.$router.redirect('/pages/order/list');
  139. }
  140. }
  141. // #ifdef MP
  142. function subscribeMessage() {
  143. let event = ['order_dispatched'];
  144. if (['groupon', 'groupon_ladder'].includes(state.orderInfo.activity_type)) {
  145. event.push('groupon_finish');
  146. event.push('groupon_fail');
  147. }
  148. sheep.$platform.useProvider('wechat').subscribeMessage(event);
  149. }
  150. // #endif
  151. onLoad(async (options) => {
  152. let id = '';
  153. // 支付订单号
  154. if (options.orderSN) {
  155. id = options.orderSN;
  156. }
  157. if (options.id) {
  158. id = options.id;
  159. }
  160. state.orderId = id;
  161. if (options.orderType === 'recharge') {
  162. state.orderType = 'recharge';
  163. }
  164. // 支付结果传值过来是失败,则直接显示失败界面
  165. if (options.payState === 'fail') {
  166. state.result = 'failed';
  167. } else {
  168. // 轮询三次检测订单支付结果
  169. getOrderInfo(state.orderId);
  170. }
  171. });
  172. onShow(() => {
  173. if(isEmpty(state.orderInfo)) return;
  174. getOrderInfo(state.orderId);
  175. })
  176. onHide(() => {
  177. state.result = 'unpaid';
  178. state.counter = 0;
  179. });
  180. </script>
  181. <style lang="scss" scoped>
  182. @keyframes rotation {
  183. 0% {
  184. transform: rotate(0deg);
  185. }
  186. 100% {
  187. transform: rotate(360deg);
  188. }
  189. }
  190. .score-img {
  191. width: 36rpx;
  192. height: 36rpx;
  193. margin: 0 4rpx;
  194. }
  195. .pay-result-box {
  196. padding: 60rpx 0;
  197. .pay-waiting {
  198. margin-top: 20rpx;
  199. width: 60rpx;
  200. height: 60rpx;
  201. border: 10rpx solid rgb(233, 231, 231);
  202. border-bottom-color: rgb(204, 204, 204);
  203. border-radius: 50%;
  204. display: inline-block;
  205. // -webkit-animation: rotation 1s linear infinite;
  206. animation: rotation 1s linear infinite;
  207. }
  208. .pay-img {
  209. width: 130rpx;
  210. height: 130rpx;
  211. }
  212. .tip-text {
  213. font-size: 30rpx;
  214. font-weight: bold;
  215. color: #333333;
  216. }
  217. .pay-total-num {
  218. font-size: 36rpx;
  219. font-weight: 500;
  220. color: #333333;
  221. font-family: OPPOSANS;
  222. }
  223. .btn-box {
  224. width: 100%;
  225. .back-btn {
  226. width: 190rpx;
  227. height: 70rpx;
  228. font-size: 28rpx;
  229. border: 2rpx solid #dfdfdf;
  230. border-radius: 35rpx;
  231. font-weight: 400;
  232. color: #595959;
  233. }
  234. .check-btn {
  235. width: 190rpx;
  236. height: 70rpx;
  237. font-size: 28rpx;
  238. border: 2rpx solid #dfdfdf;
  239. border-radius: 35rpx;
  240. font-weight: 400;
  241. color: #595959;
  242. margin-left: 32rpx;
  243. }
  244. }
  245. .subscribe-box {
  246. .subscribe-img {
  247. width: 44rpx;
  248. height: 44rpx;
  249. }
  250. .subscribe-title {
  251. font-weight: 500;
  252. font-size: 32rpx;
  253. line-height: 36rpx;
  254. color: #434343;
  255. }
  256. .subscribe-start {
  257. color: var(--ui-BG-Main);
  258. font-weight: 700;
  259. font-size: 32rpx;
  260. line-height: 36rpx;
  261. }
  262. }
  263. }
  264. </style>