confirmCreateOrder.vue 18 KB

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