confirmCreateOrder.vue 18 KB

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