confirmCreateOrder.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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" style="align-items: baseline;">
  65. <text class="price-info-unit">¥</text>
  66. <text class="price-info-num">{{(orderData.payPrice||0).toFixed(2)}}</text>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. <view class="btn-foot">
  72. <view class="right">
  73. <view class="total">
  74. <text class="label">合计:</text>
  75. <view class="price">
  76. <text class="unit">¥</text>
  77. <text class="num">{{(orderData.payPrice||0).toFixed(2)}}</text>
  78. </view>
  79. </view>
  80. <view class="btn" @click="submitOrder">提交订单</view>
  81. </view>
  82. </view>
  83. <popupBottom ref="popup" :visible.sync="couponVisible" title=" " bgColor="#f5f5f5" radius="30" maxHeight="60%">
  84. <view class="coupon" style="height:650rpx;">
  85. <div class="coupon-list" v-if="couponsList.length > 0">
  86. <div class="item acea-row row-center-wrapper" v-for="(item, index) in couponsList" :key="index">
  87. <div class="money">
  88. <image v-if="item.status==0&&item.useMinPrice<=orderData.totalPrice" class="img"
  89. src="../../static/images/coupon1.png" mode="widthFix"></image>
  90. <image v-if="item.status!=0||item.useMinPrice>orderData.totalPrice" class="img"
  91. src="../../static/images/coupon2.png" mode="widthFix"></image>
  92. <div style="z-index: 999;">
  93. ¥<span class="num">{{ item.couponPrice }}</span>
  94. </div>
  95. <div class="pic-num">满{{ item.useMinPrice }}元可用</div>
  96. </div>
  97. <div class="text">
  98. <div class="condition line1">
  99. {{ item.couponTitle }}
  100. </div>
  101. <div class="data acea-row row-between-wrapper">
  102. <div>{{ item.limitTime }}到期</div>
  103. <div v-if=" item.status==0&&item.useMinPrice<=orderData.totalPrice"
  104. class="bnt bg-color-red" @click="couponSelect(item)">选择</div>
  105. <div v-else-if="item.status!=0" class="bnt " style="background-color: #878787;">已失效
  106. </div>
  107. <div v-else-if="item.useMinPrice>orderData.totalPrice" class="bnt "
  108. style="background-color: #878787;">未达门槛</div>
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. <view v-if="couponsList.length == 0" class="no-data-box">
  114. <image src="/static/images/no_data.png" mode="aspectFit"></image>
  115. <view class="empty-title">暂无数据</view>
  116. </view>
  117. </view>
  118. </popupBottom>
  119. </view>
  120. </template>
  121. <script>
  122. import {
  123. createliveOrder, // 创建订单
  124. userAddr, // 获取用户收货地址
  125. computed
  126. } from "@/api/order.js"
  127. import {
  128. curCoupon
  129. } from "@/api/living.js"
  130. import popupBottom from '@/components/px-popup-bottom/px-popup-bottom.vue'
  131. export default {
  132. components: {
  133. popupBottom
  134. },
  135. data() {
  136. return {
  137. orderData: {},
  138. cityId: null,
  139. address: null,
  140. addressId: null,
  141. totalNum: null,
  142. orderKey: null,
  143. goodsId: null,
  144. liveId: null,
  145. orderList: [],
  146. temps: [],
  147. couponUserId: null,
  148. couponText: "请选择",
  149. couponsList: [],
  150. couponVisible: false,
  151. carts: [],
  152. checked: false,
  153. cartIds: null,
  154. confirmParam: [],
  155. }
  156. },
  157. onLoad(options) {
  158. // uni.$on('updateAddress', this.handleAddressUpdate);
  159. console.log("确认订单", options)
  160. this.orderKey = options.orderKey;
  161. this.liveId = options.liveId
  162. this.goodsId = options.goodsId
  163. this.productId = options.productId
  164. this.totalNum = Number(options.totalNum) || 0
  165. },
  166. onShow() {
  167. this.getUserAddr()
  168. uni.$on('updateAddress', (e) => {
  169. this.address = e;
  170. this.addressId = e.addressId;
  171. this.cityId = e.cityId;
  172. });
  173. },
  174. mounted() {
  175. // uni.$on('updateAddress', (e) => {
  176. // this.address = e;
  177. // this.addressId = e.addressId;
  178. // });
  179. },
  180. onUnload() {
  181. // 页面卸载时移除监听,避免内存泄漏
  182. uni.$off('updateAddress', this.handleAddressUpdate);
  183. },
  184. beforeDestroy() {
  185. // 移除事件监听,避免内存泄漏
  186. uni.$off('updateAddress');
  187. },
  188. methods: {
  189. handleAddressUpdate(item) {
  190. console.log('接收到地址数据:', item);
  191. // 在这里处理地址数据
  192. this.cityId = item.cityId;
  193. this.address = item;
  194. this.addressId = item.addressId;
  195. this.computedOrder()
  196. // 更新页面显示或其他操作
  197. },
  198. // 获取用户收货地址
  199. getUserAddr() {
  200. userAddr().then(res => {
  201. if (res.code == 200) {
  202. console.log("用户收货地址>>>>", res.data)
  203. if (res.data && !this.address) {
  204. this.address = res.data;
  205. }
  206. if (res.data && res.data.cityId) {
  207. this.cityId = res.data.cityId;
  208. }
  209. this.computedOrder();
  210. } else {
  211. uni.showToast({
  212. title: res.msg,
  213. icon: 'none'
  214. });
  215. }
  216. },
  217. rej => {}
  218. );
  219. },
  220. // 查询创建订单信息
  221. computedOrder() {
  222. let data = {
  223. cityId: this.cityId || '',
  224. totalNum: this.totalNum,
  225. productId: this.productId,
  226. orderKey: this.orderKey,
  227. couponUserId: this.couponUserId || ''
  228. }
  229. computed(data).then(res => {
  230. if (res.code == 200) {
  231. console.log("查询创建订单信息>>>>", res.data)
  232. this.orderData = res.data
  233. } else {
  234. uni.showToast({
  235. title: res.msg,
  236. icon: 'none'
  237. });
  238. }
  239. },
  240. rej => {}
  241. );
  242. },
  243. // 创建订单
  244. createLiveOrder() {
  245. let data = {
  246. cityId: this.cityId,
  247. liveId: this.liveId,
  248. orderKey: this.orderKey,
  249. userName: this.address.realName,
  250. userPhone: this.address.phone,
  251. userAddress: this.address.province + ' ' + this.address.city + ' ' + this.address.district + ' ' +
  252. this.address
  253. .detail,
  254. cartId: "5",
  255. productId: this.productId,
  256. totalNum: this.totalNum,
  257. couponUserId: this.couponUserId
  258. }
  259. return createliveOrder(data).then(res => { // 添加 return
  260. if (res.code == 200) {
  261. this.orderList = res.order;
  262. return res.order; // 返回订单数据供后续使用
  263. } else {
  264. uni.showToast({
  265. title: res.msg,
  266. icon: 'none'
  267. });
  268. throw new Error(res.msg); // 抛出错误以便 submitOrder 捕获
  269. }
  270. });
  271. },
  272. couponSelect(item) {
  273. this.couponText = "-¥" + (item.couponPrice || 0).toFixed(2);
  274. this.couponUserId = item.id;
  275. this.couponVisible = false;
  276. // this.computed();
  277. this.computedOrder()
  278. },
  279. openCoupon() {
  280. console.log("点了优惠券列表")
  281. const data = {
  282. liveId: this.liveId,
  283. goodsId: this.goodsId
  284. };
  285. curCoupon(data).then(res => {
  286. this.couponVisible = true;
  287. this.couponsList = res.data
  288. })
  289. },
  290. openAddress() {
  291. uni.navigateTo({
  292. url: '/pages_user/user/address'
  293. })
  294. },
  295. // 提交订单
  296. async submitOrder() {
  297. try {
  298. if (this.orderKey == null) {
  299. uni.showToast({
  300. icon: 'none',
  301. title: '订单KEY不存在',
  302. });
  303. return;
  304. }
  305. if (this.address == null) {
  306. uni.showToast({
  307. icon: 'none',
  308. title: '收货地址不能为空',
  309. });
  310. return;
  311. }
  312. let orderList;
  313. orderList = await this.createLiveOrder(); // 等待订单数据返回
  314. console.log("orderList>>", orderList)
  315. const orderListStr = encodeURIComponent(JSON.stringify(orderList));
  316. uni.navigateTo({
  317. url: `/pages_shopping/live/paymentOrder?orderList=${orderListStr}&couponUserId=${this.couponUserId}`
  318. });
  319. } catch (error) {
  320. uni.showToast({
  321. title: res.msg,
  322. icon: 'none'
  323. });
  324. }
  325. },
  326. }
  327. }
  328. </script>
  329. <style lang="scss">
  330. .inner-box {
  331. padding: 20rpx 20rpx 140rpx;
  332. .address-box {
  333. margin-bottom: 20rpx;
  334. box-sizing: border-box;
  335. min-height: 171rpx;
  336. background: #FFFFFF;
  337. border-radius: 16rpx;
  338. background-repeat: no-repeat;
  339. background-size: 100% 30rpx;
  340. background-position: left bottom;
  341. padding: 38rpx 30rpx 36rpx;
  342. display: flex;
  343. align-items: center;
  344. justify-content: space-between;
  345. .left {
  346. width: 92%;
  347. .name-box {
  348. display: flex;
  349. align-items: center;
  350. .text {
  351. font-size: 32rpx;
  352. font-family: PingFang SC;
  353. font-weight: bold;
  354. color: #111111;
  355. line-height: 1;
  356. &.name {
  357. margin-right: 30rpx;
  358. }
  359. }
  360. }
  361. .address {
  362. font-size: 28rpx;
  363. font-family: PingFang SC;
  364. font-weight: 500;
  365. color: #666666;
  366. line-height: 42rpx;
  367. text-align: left;
  368. margin-top: 23rpx;
  369. }
  370. }
  371. .arrow-box {
  372. width: 12rpx;
  373. height: 23rpx;
  374. display: flex;
  375. align-items: cenetr;
  376. justify-content: cenetr;
  377. image {
  378. width: 100%;
  379. height: 100%;
  380. }
  381. }
  382. }
  383. .price-info {
  384. background: #FFFFFF;
  385. border-radius: 16rpx;
  386. &-title {
  387. padding: 30rpx 30rpx 20rpx 30rpx;
  388. font-family: PingFang SC, PingFang SC;
  389. font-weight: 500;
  390. font-size: 30rpx;
  391. color: #111;
  392. }
  393. &-unit {
  394. font-size: 24rpx;
  395. }
  396. &-num {
  397. font-size: 28rpx;
  398. }
  399. }
  400. .points {
  401. height: 88rpx;
  402. padding: 0 30rpx;
  403. background: #FFFFFF;
  404. border-radius: 16rpx;
  405. display: flex;
  406. align-items: center;
  407. justify-content: space-between;
  408. .left {
  409. display: flex;
  410. align-items: center;
  411. image {
  412. width: 28rpx;
  413. height: 28rpx;
  414. margin-right: 20rpx;
  415. }
  416. .text {
  417. font-size: 28rpx;
  418. font-family: PingFang SC;
  419. font-weight: 500;
  420. color: #666666;
  421. }
  422. }
  423. .right {
  424. display: flex;
  425. align-items: center;
  426. .text {
  427. font-size: 28rpx;
  428. font-family: PingFang SC;
  429. font-weight: 500;
  430. color: #111111;
  431. }
  432. image {
  433. margin-left: 15rpx;
  434. width: 14rpx;
  435. height: 24rpx;
  436. }
  437. }
  438. }
  439. }
  440. .btn-foot {
  441. box-sizing: border-box;
  442. width: 100%;
  443. height: 121rpx;
  444. background: #FFFFFF;
  445. padding: 16rpx 30rpx 16rpx 60rpx;
  446. display: flex;
  447. align-items: center;
  448. justify-content: flex-end;
  449. position: fixed;
  450. left: 0;
  451. bottom: 0;
  452. z-index: 99;
  453. .right {
  454. display: flex;
  455. align-items: center;
  456. .total {
  457. display: flex;
  458. align-items: flex-end;
  459. margin-right: 36rpx;
  460. .label {
  461. font-size: 26rpx;
  462. font-family: PingFang SC;
  463. font-weight: 500;
  464. color: #999999;
  465. line-height: 1.5;
  466. }
  467. .price {
  468. display: flex;
  469. align-items: flex-end;
  470. .unit {
  471. font-size: 32rpx;
  472. font-family: PingFang SC;
  473. font-weight: bold;
  474. color: #FF6633;
  475. line-height: 1.2;
  476. margin-right: 10rpx;
  477. }
  478. .num {
  479. font-size: 50rpx;
  480. font-family: PingFang SC;
  481. font-weight: bold;
  482. color: #FF6633;
  483. line-height: 1;
  484. }
  485. }
  486. }
  487. .btn {
  488. width: 200rpx;
  489. height: 88rpx;
  490. line-height: 88rpx;
  491. text-align: center;
  492. font-size: 30rpx;
  493. font-family: PingFang SC;
  494. font-weight: bold;
  495. color: #FFFFFF;
  496. background: #2BC7B9;
  497. border-radius: 44rpx;
  498. }
  499. }
  500. }
  501. .coupon {
  502. height: 100%;
  503. }
  504. /*优惠券列表公共*/
  505. .coupon-list {}
  506. .coupon-list .item {
  507. display: flex;
  508. flex-direction: column;
  509. justify-content: center;
  510. align-items: center;
  511. width: 100%;
  512. height: 1.7 * 100rpx;
  513. margin-bottom: 0.16 * 100rpx;
  514. }
  515. .coupon-list .item .money {
  516. background-size: 100% 100%;
  517. width: 2.4 * 100rpx;
  518. height: 100%;
  519. color: #fff;
  520. font-size: 0.36 * 100rpx;
  521. font-weight: bold;
  522. text-align: center;
  523. display: flex;
  524. flex-direction: column;
  525. align-items: center;
  526. justify-content: center;
  527. position: relative;
  528. }
  529. .coupon-list .item .money .img {
  530. position: absolute;
  531. width: 2.4 * 100rpx;
  532. height: 100%;
  533. color: #fff;
  534. }
  535. .coupon-list .item .money .num {
  536. font-size: 0.6 * 100rpx;
  537. }
  538. .coupon-list .item .money .pic-num {
  539. font-size: 20rpx;
  540. z-index: 99;
  541. }
  542. .coupon-list .item .text {
  543. width: 4.5 * 100rpx;
  544. padding: 0 0.17 * 100rpx 0 0.24 * 100rpx;
  545. background-color: #fff;
  546. box-sizing: border-box;
  547. }
  548. .coupon-list .item .text .condition {
  549. font-size: 0.3 * 100rpx;
  550. color: #282828;
  551. height: 0.93 * 100rpx;
  552. line-height: 0.93 * 100rpx;
  553. border-bottom: 1px solid #f0f0f0;
  554. }
  555. .coupon-list .item .text .data {
  556. font-size: 0.2 * 100rpx;
  557. color: #999;
  558. height: 0.76 * 100rpx;
  559. }
  560. .coupon-list .item .text .data .bnt {
  561. width: 1.36 * 100rpx;
  562. height: 0.44 * 100rpx;
  563. border-radius: 0.22 * 100rpx;
  564. font-size: 0.22 * 100rpx;
  565. color: #fff;
  566. text-align: center;
  567. line-height: 0.44 * 100rpx;
  568. background-color: red;
  569. }
  570. </style>