paymentOrder.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const api_pay = require("../api/pay.js");
  4. const common_assets = require("../common/assets.js");
  5. const _sfc_main = {
  6. data() {
  7. return {
  8. payType: 2,
  9. order: null,
  10. // formattedDate: '',
  11. orderId: null,
  12. payDelivery: 0,
  13. payMoney: 0,
  14. config: null,
  15. payType: 1,
  16. // payLimitTime: null,
  17. user: null,
  18. combinationOrderId: "",
  19. // 需要开处方的订单id
  20. prescribeOrder: ""
  21. };
  22. },
  23. computed: {
  24. formattedDate() {
  25. var _a;
  26. return ((_a = this.order) == null ? void 0 : _a.createTime) ? common_vendor.dayjs(this.order.createTime).format("YYYY-MM-DD HH:mm:ss") : "";
  27. },
  28. payLimitTime() {
  29. var _a;
  30. return ((_a = this.order) == null ? void 0 : _a.updateTime) ? common_vendor.dayjs(this.order.updateTime).format("YYYY-MM-DD HH:mm:ss") : "";
  31. }
  32. },
  33. onLoad(options) {
  34. console.log("支付订单是>>", options);
  35. if (options.orderList) {
  36. try {
  37. const decoded = decodeURIComponent(options.orderList);
  38. this.order = JSON.parse(decoded) || {};
  39. } catch (e) {
  40. console.error("参数解析失败:", e);
  41. this.order = {};
  42. }
  43. }
  44. },
  45. //发送给朋友
  46. onShareAppMessage(res) {
  47. const combinationOrderId = this.combinationOrderId ? `&combinationOrderId=${encodeURIComponent(this.combinationOrderId)}` : "";
  48. return {
  49. title: "帮TA支付",
  50. path: "/pages_user/user/otherPaymentOrder?orderId=" + this.orderId + combinationOrderId,
  51. imageUrl: "/static/images/logo.png"
  52. //分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
  53. };
  54. },
  55. methods: {
  56. payOrder() {
  57. if (this.payType == 1) {
  58. this.doWechatPay();
  59. } else if (this.payType == 2) {
  60. this.doAlipay();
  61. } else {
  62. common_vendor.index.showToast({
  63. title: "暂时无可用支付",
  64. icon: "none"
  65. });
  66. }
  67. },
  68. // 选微信支付或者支付宝支付
  69. handlePayTypeChange(e) {
  70. this.payType = e.detail.value;
  71. console.log("当前选中:", this.payType);
  72. },
  73. async doWechatPay() {
  74. try {
  75. common_vendor.index.showLoading({ title: "发起支付中...", mask: true });
  76. let data = {
  77. orderId: this.order.orderId
  78. };
  79. await api_pay.weChatPayment(data);
  80. common_vendor.index.redirectTo({ url: "/pages_shop/success" });
  81. } catch (err) {
  82. console.error("支付流程异常:", err);
  83. } finally {
  84. common_vendor.index.hideLoading();
  85. }
  86. },
  87. // doWechatPay(){
  88. // weChatPayment(data).then(res => {
  89. // if (res.code == 200) {
  90. // }
  91. // })
  92. // },
  93. // 支付宝支付
  94. doAlipay() {
  95. ({
  96. orderId: this.order.orderId
  97. });
  98. console.log("orderId>>", this.order.orderId);
  99. },
  100. getUserInfo() {
  101. getUserInfo().then(
  102. (res) => {
  103. if (res.code == 200) {
  104. if (res.user != null) {
  105. this.user = res.user;
  106. }
  107. } else {
  108. common_vendor.index.showToast({
  109. icon: "none",
  110. title: "请求失败"
  111. });
  112. }
  113. },
  114. (rej) => {
  115. }
  116. );
  117. },
  118. getStoreConfig() {
  119. getStoreConfig().then(
  120. (res) => {
  121. if (res.code == 200) {
  122. this.config = res.data;
  123. console.log(this.config);
  124. }
  125. },
  126. (rej) => {
  127. }
  128. );
  129. },
  130. payTypeChange(e) {
  131. if (this.combinationOrderId) {
  132. this.editPayTypeByCombinationId(e.detail.value);
  133. } else {
  134. this.editPayType(e.detail.value);
  135. }
  136. },
  137. copyOrderSn(text) {
  138. common_vendor.index.setClipboardData({
  139. data: text,
  140. success: () => {
  141. common_vendor.index.showToast({
  142. title: "内容已成功复制到剪切板",
  143. icon: "none"
  144. });
  145. }
  146. });
  147. },
  148. // getStoreOrderById(){
  149. // var data = {orderId:this.orderId};
  150. // var that=this;
  151. // uni.showLoading();
  152. // getStoreOrderById(data).then(
  153. // res => {
  154. // if(res.code==200){
  155. // console.log(res);
  156. // uni.hideLoading();
  157. // that.order=res.order;
  158. // that.order.orderCodes = that.order.orderCode ? [that.order.orderCode]:[]
  159. // that.orderCode = that.order.orderCode
  160. // that.payLimitTime=res.payLimitTime;
  161. // //套餐订单处理
  162. // if(res.productPackage!=null){
  163. // this.payType=res.productPackage.payType;
  164. // console.log(this.payType)
  165. // if(this.order.payType==4){
  166. // this.order.payType=1;
  167. // }
  168. // }
  169. // this.editPayType(this.order.payType)
  170. // }else{
  171. // uni.showToast({
  172. // icon:'none',
  173. // title: res.msg,
  174. // });
  175. // }
  176. // },
  177. // rej => {}
  178. // );
  179. // },
  180. editPayType(payType) {
  181. var data = {
  182. orderId: this.orderId,
  183. payType
  184. };
  185. var that = this;
  186. common_vendor.index.showLoading();
  187. editPayType(data).then(
  188. (res) => {
  189. if (res.code == 200) {
  190. console.log(res);
  191. common_vendor.index.hideLoading();
  192. that.order = res.order;
  193. that.order.orderCodes = that.order.orderCode ? [that.order.orderCode] : [];
  194. that.orderCode = that.order.orderCode;
  195. this.payMoney = this.order.payMoney;
  196. this.payDelivery = this.order.payDelivery;
  197. } else {
  198. common_vendor.index.showToast({
  199. icon: "none",
  200. title: res.msg
  201. });
  202. }
  203. },
  204. (rej) => {
  205. }
  206. );
  207. },
  208. // getStoreOrderByCombinationId() {
  209. // var data = {combinationId:this.combinationOrderId};
  210. // var that=this;
  211. // uni.showLoading();
  212. // getStoreOrderByCombinationId(data).then(
  213. // res => {
  214. // if(res.code==200){
  215. // console.log(res);
  216. // uni.hideLoading();
  217. // that.order=res.order;
  218. // that.orderCode = res.order.orderCodes ? res.order.orderCodes.join(',') : "";
  219. // that.payLimitTime=res.payLimitTime;
  220. // //套餐订单处理
  221. // if(res.productPackage!=null){
  222. // this.payType=res.productPackage.payType;
  223. // console.log(this.payType)
  224. // if(this.order.payType==4){
  225. // this.order.payType=1;
  226. // }
  227. // }
  228. // that.prescribeOrder = res.prescribeOrder;
  229. // this.editPayTypeByCombinationId(this.order.payType)
  230. // }else{
  231. // uni.showToast({
  232. // icon:'none',
  233. // title: res.msg,
  234. // });
  235. // }
  236. // },
  237. // rej => {}
  238. // );
  239. // },
  240. // editPayTypeByCombinationId(payType){
  241. // var data = {combinationOrderId:this.combinationOrderId,payType:payType};
  242. // var that=this;
  243. // uni.showLoading();
  244. // editPayTypeByCombinationId(data).then(
  245. // res => {
  246. // if(res.code==200){
  247. // console.log(res);
  248. // uni.hideLoading();
  249. // that.order=res.order;
  250. // that.orderCode = res.order.orderCodes ? res.order.orderCodes.join(',') : "";
  251. // //this.payType=this.order.payType
  252. // this.payMoney=this.order.payMoney;
  253. // this.payDelivery=this.order.payDelivery;
  254. // that.prescribeOrder = res.prescribeOrder;
  255. // }else{
  256. // uni.showToast({
  257. // icon:'none',
  258. // title: res.msg,
  259. // });
  260. // }
  261. // },
  262. // rej => {}
  263. // );
  264. // },
  265. otherPayOrder() {
  266. common_vendor.index.navigateTo({
  267. url: "/pages_user/user/otherPaymentOrder?combinationOrderId=" + encodeURIComponent(this.combinationOrderId)
  268. });
  269. },
  270. // payOrder() {
  271. // if (this.combinationOrderId) {
  272. // let data = {
  273. // combinationOrderId: this.combinationOrderId,
  274. // payType: this.order.payType
  275. // };
  276. // let that = this;
  277. // uni.showLoading();
  278. // payByCombinationId(data).then(
  279. // res => {
  280. // if (res.code == 200) {
  281. // this.payfun(res)
  282. // } else {
  283. // uni.showToast({
  284. // icon: 'none',
  285. // title: res.msg,
  286. // });
  287. // }
  288. // },
  289. // rej => {}
  290. // );
  291. // } else {
  292. // let data = {
  293. // orderId: this.order.id,
  294. // payType: this.order.payType
  295. // };
  296. // let that = this;
  297. // uni.showLoading();
  298. // pay(data).then(
  299. // res => {
  300. // if (res.code == 200) {
  301. // this.payfun(res)
  302. // } else {
  303. // uni.showToast({
  304. // icon: 'none',
  305. // title: res.msg,
  306. // });
  307. // }
  308. // },
  309. // rej => {}
  310. // );
  311. // }
  312. // },
  313. payfun(res) {
  314. const that = this;
  315. console.log(res.result);
  316. if (res.payType == 1 || res.payType == 2) {
  317. common_vendor.index.requestPayment({
  318. provider: "wxpay",
  319. timeStamp: res.result.timeStamp,
  320. nonceStr: res.result.nonceStr,
  321. // package: res.result.packageValue,
  322. package: res.result.packageStr,
  323. signType: res.result.signType,
  324. paySign: res.result.paySign,
  325. success: function(res2) {
  326. common_vendor.index.hideLoading();
  327. common_vendor.index.redirectTo({
  328. url: "success?order=" + JSON.stringify(that.order)
  329. });
  330. },
  331. fail: function(err) {
  332. common_vendor.index.showToast({
  333. icon: "none",
  334. title: "fail:" + JSON.stringify(err)
  335. });
  336. console.log("fail:" + JSON.stringify(err));
  337. common_vendor.index.hideLoading();
  338. }
  339. });
  340. } else if (res.payType == 3) {
  341. common_vendor.index.hideLoading();
  342. if (that.order.isPrescribe) {
  343. common_vendor.index.redirectTo({
  344. url: "prescribe?orderId=" + that.prescribeOrder + "&combinationOrderId=" + encodeURIComponent(that.order.combinationOrderId)
  345. });
  346. } else {
  347. common_vendor.index.redirectTo({
  348. url: "success?order=" + JSON.stringify(that.order)
  349. });
  350. }
  351. }
  352. }
  353. }
  354. };
  355. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  356. var _a;
  357. return common_vendor.e({
  358. a: common_vendor.t($options.payLimitTime),
  359. b: common_vendor.t($data.order ? (Number($data.order.totalPrice) || 0).toFixed(2) : "0.00"),
  360. c: common_assets._imports_0$12,
  361. d: $data.payType === 1,
  362. e: common_vendor.o((...args) => $options.handlePayTypeChange && $options.handlePayTypeChange(...args)),
  363. f: common_vendor.t((_a = $data.order) == null ? void 0 : _a.orderCode),
  364. g: common_vendor.o(($event) => $options.copyOrderSn(_ctx.orderCode)),
  365. h: common_vendor.t($options.formattedDate),
  366. i: $data.order != null
  367. }, $data.order != null ? {
  368. j: common_vendor.t($data.order ? (Number($data.order.totalPrice) || 0).toFixed(2) : "0.00")
  369. } : {}, {
  370. k: common_vendor.o(($event) => $options.payOrder())
  371. });
  372. }
  373. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  374. _sfc_main.__runtimeHooks = 2;
  375. wx.createPage(MiniProgramPage);