payStateQuery.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view class="container">
  3. <view class="content"></view>
  4. </view>
  5. </template>
  6. <script setup lang="ts">
  7. import { ref } from 'vue';
  8. import { onLoad } from '@dcloudio/uni-app';
  9. import { common } from '@/utils';
  10. import { orderDetailLocal } from '@/pagesPatient/service/record/index';
  11. const orderId = ref('');
  12. // const timesMax = ref(5); // 原逻辑中定义了但未使用,或者仅作为常量
  13. let times = 0;
  14. let timer: any = null;
  15. const sleep = (val: string | number) => {
  16. let times = Number(val);
  17. return new Promise(resolve => {
  18. setTimeout(() => {
  19. resolve(true);
  20. }, times);
  21. });
  22. };
  23. const main = async () => {
  24. /** 500毫秒后再执行其他操作 否则loading直接被hide 不显示遮罩 */
  25. await sleep(500);
  26. const mainInner = async () => {
  27. times++;
  28. /** 轮询5次 */
  29. if (times > 5) {
  30. uni.hideLoading();
  31. common.showModal(`当前订单等待超时,请前往订单记录页面核实订单结果,谢谢您的配合,祝您早日康复。`, () => {
  32. common.goToUrl('/pages/st1/business/tabbar/homePage/homePage', {
  33. skipWay: "reLaunch"
  34. });
  35. });
  36. return;
  37. }
  38. if (orderId.value) {
  39. const queryData = {
  40. OrderId: orderId.value
  41. };
  42. try {
  43. let { resp } = await orderDetailLocal(queryData, false);
  44. if (common.isNotEmpty(resp)) {
  45. // 兼容原逻辑,假设 resp 为数组
  46. const order = Array.isArray(resp) ? resp[0] : resp;
  47. if (order && order.BizState == '1') {
  48. /** 支付成功 */
  49. uni.hideLoading();
  50. common.goToUrl(`/pagesPatient/st1/business/pay/payState/payState?orderId=${order.OrderId}`, {
  51. skipWay: "redirectTo"
  52. });
  53. return;
  54. } else if (order && order.BizState == '2') {
  55. /** 支付失败 */
  56. uni.hideLoading();
  57. common.showModal(`订单支付失败`, () => {
  58. common.goToUrl('/pages/st1/business/tabbar/homePage/homePage', {
  59. skipWay: "reLaunch"
  60. });
  61. });
  62. return;
  63. }
  64. }
  65. } catch (e) {
  66. console.error(e);
  67. }
  68. timer = setTimeout(() => {
  69. mainInner();
  70. if (timer) {
  71. clearTimeout(timer);
  72. timer = null;
  73. }
  74. }, 2000);
  75. }
  76. };
  77. mainInner();
  78. };
  79. onLoad((options: any) => {
  80. uni.showLoading({
  81. title: '支付中',
  82. mask: true
  83. });
  84. orderId.value = options.orderId || "";
  85. main();
  86. });
  87. </script>
  88. <style lang="scss">
  89. .container {
  90. }
  91. </style>