packageOrderPay.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. "use strict";
  2. var common_vendor = require("../common/vendor.js");
  3. var api_common = require("../api/common.js");
  4. var api_userAddress = require("../api/userAddress.js");
  5. var api_user = require("../api/user.js");
  6. var api_package = require("../api/package.js");
  7. var api_packageOrder = require("../api/packageOrder.js");
  8. require("../common/request.js");
  9. const _sfc_main = {
  10. data() {
  11. return {
  12. giftPrice: 0,
  13. payTypes: [],
  14. addressId: null,
  15. wxPay: true,
  16. address: null,
  17. orderId: null,
  18. order: null,
  19. items: null,
  20. payType: "1",
  21. couponText: "\u8BF7\u9009\u62E9\u4F18\u60E0\u5238",
  22. userCouponId: 0,
  23. coupons: [],
  24. couponShow: false,
  25. payMoney: 0,
  26. discountMoney: 0,
  27. payRemain: 0,
  28. payDelivery: 0,
  29. payPrice: 0,
  30. gifts: []
  31. };
  32. },
  33. onLoad(option) {
  34. this.orderId = option.orderId;
  35. var that = this;
  36. common_vendor.index.$on("updateAddress", (e) => {
  37. that.addressId = e.addressId;
  38. that.address = e;
  39. that.address.address = e.province + e.city + e.district + e.detail;
  40. });
  41. this.getAddressByDefault();
  42. },
  43. onShow() {
  44. this.getPackageOrderById();
  45. this.getPackageById();
  46. this.getConfigByKey();
  47. },
  48. methods: {
  49. getAddressByDefault() {
  50. api_userAddress.getAddressByDefault().then((res) => {
  51. if (res.code == 200) {
  52. if (res.data != null) {
  53. this.addressId = res.data.addressId;
  54. this.address = res.data;
  55. this.address.address = res.data.province + res.data.city + res.data.district + res.data.detail;
  56. }
  57. } else {
  58. common_vendor.index.showToast({
  59. icon: "none",
  60. title: res.msg
  61. });
  62. }
  63. }, (rej) => {
  64. });
  65. },
  66. getConfigByKey() {
  67. var data = { key: "his.package" };
  68. api_common.getConfigByKey(data).then((res) => {
  69. if (res.code == 200) {
  70. this.giftPrice = JSON.parse(res.data).giftPrice;
  71. console.log(this.giftPrice);
  72. }
  73. }, (rej) => {
  74. });
  75. },
  76. checkPayType(payType) {
  77. var flag = false;
  78. this.payTypes.forEach(function(value, index, array) {
  79. if (value.toString() == payType.toString()) {
  80. flag = true;
  81. }
  82. });
  83. return flag;
  84. },
  85. payTypeChange(e) {
  86. console.log(e.detail.value);
  87. this.payType = e.detail.value;
  88. this.compute();
  89. },
  90. couponSelect(item) {
  91. this.couponShow = false;
  92. this.userCouponId = item.id;
  93. console.log(item);
  94. this.couponText = item.price + "\u5143\u4F18\u60E0\u5238";
  95. this.compute();
  96. },
  97. open() {
  98. },
  99. close() {
  100. this.couponShow = false;
  101. },
  102. openCoupon() {
  103. this.couponShow = true;
  104. },
  105. delCoupon() {
  106. this.userCouponId = 0;
  107. this.couponText = "\u8BF7\u9009\u62E9\u4F18\u60E0\u5238";
  108. this.compute();
  109. },
  110. compute() {
  111. var data = {
  112. payType: this.payType,
  113. orderId: this.orderId,
  114. userCouponId: this.userCouponId,
  115. companyId: this.companyId,
  116. companyUserId: this.companyUserId
  117. };
  118. console.log(data);
  119. api_packageOrder.compute(data).then((res) => {
  120. if (res.code == 200) {
  121. this.payPrice = res.moneys.payPrice.toFixed(2);
  122. this.payMoney = res.moneys.payMoney.toFixed(2);
  123. this.discountMoney = res.moneys.discountMoney.toFixed(2);
  124. this.payDelivery = res.moneys.payDelivery.toFixed(2);
  125. this.payRemain = res.moneys.payRemain.toFixed(2);
  126. this.gifts = res.moneys.gifts;
  127. } else {
  128. this.payType = 1;
  129. this.compute();
  130. this.userCouponId = 0;
  131. this.couponText = "\u8BF7\u9009\u62E9\u4F18\u60E0\u5238";
  132. common_vendor.index.showToast({
  133. icon: "none",
  134. title: res.msg
  135. });
  136. }
  137. }, (err) => {
  138. });
  139. },
  140. getMyEnableCouponList() {
  141. var data = {};
  142. if (this.package.isShow == 0) {
  143. data.couponType = 5;
  144. data.cateId = this.package.privateType;
  145. } else if (this.package.isShow == 1) {
  146. data.couponType = 6;
  147. data.cateId = this.package.diseaseType;
  148. }
  149. api_user.getMyEnableCouponList(data).then((res) => {
  150. if (res.code == 200) {
  151. this.coupons = res.data;
  152. }
  153. }, (err) => {
  154. });
  155. },
  156. getPackageOrderById() {
  157. var data = { orderId: this.orderId };
  158. console.log(data);
  159. api_packageOrder.getPackageOrderById(data).then((res) => {
  160. if (res.code == 200) {
  161. this.order = res.order;
  162. this.compute();
  163. this.getPackageById(this.order.packageId);
  164. }
  165. }, (rej) => {
  166. });
  167. },
  168. getPackageById(packageId) {
  169. var data = { packageId };
  170. api_package.getPackageById(data).then((res) => {
  171. if (res.code == 200) {
  172. this.package = res.data;
  173. this.payTypes = res.data.payType.split(",");
  174. console.log(this.payTypes);
  175. this.getMyEnableCouponList();
  176. }
  177. }, (rej) => {
  178. });
  179. },
  180. openAddress() {
  181. common_vendor.index.navigateTo({
  182. url: "/pages_user/address"
  183. });
  184. },
  185. payOrder() {
  186. var data = {
  187. payType: this.payType,
  188. userCouponId: this.userCouponId,
  189. addressId: this.addressId,
  190. remark: this.order.remark,
  191. orderId: this.order.orderId
  192. };
  193. common_vendor.index.showLoading();
  194. api_packageOrder.pay(data).then((res) => {
  195. if (res.code == 200) {
  196. common_vendor.index.redirectTo({
  197. url: "./packagePayment?orderId=" + this.orderId
  198. });
  199. } else {
  200. common_vendor.index.showToast({
  201. icon: "none",
  202. title: res.msg
  203. });
  204. }
  205. }, (rej) => {
  206. });
  207. }
  208. }
  209. };
  210. if (!Array) {
  211. const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
  212. _easycom_u_popup2();
  213. }
  214. const _easycom_u_popup = () => "../uni_modules/uview-plus/components/u-popup/u-popup.js";
  215. if (!Math) {
  216. _easycom_u_popup();
  217. }
  218. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  219. return common_vendor.e({
  220. a: $data.address == null
  221. }, $data.address == null ? {
  222. b: common_vendor.o(($event) => $options.openAddress())
  223. } : {}, {
  224. c: $data.address != null
  225. }, $data.address != null ? common_vendor.e({
  226. d: common_vendor.t($data.address.realName),
  227. e: $data.address.phone != null
  228. }, $data.address.phone != null ? {
  229. f: common_vendor.t($data.address.phone)
  230. } : {}, {
  231. g: common_vendor.t($data.address.address),
  232. h: common_vendor.o(($event) => $options.openAddress())
  233. }) : {}, {
  234. i: common_vendor.t($data.payPrice),
  235. j: $data.order != null && ($data.order.userCouponId == null || $data.order.userCouponId == 0)
  236. }, $data.order != null && ($data.order.userCouponId == null || $data.order.userCouponId == 0) ? common_vendor.e({
  237. k: common_vendor.t($data.couponText),
  238. l: $data.userCouponId != 0
  239. }, $data.userCouponId != 0 ? {
  240. m: common_vendor.o(($event) => $options.delCoupon())
  241. } : {}, {
  242. n: common_vendor.o(($event) => $options.openCoupon())
  243. }) : {}, {
  244. o: common_vendor.t($data.discountMoney),
  245. p: common_vendor.t($data.payMoney),
  246. q: common_vendor.t($data.payRemain),
  247. r: common_vendor.t($data.payDelivery),
  248. s: $options.checkPayType("1")
  249. }, $options.checkPayType("1") ? {
  250. t: $data.payType == "1"
  251. } : {}, {
  252. v: $options.checkPayType("2")
  253. }, $options.checkPayType("2") ? {
  254. w: $data.payType == "2"
  255. } : {}, {
  256. x: $options.checkPayType("3")
  257. }, $options.checkPayType("3") ? {
  258. y: $data.payType == "3"
  259. } : {}, {
  260. z: common_vendor.o((...args) => $options.payTypeChange && $options.payTypeChange(...args)),
  261. A: $data.gifts.length > 0
  262. }, $data.gifts.length > 0 ? {
  263. B: common_vendor.f($data.gifts, (product, k0, i0) => {
  264. return {
  265. a: product.image,
  266. b: common_vendor.t(product.productName),
  267. c: common_vendor.t(product.sku),
  268. d: common_vendor.t(product.price.toFixed(2)),
  269. e: common_vendor.t(product.count)
  270. };
  271. })
  272. } : {}, {
  273. C: $data.order != null
  274. }, $data.order != null ? {
  275. D: $data.order.remark,
  276. E: common_vendor.o(($event) => $data.order.remark = $event.detail.value)
  277. } : {}, {
  278. F: $data.coupons.length > 0
  279. }, $data.coupons.length > 0 ? {
  280. G: common_vendor.f($data.coupons, (item, k0, i0) => {
  281. return common_vendor.e({
  282. a: item.status == 0
  283. }, item.status == 0 ? {} : {}, {
  284. b: item.status != 0
  285. }, item.status != 0 ? {} : {}, {
  286. c: common_vendor.t(item.price.toFixed(2)),
  287. d: common_vendor.t(item.minPrice.toFixed(2)),
  288. e: common_vendor.t(item.title),
  289. f: item.status == 0 || item.status == 2
  290. }, item.status == 0 || item.status == 2 ? {
  291. g: common_vendor.t(item.limitTime)
  292. } : {}, {
  293. h: item.status == 1
  294. }, item.status == 1 ? {
  295. i: common_vendor.t(item.useTime)
  296. } : {}, {
  297. j: item.status == 1
  298. }, item.status == 1 ? {} : {}, {
  299. k: item.status == 2
  300. }, item.status == 2 ? {} : {}, {
  301. l: item.status == 0
  302. }, item.status == 0 ? {} : {}, {
  303. m: common_vendor.o(($event) => $options.couponSelect(item))
  304. });
  305. })
  306. } : {}, {
  307. H: $data.coupons.length == 0
  308. }, $data.coupons.length == 0 ? {} : {}, {
  309. I: common_vendor.o($options.close),
  310. J: common_vendor.o($options.open),
  311. K: common_vendor.p({
  312. closeable: true,
  313. show: $data.couponShow,
  314. round: 10,
  315. mode: "bottom"
  316. }),
  317. L: $data.order != null
  318. }, $data.order != null ? {
  319. M: common_vendor.t($data.payMoney),
  320. N: common_vendor.o(($event) => $options.payOrder())
  321. } : {});
  322. }
  323. var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "E:/Project/2023/\u95EE\u8BCA\u5E73\u53F0/his_user_miniapp/pages_order/packageOrderPay.vue"]]);
  324. wx.createPage(MiniProgramPage);