paymentOrder.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. // console.log(text)
  139. // // 复制方法
  140. // uni.setClipboardData({
  141. // data: text,
  142. // success: () => {
  143. // uni.showToast({
  144. // title: '内容已成功复制到剪切板',
  145. // icon: 'none'
  146. // })
  147. // }
  148. // });
  149. // },
  150. // getStoreOrderById(){
  151. // var data = {orderId:this.orderId};
  152. // var that=this;
  153. // uni.showLoading();
  154. // getStoreOrderById(data).then(
  155. // res => {
  156. // if(res.code==200){
  157. // console.log(res);
  158. // uni.hideLoading();
  159. // that.order=res.order;
  160. // that.order.orderCodes = that.order.orderCode ? [that.order.orderCode]:[]
  161. // that.orderCode = that.order.orderCode
  162. // that.payLimitTime=res.payLimitTime;
  163. // //套餐订单处理
  164. // if(res.productPackage!=null){
  165. // this.payType=res.productPackage.payType;
  166. // console.log(this.payType)
  167. // if(this.order.payType==4){
  168. // this.order.payType=1;
  169. // }
  170. // }
  171. // this.editPayType(this.order.payType)
  172. // }else{
  173. // uni.showToast({
  174. // icon:'none',
  175. // title: res.msg,
  176. // });
  177. // }
  178. // },
  179. // rej => {}
  180. // );
  181. // },
  182. editPayType(payType) {
  183. var data = {
  184. orderId: this.orderId,
  185. payType
  186. };
  187. var that = this;
  188. common_vendor.index.showLoading();
  189. editPayType(data).then(
  190. (res) => {
  191. if (res.code == 200) {
  192. console.log(res);
  193. common_vendor.index.hideLoading();
  194. that.order = res.order;
  195. that.order.orderCodes = that.order.orderCode ? [that.order.orderCode] : [];
  196. that.orderCode = that.order.orderCode;
  197. this.payMoney = this.order.payMoney;
  198. this.payDelivery = this.order.payDelivery;
  199. } else {
  200. common_vendor.index.showToast({
  201. icon: "none",
  202. title: res.msg
  203. });
  204. }
  205. },
  206. (rej) => {
  207. }
  208. );
  209. },
  210. // getStoreOrderByCombinationId() {
  211. // var data = {combinationId:this.combinationOrderId};
  212. // var that=this;
  213. // uni.showLoading();
  214. // getStoreOrderByCombinationId(data).then(
  215. // res => {
  216. // if(res.code==200){
  217. // console.log(res);
  218. // uni.hideLoading();
  219. // that.order=res.order;
  220. // that.orderCode = res.order.orderCodes ? res.order.orderCodes.join(',') : "";
  221. // that.payLimitTime=res.payLimitTime;
  222. // //套餐订单处理
  223. // if(res.productPackage!=null){
  224. // this.payType=res.productPackage.payType;
  225. // console.log(this.payType)
  226. // if(this.order.payType==4){
  227. // this.order.payType=1;
  228. // }
  229. // }
  230. // that.prescribeOrder = res.prescribeOrder;
  231. // this.editPayTypeByCombinationId(this.order.payType)
  232. // }else{
  233. // uni.showToast({
  234. // icon:'none',
  235. // title: res.msg,
  236. // });
  237. // }
  238. // },
  239. // rej => {}
  240. // );
  241. // },
  242. // editPayTypeByCombinationId(payType){
  243. // var data = {combinationOrderId:this.combinationOrderId,payType:payType};
  244. // var that=this;
  245. // uni.showLoading();
  246. // editPayTypeByCombinationId(data).then(
  247. // res => {
  248. // if(res.code==200){
  249. // console.log(res);
  250. // uni.hideLoading();
  251. // that.order=res.order;
  252. // that.orderCode = res.order.orderCodes ? res.order.orderCodes.join(',') : "";
  253. // //this.payType=this.order.payType
  254. // this.payMoney=this.order.payMoney;
  255. // this.payDelivery=this.order.payDelivery;
  256. // that.prescribeOrder = res.prescribeOrder;
  257. // }else{
  258. // uni.showToast({
  259. // icon:'none',
  260. // title: res.msg,
  261. // });
  262. // }
  263. // },
  264. // rej => {}
  265. // );
  266. // },
  267. otherPayOrder() {
  268. common_vendor.index.navigateTo({
  269. url: "/pages_user/user/otherPaymentOrder?combinationOrderId=" + encodeURIComponent(this.combinationOrderId)
  270. });
  271. },
  272. // payOrder() {
  273. // if (this.combinationOrderId) {
  274. // let data = {
  275. // combinationOrderId: this.combinationOrderId,
  276. // payType: this.order.payType
  277. // };
  278. // let that = this;
  279. // uni.showLoading();
  280. // payByCombinationId(data).then(
  281. // res => {
  282. // if (res.code == 200) {
  283. // this.payfun(res)
  284. // } else {
  285. // uni.showToast({
  286. // icon: 'none',
  287. // title: res.msg,
  288. // });
  289. // }
  290. // },
  291. // rej => {}
  292. // );
  293. // } else {
  294. // let data = {
  295. // orderId: this.order.id,
  296. // payType: this.order.payType
  297. // };
  298. // let that = this;
  299. // uni.showLoading();
  300. // pay(data).then(
  301. // res => {
  302. // if (res.code == 200) {
  303. // this.payfun(res)
  304. // } else {
  305. // uni.showToast({
  306. // icon: 'none',
  307. // title: res.msg,
  308. // });
  309. // }
  310. // },
  311. // rej => {}
  312. // );
  313. // }
  314. // },
  315. payfun(res) {
  316. const that = this;
  317. console.log(res.result);
  318. if (res.payType == 1 || res.payType == 2) {
  319. common_vendor.index.requestPayment({
  320. provider: "wxpay",
  321. timeStamp: res.result.timeStamp,
  322. nonceStr: res.result.nonceStr,
  323. // package: res.result.packageValue,
  324. package: res.result.packageStr,
  325. signType: res.result.signType,
  326. paySign: res.result.paySign,
  327. success: function(res2) {
  328. common_vendor.index.hideLoading();
  329. common_vendor.index.redirectTo({
  330. url: "success?order=" + JSON.stringify(that.order)
  331. });
  332. },
  333. fail: function(err) {
  334. common_vendor.index.showToast({
  335. icon: "none",
  336. title: "fail:" + JSON.stringify(err)
  337. });
  338. console.log("fail:" + JSON.stringify(err));
  339. common_vendor.index.hideLoading();
  340. }
  341. });
  342. } else if (res.payType == 3) {
  343. common_vendor.index.hideLoading();
  344. if (that.order.isPrescribe) {
  345. common_vendor.index.redirectTo({
  346. url: "prescribe?orderId=" + that.prescribeOrder + "&combinationOrderId=" + encodeURIComponent(that.order.combinationOrderId)
  347. });
  348. } else {
  349. common_vendor.index.redirectTo({
  350. url: "success?order=" + JSON.stringify(that.order)
  351. });
  352. }
  353. }
  354. }
  355. }
  356. };
  357. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  358. var _a;
  359. return common_vendor.e({
  360. a: common_vendor.t($options.payLimitTime),
  361. b: common_vendor.t($data.order ? (Number($data.order.totalPrice) || 0).toFixed(2) : "0.00"),
  362. c: common_assets._imports_0$11,
  363. d: $data.payType === 1,
  364. e: common_vendor.o((...args) => $options.handlePayTypeChange && $options.handlePayTypeChange(...args)),
  365. f: common_vendor.t((_a = $data.order) == null ? void 0 : _a.orderCode),
  366. g: common_vendor.t($options.formattedDate),
  367. h: $data.order != null
  368. }, $data.order != null ? {
  369. i: common_vendor.t($data.order ? (Number($data.order.totalPrice) || 0).toFixed(2) : "0.00")
  370. } : {}, {
  371. j: common_vendor.o(($event) => $options.payOrder())
  372. });
  373. }
  374. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  375. _sfc_main.__runtimeHooks = 2;
  376. wx.createPage(MiniProgramPage);