result.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_index = require("../../sheep/index.js");
  4. const sheep_api_pay_order = require("../../sheep/api/pay/order.js");
  5. const sheep_hooks_useGoods = require("../../sheep/hooks/useGoods.js");
  6. const sheep_api_trade_order = require("../../sheep/api/trade/order.js");
  7. const sheep_hooks_useModal = require("../../sheep/hooks/useModal.js");
  8. require("../../sheep/url/index.js");
  9. require("../../sheep/store/index.js");
  10. require("../../sheep/store/app.js");
  11. require("../../sheep/api/promotion/diy.js");
  12. require("../../sheep/request/index.js");
  13. require("../../sheep/config/index.js");
  14. require("../../sheep/platform/index.js");
  15. require("../../sheep/platform/provider/wechat/index.js");
  16. require("../../sheep/platform/provider/wechat/miniProgram.js");
  17. require("../../sheep/api/member/auth.js");
  18. require("../../sheep/api/member/social.js");
  19. require("../../sheep/api/member/user.js");
  20. require("../../sheep/platform/provider/apple/index.js");
  21. require("../../sheep/platform/share.js");
  22. require("../../sheep/router/index.js");
  23. require("../../sheep/helper/throttle.js");
  24. require("../../sheep/platform/pay.js");
  25. require("../../sheep/helper/index.js");
  26. require("../../sheep/helper/test.js");
  27. require("../../sheep/helper/digit.js");
  28. require("../../sheep/store/user.js");
  29. require("../../sheep/store/cart.js");
  30. require("../../sheep/api/trade/cart.js");
  31. require("../../sheep/api/pay/wallet.js");
  32. require("../../sheep/api/promotion/coupon.js");
  33. require("../../sheep/store/sys.js");
  34. require("../../sheep/store/modal.js");
  35. require("../../sheep/config/zIndex.js");
  36. require("../../sheep/util/index.js");
  37. require("../../sheep/api/member/signin.js");
  38. if (!Array) {
  39. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  40. _easycom_s_layout2();
  41. }
  42. const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
  43. if (!Math) {
  44. _easycom_s_layout();
  45. }
  46. const _sfc_main = {
  47. __name: "result",
  48. setup(__props) {
  49. const state = common_vendor.reactive({
  50. id: 0,
  51. // 支付单号
  52. orderType: "goods",
  53. // 订单类型
  54. result: "unpaid",
  55. // 支付状态
  56. orderInfo: {},
  57. // 支付订单信息
  58. tradeOrder: {},
  59. // 商品订单信息,只有在 orderType 为 goods 才会请求。目的:【我的拼团】按钮的展示
  60. counter: 0
  61. // 获取结果次数
  62. });
  63. const payResult = common_vendor.computed(() => {
  64. if (state.result === "unpaid") {
  65. return "waiting";
  66. }
  67. if (state.result === "paid") {
  68. return "success";
  69. }
  70. if (state.result === "failed") {
  71. return "failed";
  72. }
  73. if (state.result === "closed") {
  74. return "closed";
  75. }
  76. });
  77. common_vendor.watchEffect(() => {
  78. if (payResult.value == "success") {
  79. sheep_hooks_useModal.showWalletModal({ points: state.orderInfo.jf, socialStatus: state.orderInfo.sj });
  80. }
  81. });
  82. async function getOrderInfo(id) {
  83. state.counter++;
  84. const {
  85. data,
  86. code
  87. } = await sheep_api_pay_order.PayOrderApi.getByStatus(id);
  88. if (code === 0) {
  89. state.orderInfo = data;
  90. if (!state.orderInfo || state.orderInfo.status === 30) {
  91. state.result = "closed";
  92. return;
  93. }
  94. if (state.orderInfo.status !== 0) {
  95. state.result = "paid";
  96. subscribeMessage();
  97. if (state.orderType === "goods") {
  98. const {
  99. data: data2,
  100. code: code2
  101. } = await sheep_api_trade_order.OrderApi.getByStatus(state.orderInfo.merchantOrderId);
  102. if (code2 === 0) {
  103. state.tradeOrder = data2;
  104. }
  105. }
  106. return;
  107. }
  108. }
  109. if (state.counter < 3 && state.result === "unpaid") {
  110. setTimeout(() => {
  111. getOrderInfo(id);
  112. }, 1500);
  113. }
  114. if (state.counter >= 3) {
  115. state.result = "failed";
  116. }
  117. }
  118. function onOrder() {
  119. if (state.orderType === "recharge") {
  120. sheep_index.sheep.$router.redirect("/pages/pay/recharge-log");
  121. } else {
  122. sheep_index.sheep.$router.redirect("/pages/order/list");
  123. }
  124. }
  125. function subscribeMessage() {
  126. let event = ["order_dispatched"];
  127. if (state.tradeOrder.type === 3) {
  128. event.push("groupon_finish");
  129. event.push("groupon_fail");
  130. }
  131. sheep_index.sheep.$platform.useProvider("wechat").subscribeMessage(event);
  132. }
  133. common_vendor.onLoad(async (options) => {
  134. if (options.id) {
  135. state.id = options.id;
  136. }
  137. if (options.orderType) {
  138. state.orderType = options.orderType;
  139. }
  140. await getOrderInfo(state.id);
  141. });
  142. common_vendor.onShow(() => {
  143. if (common_vendor.lodashExports.isEmpty(state.orderInfo)) {
  144. return;
  145. }
  146. getOrderInfo(state.id);
  147. });
  148. common_vendor.onHide(() => {
  149. state.result = "unpaid";
  150. state.counter = 0;
  151. });
  152. return (_ctx, _cache) => {
  153. return common_vendor.e({
  154. a: payResult.value === "waiting"
  155. }, payResult.value === "waiting" ? {} : {}, {
  156. b: payResult.value === "success"
  157. }, payResult.value === "success" ? {
  158. c: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/order_pay_success.gif")
  159. } : {}, {
  160. d: ["failed", "closed"].includes(payResult.value)
  161. }, ["failed", "closed"].includes(payResult.value) ? {
  162. e: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/order_paty_fail.gif")
  163. } : {}, {
  164. f: payResult.value === "success"
  165. }, payResult.value === "success" ? {} : {}, {
  166. g: payResult.value === "failed"
  167. }, payResult.value === "failed" ? {} : {}, {
  168. h: payResult.value === "closed"
  169. }, payResult.value === "closed" ? {} : {}, {
  170. i: payResult.value === "waiting"
  171. }, payResult.value === "waiting" ? {} : {}, {
  172. j: payResult.value === "success"
  173. }, payResult.value === "success" ? {
  174. k: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price))
  175. } : {}, {
  176. l: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/index/index")),
  177. m: payResult.value === "failed"
  178. }, payResult.value === "failed" ? {
  179. n: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.redirect("/pages/pay/index", {
  180. id: state.id,
  181. orderType: state.orderType
  182. }))
  183. } : {}, {
  184. o: payResult.value === "success"
  185. }, payResult.value === "success" ? {
  186. p: common_vendor.o(onOrder)
  187. } : {}, {
  188. q: payResult.value === "success" && state.tradeOrder.type === 3
  189. }, payResult.value === "success" && state.tradeOrder.type === 3 ? {
  190. r: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.redirect("/pages/activity/groupon/order"))
  191. } : {}, {
  192. s: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/cargo.png"),
  193. t: common_vendor.o(subscribeMessage),
  194. v: common_vendor.p({
  195. title: "支付结果",
  196. bgStyle: {
  197. color: "#FFF"
  198. }
  199. })
  200. });
  201. };
  202. }
  203. };
  204. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-42b1ec48"], ["__file", "D:/zx/mall-front-app/pages/pay/result.vue"]]);
  205. wx.createPage(MiniProgramPage);