paymentOrder.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. "use strict";
  2. var common_vendor = require("../common/vendor.js");
  3. var api_pay = require("../api/pay.js");
  4. require("../common/request.js");
  5. const _sfc_main = {
  6. data() {
  7. return {
  8. payType: 2,
  9. order: null,
  10. orderId: null,
  11. payDelivery: 0,
  12. payMoney: 0,
  13. config: null,
  14. payType: 1,
  15. user: null,
  16. combinationOrderId: "",
  17. prescribeOrder: ""
  18. };
  19. },
  20. computed: {
  21. formattedDate() {
  22. var _a;
  23. return ((_a = this.order) == null ? void 0 : _a.createTime) ? common_vendor.dayjs(this.order.createTime).format("YYYY-MM-DD HH:mm:ss") : "";
  24. },
  25. payLimitTime() {
  26. var _a;
  27. return ((_a = this.order) == null ? void 0 : _a.updateTime) ? common_vendor.dayjs(this.order.updateTime).format("YYYY-MM-DD HH:mm:ss") : "";
  28. }
  29. },
  30. onLoad(options) {
  31. console.log("\u652F\u4ED8\u8BA2\u5355\u662F>>", options);
  32. if (options.orderList) {
  33. try {
  34. const decoded = decodeURIComponent(options.orderList);
  35. this.order = JSON.parse(decoded) || {};
  36. } catch (e) {
  37. console.error("\u53C2\u6570\u89E3\u6790\u5931\u8D25:", e);
  38. this.order = {};
  39. }
  40. }
  41. },
  42. onShareAppMessage(res) {
  43. const combinationOrderId = this.combinationOrderId ? `&combinationOrderId=${encodeURIComponent(this.combinationOrderId)}` : "";
  44. return {
  45. title: "\u5E2ETA\u652F\u4ED8",
  46. path: "/pages_user/user/otherPaymentOrder?orderId=" + this.orderId + combinationOrderId,
  47. imageUrl: "/static/images/logo.png"
  48. };
  49. },
  50. methods: {
  51. payOrder() {
  52. if (this.payType == 1) {
  53. this.doWechatPay();
  54. } else if (this.payType == 2) {
  55. this.doAlipay();
  56. } else {
  57. common_vendor.index.showToast({
  58. title: "\u6682\u65F6\u65E0\u53EF\u7528\u652F\u4ED8",
  59. icon: "none"
  60. });
  61. }
  62. },
  63. handlePayTypeChange(e) {
  64. this.payType = e.detail.value;
  65. console.log("\u5F53\u524D\u9009\u4E2D:", this.payType);
  66. },
  67. async doWechatPay() {
  68. try {
  69. common_vendor.index.showLoading({ title: "\u53D1\u8D77\u652F\u4ED8\u4E2D...", mask: true });
  70. let data = {
  71. orderId: this.order.orderId
  72. };
  73. await api_pay.weChatPayment(data);
  74. common_vendor.index.redirectTo({ url: "/pages_shop/success" });
  75. } catch (err) {
  76. console.error("\u652F\u4ED8\u6D41\u7A0B\u5F02\u5E38:", err);
  77. } finally {
  78. common_vendor.index.hideLoading();
  79. }
  80. },
  81. doAlipay() {
  82. ({
  83. orderId: this.order.orderId
  84. });
  85. console.log("orderId>>", this.order.orderId);
  86. },
  87. getUserInfo() {
  88. getUserInfo().then((res) => {
  89. if (res.code == 200) {
  90. if (res.user != null) {
  91. this.user = res.user;
  92. }
  93. } else {
  94. common_vendor.index.showToast({
  95. icon: "none",
  96. title: "\u8BF7\u6C42\u5931\u8D25"
  97. });
  98. }
  99. }, (rej) => {
  100. });
  101. },
  102. getStoreConfig() {
  103. getStoreConfig().then((res) => {
  104. if (res.code == 200) {
  105. this.config = res.data;
  106. console.log(this.config);
  107. }
  108. }, (rej) => {
  109. });
  110. },
  111. payTypeChange(e) {
  112. if (this.combinationOrderId) {
  113. this.editPayTypeByCombinationId(e.detail.value);
  114. } else {
  115. this.editPayType(e.detail.value);
  116. }
  117. },
  118. copyOrderSn(text) {
  119. common_vendor.index.setClipboardData({
  120. data: text,
  121. success: () => {
  122. common_vendor.index.showToast({
  123. title: "\u5185\u5BB9\u5DF2\u6210\u529F\u590D\u5236\u5230\u526A\u5207\u677F",
  124. icon: "none"
  125. });
  126. }
  127. });
  128. },
  129. editPayType(payType) {
  130. var data = {
  131. orderId: this.orderId,
  132. payType
  133. };
  134. var that = this;
  135. common_vendor.index.showLoading();
  136. editPayType(data).then((res) => {
  137. if (res.code == 200) {
  138. console.log(res);
  139. common_vendor.index.hideLoading();
  140. that.order = res.order;
  141. that.order.orderCodes = that.order.orderCode ? [that.order.orderCode] : [];
  142. that.orderCode = that.order.orderCode;
  143. this.payMoney = this.order.payMoney;
  144. this.payDelivery = this.order.payDelivery;
  145. } else {
  146. common_vendor.index.showToast({
  147. icon: "none",
  148. title: res.msg
  149. });
  150. }
  151. }, (rej) => {
  152. });
  153. },
  154. otherPayOrder() {
  155. common_vendor.index.navigateTo({
  156. url: "/pages_user/user/otherPaymentOrder?combinationOrderId=" + encodeURIComponent(this.combinationOrderId)
  157. });
  158. },
  159. payfun(res) {
  160. const that = this;
  161. console.log(res.result);
  162. if (res.payType == 1 || res.payType == 2) {
  163. common_vendor.index.requestPayment({
  164. provider: "wxpay",
  165. timeStamp: res.result.timeStamp,
  166. nonceStr: res.result.nonceStr,
  167. package: res.result.packageStr,
  168. signType: res.result.signType,
  169. paySign: res.result.paySign,
  170. success: function(res2) {
  171. common_vendor.index.hideLoading();
  172. common_vendor.index.redirectTo({
  173. url: "success?order=" + JSON.stringify(that.order)
  174. });
  175. },
  176. fail: function(err) {
  177. common_vendor.index.showToast({
  178. icon: "none",
  179. title: "fail:" + JSON.stringify(err)
  180. });
  181. console.log("fail:" + JSON.stringify(err));
  182. common_vendor.index.hideLoading();
  183. }
  184. });
  185. } else if (res.payType == 3) {
  186. common_vendor.index.hideLoading();
  187. if (that.order.isPrescribe) {
  188. common_vendor.index.redirectTo({
  189. url: "prescribe?orderId=" + that.prescribeOrder + "&combinationOrderId=" + encodeURIComponent(that.order.combinationOrderId)
  190. });
  191. } else {
  192. common_vendor.index.redirectTo({
  193. url: "success?order=" + JSON.stringify(that.order)
  194. });
  195. }
  196. }
  197. }
  198. }
  199. };
  200. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  201. var _a;
  202. return common_vendor.e({
  203. a: common_vendor.t($options.payLimitTime),
  204. b: common_vendor.t($data.order ? (Number($data.order.totalPrice) || 0).toFixed(2) : "0.00"),
  205. c: $data.payType === 1,
  206. d: common_vendor.o((...args) => $options.handlePayTypeChange && $options.handlePayTypeChange(...args)),
  207. e: common_vendor.t((_a = $data.order) == null ? void 0 : _a.orderCode),
  208. f: common_vendor.o(($event) => $options.copyOrderSn(_ctx.orderCode)),
  209. g: common_vendor.t($options.formattedDate),
  210. h: $data.order != null
  211. }, $data.order != null ? {
  212. i: common_vendor.t($data.order ? (Number($data.order.totalPrice) || 0).toFixed(2) : "0.00")
  213. } : {}, {
  214. j: common_vendor.o(($event) => $options.payOrder())
  215. });
  216. }
  217. var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "C:/Users/Administrator/Desktop/\u9879\u76EE/\u76F4\u64AD/liveH5-v3/pages_shop/paymentOrder.vue"]]);
  218. _sfc_main.__runtimeHooks = 2;
  219. wx.createPage(MiniProgramPage);