confirmCreateOrder.vue 17 KB

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