confirmCreateOrder.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. <template>
  2. <view>
  3. <view class="inner-box">
  4. <!-- 收货人 -->
  5. <view class="address-box" v-if="address==null" @click="openAddress()">
  6. <view class="left">
  7. <view class="name-box">
  8. <text class="text name">添加收货地址</text>
  9. </view>
  10. </view>
  11. <view class="arrow-box">
  12. <image src="/static/images/arrow_gray.png" mode=""></image>
  13. </view>
  14. </view>
  15. <view class="address-box" v-if="address!=null" @click="openAddress()">
  16. <view class="left">
  17. <view class="name-box">
  18. <text class="text name">{{address.realName}}</text>
  19. <text class="text" v-if="address.phone!=null">{{address.phone}}</text>
  20. </view>
  21. <view class="address">
  22. {{address.province}}{{address.city}}{{address.district}}{{address.detail}}
  23. </view>
  24. </view>
  25. <view class="arrow-box">
  26. <image src="/static/images/arrow_gray.png" mode=""></image>
  27. </view>
  28. </view>
  29. <!-- 积分 -->
  30. <view class="price-info">
  31. <view class="price-info-title">价格明细</view>
  32. <view class="points">
  33. <view class="left">
  34. <text class="text">商品总价</text>
  35. </view>
  36. <view class="right" style="align-items: baseline;">
  37. <text class="price-info-unit">¥</text>
  38. <text class="price-info-num">{{(orderData.payPrice||0).toFixed(2)}}</text>
  39. </view>
  40. </view>
  41. <view class="points" @click="openCoupon()">
  42. <view class="left">
  43. <text class="text">优惠券</text>
  44. </view>
  45. <view class="right">
  46. <text class="text">{{couponText}}</text>
  47. <image src="/static/images/arrow4.png" mode=""></image>
  48. </view>
  49. </view>
  50. <view class="points">
  51. <view class="left">
  52. <text class="text">运费</text>
  53. </view>
  54. <view class="right">
  55. <text class="text"
  56. v-if="address!=null">{{orderData.payDelivery==null||orderData.payDelivery==0?'免运费':orderData.payDelivery.toFixed(2)}}</text>
  57. <text class="text" v-if="address==null">--</text>
  58. </view>
  59. </view>
  60. <!-- <view class="points">
  61. <view class="left">
  62. <text class="text">服务费</text>
  63. </view>
  64. <view class="right">
  65. <text class="text">{{price.serviceFee.toFixed(2)}}</text>
  66. </view>
  67. </view> -->
  68. <view class="points">
  69. <view class="left">
  70. <text class="text">合计</text>
  71. </view>
  72. <view class="right" style="align-items: baseline;">
  73. <text class="price-info-unit">¥</text>
  74. <text class="price-info-num">{{(orderData.totalPrice||0).toFixed(2)}}</text>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <view class="btn-foot">
  80. <view class="right">
  81. <view class="total">
  82. <text class="label">合计:</text>
  83. <view class="price">
  84. <text class="unit">¥</text>
  85. <text class="num">{{(orderData.totalPrice||0).toFixed(2)}}</text>
  86. </view>
  87. </view>
  88. <view class="btn" @click="submitOrder">提交订单</view>
  89. </view>
  90. </view>
  91. <popupBottom ref="popup" :visible.sync="couponVisible" title=" " bgColor="#f5f5f5" radius="30" maxHeight="60%">
  92. <view class="coupon" style="height:650rpx;">
  93. <div class="coupon-list" v-if="couponsList.length > 0">
  94. <div class="item acea-row row-center-wrapper" v-for="(item, index) in couponsList" :key="index">
  95. <div class="money">
  96. <image v-if="item.status==0" class="img" src="../../static/images/coupon1.png"
  97. mode="widthFix"></image>
  98. <image v-if="item.status!=0" class="img" src="../../static/images/coupon2.png"
  99. mode="widthFix"></image>
  100. <div style="z-index: 999;">
  101. ¥<span class="num">{{ item.couponPrice }}</span>
  102. </div>
  103. <div class="pic-num">满{{ item.useMinPrice }}元可用</div>
  104. </div>
  105. <div class="text">
  106. <div class="condition line1">
  107. {{ item.couponTitle }}
  108. </div>
  109. <div class="data acea-row row-between-wrapper">
  110. <div>{{ item.limitTime }}到期</div>
  111. <div class="bnt bg-color-red" @click="couponSelect(item)">选择</div>
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. <view v-if="couponsList.length == 0" class="no-data-box">
  117. <image src="/static/images/no_data.png" mode="aspectFit"></image>
  118. <view class="empty-title">暂无数据</view>
  119. </view>
  120. </view>
  121. </popupBottom>
  122. </view>
  123. </template>
  124. <script>
  125. import {
  126. createliveOrder, // 创建订单
  127. userAddr, // 获取用户收货地址
  128. cartOrder, //购物车订单
  129. computed
  130. // checked //获取购物车选中商品
  131. } from "@/api/order.js"
  132. import popupBottom from '@/components/px-popup-bottom/px-popup-bottom.vue'
  133. export default {
  134. components: {
  135. popupBottom
  136. },
  137. data() {
  138. return {
  139. orderData: {},
  140. cityId: null,
  141. // priceSum: null,
  142. cartsSelect: [],
  143. address: null,
  144. addressId: null,
  145. totalNum: null,
  146. orderKey: null,
  147. // price: null,
  148. liveId: null,
  149. orderList: [],
  150. userInfo: null,
  151. temps: [],
  152. couponUserId: null,
  153. couponText: "请选择",
  154. couponsList: [],
  155. couponVisible: false,
  156. carts: [],
  157. checked: false,
  158. // type: null,
  159. cartIds: null,
  160. confirmParam: [],
  161. }
  162. },
  163. onLoad(options) {
  164. // uni.$on('updateAddress', this.handleAddressUpdate);
  165. console.log("确认订单", options)
  166. this.orderKey = options.orderKey;
  167. this.liveId = options.liveId
  168. this.productId = options.productId
  169. this.totalNum = Number(options.totalNum) || 0
  170. },
  171. mounted() {
  172. this.getUserAddr()
  173. uni.$on('updateAddress', (e) => {
  174. this.address = e;
  175. this.addressId = e.addressId;
  176. });
  177. },
  178. onUnload() {
  179. // 页面卸载时移除监听,避免内存泄漏
  180. uni.$off('updateAddress', this.handleAddressUpdate);
  181. },
  182. beforeDestroy() {
  183. // 移除事件监听,避免内存泄漏
  184. uni.$off('updateAddress');
  185. },
  186. methods: {
  187. handleAddressUpdate(item) {
  188. console.log('接收到地址数据:', item);
  189. // 在这里处理地址数据
  190. this.cityId = item.cityId;
  191. this.address = item;
  192. this.addressId = item.addressId;
  193. this.computedOrder()
  194. // 更新页面显示或其他操作
  195. },
  196. // 获取用户收货地址
  197. getUserAddr() {
  198. userAddr().then(res => {
  199. if (res.code == 200) {
  200. console.log("用户收货地址>>>>", res.data)
  201. this.address = res.data;
  202. if (res.data && res.data.cityId) {
  203. this.cityId = res.data.cityId;
  204. }
  205. this.computedOrder();
  206. } else {
  207. uni.showToast({
  208. title: res.msg,
  209. icon: 'none'
  210. });
  211. }
  212. },
  213. rej => {}
  214. );
  215. },
  216. // 查询创建订单信息
  217. computedOrder() {
  218. let data = {
  219. cityId: this.cityId || '',
  220. totalNum: this.totalNum,
  221. productId: this.productId,
  222. orderKey: this.orderKey,
  223. }
  224. computed(data).then(res => {
  225. if (res.code == 200) {
  226. console.log("查询创建订单信息>>>>", res.data)
  227. this.orderData = res.data
  228. } else {
  229. uni.showToast({
  230. title: res.msg,
  231. icon: 'none'
  232. });
  233. }
  234. },
  235. rej => {}
  236. );
  237. },
  238. // 创建订单
  239. createLiveOrder() {
  240. let data = {
  241. cityId: this.cityId,
  242. liveId: this.liveId,
  243. orderKey: this.orderKey,
  244. userName: this.address.realName,
  245. userPhone: this.address.phone,
  246. userAddress: this.address.province + ' ' + this.address.city + ' ' + this.address.district + ' ' +
  247. this.address
  248. .detail,
  249. cartId: "5",
  250. productId: this.productId,
  251. totalNum: this.totalNum,
  252. }
  253. return createliveOrder(data).then(res => { // 添加 return
  254. if (res.code == 200) {
  255. this.orderList = res.order;
  256. return res.order; // 返回订单数据供后续使用
  257. } else {
  258. uni.showToast({
  259. title: res.msg,
  260. icon: 'none'
  261. });
  262. throw new Error(res.msg); // 抛出错误以便 submitOrder 捕获
  263. }
  264. });
  265. },
  266. getWeixinOrderTemps: function() {
  267. getWeixinOrderTemps().then(
  268. res => {
  269. if (res.code == 200) {
  270. this.temps = res.temp
  271. } else {
  272. }
  273. },
  274. rej => {}
  275. );
  276. },
  277. couponSelect(item) {
  278. this.couponText = "-¥" + (item.couponPrice || 0).toFixed(2);
  279. this.couponUserId = item.id;
  280. this.couponVisible = false;
  281. this.computed();
  282. },
  283. openCoupon() {
  284. let that = this;
  285. var data = {
  286. couponType: 2,
  287. useMinPrice: this.orderData.payPrice
  288. };
  289. getMyEnableCouponList(data).then(res => {
  290. this.couponVisible = true;
  291. that.couponsList = res.data
  292. })
  293. },
  294. integralChange(e) {
  295. this.form.useIntegral = e ? 1 : 0
  296. this.computed()
  297. },
  298. openAddress() {
  299. uni.navigateTo({
  300. url: '/pages_user/user/address'
  301. })
  302. },
  303. // 提交订单
  304. async submitOrder() {
  305. try {
  306. if (this.orderKey == null) {
  307. uni.showToast({
  308. icon: 'none',
  309. title: '订单KEY不存在',
  310. });
  311. return;
  312. }
  313. if (this.address == null) {
  314. uni.showToast({
  315. icon: 'none',
  316. title: '收货地址不能为空',
  317. });
  318. return;
  319. }
  320. let orderList;
  321. orderList = await this.createLiveOrder(); // 等待订单数据返回
  322. console.log("orderList>>", orderList)
  323. const orderListStr = encodeURIComponent(JSON.stringify(orderList));
  324. uni.navigateTo({
  325. url: `/pages_shopping/live/paymentOrder?orderList=${orderListStr}`
  326. });
  327. } catch (error) {
  328. uni.showToast({
  329. title: res.msg,
  330. icon: 'none'
  331. });
  332. }
  333. },
  334. }
  335. }
  336. </script>
  337. <style lang="scss">
  338. .inner-box {
  339. padding: 20upx 20upx 140upx;
  340. .address-box {
  341. margin-bottom: 20rpx;
  342. box-sizing: border-box;
  343. min-height: 171upx;
  344. background: #FFFFFF;
  345. border-radius: 16upx;
  346. background-repeat: no-repeat;
  347. background-size: 100% 30upx;
  348. background-position: left bottom;
  349. padding: 38upx 30upx 36upx;
  350. display: flex;
  351. align-items: center;
  352. justify-content: space-between;
  353. .left {
  354. width: 92%;
  355. .name-box {
  356. display: flex;
  357. align-items: center;
  358. .text {
  359. font-size: 32upx;
  360. font-family: PingFang SC;
  361. font-weight: bold;
  362. color: #111111;
  363. line-height: 1;
  364. &.name {
  365. margin-right: 30upx;
  366. }
  367. }
  368. }
  369. .address {
  370. font-size: 28upx;
  371. font-family: PingFang SC;
  372. font-weight: 500;
  373. color: #666666;
  374. line-height: 42upx;
  375. text-align: left;
  376. margin-top: 23upx;
  377. }
  378. }
  379. .arrow-box {
  380. width: 12upx;
  381. height: 23upx;
  382. display: flex;
  383. align-items: cenetr;
  384. justify-content: cenetr;
  385. image {
  386. width: 100%;
  387. height: 100%;
  388. }
  389. }
  390. }
  391. .shopbox {
  392. background: #FFFFFF;
  393. border-radius: 16rpx;
  394. margin-bottom: 20rpx;
  395. .points {
  396. padding: 0 !important;
  397. }
  398. .remarks {
  399. padding: 0 !important;
  400. }
  401. }
  402. .shopbox-name {
  403. padding: 30rpx 30rpx 0 30rpx;
  404. font-family: PingFang SC, PingFang SC;
  405. font-weight: 400;
  406. font-size: 30rpx;
  407. color: #111;
  408. overflow: hidden;
  409. white-space: nowrap;
  410. text-overflow: ellipsis;
  411. }
  412. .goods-list {
  413. // margin-top: 20upx;
  414. padding: 0 30upx;
  415. background-color: #FFFFFF;
  416. border-radius: 16upx;
  417. .item {
  418. padding: 30upx 0;
  419. border-bottom: 1px solid #EDEEEF;
  420. display: flex;
  421. align-items: center;
  422. .img-box {
  423. width: 160upx;
  424. height: 160upx;
  425. margin-right: 30upx;
  426. image {
  427. width: 100%;
  428. height: 100%;
  429. }
  430. }
  431. .info-box {
  432. width: calc(100% - 190upx);
  433. height: 160upx;
  434. display: flex;
  435. flex-direction: column;
  436. justify-content: space-between;
  437. .name-box {
  438. font-size: 28upx;
  439. font-family: PingFang SC;
  440. font-weight: 500;
  441. color: #111111;
  442. line-height: 40upx;
  443. .tag {
  444. display: inline-block;
  445. padding: 0 6upx;
  446. height: 30upx;
  447. background: linear-gradient(90deg, #66b2ef 0%, #0bb3f2 100%);
  448. border-radius: 4upx;
  449. margin-right: 10upx;
  450. font-size: 22upx;
  451. font-family: PingFang SC;
  452. font-weight: bold;
  453. color: #FFFFFF;
  454. line-height: 30upx;
  455. float: left;
  456. margin-top: 7upx;
  457. }
  458. }
  459. .spec {
  460. margin-top: 10upx;
  461. font-size: 24upx;
  462. font-family: PingFang SC;
  463. font-weight: 500;
  464. color: #999999;
  465. line-height: 1;
  466. }
  467. .price-num {
  468. display: flex;
  469. align-items: center;
  470. justify-content: space-between;
  471. .price {
  472. display: flex;
  473. align-items: flex-end;
  474. .unit {
  475. font-size: 24upx;
  476. font-family: PingFang SC;
  477. font-weight: 500;
  478. color: #111111;
  479. line-height: 1.2;
  480. margin-right: 4upx;
  481. }
  482. .num {
  483. font-size: 32upx;
  484. font-family: PingFang SC;
  485. font-weight: 500;
  486. color: #111111;
  487. line-height: 1;
  488. }
  489. }
  490. .num {
  491. font-size: 24upx;
  492. font-family: PingFang SC;
  493. font-weight: 500;
  494. color: #999999;
  495. line-height: 1;
  496. }
  497. }
  498. }
  499. }
  500. .sub-total {
  501. height: 88upx;
  502. display: flex;
  503. align-items: center;
  504. justify-content: flex-end;
  505. .label {
  506. font-size: 24upx;
  507. font-family: PingFang SC;
  508. font-weight: 500;
  509. color: #999999;
  510. }
  511. .price {
  512. display: flex;
  513. align-items: flex-end;
  514. .unit {
  515. font-size: 24upx;
  516. font-family: PingFang SC;
  517. font-weight: 500;
  518. color: #FF6633;
  519. line-height: 1.2;
  520. margin-right: 4upx;
  521. }
  522. .num {
  523. font-size: 32upx;
  524. font-family: PingFang SC;
  525. font-weight: bold;
  526. color: #FF6633;
  527. line-height: 1;
  528. }
  529. }
  530. }
  531. }
  532. .price-info {
  533. background: #FFFFFF;
  534. border-radius: 16upx;
  535. &-title {
  536. padding: 30rpx 30rpx 20rpx 30rpx;
  537. font-family: PingFang SC, PingFang SC;
  538. font-weight: 500;
  539. font-size: 30rpx;
  540. color: #111;
  541. }
  542. &-unit {
  543. font-size: 24rpx;
  544. }
  545. &-num {
  546. font-size: 28rpx;
  547. }
  548. }
  549. .points {
  550. height: 88upx;
  551. padding: 0 30upx;
  552. background: #FFFFFF;
  553. border-radius: 16upx;
  554. display: flex;
  555. align-items: center;
  556. justify-content: space-between;
  557. .left {
  558. display: flex;
  559. align-items: center;
  560. image {
  561. width: 28upx;
  562. height: 28upx;
  563. margin-right: 20upx;
  564. }
  565. .text {
  566. font-size: 28upx;
  567. font-family: PingFang SC;
  568. font-weight: 500;
  569. color: #666666;
  570. }
  571. }
  572. .right {
  573. display: flex;
  574. align-items: center;
  575. .text {
  576. font-size: 28upx;
  577. font-family: PingFang SC;
  578. font-weight: 500;
  579. color: #111111;
  580. }
  581. image {
  582. margin-left: 15upx;
  583. width: 14upx;
  584. height: 24upx;
  585. }
  586. }
  587. }
  588. .remarks {
  589. // height: 88upx;
  590. padding: 0 30upx;
  591. background: #FFFFFF;
  592. border-radius: 16upx;
  593. margin-top: 20upx;
  594. display: flex;
  595. align-items: center;
  596. input {
  597. width: 100%;
  598. font-size: 28upx;
  599. font-family: PingFang SC;
  600. font-weight: 500;
  601. color: #000000;
  602. }
  603. .input {
  604. font-size: 28upx;
  605. font-family: PingFang SC;
  606. font-weight: 500;
  607. color: #999999;
  608. }
  609. }
  610. }
  611. .btn-foot {
  612. box-sizing: border-box;
  613. width: 100%;
  614. height: 121upx;
  615. background: #FFFFFF;
  616. padding: 16upx 30upx 16upx 60upx;
  617. display: flex;
  618. align-items: center;
  619. justify-content: flex-end;
  620. position: fixed;
  621. left: 0;
  622. bottom: 0;
  623. z-index: 99;
  624. .right {
  625. display: flex;
  626. align-items: center;
  627. .total {
  628. display: flex;
  629. align-items: flex-end;
  630. margin-right: 36upx;
  631. .label {
  632. font-size: 26upx;
  633. font-family: PingFang SC;
  634. font-weight: 500;
  635. color: #999999;
  636. line-height: 1.5;
  637. }
  638. .price {
  639. display: flex;
  640. align-items: flex-end;
  641. .unit {
  642. font-size: 32upx;
  643. font-family: PingFang SC;
  644. font-weight: bold;
  645. color: #FF6633;
  646. line-height: 1.2;
  647. margin-right: 10upx;
  648. }
  649. .num {
  650. font-size: 50upx;
  651. font-family: PingFang SC;
  652. font-weight: bold;
  653. color: #FF6633;
  654. line-height: 1;
  655. }
  656. }
  657. }
  658. .btn {
  659. width: 200upx;
  660. height: 88upx;
  661. line-height: 88upx;
  662. text-align: center;
  663. font-size: 30upx;
  664. font-family: PingFang SC;
  665. font-weight: bold;
  666. color: #FFFFFF;
  667. background: #0bb3f2;
  668. border-radius: 44upx;
  669. }
  670. }
  671. }
  672. </style>