index.js 7.0 KB

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