confirmCreateOrder.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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="shopbox" v-for="(shop,idx) in carts" :key="idx">
  31. <view class="shopbox-name" v-if="shop.storeName && shop.storeName != 'null'">
  32. <text>{{shop.storeName}}</text>
  33. </view>
  34. <view class="goods-list">
  35. <view v-for="(item,index) in shop.list" :key="index" class="item">
  36. <view class="img-box">
  37. <image :src="item.productAttrImage?item.productAttrImage:item.productImage"
  38. mode="aspectFill"></image>
  39. </view>
  40. <view class="info-box">
  41. <view>
  42. <view class="name-box ellipsis2">
  43. <view class="tag">{{utils.getDictLabelName("storeProductType",item.productType)}}
  44. </view>{{item.productName}}
  45. </view>
  46. <view class="spec ellipsis2">{{item.productAttrName}}</view>
  47. </view>
  48. <view class="price-num">
  49. <view class="price">
  50. <text class="unit">¥</text>
  51. <text class="num">{{(item.price||0).toFixed(2)}}</text>
  52. </view>
  53. <view class="num">x{{item.cartNum}}</view>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 运费 -->
  58. <view class="points">
  59. <view class="left">
  60. <text class="text">运费</text>
  61. </view>
  62. <view class="right" v-if="price&&price.length > 0">
  63. <text
  64. class="text">{{price[idx].payPostage==null||price[idx].payPostage==0?'免运费':(price[idx].payPostage||0).toFixed(2)}}</text>
  65. </view>
  66. </view>
  67. <!-- 备注 -->
  68. <view class="points">
  69. <view class="left">
  70. <text class="text">备注</text>
  71. </view>
  72. <view class="remarks">
  73. <input type="text" v-model="shop.markinfo" placeholder="备注留言(选填)"
  74. placeholder-class="input" />
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <!-- 积分 -->
  80. <view class="price-info">
  81. <view class="price-info-title">价格明细</view>
  82. <view class="points">
  83. <view class="left">
  84. <text class="text">商品总价</text>
  85. </view>
  86. <view class="right" style="align-items: baseline;">
  87. <text class="price-info-unit">¥</text>
  88. <text class="price-info-num">{{(priceSum||0).toFixed(2)}}</text>
  89. </view>
  90. </view>
  91. <view class="points">
  92. <view class="left">
  93. <text class="text">运费</text>
  94. </view>
  95. <view class="right">
  96. <text class="text" v-if="address!=null">{{price.pay_delivery==null||price.pay_delivery==0?'免运费':price.pay_delivery.toFixed(2)}}</text>
  97. <text class="text" v-if="address==null">--</text>
  98. </view>
  99. </view>
  100. <!-- <view class="points">
  101. <view class="left">
  102. <text class="text">服务费</text>
  103. </view>
  104. <view class="right">
  105. <text class="text">{{price.serviceFee.toFixed(2)}}</text>
  106. </view>
  107. </view> -->
  108. <view class="points">
  109. <view class="left">
  110. <text class="text">合计</text>
  111. </view>
  112. <view class="right" style="align-items: baseline;">
  113. <text class="price-info-unit">¥</text>
  114. <text class="price-info-num">{{(priceSum||0).toFixed(2)}}</text>
  115. </view>
  116. </view>
  117. </view>
  118. </view>
  119. <view class="btn-foot">
  120. <view class="right">
  121. <view class="total">
  122. <text class="label">合计:</text>
  123. <view class="price">
  124. <text class="unit">¥</text>
  125. <text class="num">{{(priceSum||0).toFixed(2)}}</text>
  126. </view>
  127. </view>
  128. <view class="btn" @click="submitOrder">提交订单</view>
  129. </view>
  130. </view>
  131. </view>
  132. </template>
  133. <script>
  134. import {
  135. createliveOrder, // 创建订单
  136. userAddr, // 获取用户收货地址
  137. cartOrder, //购物车订单
  138. checked //获取购物车选中商品
  139. } from "@/api/order.js"
  140. export default {
  141. data() {
  142. return {
  143. cityId:null,
  144. priceSum: null,
  145. cartsSelect: [],
  146. address: null,
  147. addressId: null,
  148. totalNum: null,
  149. orderKey: null,
  150. price: null,
  151. liveId: null,
  152. orderList: [],
  153. userInfo: null,
  154. temps: [],
  155. couponUserId: null,
  156. couponText: "请选择",
  157. couponsList: [],
  158. couponVisible: false,
  159. carts: [],
  160. checked: false,
  161. // type: null,
  162. cartIds: null,
  163. confirmParam: [],
  164. }
  165. },
  166. onLoad(options) {
  167. uni.$on('updateAddress', this.handleAddressUpdate);
  168. console.log("确认订单", options)
  169. this.orderKey = options.orderKey;
  170. this.liveId = options.liveId
  171. this.productId = options.productId
  172. this.totalNum = Number(options.totalNum) || 0
  173. this.price = Number(options.price) || 0
  174. this.priceSum = this.price * this.totalNum
  175. },
  176. mounted() {
  177. this.getUserAddr()
  178. uni.$on('updateAddress', (e) => {
  179. this.address = e;
  180. this.addressId = e.addressId;
  181. });
  182. },
  183. onUnload() {
  184. // 页面卸载时移除监听,避免内存泄漏
  185. uni.$off('updateAddress', this.handleAddressUpdate);
  186. },
  187. beforeDestroy() {
  188. // 移除事件监听,避免内存泄漏
  189. uni.$off('updateAddress');
  190. },
  191. methods: {
  192. handleAddressUpdate(item) {
  193. console.log('接收到地址数据:', item);
  194. // 在这里处理地址数据
  195. this.cityId = item.cityId;
  196. // 更新页面显示或其他操作
  197. },
  198. // 获取用户收货地址
  199. getUserAddr() {
  200. userAddr().then(res => {
  201. if (res.code == 200) {
  202. console.log("用户收货地址>>>>", res.data)
  203. this.address = res.data;
  204. } else {
  205. uni.showToast({
  206. title: res.msg,
  207. icon: 'none'
  208. });
  209. }
  210. },
  211. rej => {}
  212. );
  213. },
  214. // 创建订单
  215. createLiveOrder() {
  216. let data = {
  217. cityId:this.cityId,
  218. liveId: this.liveId,
  219. orderKey: this.orderKey,
  220. userName: this.address.realName,
  221. userPhone: this.address.phone,
  222. userAddress: this.address.province+' ' + this.address.city+' ' + this.address.district+' ' + this.address
  223. .detail,
  224. cartId: "5",
  225. productId: this.productId,
  226. totalNum: this.totalNum,
  227. }
  228. return createliveOrder(data).then(res => { // 添加 return
  229. if (res.code == 200) {
  230. this.orderList = res.order;
  231. return res.order; // 返回订单数据供后续使用
  232. } else {
  233. uni.showToast({
  234. title: res.msg,
  235. icon: 'none'
  236. });
  237. throw new Error(res.msg); // 抛出错误以便 submitOrder 捕获
  238. }
  239. });
  240. },
  241. getWeixinOrderTemps: function() {
  242. getWeixinOrderTemps().then(
  243. res => {
  244. if (res.code == 200) {
  245. this.temps = res.temp
  246. } else {
  247. }
  248. },
  249. rej => {}
  250. );
  251. },
  252. couponSelect(item) {
  253. this.couponText = "-¥" + (item.couponPrice || 0).toFixed(2);
  254. this.couponUserId = item.id;
  255. this.couponVisible = false;
  256. this.computed();
  257. },
  258. openCoupon() {
  259. let that = this;
  260. var data = {
  261. couponType: 2,
  262. useMinPrice: this.price.payPrice
  263. };
  264. getMyEnableCouponList(data).then(res => {
  265. this.couponVisible = true;
  266. that.couponsList = res.data
  267. })
  268. },
  269. integralChange(e) {
  270. this.form.useIntegral = e ? 1 : 0
  271. this.computed()
  272. },
  273. openAddress() {
  274. uni.navigateTo({
  275. url: '/pages_user/user/address'
  276. })
  277. },
  278. // 提交订单
  279. async submitOrder() {
  280. try {
  281. if (this.orderKey == null) {
  282. uni.showToast({
  283. icon: 'none',
  284. title: '订单KEY不存在',
  285. });
  286. return;
  287. }
  288. if (this.address == null) {
  289. uni.showToast({
  290. icon: 'none',
  291. title: '收货地址不能为空',
  292. });
  293. return;
  294. }
  295. let orderList;
  296. orderList = await this.createLiveOrder(); // 等待订单数据返回
  297. console.log("orderList>>", orderList)
  298. const orderListStr = encodeURIComponent(JSON.stringify(orderList));
  299. uni.navigateTo({
  300. url: `/pages_shopping/live/paymentOrder?orderList=${orderListStr}`
  301. });
  302. } catch (error) {
  303. uni.showToast({
  304. title: res.msg,
  305. icon: 'none'
  306. });
  307. }
  308. },
  309. // 购物车支付订单
  310. async creatCartOrder() {
  311. try {
  312. if (this.orderKey == null) {
  313. uni.showToast({
  314. icon: 'none',
  315. title: '订单KEY不存在',
  316. });
  317. return;
  318. }
  319. if (this.address == null) {
  320. uni.showToast({
  321. icon: 'none',
  322. title: '收货地址不能为空',
  323. });
  324. return;
  325. }
  326. const orderList = await this.cartOrder(); // 等待订单数据返回
  327. const orderListStr = encodeURIComponent(JSON.stringify(orderList));
  328. uni.navigateTo({
  329. url: `/pages_shopping/live/paymentOrder?orderList=${orderListStr}`
  330. });
  331. } catch (error) {
  332. console.error('订单创建失败:', error);
  333. uni.showToast({
  334. title: '提交失败',
  335. icon: 'none'
  336. });
  337. }
  338. },
  339. }
  340. }
  341. </script>
  342. <style lang="scss">
  343. .inner-box {
  344. padding: 20upx 20upx 140upx;
  345. .address-box {
  346. margin-bottom: 20rpx;
  347. box-sizing: border-box;
  348. min-height: 171upx;
  349. background: #FFFFFF;
  350. border-radius: 16upx;
  351. background-repeat: no-repeat;
  352. background-size: 100% 30upx;
  353. background-position: left bottom;
  354. padding: 38upx 30upx 36upx;
  355. display: flex;
  356. align-items: center;
  357. justify-content: space-between;
  358. .left {
  359. width: 92%;
  360. .name-box {
  361. display: flex;
  362. align-items: center;
  363. .text {
  364. font-size: 32upx;
  365. font-family: PingFang SC;
  366. font-weight: bold;
  367. color: #111111;
  368. line-height: 1;
  369. &.name {
  370. margin-right: 30upx;
  371. }
  372. }
  373. }
  374. .address {
  375. font-size: 28upx;
  376. font-family: PingFang SC;
  377. font-weight: 500;
  378. color: #666666;
  379. line-height: 42upx;
  380. text-align: left;
  381. margin-top: 23upx;
  382. }
  383. }
  384. .arrow-box {
  385. width: 12upx;
  386. height: 23upx;
  387. display: flex;
  388. align-items: cenetr;
  389. justify-content: cenetr;
  390. image {
  391. width: 100%;
  392. height: 100%;
  393. }
  394. }
  395. }
  396. .shopbox {
  397. background: #FFFFFF;
  398. border-radius: 16rpx;
  399. margin-bottom: 20rpx;
  400. .points {
  401. padding: 0 !important;
  402. }
  403. .remarks {
  404. padding: 0 !important;
  405. }
  406. }
  407. .shopbox-name {
  408. padding: 30rpx 30rpx 0 30rpx;
  409. font-family: PingFang SC, PingFang SC;
  410. font-weight: 400;
  411. font-size: 30rpx;
  412. color: #111;
  413. overflow: hidden;
  414. white-space: nowrap;
  415. text-overflow: ellipsis;
  416. }
  417. .goods-list {
  418. // margin-top: 20upx;
  419. padding: 0 30upx;
  420. background-color: #FFFFFF;
  421. border-radius: 16upx;
  422. .item {
  423. padding: 30upx 0;
  424. border-bottom: 1px solid #EDEEEF;
  425. display: flex;
  426. align-items: center;
  427. .img-box {
  428. width: 160upx;
  429. height: 160upx;
  430. margin-right: 30upx;
  431. image {
  432. width: 100%;
  433. height: 100%;
  434. }
  435. }
  436. .info-box {
  437. width: calc(100% - 190upx);
  438. height: 160upx;
  439. display: flex;
  440. flex-direction: column;
  441. justify-content: space-between;
  442. .name-box {
  443. font-size: 28upx;
  444. font-family: PingFang SC;
  445. font-weight: 500;
  446. color: #111111;
  447. line-height: 40upx;
  448. .tag {
  449. display: inline-block;
  450. padding: 0 6upx;
  451. height: 30upx;
  452. background: linear-gradient(90deg, #66b2ef 0%, #0bb3f2 100%);
  453. border-radius: 4upx;
  454. margin-right: 10upx;
  455. font-size: 22upx;
  456. font-family: PingFang SC;
  457. font-weight: bold;
  458. color: #FFFFFF;
  459. line-height: 30upx;
  460. float: left;
  461. margin-top: 7upx;
  462. }
  463. }
  464. .spec {
  465. margin-top: 10upx;
  466. font-size: 24upx;
  467. font-family: PingFang SC;
  468. font-weight: 500;
  469. color: #999999;
  470. line-height: 1;
  471. }
  472. .price-num {
  473. display: flex;
  474. align-items: center;
  475. justify-content: space-between;
  476. .price {
  477. display: flex;
  478. align-items: flex-end;
  479. .unit {
  480. font-size: 24upx;
  481. font-family: PingFang SC;
  482. font-weight: 500;
  483. color: #111111;
  484. line-height: 1.2;
  485. margin-right: 4upx;
  486. }
  487. .num {
  488. font-size: 32upx;
  489. font-family: PingFang SC;
  490. font-weight: 500;
  491. color: #111111;
  492. line-height: 1;
  493. }
  494. }
  495. .num {
  496. font-size: 24upx;
  497. font-family: PingFang SC;
  498. font-weight: 500;
  499. color: #999999;
  500. line-height: 1;
  501. }
  502. }
  503. }
  504. }
  505. .sub-total {
  506. height: 88upx;
  507. display: flex;
  508. align-items: center;
  509. justify-content: flex-end;
  510. .label {
  511. font-size: 24upx;
  512. font-family: PingFang SC;
  513. font-weight: 500;
  514. color: #999999;
  515. }
  516. .price {
  517. display: flex;
  518. align-items: flex-end;
  519. .unit {
  520. font-size: 24upx;
  521. font-family: PingFang SC;
  522. font-weight: 500;
  523. color: #FF6633;
  524. line-height: 1.2;
  525. margin-right: 4upx;
  526. }
  527. .num {
  528. font-size: 32upx;
  529. font-family: PingFang SC;
  530. font-weight: bold;
  531. color: #FF6633;
  532. line-height: 1;
  533. }
  534. }
  535. }
  536. }
  537. .price-info {
  538. background: #FFFFFF;
  539. border-radius: 16upx;
  540. &-title {
  541. padding: 30rpx 30rpx 20rpx 30rpx;
  542. font-family: PingFang SC, PingFang SC;
  543. font-weight: 500;
  544. font-size: 30rpx;
  545. color: #111;
  546. }
  547. &-unit {
  548. font-size: 24rpx;
  549. }
  550. &-num {
  551. font-size: 28rpx;
  552. }
  553. }
  554. .points {
  555. height: 88upx;
  556. padding: 0 30upx;
  557. background: #FFFFFF;
  558. border-radius: 16upx;
  559. display: flex;
  560. align-items: center;
  561. justify-content: space-between;
  562. .left {
  563. display: flex;
  564. align-items: center;
  565. image {
  566. width: 28upx;
  567. height: 28upx;
  568. margin-right: 20upx;
  569. }
  570. .text {
  571. font-size: 28upx;
  572. font-family: PingFang SC;
  573. font-weight: 500;
  574. color: #666666;
  575. }
  576. }
  577. .right {
  578. display: flex;
  579. align-items: center;
  580. .text {
  581. font-size: 28upx;
  582. font-family: PingFang SC;
  583. font-weight: 500;
  584. color: #111111;
  585. }
  586. image {
  587. margin-left: 15upx;
  588. width: 14upx;
  589. height: 24upx;
  590. }
  591. }
  592. }
  593. .remarks {
  594. // height: 88upx;
  595. padding: 0 30upx;
  596. background: #FFFFFF;
  597. border-radius: 16upx;
  598. margin-top: 20upx;
  599. display: flex;
  600. align-items: center;
  601. input {
  602. width: 100%;
  603. font-size: 28upx;
  604. font-family: PingFang SC;
  605. font-weight: 500;
  606. color: #000000;
  607. }
  608. .input {
  609. font-size: 28upx;
  610. font-family: PingFang SC;
  611. font-weight: 500;
  612. color: #999999;
  613. }
  614. }
  615. }
  616. .btn-foot {
  617. box-sizing: border-box;
  618. width: 100%;
  619. height: 121upx;
  620. background: #FFFFFF;
  621. padding: 16upx 30upx 16upx 60upx;
  622. display: flex;
  623. align-items: center;
  624. justify-content: flex-end;
  625. position: fixed;
  626. left: 0;
  627. bottom: 0;
  628. z-index: 99;
  629. .right {
  630. display: flex;
  631. align-items: center;
  632. .total {
  633. display: flex;
  634. align-items: flex-end;
  635. margin-right: 36upx;
  636. .label {
  637. font-size: 26upx;
  638. font-family: PingFang SC;
  639. font-weight: 500;
  640. color: #999999;
  641. line-height: 1.5;
  642. }
  643. .price {
  644. display: flex;
  645. align-items: flex-end;
  646. .unit {
  647. font-size: 32upx;
  648. font-family: PingFang SC;
  649. font-weight: bold;
  650. color: #FF6633;
  651. line-height: 1.2;
  652. margin-right: 10upx;
  653. }
  654. .num {
  655. font-size: 50upx;
  656. font-family: PingFang SC;
  657. font-weight: bold;
  658. color: #FF6633;
  659. line-height: 1;
  660. }
  661. }
  662. }
  663. .btn {
  664. width: 200upx;
  665. height: 88upx;
  666. line-height: 88upx;
  667. text-align: center;
  668. font-size: 30upx;
  669. font-family: PingFang SC;
  670. font-weight: bold;
  671. color: #FFFFFF;
  672. background: #0bb3f2;
  673. border-radius: 44upx;
  674. }
  675. }
  676. }
  677. </style>