confirmCreateOrder.vue 18 KB

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