confirmCreateOrder.vue 17 KB

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