resultYuan.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <!-- 支付结果页面 -->
  2. <template>
  3. <s-layout :title="t('order.payment_result')" :bgStyle="{ color: '#FFF' }">
  4. <view class="pay-result-box ss-flex-col ss-row-center ss-col-center">
  5. <!-- 信息展示 -->
  6. <view class="pay-waiting ss-m-b-30" v-if="payResult === 'waiting'" />
  7. <image class="pay-img ss-m-b-30" v-if="payResult === 'success'"
  8. :src="sheep.$url.static('/static/images/order_pay_success.gif')" />
  9. <image class="pay-img ss-m-b-30" v-if="['failed', 'closed'].includes(payResult)"
  10. :src="sheep.$url.static('/static/images/order_paty_fail.gif')" />
  11. <view class="tip-text ss-m-b-30" v-if="payResult === 'success'">{{ t('order.payment_successful') }}</view>
  12. <view class="tip-text ss-m-b-30" v-if="payResult === 'failed'">{{ t('order.payment_failed') }}</view>
  13. <view class="tip-text ss-m-b-30" v-if="payResult === 'closed'">{{ t('order.order_closed') }}</view>
  14. <view class="tip-text ss-m-b-30" v-if="payResult === 'waiting'">{{ t('order.checking_payment_result') }}...</view>
  15. <view class="pay-total-num ss-flex" v-if="payResult === 'success'">
  16. <view>¥{{ fen2yuan(state.orderInfo.price) }}</view>
  17. </view>
  18. <!-- 操作区 -->
  19. <view class="btn-box ss-flex ss-row-center ss-m-t-50">
  20. <button class="back-btn ss-reset-button" @tap="sheep.$router.go('/pages/index/index')">
  21. {{ t('order.return_home') }}
  22. </button>
  23. <button class="check-btn ss-reset-button" v-if="payResult === 'failed'" @tap="
  24. sheep.$router.redirect('/pages/pay/index', { id: state.id, orderType: state.orderType })
  25. ">
  26. {{ t('order.retry_payment') }}
  27. </button>
  28. <button class="check-btn ss-reset-button" v-if="payResult === 'success' && !isTopUp" @tap="onOrder">
  29. {{ t('order.view_order') }}
  30. </button>
  31. <button class="check-btn ss-reset-button" v-if="payResult === 'success' && isTopUp" @tap="sheep.$router.redirect('/pages/user/wallet/score')">
  32. {{ t('order.view_wallet') }}
  33. </button>
  34. <!-- TODO 非繁人:拼团接入 -->
  35. <button class="check-btn ss-reset-button" v-if="payResult === 'success' && state.tradeOrder.type === 3"
  36. @tap="sheep.$router.redirect('/pages/activity/groupon/order')">
  37. {{ t('order.my_group_buying') }}
  38. </button>
  39. </view>
  40. <!-- TODO 非繁人:订阅 -->
  41. <!-- #ifdef MP -->
  42. <view class="subscribe-box ss-flex ss-m-t-44">
  43. <image class="subscribe-img" :src="sheep.$url.static('/static/images/cargo.png')" />
  44. <view class="subscribe-title ss-m-r-48 ss-m-l-16">{{ t('order.get_realtime_shipping_info') }}</view>
  45. <view class="subscribe-start" @tap="subscribeMessage">{{ t('order.subscribe_now') }}</view>
  46. </view>
  47. <!-- #endif -->
  48. </view>
  49. </s-layout>
  50. </template>
  51. <script setup>
  52. import {
  53. onLoad,
  54. onHide,
  55. onShow
  56. } from '@dcloudio/uni-app';
  57. import {
  58. reactive,
  59. computed,
  60. watchEffect
  61. } from 'vue';
  62. import {
  63. isEmpty
  64. } from 'lodash';
  65. import sheep from '@/sheep';
  66. import PayOrderApi from '@/sheep/api/pay/order';
  67. import {
  68. fen2yuan
  69. } from '../../sheep/hooks/useGoods';
  70. import OrderApi from '@/sheep/api/trade/order';
  71. import {
  72. showWalletModal,
  73. colseWalletModal
  74. } from '@/sheep/hooks/useModal';
  75. import { t } from '@/locale'
  76. const state = reactive({
  77. id: 0, // 支付单号
  78. orderType: 'goods', // 订单类型
  79. result: 'unpaid', // 支付状态
  80. orderInfo: {}, // 支付订单信息
  81. tradeOrder: {}, // 商品订单信息,只有在 orderType 为 goods 才会请求。目的:【我的拼团】按钮的展示
  82. counter: 0, // 获取结果次数
  83. });
  84. // 支付结果 result => payResult
  85. const payResult = computed(() => {
  86. if (state.result === 'unpaid') {
  87. return 'waiting';
  88. }
  89. if (state.result === 'paid') {
  90. return 'success';
  91. }
  92. if (state.result === 'failed') {
  93. return 'failed';
  94. }
  95. if (state.result === 'closed') {
  96. return 'closed';
  97. }
  98. });
  99. watchEffect(()=>{
  100. if(payResult.value == 'success'){
  101. showWalletModal({points: state.orderInfo.jf,socialStatus: state.orderInfo.sj})
  102. }
  103. })
  104. // 获得订单信息
  105. async function getOrderInfo(id) {
  106. state.counter++;
  107. // 1. 加载订单信息
  108. // 测试
  109. // await PayOrderApi.getByStatus3(id);
  110. const {
  111. data,
  112. code
  113. } = await PayOrderApi.getByStatus2(id);
  114. if (code === 0) {
  115. state.orderInfo = data;
  116. if (!state.orderInfo || state.orderInfo.status === 30) {
  117. // 支付关闭
  118. state.result = 'closed';
  119. return;
  120. }
  121. if (state.orderInfo.status !== 0) {
  122. // 非待支付,可能是已支付,可能是已退款
  123. state.result = 'paid';
  124. // #ifdef MP
  125. subscribeMessage();
  126. // #endif
  127. // 特殊:获得商品订单信息
  128. // if (state.orderType === 'goods') {
  129. // const {
  130. // data,
  131. // code
  132. // } = await PayOrderApi.getByStatus2(state.orderInfo.merchantOrderId);
  133. // if (code === 0) {
  134. // state.tradeOrder = data;
  135. // }
  136. // }
  137. return;
  138. }
  139. }
  140. // 2.1 情况三一:未支付,且轮询次数小于三次,则继续轮询
  141. if (state.counter < 3 && state.result === 'unpaid') {
  142. setTimeout(() => {
  143. getOrderInfo(id);
  144. }, 1500);
  145. }
  146. // 2.2 情况二:超过三次检测才判断为支付失败
  147. if (state.counter >= 3) {
  148. state.result = 'failed';
  149. }
  150. }
  151. function onOrder() {
  152. // TODO 非繁人:待测试
  153. if (state.orderType === 'recharge') {
  154. sheep.$router.redirect('/pages/pay/recharge-log');
  155. } else {
  156. sheep.$router.redirect('/pages/order/list',{type:2});
  157. }
  158. }
  159. // TODO 非繁人:待测试
  160. // #ifdef MP
  161. function subscribeMessage() {
  162. let event = ['order_dispatched'];
  163. if (state.tradeOrder.type === 3) {
  164. event.push('groupon_finish');
  165. event.push('groupon_fail');
  166. }
  167. sheep.$platform.useProvider('wechat').subscribeMessage(event);
  168. }
  169. // #endif
  170. // 是否充值消费分订单
  171. const isTopUp = computed(() => {
  172. return state.orderInfo.no.includes("top-up") ;
  173. });
  174. onLoad(async (options) => {
  175. // console.log(options.payRes)
  176. // 支付订单号
  177. if (options.id) {
  178. state.id = options.id;
  179. }
  180. // 订单类型
  181. if (options.orderType) {
  182. state.orderType = options.orderType;
  183. }
  184. // 传payRes过来,是0元购,不需要在当前页面请求了
  185. if (options.payRes) {
  186. state.payState = 'success'
  187. state.orderInfo = JSON.parse(options.payRes)
  188. state.result = 'paid';
  189. } else {
  190. // console.log('getOrderInfo')
  191. // 轮询三次检测订单支付结果
  192. await getOrderInfo(state.id);
  193. }
  194. });
  195. onShow(() => {
  196. if (isEmpty(state.orderInfo) || state.payState === 'success') {
  197. return;
  198. }
  199. getOrderInfo(state.id);
  200. });
  201. onHide(() => {
  202. state.result = 'unpaid';
  203. state.counter = 0;
  204. });
  205. </script>
  206. <style lang="scss" scoped>
  207. @keyframes rotation {
  208. 0% {
  209. transform: rotate(0deg);
  210. }
  211. 100% {
  212. transform: rotate(360deg);
  213. }
  214. }
  215. .score-img {
  216. width: 36rpx;
  217. height: 36rpx;
  218. margin: 0 4rpx;
  219. }
  220. .pay-result-box {
  221. padding: 60rpx 0;
  222. .pay-waiting {
  223. margin-top: 20rpx;
  224. width: 60rpx;
  225. height: 60rpx;
  226. border: 10rpx solid rgb(233, 231, 231);
  227. border-bottom-color: rgb(204, 204, 204);
  228. border-radius: 50%;
  229. display: inline-block;
  230. // -webkit-animation: rotation 1s linear infinite;
  231. animation: rotation 1s linear infinite;
  232. }
  233. .pay-img {
  234. width: 130rpx;
  235. height: 130rpx;
  236. }
  237. .tip-text {
  238. font-size: 30rpx;
  239. font-weight: bold;
  240. color: #333333;
  241. }
  242. .pay-total-num {
  243. font-size: 36rpx;
  244. font-weight: 500;
  245. color: #333333;
  246. font-family: OPPOSANS;
  247. }
  248. .btn-box {
  249. width: 100%;
  250. .back-btn {
  251. width: 190rpx;
  252. height: 70rpx;
  253. font-size: 28rpx;
  254. border: 2rpx solid #dfdfdf;
  255. border-radius: 35rpx;
  256. font-weight: 400;
  257. color: #595959;
  258. }
  259. .check-btn {
  260. width: 190rpx;
  261. height: 70rpx;
  262. font-size: 28rpx;
  263. border: 2rpx solid #dfdfdf;
  264. border-radius: 35rpx;
  265. font-weight: 400;
  266. color: #595959;
  267. margin-left: 32rpx;
  268. }
  269. }
  270. .subscribe-box {
  271. .subscribe-img {
  272. width: 44rpx;
  273. height: 44rpx;
  274. }
  275. .subscribe-title {
  276. font-weight: 500;
  277. font-size: 32rpx;
  278. line-height: 36rpx;
  279. color: #434343;
  280. }
  281. .subscribe-start {
  282. color: var(--ui-BG-Main);
  283. font-weight: 700;
  284. font-size: 32rpx;
  285. line-height: 36rpx;
  286. }
  287. }
  288. }
  289. </style>