index.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_index = require("../../sheep/index.js");
  4. const sheep_hooks_useGoods = require("../../sheep/hooks/useGoods.js");
  5. const sheep_api_pay_order = require("../../sheep/api/pay/order.js");
  6. const sheep_api_pay_channel = require("../../sheep/api/pay/channel.js");
  7. const sheep_platform_pay = require("../../sheep/platform/pay.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/hooks/useModal.js");
  24. require("../../sheep/helper/index.js");
  25. require("../../sheep/helper/test.js");
  26. require("../../sheep/helper/digit.js");
  27. require("../../sheep/helper/throttle.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/trade/order.js");
  33. require("../../sheep/api/promotion/coupon.js");
  34. require("../../sheep/store/sys.js");
  35. require("../../sheep/store/modal.js");
  36. require("../../sheep/config/zIndex.js");
  37. require("../../sheep/util/index.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: "index",
  48. setup(__props) {
  49. const userWallet = common_vendor.computed(() => sheep_index.sheep.$store("user").userWallet);
  50. const state = common_vendor.reactive({
  51. orderType: "goods",
  52. // 订单类型; goods - 商品订单, recharge - 充值订单
  53. orderInfo: {},
  54. // 支付单信息
  55. payStatus: 0,
  56. // 0=检测支付环境, -2=未查询到支付单信息, -1=支付已过期, 1=待支付,2=订单已支付
  57. payMethods: [],
  58. // 可选的支付方式
  59. payment: ""
  60. // 选中的支付方式
  61. });
  62. const onPay = () => {
  63. if (state.payment === "") {
  64. sheep_index.sheep.$helper.toast("请选择支付方式");
  65. return;
  66. }
  67. if (state.payment === "wallet") {
  68. common_vendor.index.showModal({
  69. title: "提示",
  70. content: "确定要支付吗?",
  71. success: function(res) {
  72. if (res.confirm) {
  73. sheep_index.sheep.$platform.pay(state.payment, state.orderType, state.orderInfo.id);
  74. }
  75. }
  76. });
  77. } else {
  78. sheep_index.sheep.$platform.pay(state.payment, state.orderType, state.orderInfo.id);
  79. }
  80. };
  81. const payDescText = common_vendor.computed(() => {
  82. if (state.payStatus === 2) {
  83. return "该订单已支付";
  84. }
  85. if (state.payStatus === 1) {
  86. const time = sheep_hooks_useGoods.useDurationTime(state.orderInfo.expireTime);
  87. if (time.ms <= 0) {
  88. state.payStatus = -1;
  89. return "";
  90. }
  91. return `剩余支付时间 ${time.h}:${time.m}:${time.s} `;
  92. }
  93. if (state.payStatus === -2) {
  94. return "未查询到支付单信息";
  95. }
  96. return "";
  97. });
  98. function checkPayStatus() {
  99. if (state.orderInfo.status === 10 || state.orderInfo.status === 20) {
  100. state.payStatus = 2;
  101. return;
  102. }
  103. if (state.orderInfo.status === 30) {
  104. state.payStatus = -1;
  105. return;
  106. }
  107. state.payStatus = 1;
  108. }
  109. function onTapPay(e) {
  110. state.payment = e.detail.value;
  111. }
  112. async function setOrder(id) {
  113. const { data, code } = await sheep_api_pay_order.PayOrderApi.getOrder(id);
  114. if (code !== 0 || !data) {
  115. state.payStatus = -2;
  116. return;
  117. }
  118. state.orderInfo = data;
  119. await setPayMethods();
  120. checkPayStatus();
  121. }
  122. async function setPayMethods() {
  123. const { data, code } = await sheep_api_pay_channel.PayChannelApi.getEnableChannelCodeList(state.orderInfo.appId);
  124. if (code !== 0) {
  125. return;
  126. }
  127. state.payMethods = sheep_platform_pay.getPayMethods(data);
  128. }
  129. common_vendor.onLoad((options) => {
  130. if (sheep_index.sheep.$platform.name === "WechatOfficialAccount" && sheep_index.sheep.$platform.os === "ios" && !sheep_index.sheep.$platform.landingPage.includes("pages/pay/index")) {
  131. location.reload();
  132. return;
  133. }
  134. let id = options.id;
  135. if (options.orderType) {
  136. state.orderType = options.orderType;
  137. }
  138. setOrder(id);
  139. sheep_index.sheep.$store("user").getWallet();
  140. });
  141. return (_ctx, _cache) => {
  142. return common_vendor.e({
  143. a: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price)),
  144. b: common_vendor.t(common_vendor.unref(payDescText)),
  145. c: common_vendor.f(state.payMethods, (item, k0, i0) => {
  146. return common_vendor.e({
  147. a: item.disabled
  148. }, item.disabled ? {
  149. b: common_vendor.unref(sheep_index.sheep).$url.static("/static/img/shop/pay/cod_disabled.png")
  150. } : {
  151. c: common_vendor.unref(sheep_index.sheep).$url.static(item.icon)
  152. }, {
  153. d: common_vendor.t(item.title),
  154. e: item.value === "wallet"
  155. }, item.value === "wallet" ? {
  156. f: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(common_vendor.unref(userWallet).balance))
  157. } : {}, {
  158. g: item.value,
  159. h: item.disabled,
  160. i: state.payment === item.value,
  161. j: item.disabled ? 1 : "",
  162. k: item.title
  163. });
  164. }),
  165. d: common_vendor.o(onTapPay),
  166. e: state.payStatus === 0
  167. }, state.payStatus === 0 ? {} : state.payStatus === -1 ? {} : {
  168. g: common_vendor.o(onPay),
  169. h: state.payStatus !== 1,
  170. i: state.payStatus !== 1 ? 1 : ""
  171. }, {
  172. f: state.payStatus === -1,
  173. j: common_vendor.p({
  174. title: "收银台"
  175. })
  176. });
  177. };
  178. }
  179. };
  180. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-d7fd7b38"], ["__file", "/Users/RuHu.Xu/Desktop/mall-newfeifan-zx-app/pages/pay/index.vue"]]);
  181. wx.createPage(MiniProgramPage);