confirm.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <template>
  2. <s-layout title="确认订单">
  3. <view class="bgc"></view>
  4. <view style="padding: 0 30rpx;">
  5. <!-- <view class="head tab-right-active">
  6. <view class="tab-box" v-if="state.tabIndex>0">
  7. <view class="item left" :class="{'active':state.tabIndex == 1}" @click="state.tabIndex = 1">
  8. <view class="tit-box">
  9. <text>配送</text>
  10. </view>
  11. </view>
  12. <view class="item right" :class="{'active':state.tabIndex == 2}" @click="state.tabIndex=2">
  13. <view class="tit-box">
  14. <text>到店自取</text>
  15. </view>
  16. </view>
  17. </view>
  18. </view> -->
  19. <!-- TODO:这个判断先删除 v-if="state.orderInfo.need_address === 1" -->
  20. <view class="bg-white address-box ss-m-b-14 ss-r-b-10" @tap="onSelectAddress">
  21. <s-address-item :item="state.addressInfo" :hasBorderBottom="false">
  22. <view class="ss-rest-button">
  23. <text class="_icon-forward" />
  24. </view>
  25. </s-address-item>
  26. </view>
  27. <view class="bg-white address-box ss-m-b-14 ss-r-b-10 tab2-box" v-if="state.tabIndex == 2">
  28. <view class="top-address">
  29. 我是商家的预留地址
  30. </view>
  31. <view class="under-box">
  32. <view class="time font">
  33. <view>自取时间</view>
  34. <view class="chooseTime" @click="chooseTime">
  35. <picker mode="time" :value="state.time" :end="'23:59'" @change="bindTimeChange" >
  36. <view>{{state.time}}</view>
  37. </picker>
  38. <text class="_icon-forward right-forwrad-icon"></text>
  39. </view>
  40. </view>
  41. <view class="line">
  42. </view>
  43. <view class="tel font">
  44. <view>预留电话</view>
  45. <view class="edit-icon">
  46. <view class="ss-flex ss-col-center width">
  47. <input maxlength="20" v-model="state.tel"
  48. :inputBorder="false" :clearable="false" :focus="state.focus" @blur="onBlur"/>
  49. </view>
  50. <image :src="sheep.$url.static('/static/img/shop/user/address/edit.png')" @click="editTel"/>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 商品信息 -->
  56. <view class="order-card-box ss-m-b-14">
  57. <s-goods-item v-for="item in state.orderInfo.items" :key="item.skuId" :img="item.picUrl"
  58. :title="item.spuName" :skuText="item.properties.map((property) => property.valueName).join(' ')"
  59. :price="item.price" :num="item.count" marginBottom="10" />
  60. <view class="order-item ss-flex ss-col-center ss-row-between ss-p-x-20 bg-white ss-r-10">
  61. <view class="item-title">订单备注</view>
  62. <view class="ss-flex ss-col-center">
  63. <uni-easyinput maxlength="20" placeholder="建议留言前先与商家沟通" v-model="state.orderPayload.remark"
  64. :inputBorder="false" :clearable="false" />
  65. </view>
  66. </view>
  67. </view>
  68. <!-- 价格信息 -->
  69. <view class="bg-white total-card-box ss-p-20 ss-m-b-14 ss-r-10" v-if="false">
  70. <view class="total-box-content border-bottom">
  71. <view class="order-item ss-flex ss-col-center ss-row-between">
  72. <view class="item-title">商品金额</view>
  73. <view class="ss-flex ss-col-center">
  74. <text class="item-value ss-m-r-24">
  75. ¥{{ fen2yuan(state.orderInfo.price.totalPrice) }}
  76. </text>
  77. </view>
  78. </view>
  79. <!-- TODO 芋艿:接入积分 -->
  80. <view class="order-item ss-flex ss-col-center ss-row-between"
  81. v-if="state.orderPayload.order_type === 'score'">
  82. <view class="item-title">扣除积分</view>
  83. <view class="ss-flex ss-col-center">
  84. <image :src="sheep.$url.static('/static/img/shop/goods/score1.svg')" class="score-img" />
  85. <text class="item-value ss-m-r-24">{{ state.orderInfo.score_amount }}</text>
  86. </view>
  87. </view>
  88. <view class="order-item ss-flex ss-col-center ss-row-between">
  89. <view class="item-title">运费</view>
  90. <view class="ss-flex ss-col-center">
  91. <text class="item-value ss-m-r-24">
  92. +¥{{ fen2yuan(state.orderInfo.price.deliveryPrice) }}
  93. </text>
  94. </view>
  95. </view>
  96. <!-- 优惠劵:只有 type = 0 普通订单(非拼团、秒杀、砍价),才可以使用优惠劵 -->
  97. <view class="order-item ss-flex ss-col-center ss-row-between" v-if="state.orderInfo.type === 0">
  98. <view class="item-title">优惠券</view>
  99. <view class="ss-flex ss-col-center" @tap="state.showCoupon = true">
  100. <text class="item-value text-red" v-if="state.orderPayload.couponId > 0">
  101. -¥{{ fen2yuan(state.orderInfo.price.couponPrice) }}
  102. </text>
  103. <text class="item-value" :class="state.couponInfo.length > 0 ? 'text-red' : 'text-disabled'"
  104. v-else>
  105. {{
  106. state.couponInfo.length > 0 ? state.couponInfo.length + ' 张可用' : '暂无可用优惠券'
  107. }}
  108. </text>
  109. <text class="_icon-forward item-icon" />
  110. </view>
  111. </view>
  112. <view class="order-item ss-flex ss-col-center ss-row-between"
  113. v-if="state.orderInfo.price.discountPrice > 0">
  114. <view class="item-title">活动优惠</view>
  115. <view class="ss-flex ss-col-center">
  116. <!-- @tap="state.showDiscount = true" TODO 芋艿:后续要把优惠信息打进去 -->
  117. <text class="item-value text-red">
  118. -¥{{ fen2yuan(state.orderInfo.price.discountPrice) }}
  119. </text>
  120. <text class="_icon-forward item-icon" />
  121. </view>
  122. </view>
  123. <view class="order-item ss-flex ss-col-center ss-row-between"
  124. v-if="state.orderInfo.price.vipPrice > 0">
  125. <view class="item-title">会员优惠</view>
  126. <view class="ss-flex ss-col-center">
  127. <text class="item-value text-red">
  128. -¥{{ fen2yuan(state.orderInfo.price.vipPrice) }}
  129. </text>
  130. </view>
  131. </view>
  132. </view>
  133. <view class="total-box-footer ss-font-28 ss-flex ss-row-right ss-col-center ss-m-r-28">
  134. <view class="total-num ss-m-r-20">
  135. 共{{ state.orderInfo.items.reduce((acc, item) => acc + item.count, 0) }}件
  136. </view>
  137. <view>合计:</view>
  138. <view class="total-num text-red"> ¥{{ fen2yuan(state.orderInfo.price.payPrice) }} </view>
  139. </view>
  140. </view>
  141. </view>
  142. <!-- 选择优惠券弹框 -->
  143. <s-coupon-select v-model="state.couponInfo" :show="state.showCoupon" @confirm="onSelectCoupon"
  144. @close="state.showCoupon = false" />
  145. <!-- 满额折扣弹框 TODO 芋艿:后续要把优惠信息打进去 -->
  146. <s-discount-list v-model="state.orderInfo" :show="state.showDiscount" @close="state.showDiscount = false" />
  147. <!-- 底部 -->
  148. <su-fixed bottom :opacity="false" bg="bg-white" placeholder :noFixed="false" :index="200">
  149. <view class="footer-box border-top ss-flex ss-row-between ss-p-x-20 ss-col-center">
  150. <view class="total-box-footer ss-flex ss-col-center">
  151. <view class="total-num ss-font-30 text-red">
  152. ¥{{ fen2yuan(state.orderInfo.price.payPrice) }}
  153. </view>
  154. </view>
  155. <button class="ss-reset-button ui-BG-Main-Gradient ss-r-40 submit-btn ui-Shadow-Main" @tap="onConfirm">
  156. 提交订单
  157. </button>
  158. </view>
  159. </su-fixed>
  160. </s-layout>
  161. </template>
  162. <script setup>
  163. import {
  164. reactive,
  165. computed,
  166. getCurrentInstance,
  167. ref,
  168. onMounted
  169. } from 'vue';
  170. import {
  171. onLoad
  172. } from '@dcloudio/uni-app';
  173. import sheep from '@/sheep';
  174. import {
  175. isEmpty
  176. } from 'lodash';
  177. import OrderApi from '@/sheep/api/trade/order';
  178. import CouponApi from '@/sheep/api/promotion/coupon';
  179. import {
  180. fen2yuan
  181. } from '@/sheep/hooks/useGoods';
  182. const state = reactive({
  183. orderPayload: {},
  184. orderInfo: {
  185. items: [], // 商品项列表
  186. price: {}, // 价格信息
  187. },
  188. addressInfo: {}, // 选择的收货地址
  189. showCoupon: false, // 是否展示优惠劵
  190. couponInfo: [], // 优惠劵列表
  191. showDiscount: false, // 是否展示营销活动
  192. tabIndex: 1, //头部选项卡 参数为 0不显示选项卡,1,2
  193. // time:
  194. hours: computed(() => new Date().getHours()),
  195. time: computed(() => {
  196. const hours = new Date().getHours();
  197. const minutes = new Date().getMinutes();
  198. return `${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}`;
  199. }),
  200. tel:'18827761619',
  201. focus:false
  202. });
  203. function bindTimeChange(e) {
  204. console.log(e,'eeeeeeeee')
  205. const selectedTime = e.target.value;
  206. const currentTime = state.time
  207. console.log(selectedTime,currentTime,'currentTime')
  208. if (selectedTime < currentTime) {
  209. console.log('进来了小于当前时间')
  210. // 用户选择的时间早于当前时间,您可以进行相应的处理,比如提示用户或重置为当前时间
  211. state.time = currentTime;
  212. console.log(state.time,'小于小于')
  213. } else {
  214. console.log('进来了大于大于')
  215. state.time = selectedTime;
  216. console.log(state.time,'大于大于')
  217. }
  218. }
  219. function editTel(){
  220. console.log('点击了')
  221. // 获取输入框元素
  222. state.focus=true
  223. }
  224. function onBlur() {
  225. console.log('我失焦了');
  226. validatePhoneNumber(state.tel);
  227. }
  228. function validatePhoneNumber(phoneNumber) {
  229. const phonePattern = /^1[0-9]{10}$/; // 手机号正则表达式
  230. if (phonePattern.test(phoneNumber)) {
  231. console.log('手机号合法');
  232. // uni.showToast({
  233. // title: '手机号合法',
  234. // });
  235. } else {
  236. uni.showToast({
  237. icon: 'none',
  238. title: '手机号不合法',
  239. });
  240. state.tel=''
  241. console.log('手机号不合法');
  242. }
  243. }
  244. // 选择地址
  245. function onSelectAddress() {
  246. uni.$once('SELECT_ADDRESS', (e) => {
  247. changeConsignee(e.addressInfo);
  248. });
  249. sheep.$router.go('/pages/user/address/list');
  250. }
  251. // 更改收货人地址&计算订单信息
  252. async function changeConsignee(addressInfo = {}) {
  253. if (!isEmpty(addressInfo)) {
  254. state.addressInfo = addressInfo;
  255. }
  256. await getOrderInfo();
  257. }
  258. // 选择优惠券
  259. async function onSelectCoupon(couponId) {
  260. state.orderPayload.couponId = couponId || 0;
  261. await getOrderInfo();
  262. state.showCoupon = false;
  263. }
  264. // 提交订单
  265. function onConfirm() {
  266. if (!state.addressInfo.id) {
  267. sheep.$helper.toast('请选择收货地址');
  268. return;
  269. }
  270. submitOrder();
  271. }
  272. // 创建订单&跳转
  273. async function submitOrder() {
  274. const {
  275. code,
  276. data
  277. } = await OrderApi.createOrder({
  278. items: state.orderPayload.items,
  279. couponId: state.orderPayload.couponId,
  280. addressId: state.addressInfo.id,
  281. deliveryType: state.tabIndex, // TODO 芋艿:需要支持【门店自提】
  282. pointStatus: false, // TODO 芋艿:需要支持【积分选择】
  283. combinationActivityId: state.orderPayload.combinationActivityId,
  284. combinationHeadId: state.orderPayload.combinationHeadId,
  285. seckillActivityId: state.orderPayload.seckillActivityId
  286. });
  287. if (code !== 0) {
  288. return;
  289. }
  290. // 更新购物车列表,如果来自购物车
  291. if (state.orderPayload.items[0].cartId > 0) {
  292. sheep.$store('cart').getList();
  293. }
  294. // 跳转到支付页面
  295. sheep.$router.redirect('/pages/pay/index', {
  296. id: data.payOrderId,
  297. });
  298. }
  299. // 检查库存 & 计算订单价格
  300. async function getOrderInfo() {
  301. // 计算价格
  302. const {
  303. data,
  304. code
  305. } = await OrderApi.settlementOrder({
  306. items: state.orderPayload.items,
  307. couponId: state.orderPayload.couponId,
  308. addressId: state.addressInfo.id,
  309. deliveryType: state.tabIndex, // TODO 芋艿:需要支持【门店自提】
  310. pointStatus: false, // TODO 芋艿:需要支持【积分选择】
  311. combinationActivityId: state.orderPayload.combinationActivityId,
  312. combinationHeadId: state.orderPayload.combinationHeadId,
  313. seckillActivityId: state.orderPayload.seckillActivityId
  314. });
  315. if (code !== 0) {
  316. return;
  317. }
  318. state.orderInfo = data;
  319. // 设置收货地址
  320. if (state.orderInfo.address) {
  321. state.addressInfo = state.orderInfo.address;
  322. }
  323. }
  324. // 获取可用优惠券
  325. async function getCoupons() {
  326. const {
  327. code,
  328. data
  329. } = await CouponApi.getMatchCouponList(
  330. state.orderInfo.price.payPrice,
  331. state.orderInfo.items.map((item) => item.spuId),
  332. state.orderPayload.items.map((item) => item.skuId),
  333. state.orderPayload.items.map((item) => item.categoryId),
  334. );
  335. if (code === 0) {
  336. state.couponInfo = data;
  337. }
  338. }
  339. onLoad(async (options) => {
  340. if (!options.data) {
  341. sheep.$helper.toast('参数不正确,请检查!');
  342. return;
  343. }
  344. state.orderPayload = JSON.parse(options.data);
  345. await getOrderInfo();
  346. await getCoupons();
  347. });
  348. </script>
  349. <style lang="scss" scoped>
  350. :deep() {
  351. .uni-input-wrapper {
  352. width: 320rpx;
  353. }
  354. .uni-easyinput__content-input {
  355. font-size: 28rpx;
  356. height: 72rpx;
  357. text-align: right !important;
  358. padding-right: 0 !important;
  359. .uni-input-input {
  360. font-weight: 500;
  361. color: #333333;
  362. font-size: 26rpx;
  363. height: 32rpx;
  364. margin-top: 4rpx;
  365. }
  366. }
  367. .uni-easyinput__content {
  368. display: flex !important;
  369. align-items: center !important;
  370. justify-content: right !important;
  371. }
  372. }
  373. .score-img {
  374. width: 36rpx;
  375. height: 36rpx;
  376. margin: 0 4rpx;
  377. }
  378. .order-item {
  379. height: 80rpx;
  380. .item-title {
  381. font-size: 28rpx;
  382. font-weight: 400;
  383. }
  384. .item-value {
  385. font-size: 28rpx;
  386. font-weight: 500;
  387. font-family: OPPOSANS;
  388. }
  389. .text-disabled {
  390. color: #bbbbbb;
  391. }
  392. .item-icon {
  393. color: $dark-9;
  394. }
  395. .remark-input {
  396. text-align: right;
  397. }
  398. .item-placeholder {
  399. color: $dark-9;
  400. font-size: 26rpx;
  401. text-align: right;
  402. }
  403. }
  404. .total-box-footer {
  405. height: 90rpx;
  406. .total-num {
  407. color: #333333;
  408. font-family: OPPOSANS;
  409. }
  410. }
  411. .footer-box {
  412. height: 100rpx;
  413. .submit-btn {
  414. width: 240rpx;
  415. height: 70rpx;
  416. font-size: 28rpx;
  417. font-weight: 500;
  418. .goto-pay-text {
  419. line-height: 28rpx;
  420. }
  421. }
  422. .cancel-btn {
  423. width: 240rpx;
  424. height: 80rpx;
  425. font-size: 26rpx;
  426. background-color: #e5e5e5;
  427. color: $dark-9;
  428. }
  429. }
  430. .title {
  431. font-size: 36rpx;
  432. font-weight: bold;
  433. color: #333333;
  434. }
  435. .subtitle {
  436. font-size: 28rpx;
  437. color: #999999;
  438. }
  439. .cicon-checkbox {
  440. font-size: 36rpx;
  441. color: var(--ui-BG-Main);
  442. }
  443. .cicon-box {
  444. font-size: 36rpx;
  445. color: #999999;
  446. }
  447. .bg-red {
  448. background-color: #EC3534;
  449. }
  450. .bgc {
  451. position: fixed;
  452. top: 0;
  453. left: 0;
  454. width: 100%;
  455. height: 600rpx;
  456. z-index: -1;
  457. background: linear-gradient(180deg, #EC3534 0%, rgba(236, 53, 52, 0) 100%);
  458. }
  459. .head {
  460. // background: linear-gradient(to bottom, #ffc107, #f1f1f1);
  461. padding-top: 20px;
  462. .tab-box {
  463. position: relative;
  464. height: 40px;
  465. // margin: 0 12px;
  466. .item {
  467. position: absolute;
  468. top: 0;
  469. bottom: 0;
  470. height: 40px;
  471. text-align: center;
  472. font-size: 14px;
  473. width: 50%;
  474. .tit-box {
  475. position: relative;
  476. height: 36px;
  477. line-height: 36px;
  478. border-top-left-radius: 6px;
  479. border-top-right-radius: 6px;
  480. background-color: rgba(#ffffff, .6);
  481. width: 100%;
  482. }
  483. }
  484. .item:first-child {
  485. display: flex;
  486. flex-direction: row;
  487. justify-content: flex-start;
  488. align-items: flex-end;
  489. left: 0;
  490. }
  491. .item:last-child {
  492. display: flex;
  493. flex-direction: row;
  494. justify-content: flex-end;
  495. align-items: flex-end;
  496. right: 0;
  497. }
  498. .active {
  499. height: 40px;
  500. width: 51%;
  501. font-weight: bold;
  502. .tit-box {
  503. height: 40px;
  504. line-height: 40px;
  505. background-color: rgba(#ffffff, 1);
  506. }
  507. }
  508. .left .tit-box {
  509. // margin-left: 12px;
  510. margin-right: -12px;
  511. padding-right: 12px;
  512. }
  513. .right .tit-box {
  514. // margin-right: 12px;
  515. margin-left: -12px;
  516. padding-left: 12px;
  517. }
  518. .left.active .tit-box {
  519. margin: 0;
  520. }
  521. .right.active .tit-box {
  522. margin: 0;
  523. }
  524. .left.active .tit-box:after {
  525. content: '';
  526. position: absolute;
  527. right: -12px;
  528. bottom: 0;
  529. border-top: 12px solid transparent;
  530. border-right: 12px solid transparent;
  531. border-bottom: 36px solid #ffffff;
  532. }
  533. .right.active .tit-box:after {
  534. content: '';
  535. position: absolute;
  536. left: -12px;
  537. bottom: 0;
  538. border-top: 12px solid transparent;
  539. border-left: 12px solid transparent;
  540. border-bottom: 36px solid #ffffff;
  541. }
  542. }
  543. .head-bottom {
  544. overflow: hidden;
  545. background: #ffffff;
  546. border-top-left-radius: 6px;
  547. border-top-right-radius: 6px;
  548. border-bottom-left-radius: 6px;
  549. border-bottom-right-radius: 6px;
  550. .tab {
  551. .t-top {
  552. &-box {
  553. margin: 0;
  554. padding: 12px;
  555. .txt1 {
  556. font-size: 18px;
  557. color: #888;
  558. }
  559. .icon1 {
  560. margin-left: 8px;
  561. color: #bbb;
  562. }
  563. }
  564. &-box:active {
  565. background-color: #f5f5f5;
  566. }
  567. }
  568. .t-bb {
  569. margin: 0 12px;
  570. height: 0.5px;
  571. background-color: #E4E7ED;
  572. }
  573. .t-bottom {
  574. padding: 12px;
  575. .row1 {
  576. display: flex;
  577. flex-direction: row;
  578. justify-content: space-between;
  579. //padding: 12px 0 0;
  580. .left {
  581. font-size: 14px;
  582. font-weight: bold;
  583. }
  584. .right {
  585. font-size: 14px;
  586. color: #ff9800;
  587. i {
  588. margin-left: 8px;
  589. color: #bbb;
  590. }
  591. }
  592. }
  593. .row2 {
  594. margin-top: 6px;
  595. font-size: 12px;
  596. color: #ff9800;
  597. }
  598. }
  599. }
  600. }
  601. .head-bottom.selectOne {
  602. border-top-left-radius: 0;
  603. border-top-right-radius: px;
  604. }
  605. .head-bottom.selectTow {
  606. border-top-left-radius: 6px;
  607. border-top-right-radius: 0;
  608. }
  609. }
  610. .tab2-box {
  611. padding: 30rpx 20rpx;
  612. .top-address {
  613. font-weight: 600;
  614. font-size: 40rpx;
  615. color: #313131;
  616. margin-bottom: 20rpx;
  617. }
  618. .under-box {
  619. display: flex;
  620. .font {
  621. font-weight: 400;
  622. font-size: 30rpx;
  623. color: #7C7C7C;
  624. }
  625. .line {
  626. width: 2rpx;
  627. background-color: #D8D8D8;
  628. margin: 0 14rpx;
  629. }
  630. .time {
  631. .chooseTime {
  632. display: flex;
  633. align-items: center;
  634. }
  635. }
  636. .tel {
  637. .edit-icon {
  638. display: flex;
  639. align-items: center;
  640. image {
  641. width: 24rpx;
  642. height: 24rpx;
  643. margin-left: 18rpx;
  644. }
  645. .width{
  646. width:200rpx;
  647. }
  648. }
  649. }
  650. }
  651. }
  652. </style>