confirmCreateOrder.vue 17 KB

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