confirmCreateOrder.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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="couponVisible = true;">
  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. liveOrderKey, // 生成订单key
  129. } from "@/api/order.js"
  130. import {
  131. curCoupon
  132. } from "@/api/living.js"
  133. import popupBottom from '@/components/px-popup-bottom/px-popup-bottom.vue'
  134. export default {
  135. components: {
  136. popupBottom
  137. },
  138. data() {
  139. return {
  140. orderData: {},
  141. cityId: null,
  142. address: null,
  143. addressId: null,
  144. totalNum: null,
  145. orderKey: null,
  146. goodsId: null,
  147. liveId: null,
  148. orderList: [],
  149. temps: [],
  150. couponUserId: null,
  151. couponText: "请选择",
  152. couponsList: [],
  153. couponVisible: false,
  154. carts: [],
  155. checked: false,
  156. cartIds: null,
  157. confirmParam: [],
  158. type: '',
  159. isFirstLoad: true,
  160. recordId:null
  161. }
  162. },
  163. onLoad(options) {
  164. console.log("确认订单", options)
  165. this.orderKey = options.orderKey;
  166. this.liveId = options.liveId
  167. this.goodsId = options.goodsId
  168. this.productId = options.productId
  169. this.totalNum = Number(options.totalNum) || 0
  170. this.type = options.type
  171. this.isFirstLoad = true;
  172. this.recordId=options.recordId
  173. if (options.type == 'win') {
  174. this.getKey()
  175. }
  176. },
  177. onShow() {
  178. this.openCoupon()
  179. this.getUserAddr()
  180. uni.$on('updateAddress', (e) => {
  181. this.address = e;
  182. this.addressId = e.addressId;
  183. this.cityId = e.cityId;
  184. });
  185. },
  186. mounted() {
  187. // uni.$on('updateAddress', (e) => {
  188. // this.address = e;
  189. // this.addressId = e.addressId;
  190. // });
  191. },
  192. onUnload() {
  193. uni.$off('updateAddress', this.handleAddressUpdate);
  194. },
  195. beforeDestroy() {
  196. uni.$off('updateAddress');
  197. },
  198. methods: {
  199. handleAddressUpdate(item) {
  200. console.log('接收到地址数据:', item);
  201. this.cityId = item.cityId;
  202. this.address = item;
  203. this.addressId = item.addressId;
  204. if (this.type == 'win') {
  205. this.computedRewardOrder()
  206. } else {
  207. this.computedOrder()
  208. }
  209. },
  210. // 获取用户收货地址
  211. getUserAddr() {
  212. userAddr().then(res => {
  213. if (res.code == 200) {
  214. console.log("用户收货地址>>>>", res.data)
  215. if (res.data && !this.address) {
  216. this.address = res.data;
  217. }
  218. if (res.data && res.data.cityId) {
  219. this.cityId = res.data.cityId;
  220. }
  221. if (this.type == 'win') {
  222. this.computedRewardOrder()
  223. } else {
  224. this.computedOrder()
  225. }
  226. } else {
  227. uni.showToast({
  228. title: res.msg,
  229. icon: 'none'
  230. });
  231. }
  232. },
  233. rej => {}
  234. );
  235. },
  236. // 获得key
  237. getKey() {
  238. liveOrderKey().then(res => {
  239. if (res.code == 200) {
  240. this.orderKey = res.orderKey
  241. } else {
  242. uni.showToast({
  243. title: res.msg,
  244. icon: 'none'
  245. });
  246. }
  247. },
  248. rej => {}
  249. );
  250. },
  251. // 查询创建订单信息
  252. computedOrder() {
  253. let data = {
  254. cityId: this.cityId || '',
  255. totalNum: this.totalNum,
  256. productId: this.productId,
  257. orderKey: this.orderKey,
  258. couponUserId: this.couponUserId || ''
  259. }
  260. computed(data).then(res => {
  261. if (res.code == 200) {
  262. console.log("查询创建订单信息>>>>", res.data)
  263. this.orderData = res.data
  264. } else {
  265. uni.showToast({
  266. title: res.msg,
  267. icon: 'none'
  268. });
  269. }
  270. },
  271. rej => {}
  272. );
  273. },
  274. // 查询中奖创建订单信息
  275. computedRewardOrder() {
  276. let data = {
  277. cityId: this.cityId || '',
  278. productId: this.productId ,
  279. orderKey: this.orderKey,
  280. totalNum: 1,
  281. }
  282. computedReward(data).then(res => {
  283. if (res.code == 200) {
  284. console.log("查询创建订单信息>>>>", res.data)
  285. this.orderData = res.data||{}
  286. } else {
  287. uni.showToast({
  288. title: res.msg,
  289. icon: 'none'
  290. });
  291. }
  292. },
  293. rej => {}
  294. );
  295. },
  296. // 创建订单
  297. createLiveOrder() {
  298. let data = {
  299. cityId: this.cityId,
  300. liveId: this.liveId,
  301. orderKey: this.orderKey,
  302. userName: this.address.realName,
  303. userPhone: this.address.phone,
  304. userAddress: this.address.province + ' ' + this.address.city + ' ' + this.address.district + ' ' +
  305. this.address
  306. .detail,
  307. cartId: "5",
  308. productId: this.productId,
  309. totalNum: this.totalNum,
  310. couponUserId: this.couponUserId
  311. }
  312. return createliveOrder(data).then(res => {
  313. if (res.code == 200) {
  314. this.orderList = res.order;
  315. return res.order;
  316. } else {
  317. uni.showToast({
  318. title: res.msg,
  319. icon: 'none'
  320. });
  321. throw new Error(res.msg);
  322. }
  323. });
  324. },
  325. // 创建抽奖订单
  326. createRewardOrder() {
  327. let data = {
  328. cityId: this.cityId,
  329. liveId: this.liveId,
  330. orderKey: this.orderKey,
  331. userName: this.address.realName,
  332. userPhone: this.address.phone,
  333. userAddress: this.address.province + ' ' + this.address.city + ' ' + this.address.district + ' ' + this.address.detail,
  334. cartId: "5",
  335. productId: this.productId,
  336. totalNum: 1,
  337. couponUserId: this.couponUserId,
  338. recordId:this.recordId
  339. }
  340. return createReward(data).then(res => {
  341. if (res.code == 200) {
  342. this.orderList = res.order || {};
  343. return res.order || {};
  344. } else {
  345. uni.showToast({
  346. title: res.msg,
  347. icon: 'none'
  348. });
  349. throw new Error(res.msg);
  350. }
  351. });
  352. },
  353. couponSelect(item) {
  354. this.couponText = "-¥" + (item.couponPrice || 0).toFixed(2);
  355. this.couponUserId = item.id;
  356. this.couponVisible = false;
  357. if (this.type == 'win') {
  358. this.computedRewardOrder()
  359. } else {
  360. this.computedOrder()
  361. }
  362. },
  363. // 自动选择最大优惠券
  364. autoSelectMaxCoupon() {
  365. if (this.couponsList.length === 0 || !this.isFirstLoad) {
  366. return;
  367. }
  368. const availableCoupons = this.couponsList.filter(item =>
  369. item.status === 0 && item.useMinPrice <= (this.orderData.totalPrice || 0)
  370. );
  371. if (availableCoupons.length === 0) {
  372. return;
  373. }
  374. availableCoupons.sort((a, b) => b.couponPrice - a.couponPrice);
  375. const maxCoupon = availableCoupons[0];
  376. this.couponText = "-¥" + (maxCoupon.couponPrice || 0).toFixed(2);
  377. this.couponUserId = maxCoupon.id;
  378. console.log('自动选择最大优惠券:', maxCoupon);
  379. this.isFirstLoad = false;
  380. // 重新计算订单价格
  381. if (this.type == 'win') {
  382. this.computedRewardOrder()
  383. } else {
  384. this.computedOrder()
  385. }
  386. },
  387. openCoupon() {
  388. console.log("点了优惠券列表")
  389. if (!this.liveId || !this.goodsId) {
  390. console.log('缺少必要参数,跳过优惠券请求');
  391. return;
  392. }
  393. const data = {
  394. liveId: this.liveId,
  395. goodsId: this.goodsId
  396. };
  397. curCoupon(data).then(res => {
  398. this.couponsList = res.data || [];
  399. if (this.isFirstLoad) {
  400. setTimeout(() => {
  401. this.autoSelectMaxCoupon();
  402. }, 100);
  403. }
  404. })
  405. },
  406. openAddress() {
  407. uni.navigateTo({
  408. url: '/pages_user/user/address'
  409. })
  410. },
  411. // 提交订单
  412. async submitOrder() {
  413. try {
  414. if (this.orderKey == null) {
  415. uni.showToast({
  416. icon: 'none',
  417. title: '订单KEY不存在',
  418. });
  419. return;
  420. }
  421. if (this.address == null) {
  422. uni.showToast({
  423. icon: 'none',
  424. title: '收货地址不能为空',
  425. });
  426. return;
  427. }
  428. let orderList;
  429. if (this.type == "win") {
  430. orderList = await this.createRewardOrder(); // 中奖订单
  431. } else {
  432. orderList = await this.createLiveOrder(); // 购买订单
  433. }
  434. console.log("orderList>>", orderList)
  435. const orderListStr = encodeURIComponent(JSON.stringify(orderList));
  436. uni.navigateTo({
  437. url: `/pages_shopping/live/paymentOrder?orderList=${orderListStr}&couponUserId=${this.couponUserId}&type=${this.type}`
  438. });
  439. } catch (error) {
  440. console.error('提交订单错误:', error);
  441. uni.showToast({
  442. title: error.message || '提交订单失败',
  443. icon: 'none'
  444. });
  445. }
  446. },
  447. }
  448. }
  449. </script>
  450. <style lang="scss">
  451. .inner-box {
  452. padding: 20rpx 20rpx 140rpx;
  453. .address-box {
  454. margin-bottom: 20rpx;
  455. box-sizing: border-box;
  456. min-height: 171rpx;
  457. background: #FFFFFF;
  458. border-radius: 16rpx;
  459. background-repeat: no-repeat;
  460. background-size: 100% 30rpx;
  461. background-position: left bottom;
  462. padding: 38rpx 30rpx 36rpx;
  463. display: flex;
  464. align-items: center;
  465. justify-content: space-between;
  466. .left {
  467. width: 92%;
  468. .name-box {
  469. display: flex;
  470. align-items: center;
  471. .text {
  472. font-size: 32rpx;
  473. font-family: PingFang SC;
  474. font-weight: bold;
  475. color: #111111;
  476. line-height: 1;
  477. &.name {
  478. margin-right: 30rpx;
  479. }
  480. }
  481. }
  482. .address {
  483. font-size: 28rpx;
  484. font-family: PingFang SC;
  485. font-weight: 500;
  486. color: #666666;
  487. line-height: 42rpx;
  488. text-align: left;
  489. margin-top: 23rpx;
  490. }
  491. }
  492. .arrow-box {
  493. width: 12rpx;
  494. height: 23rpx;
  495. display: flex;
  496. align-items: cenetr;
  497. justify-content: cenetr;
  498. image {
  499. width: 100%;
  500. height: 100%;
  501. }
  502. }
  503. }
  504. .price-info {
  505. background: #FFFFFF;
  506. border-radius: 16rpx;
  507. &-title {
  508. padding: 30rpx 30rpx 20rpx 30rpx;
  509. font-family: PingFang SC, PingFang SC;
  510. font-weight: 500;
  511. font-size: 30rpx;
  512. color: #111;
  513. }
  514. &-unit {
  515. font-size: 24rpx;
  516. }
  517. &-num {
  518. font-size: 28rpx;
  519. }
  520. }
  521. .points {
  522. height: 88rpx;
  523. padding: 0 30rpx;
  524. background: #FFFFFF;
  525. border-radius: 16rpx;
  526. display: flex;
  527. align-items: center;
  528. justify-content: space-between;
  529. .left {
  530. display: flex;
  531. align-items: center;
  532. image {
  533. width: 28rpx;
  534. height: 28rpx;
  535. margin-right: 20rpx;
  536. }
  537. .text {
  538. font-size: 28rpx;
  539. font-family: PingFang SC;
  540. font-weight: 500;
  541. color: #666666;
  542. }
  543. }
  544. .right {
  545. display: flex;
  546. align-items: center;
  547. .text {
  548. font-size: 28rpx;
  549. font-family: PingFang SC;
  550. font-weight: 500;
  551. color: #111111;
  552. }
  553. image {
  554. margin-left: 15rpx;
  555. width: 14rpx;
  556. height: 24rpx;
  557. }
  558. }
  559. }
  560. }
  561. .btn-foot {
  562. box-sizing: border-box;
  563. width: 100%;
  564. height: 121rpx;
  565. background: #FFFFFF;
  566. padding: 16rpx 30rpx 16rpx 60rpx;
  567. display: flex;
  568. align-items: center;
  569. justify-content: flex-end;
  570. position: fixed;
  571. left: 0;
  572. bottom: 0;
  573. z-index: 99;
  574. .right {
  575. display: flex;
  576. align-items: center;
  577. .total {
  578. display: flex;
  579. align-items: flex-end;
  580. margin-right: 36rpx;
  581. .label {
  582. font-size: 26rpx;
  583. font-family: PingFang SC;
  584. font-weight: 500;
  585. color: #999999;
  586. line-height: 1.5;
  587. }
  588. .price {
  589. display: flex;
  590. align-items: flex-end;
  591. .unit {
  592. font-size: 32rpx;
  593. font-family: PingFang SC;
  594. font-weight: bold;
  595. color: #FF6633;
  596. line-height: 1.2;
  597. margin-right: 10rpx;
  598. }
  599. .num {
  600. font-size: 50rpx;
  601. font-family: PingFang SC;
  602. font-weight: bold;
  603. color: #FF6633;
  604. line-height: 1;
  605. }
  606. }
  607. }
  608. .btn {
  609. width: 200rpx;
  610. height: 88rpx;
  611. line-height: 88rpx;
  612. text-align: center;
  613. font-size: 30rpx;
  614. font-family: PingFang SC;
  615. font-weight: bold;
  616. color: #FFFFFF;
  617. background: #2BC7B9;
  618. border-radius: 44rpx;
  619. }
  620. }
  621. }
  622. .coupon {
  623. height: 100%;
  624. }
  625. /*优惠券列表公共*/
  626. .coupon-list {}
  627. .coupon-list .item {
  628. display: flex;
  629. flex-direction: column;
  630. justify-content: center;
  631. align-items: center;
  632. width: 100%;
  633. height: 1.7 * 100rpx;
  634. margin-bottom: 0.16 * 100rpx;
  635. }
  636. .coupon-list .item .money {
  637. background-size: 100% 100%;
  638. width: 2.4 * 100rpx;
  639. height: 100%;
  640. color: #fff;
  641. font-size: 0.36 * 100rpx;
  642. font-weight: bold;
  643. text-align: center;
  644. display: flex;
  645. flex-direction: column;
  646. align-items: center;
  647. justify-content: center;
  648. position: relative;
  649. }
  650. .coupon-list .item .money .img {
  651. position: absolute;
  652. width: 2.4 * 100rpx;
  653. height: 100%;
  654. color: #fff;
  655. }
  656. .coupon-list .item .money .num {
  657. font-size: 0.6 * 100rpx;
  658. }
  659. .coupon-list .item .money .pic-num {
  660. font-size: 20rpx;
  661. z-index: 99;
  662. }
  663. .coupon-list .item .text {
  664. width: 4.5 * 100rpx;
  665. padding: 0 0.17 * 100rpx 0 0.24 * 100rpx;
  666. background-color: #fff;
  667. box-sizing: border-box;
  668. }
  669. .coupon-list .item .text .condition {
  670. font-size: 0.3 * 100rpx;
  671. color: #282828;
  672. height: 0.93 * 100rpx;
  673. line-height: 0.93 * 100rpx;
  674. border-bottom: 1px solid #f0f0f0;
  675. }
  676. .coupon-list .item .text .data {
  677. font-size: 0.2 * 100rpx;
  678. color: #999;
  679. height: 0.76 * 100rpx;
  680. }
  681. .coupon-list .item .text .data .bnt {
  682. width: 1.36 * 100rpx;
  683. height: 0.44 * 100rpx;
  684. border-radius: 0.22 * 100rpx;
  685. font-size: 0.22 * 100rpx;
  686. color: #fff;
  687. text-align: center;
  688. line-height: 0.44 * 100rpx;
  689. background-color: red;
  690. }
  691. </style>