confirmCreateOrder.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const api_order = require("../api/order.js");
  4. const common_assets = require("../common/assets.js");
  5. const EvanSwitch = () => "../components/evan-switch/evan-switch.js";
  6. const popupBottom = () => "../components/px-popup-bottom/px-popup-bottom.js";
  7. const _sfc_main = {
  8. components: {
  9. EvanSwitch,
  10. popupBottom
  11. },
  12. data() {
  13. return {
  14. priceSum: null,
  15. cartsSelect: [],
  16. address: null,
  17. addressId: null,
  18. totalNum: null,
  19. orderKey: null,
  20. price: null,
  21. liveId: null,
  22. orderList: [],
  23. userInfo: null,
  24. userAddrLiat: [],
  25. //用户地址
  26. temps: [],
  27. couponUserId: null,
  28. couponText: "请选择",
  29. couponsList: [],
  30. couponVisible: false,
  31. priceAll: {
  32. payPrice: 0,
  33. totalPostage: 0,
  34. usedIntegral: 0,
  35. totalPrice: 0
  36. },
  37. carts: [],
  38. checked: false,
  39. type: null,
  40. cartIds: null,
  41. // form:{
  42. // useIntegral:0,
  43. // orderKey:null,
  44. // addressId:null,
  45. // mark:null,
  46. // companyId:null,
  47. // companyUserId:null,
  48. // createOrderKey:null,
  49. // },
  50. confirmParam: []
  51. };
  52. },
  53. onLoad(options) {
  54. console.log("确认订单", options);
  55. this.orderKey = options.orderKey;
  56. this.type = options.type;
  57. if (this.type == "goods") {
  58. this.liveId = options.liveId;
  59. this.productId = options.productId;
  60. this.totalNum = Number(options.totalNum);
  61. this.price = Number(options.price);
  62. this.priceSum = this.price * this.totalNum;
  63. }
  64. if (this.type == "cart") {
  65. this.getChecked();
  66. }
  67. },
  68. mounted() {
  69. this.getUserAddr();
  70. common_vendor.index.$on("updateAddress", (e) => {
  71. this.address = e;
  72. this.addressId = e.addressId;
  73. });
  74. },
  75. beforeDestroy() {
  76. common_vendor.index.$off("updateAddress");
  77. },
  78. methods: {
  79. //获取购物车选中商品
  80. getChecked() {
  81. api_order.checked().then(
  82. (res) => {
  83. if (res.code == 200) {
  84. this.cartsSelect = res.rows;
  85. this.priceSum = res.rows.reduce((sum, item) => {
  86. return sum + item.price * item.cartNum;
  87. }, 0);
  88. console.log("获取购物车选中商品>>>>", this.priceSum);
  89. } else {
  90. common_vendor.index.showToast({
  91. title: res.msg,
  92. icon: "none"
  93. });
  94. }
  95. },
  96. (rej) => {
  97. }
  98. );
  99. },
  100. // 获取用户收货地址
  101. getUserAddr() {
  102. this.userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
  103. api_order.userAddr(this.userInfo.userId).then(
  104. (res) => {
  105. if (res.code == 200) {
  106. console.log("用户收货地址>>>>", res.data);
  107. this.address = res.data.find((item) => item.isDefault == 1);
  108. } else {
  109. common_vendor.index.showToast({
  110. title: res.msg,
  111. icon: "none"
  112. });
  113. }
  114. },
  115. (rej) => {
  116. }
  117. );
  118. },
  119. // 创建购物车订单
  120. createCartLiveOrder() {
  121. let data = {
  122. orderKey: this.orderKey,
  123. userName: this.address.realName,
  124. userPhone: this.address.phone,
  125. userAddress: this.address.province + this.address.city + this.address.district + this.address.detail
  126. };
  127. return api_order.cartOrder(data).then((res) => {
  128. if (res.code == 200) {
  129. console.log("创建购物车订单res", res);
  130. this.OrderList = res.order;
  131. return res.order;
  132. } else {
  133. common_vendor.index.showToast({
  134. title: res.msg,
  135. icon: "none"
  136. });
  137. throw new Error(res.msg);
  138. }
  139. });
  140. },
  141. // 创建订单
  142. createLiveOrder() {
  143. let data = {
  144. liveId: this.liveId,
  145. orderKey: this.orderKey,
  146. userName: this.address.realName,
  147. userPhone: this.address.phone,
  148. userAddress: this.address.province + this.address.city + this.address.district + this.address.detail,
  149. cartId: "5",
  150. productId: this.productId,
  151. totalNum: this.totalNum
  152. };
  153. return api_order.createliveOrder(data).then((res) => {
  154. if (res.code == 200) {
  155. this.orderList = res.order;
  156. return res.order;
  157. } else {
  158. common_vendor.index.showToast({
  159. title: res.msg,
  160. icon: "none"
  161. });
  162. throw new Error(res.msg);
  163. }
  164. });
  165. },
  166. getWeixinOrderTemps: function() {
  167. getWeixinOrderTemps().then(
  168. (res) => {
  169. if (res.code == 200) {
  170. this.temps = res.temp;
  171. }
  172. },
  173. (rej) => {
  174. }
  175. );
  176. },
  177. couponSelect(item) {
  178. this.couponText = "-¥" + item.couponPrice.toFixed(2);
  179. this.couponUserId = item.id;
  180. this.couponVisible = false;
  181. this.computed();
  182. },
  183. openCoupon() {
  184. let that = this;
  185. var data = {
  186. couponType: 2,
  187. useMinPrice: this.price.payPrice
  188. };
  189. getMyEnableCouponList(data).then((res) => {
  190. this.couponVisible = true;
  191. that.couponsList = res.data;
  192. });
  193. },
  194. integralChange(e) {
  195. this.form.useIntegral = e ? 1 : 0;
  196. this.computed();
  197. },
  198. openAddress() {
  199. common_vendor.index.navigateTo({
  200. url: "/pages_user/address"
  201. });
  202. },
  203. // 提交订单
  204. async submitOrder() {
  205. try {
  206. if (this.orderKey == null) {
  207. common_vendor.index.showToast({
  208. icon: "none",
  209. title: "订单KEY不存在"
  210. });
  211. return;
  212. }
  213. if (this.address == null) {
  214. common_vendor.index.showToast({
  215. icon: "none",
  216. title: "收货地址不能为空"
  217. });
  218. return;
  219. }
  220. let orderList;
  221. if (this.type == "cart") {
  222. orderList = await this.createCartLiveOrder();
  223. } else if (this.type == "goods") {
  224. orderList = await this.createLiveOrder();
  225. }
  226. console.log("orderList>>", orderList);
  227. const orderListStr = encodeURIComponent(JSON.stringify(orderList));
  228. common_vendor.index.navigateTo({
  229. url: `/pages_shop/paymentOrder?orderList=${orderListStr}`
  230. });
  231. } catch (error) {
  232. console.error("订单创建失败:", error);
  233. common_vendor.index.showToast({
  234. title: "提交失败",
  235. icon: "none"
  236. });
  237. }
  238. },
  239. // 购物车支付订单
  240. async creatCartOrder() {
  241. try {
  242. if (this.orderKey == null) {
  243. common_vendor.index.showToast({
  244. icon: "none",
  245. title: "订单KEY不存在"
  246. });
  247. return;
  248. }
  249. if (this.address == null) {
  250. common_vendor.index.showToast({
  251. icon: "none",
  252. title: "收货地址不能为空"
  253. });
  254. return;
  255. }
  256. const orderList = await this.cartOrder();
  257. const orderListStr = encodeURIComponent(JSON.stringify(orderList));
  258. common_vendor.index.navigateTo({
  259. url: `/pages_shop/paymentOrder?orderList=${orderListStr}`
  260. });
  261. } catch (error) {
  262. console.error("订单创建失败:", error);
  263. common_vendor.index.showToast({
  264. title: "提交失败",
  265. icon: "none"
  266. });
  267. }
  268. }
  269. // var that=this;
  270. // if(this.form.orderKey==null){
  271. // uni.showToast({
  272. // icon:'none',
  273. // title: '订单KEY不存在',
  274. // });
  275. // return;
  276. // }
  277. // if(this.form.addressId==null){
  278. // uni.showToast({
  279. // icon:'none',
  280. // title: '收货地址不能为空',
  281. // });
  282. // return;
  283. // }
  284. // uni.requestSubscribeMessage({
  285. // tmplIds: this.temps,
  286. // success(res) {
  287. // that.createOrder();
  288. // },
  289. // fail(res) {
  290. // that.createOrder();
  291. // }
  292. // })
  293. // createOrder() {
  294. // const mark = this.carts.map(item => item.markinfo)
  295. // var that = this;
  296. // var data = null;
  297. // var tuiUserId = uni.getStorageSync('tuiUserId');
  298. // uni.showLoading({
  299. // title: '正在处理中...'
  300. // });
  301. // if (tuiUserId != null && tuiUserId != undefined && tuiUserId > 0) {
  302. // data = {
  303. // createOrderKey: this.form.createOrderKey,
  304. // orderCreateType: 3,
  305. // tuiUserId: tuiUserId,
  306. // companyId: this.form.companyId,
  307. // companyUserId: this.form.companyUserId,
  308. // couponUserId: this.couponUserId,
  309. // mark: mark,
  310. // orderKeys: this.form.orderKey,
  311. // addressId: this.form.addressId,
  312. // useIntegral: this.form.useIntegral,
  313. // payType: 1
  314. // };
  315. // } else {
  316. // data = {
  317. // createOrderKey: this.form.createOrderKey,
  318. // orderCreateType: 3,
  319. // companyId: this.form.companyId,
  320. // companyUserId: this.form.companyUserId,
  321. // couponUserId: this.couponUserId,
  322. // mark: mark,
  323. // orderKeys: this.form.orderKey,
  324. // addressId: this.form.addressId,
  325. // useIntegral: this.form.useIntegral,
  326. // payType: 1
  327. // };
  328. // }
  329. // create(data).then(
  330. // res => {
  331. // uni.hideLoading()
  332. // if (!res.code && res.code !== 0) {
  333. // uni.hideLoading()
  334. // // if(res.order.isPrescribe==1){
  335. // // setTimeout(function(){
  336. // // uni.redirectTo({
  337. // // url:"prescribe?orderId="+res.order.id
  338. // // })
  339. // // },200);
  340. // // }
  341. // // else{
  342. // // setTimeout(function(){
  343. // // uni.redirectTo({
  344. // // url: './paymentOrder?orderId='+res.order.id
  345. // // })
  346. // // },200);
  347. // // }
  348. // if (res.some(item => item.order.isPrescribe) == 1) {
  349. // setTimeout(function() {
  350. // let orderIds = res.filter(item => item.order.isPrescribe == 1).map(it => it
  351. // .order.id)
  352. // orderIds = orderIds.join(',')
  353. // uni.redirectTo({
  354. // url: "prescribe?orderId=" + orderIds + "&combinationOrderId=" +
  355. // encodeURIComponent(res[0].order.combinationOrderId)
  356. // })
  357. // }, 200);
  358. // } else {
  359. // setTimeout(function() {
  360. // uni.redirectTo({
  361. // url: './paymentOrder?combinationOrderId=' + encodeURIComponent(
  362. // res[0].order.combinationOrderId)
  363. // })
  364. // }, 200);
  365. // }
  366. // return;
  367. // } else {
  368. // if (res.code == 501) {
  369. // uni.showToast({
  370. // icon: 'none',
  371. // title: res.msg,
  372. // });
  373. // setTimeout(function() {
  374. // uni.navigateBack({
  375. // delta: 1
  376. // })
  377. // }, 200);
  378. // return;
  379. // } else {
  380. // uni.showToast({
  381. // icon: 'none',
  382. // title: res.msg,
  383. // });
  384. // }
  385. // }
  386. // },
  387. // rej => {}
  388. // );
  389. // },// confirm(item) {
  390. // // let data = {type:this.type,cartIds:this.cartIds};
  391. // confirm(this.confirmParam).then(
  392. // res => {
  393. // if (res.code == 200) {
  394. // this.carts = res.carts.map(item => ({
  395. // ...item,
  396. // markinfo: ""
  397. // }));
  398. // this.form.orderKey = res.orderKeys;
  399. // if (res.address != null) {
  400. // this.form.addressId = res.address.id;
  401. // this.address = res.address;
  402. // }
  403. // this.computed()
  404. // } else {
  405. // uni.showToast({
  406. // icon: 'none',
  407. // title: res.msg,
  408. // });
  409. // }
  410. // },
  411. // rej => {}
  412. // );
  413. // },
  414. // computed(item) {
  415. // let data = {
  416. // createOrderKey: this.form.createOrderKey,
  417. // couponUserId: this.couponUserId,
  418. // orderKeys: this.form.orderKey,
  419. // addressId: this.form.addressId,
  420. // useIntegral: this.form.useIntegral
  421. // };
  422. // computed(data).then(
  423. // res => {
  424. // if (res.code == 200) {
  425. // // this.price=res.data
  426. // this.price = res.data && res.data.length > 0 ? res.data : []
  427. // this.priceAll = res.data && res.data.length > 0 ? res.data[res.data.length - 1] : {
  428. // payPrice: 0,
  429. // totalPostage: 0,
  430. // usedIntegral: 0,
  431. // totalPrice: 0.00,
  432. // }
  433. // } else {
  434. // if (res.code == 501) {
  435. // uni.showToast({
  436. // icon: 'none',
  437. // title: res.msg,
  438. // });
  439. // setTimeout(function() {
  440. // uni.navigateBack({
  441. // delta: 1
  442. // })
  443. // }, 500);
  444. // return;
  445. // } else {
  446. // uni.showToast({
  447. // icon: 'none',
  448. // title: res.msg,
  449. // });
  450. // }
  451. // }
  452. // },
  453. // rej => {}
  454. // );
  455. // },
  456. }
  457. };
  458. if (!Array) {
  459. const _component_popupBottom = common_vendor.resolveComponent("popupBottom");
  460. _component_popupBottom();
  461. }
  462. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  463. var _a, _b, _c;
  464. return common_vendor.e({
  465. a: $data.address == null
  466. }, $data.address == null ? {
  467. b: common_assets._imports_0$10,
  468. c: common_vendor.o(($event) => $options.openAddress())
  469. } : {}, {
  470. d: $data.address != null
  471. }, $data.address != null ? common_vendor.e({
  472. e: common_vendor.t($data.address.realName),
  473. f: $data.address.phone != null
  474. }, $data.address.phone != null ? {
  475. g: common_vendor.t(_ctx.$parsePhone($data.address.phone))
  476. } : {}, {
  477. h: common_vendor.t($data.address.province),
  478. i: common_vendor.t($data.address.city),
  479. j: common_vendor.t($data.address.district),
  480. k: common_vendor.t($data.address.detail),
  481. l: common_assets._imports_0$10,
  482. m: common_vendor.o(($event) => $options.openAddress())
  483. }) : {}, {
  484. n: common_vendor.f($data.carts, (shop, idx, i0) => {
  485. return common_vendor.e({
  486. a: shop.storeName && shop.storeName != "null"
  487. }, shop.storeName && shop.storeName != "null" ? {
  488. b: common_vendor.t(shop.storeName)
  489. } : {}, {
  490. c: common_vendor.f(shop.list, (item, index, i1) => {
  491. var _a2;
  492. return {
  493. a: item.productAttrImage ? item.productAttrImage : item.productImage,
  494. b: common_vendor.t(_ctx.utils.getDictLabelName("storeProductType", item.productType)),
  495. c: common_vendor.t(item.productName),
  496. d: common_vendor.t(item.productAttrName),
  497. e: common_vendor.t((_a2 = item.price) == null ? void 0 : _a2.toFixed(2)),
  498. f: common_vendor.t(item.cartNum),
  499. g: index
  500. };
  501. })
  502. }, $data.price && $data.price.length > 0 ? {
  503. d: common_vendor.t($data.price[idx].payPostage == null || $data.price[idx].payPostage == 0 ? "免运费" : $data.price[idx].payPostage.toFixed(2))
  504. } : {}, {
  505. e: shop.markinfo,
  506. f: common_vendor.o(($event) => shop.markinfo = $event.detail.value, idx),
  507. g: idx
  508. });
  509. }),
  510. o: $data.price && $data.price.length > 0,
  511. p: common_vendor.t((_a = $data.priceSum) == null ? void 0 : _a.toFixed(2)),
  512. q: common_vendor.t((_b = $data.priceSum) == null ? void 0 : _b.toFixed(2)),
  513. r: common_vendor.t((_c = $data.priceSum) == null ? void 0 : _c.toFixed(2)),
  514. s: common_vendor.o((...args) => $options.submitOrder && $options.submitOrder(...args)),
  515. t: $data.couponsList.length > 0
  516. }, $data.couponsList.length > 0 ? {
  517. v: common_vendor.f($data.couponsList, (item, index, i0) => {
  518. return common_vendor.e({
  519. a: item.status == 0
  520. }, item.status == 0 ? {
  521. b: common_assets._imports_2$5
  522. } : {}, {
  523. c: item.status != 0
  524. }, item.status != 0 ? {
  525. d: common_assets._imports_3$2
  526. } : {}, {
  527. e: common_vendor.t(item.couponPrice),
  528. f: common_vendor.t(item.useMinPrice),
  529. g: common_vendor.t(item.couponTitle),
  530. h: common_vendor.t(item.limitTime),
  531. i: common_vendor.o(($event) => $options.couponSelect(item), index),
  532. j: index
  533. });
  534. })
  535. } : {}, {
  536. w: $data.couponsList.length == 0
  537. }, $data.couponsList.length == 0 ? {
  538. x: common_assets._imports_2$2
  539. } : {}, {
  540. y: common_vendor.sr("popup", "5fa01107-0"),
  541. z: common_vendor.p({
  542. visible: $data.couponVisible,
  543. title: " ",
  544. bgColor: "#f5f5f5",
  545. radius: "30",
  546. maxHeight: "60%"
  547. })
  548. });
  549. }
  550. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-5fa01107"]]);
  551. wx.createPage(MiniProgramPage);