confirmCreateOrder.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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. createReward, // 创建中奖订单
  125. userAddr, // 获取用户收货地址
  126. computed,
  127. computedReward
  128. } from "@/api/order.js"
  129. import {
  130. curCoupon
  131. } from "@/api/living.js"
  132. import popupBottom from '@/components/px-popup-bottom/px-popup-bottom.vue'
  133. export default {
  134. components: {
  135. popupBottom
  136. },
  137. data() {
  138. return {
  139. orderData: {},
  140. cityId: null,
  141. address: null,
  142. addressId: null,
  143. totalNum: null,
  144. orderKey: null,
  145. goodsId: null,
  146. liveId: null,
  147. orderList: [],
  148. temps: [],
  149. couponUserId: null,
  150. couponText: "请选择",
  151. couponsList: [],
  152. couponVisible: false,
  153. carts: [],
  154. checked: false,
  155. cartIds: null,
  156. confirmParam: [],
  157. type:'',
  158. }
  159. },
  160. onLoad(options) {
  161. // uni.$on('updateAddress', this.handleAddressUpdate);
  162. console.log("确认订单", options)
  163. this.orderKey = options.orderKey;
  164. this.liveId = options.liveId
  165. this.goodsId = options.goodsId
  166. this.productId = options.productId
  167. this.totalNum = Number(options.totalNum) || 0
  168. this.type=options.type
  169. },
  170. onShow() {
  171. this.getUserAddr()
  172. uni.$on('updateAddress', (e) => {
  173. this.address = e;
  174. this.addressId = e.addressId;
  175. this.cityId = e.cityId;
  176. });
  177. },
  178. mounted() {
  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. handleAddressUpdate(item) {
  194. console.log('接收到地址数据:', item);
  195. // 在这里处理地址数据
  196. this.cityId = item.cityId;
  197. this.address = item;
  198. this.addressId = item.addressId;
  199. if (this.type == 'win') {
  200. this.computedRewardOrder()
  201. } else {
  202. this.computedOrder()
  203. }
  204. // 更新页面显示或其他操作
  205. },
  206. // 获取用户收货地址
  207. getUserAddr() {
  208. userAddr().then(res => {
  209. if (res.code == 200) {
  210. console.log("用户收货地址>>>>", res.data)
  211. if (res.data && !this.address) {
  212. this.address = res.data;
  213. }
  214. if (res.data && res.data.cityId) {
  215. this.cityId = res.data.cityId;
  216. }
  217. if (this.type == 'win') {
  218. this.computedRewardOrder()
  219. } else {
  220. this.computedOrder()
  221. }
  222. } else {
  223. uni.showToast({
  224. title: res.msg,
  225. icon: 'none'
  226. });
  227. }
  228. },
  229. rej => {}
  230. );
  231. },
  232. // 查询创建订单信息
  233. computedOrder() {
  234. let data = {
  235. cityId: this.cityId || '',
  236. totalNum: this.totalNum,
  237. productId: this.productId,
  238. orderKey: this.orderKey,
  239. couponUserId: this.couponUserId || ''
  240. }
  241. computed(data).then(res => {
  242. if (res.code == 200) {
  243. console.log("查询创建订单信息>>>>", res.data)
  244. this.orderData = res.data
  245. } else {
  246. uni.showToast({
  247. title: res.msg,
  248. icon: 'none'
  249. });
  250. }
  251. },
  252. rej => {}
  253. );
  254. },
  255. // 查询中奖创建订单信息
  256. computedRewardOrder() {
  257. let data = {
  258. cityId: this.cityId || '',
  259. productId: this.productId,
  260. orderKey: this.orderKey,
  261. totalNum: 1,
  262. }
  263. computedReward(data).then(res => {
  264. if (res.code == 200) {
  265. console.log("查询创建订单信息>>>>", res.data)
  266. this.orderData = res.data
  267. } else {
  268. uni.showToast({
  269. title: res.msg,
  270. icon: 'none'
  271. });
  272. }
  273. },
  274. rej => {}
  275. );
  276. },
  277. // 创建订单
  278. createLiveOrder() {
  279. let data = {
  280. cityId: this.cityId,
  281. liveId: this.liveId,
  282. orderKey: this.orderKey,
  283. userName: this.address.realName,
  284. userPhone: this.address.phone,
  285. userAddress: this.address.province + ' ' + this.address.city + ' ' + this.address.district + ' ' +
  286. this.address
  287. .detail,
  288. cartId: "5",
  289. productId: this.productId,
  290. totalNum: this.totalNum,
  291. couponUserId: this.couponUserId
  292. }
  293. return createliveOrder(data).then(res => { // 添加 return
  294. if (res.code == 200) {
  295. this.orderList = res.order;
  296. return res.order; // 返回订单数据供后续使用
  297. } else {
  298. uni.showToast({
  299. title: res.msg,
  300. icon: 'none'
  301. });
  302. throw new Error(res.msg); // 抛出错误以便 submitOrder 捕获
  303. }
  304. });
  305. },
  306. couponSelect(item) {
  307. this.couponText = "-¥" + (item.couponPrice || 0).toFixed(2);
  308. this.couponUserId = item.id;
  309. this.couponVisible = false;
  310. if (this.type == 'win') {
  311. this.computedRewardOrder()
  312. } else {
  313. this.computedOrder()
  314. }
  315. },
  316. openCoupon() {
  317. console.log("点了优惠券列表")
  318. const data = {
  319. liveId: this.liveId,
  320. goodsId: this.goodsId
  321. };
  322. curCoupon(data).then(res => {
  323. this.couponVisible = true;
  324. this.couponsList = res.data
  325. })
  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: 20rpx 20rpx 140rpx;
  369. .address-box {
  370. margin-bottom: 20rpx;
  371. box-sizing: border-box;
  372. min-height: 171rpx;
  373. background: #FFFFFF;
  374. border-radius: 16rpx;
  375. background-repeat: no-repeat;
  376. background-size: 100% 30rpx;
  377. background-position: left bottom;
  378. padding: 38rpx 30rpx 36rpx;
  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: 32rpx;
  389. font-family: PingFang SC;
  390. font-weight: bold;
  391. color: #111111;
  392. line-height: 1;
  393. &.name {
  394. margin-right: 30rpx;
  395. }
  396. }
  397. }
  398. .address {
  399. font-size: 28rpx;
  400. font-family: PingFang SC;
  401. font-weight: 500;
  402. color: #666666;
  403. line-height: 42rpx;
  404. text-align: left;
  405. margin-top: 23rpx;
  406. }
  407. }
  408. .arrow-box {
  409. width: 12rpx;
  410. height: 23rpx;
  411. display: flex;
  412. align-items: cenetr;
  413. justify-content: cenetr;
  414. image {
  415. width: 100%;
  416. height: 100%;
  417. }
  418. }
  419. }
  420. .price-info {
  421. background: #FFFFFF;
  422. border-radius: 16rpx;
  423. &-title {
  424. padding: 30rpx 30rpx 20rpx 30rpx;
  425. font-family: PingFang SC, PingFang SC;
  426. font-weight: 500;
  427. font-size: 30rpx;
  428. color: #111;
  429. }
  430. &-unit {
  431. font-size: 24rpx;
  432. }
  433. &-num {
  434. font-size: 28rpx;
  435. }
  436. }
  437. .points {
  438. height: 88rpx;
  439. padding: 0 30rpx;
  440. background: #FFFFFF;
  441. border-radius: 16rpx;
  442. display: flex;
  443. align-items: center;
  444. justify-content: space-between;
  445. .left {
  446. display: flex;
  447. align-items: center;
  448. image {
  449. width: 28rpx;
  450. height: 28rpx;
  451. margin-right: 20rpx;
  452. }
  453. .text {
  454. font-size: 28rpx;
  455. font-family: PingFang SC;
  456. font-weight: 500;
  457. color: #666666;
  458. }
  459. }
  460. .right {
  461. display: flex;
  462. align-items: center;
  463. .text {
  464. font-size: 28rpx;
  465. font-family: PingFang SC;
  466. font-weight: 500;
  467. color: #111111;
  468. }
  469. image {
  470. margin-left: 15rpx;
  471. width: 14rpx;
  472. height: 24rpx;
  473. }
  474. }
  475. }
  476. }
  477. .btn-foot {
  478. box-sizing: border-box;
  479. width: 100%;
  480. height: 121rpx;
  481. background: #FFFFFF;
  482. padding: 16rpx 30rpx 16rpx 60rpx;
  483. display: flex;
  484. align-items: center;
  485. justify-content: flex-end;
  486. position: fixed;
  487. left: 0;
  488. bottom: 0;
  489. z-index: 99;
  490. .right {
  491. display: flex;
  492. align-items: center;
  493. .total {
  494. display: flex;
  495. align-items: flex-end;
  496. margin-right: 36rpx;
  497. .label {
  498. font-size: 26rpx;
  499. font-family: PingFang SC;
  500. font-weight: 500;
  501. color: #999999;
  502. line-height: 1.5;
  503. }
  504. .price {
  505. display: flex;
  506. align-items: flex-end;
  507. .unit {
  508. font-size: 32rpx;
  509. font-family: PingFang SC;
  510. font-weight: bold;
  511. color: #FF6633;
  512. line-height: 1.2;
  513. margin-right: 10rpx;
  514. }
  515. .num {
  516. font-size: 50rpx;
  517. font-family: PingFang SC;
  518. font-weight: bold;
  519. color: #FF6633;
  520. line-height: 1;
  521. }
  522. }
  523. }
  524. .btn {
  525. width: 200rpx;
  526. height: 88rpx;
  527. line-height: 88rpx;
  528. text-align: center;
  529. font-size: 30rpx;
  530. font-family: PingFang SC;
  531. font-weight: bold;
  532. color: #FFFFFF;
  533. background: #2BC7B9;
  534. border-radius: 44rpx;
  535. }
  536. }
  537. }
  538. .coupon {
  539. height: 100%;
  540. }
  541. /*优惠券列表公共*/
  542. .coupon-list {}
  543. .coupon-list .item {
  544. display: flex;
  545. flex-direction: column;
  546. justify-content: center;
  547. align-items: center;
  548. width: 100%;
  549. height: 1.7 * 100rpx;
  550. margin-bottom: 0.16 * 100rpx;
  551. }
  552. .coupon-list .item .money {
  553. background-size: 100% 100%;
  554. width: 2.4 * 100rpx;
  555. height: 100%;
  556. color: #fff;
  557. font-size: 0.36 * 100rpx;
  558. font-weight: bold;
  559. text-align: center;
  560. display: flex;
  561. flex-direction: column;
  562. align-items: center;
  563. justify-content: center;
  564. position: relative;
  565. }
  566. .coupon-list .item .money .img {
  567. position: absolute;
  568. width: 2.4 * 100rpx;
  569. height: 100%;
  570. color: #fff;
  571. }
  572. .coupon-list .item .money .num {
  573. font-size: 0.6 * 100rpx;
  574. }
  575. .coupon-list .item .money .pic-num {
  576. font-size: 20rpx;
  577. z-index: 99;
  578. }
  579. .coupon-list .item .text {
  580. width: 4.5 * 100rpx;
  581. padding: 0 0.17 * 100rpx 0 0.24 * 100rpx;
  582. background-color: #fff;
  583. box-sizing: border-box;
  584. }
  585. .coupon-list .item .text .condition {
  586. font-size: 0.3 * 100rpx;
  587. color: #282828;
  588. height: 0.93 * 100rpx;
  589. line-height: 0.93 * 100rpx;
  590. border-bottom: 1px solid #f0f0f0;
  591. }
  592. .coupon-list .item .text .data {
  593. font-size: 0.2 * 100rpx;
  594. color: #999;
  595. height: 0.76 * 100rpx;
  596. }
  597. .coupon-list .item .text .data .bnt {
  598. width: 1.36 * 100rpx;
  599. height: 0.44 * 100rpx;
  600. border-radius: 0.22 * 100rpx;
  601. font-size: 0.22 * 100rpx;
  602. color: #fff;
  603. text-align: center;
  604. line-height: 0.44 * 100rpx;
  605. background-color: red;
  606. }
  607. </style>