confirmCreateOrder.vue 17 KB

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