surePay.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. <template>
  2. <view class="container">
  3. <uv-navbar title="确认订单" placeholder autoBack></uv-navbar>
  4. <view
  5. class="topStatus u-flex-center-sb"
  6. v-if="isAbleSelectSelfPickupBo.ablePickup"
  7. >
  8. <view
  9. class="top-item"
  10. :class="status == 0 ? 'active-right' : ''"
  11. @click.stop="changeStatus(0)"
  12. >
  13. <image
  14. v-if="status == 0"
  15. class="item-icon"
  16. :src="$handleImageUrl('/home/icon_left.png')"
  17. mode=""
  18. >
  19. </image>
  20. <view class="item-text u-1A1A1A u-font30 mr-15">快递配送</view>
  21. </view>
  22. <view
  23. class="top-item"
  24. :class="status == 10 ? 'active-left' : ''"
  25. @click.stop="changeStatus(10)"
  26. >
  27. <image
  28. v-if="status == 10"
  29. class="item-icon"
  30. :src="$handleImageUrl('/home/icon_right.png')"
  31. mode=""
  32. >
  33. </image>
  34. <view class="item-text u-1A1A1A u-font30">上门自提</view>
  35. </view>
  36. </view>
  37. <view
  38. class="carbox"
  39. :class="isAbleSelectSelfPickupBo.ablePickup ? 'changeTabtwo' : ''"
  40. >
  41. <view class="addressBox">
  42. <view class="" v-if="status == 0">
  43. <ldAddress
  44. :value="sureDataAll.shopOrderAddress"
  45. :link="true"
  46. ></ldAddress>
  47. </view>
  48. <view class="goHome u-p30" v-if="status == 10">
  49. <view class="u-flex-center">
  50. <view class="u-mr45 u-font28 u-999 u-flex-center">
  51. <text class="u-333 u-bold">提货人:</text>
  52. <input
  53. style="width: 150rpx"
  54. type="text"
  55. v-model="dataJson.selfPickupBo.receiverName"
  56. maxlength="8"
  57. placeholder="提货人姓名"
  58. placeholder-style="font-size:30rpx;"
  59. />
  60. </view>
  61. <view class="u-font28 u-999 u-flex-center">
  62. <text class="u-mr10 iconfont u-02331F u-font30">&#xe60d;</text>
  63. <input
  64. style="width: 260rpx"
  65. type="number"
  66. v-model="dataJson.selfPickupBo.receiverPhone"
  67. maxlength="11"
  68. placeholder="提货人手机号"
  69. placeholder-style="font-size:30rpx;"
  70. />
  71. </view>
  72. </view>
  73. <view class="u-font28 u-999 u-flex-center" style="margin-top: 20rpx">
  74. <view class="u-mr45 u-font28 u-999 u-flex-center z-flex-pick-up">
  75. <text class="u-333 u-bold z-pick-up">自提点:</text>
  76. <picker
  77. @change="confirmPickUp"
  78. range-key="pointName"
  79. :range="shopPickUpAddressList"
  80. >
  81. <text class="u-999 u-bold" style="min-width: 200rpx">{{
  82. pickUpAdress || "请选择自提点地址"
  83. }}</text>
  84. </picker>
  85. <!-- <uv-select
  86. v-if="showPickUp"
  87. :list="shopPickUpAddressList"
  88. value-name="id"
  89. label-name="point_name"
  90. @confirm="confirmPickUp"
  91. ></uv-select> -->
  92. </view>
  93. </view>
  94. <view
  95. class="u-font28 u-999 u-flex-center"
  96. style="margin-top: 20rpx"
  97. v-if="pickUpAdressDetail"
  98. >
  99. <view class="u-mr45 u-font28 u-999 u-flex-center z-flex-pick-up">
  100. <text class="u-333 u-bold z-pick-up">详细地址:</text>
  101. <text class="u-999 u-bold address-box">{{
  102. pickUpAdressDetail
  103. }}</text>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. <view class="shopList u-mt10">
  109. <view class="listText u-bold">
  110. <view class="u-font28 u-181818">{{
  111. sureDataAll.businessName || ""
  112. }}</view>
  113. </view>
  114. <view v-for="(item, i) in sureDataAll.shopOrderDetailBoList" :key="i">
  115. <ld-goods :value="item" :exchange="dataJson.exchange"></ld-goods>
  116. </view>
  117. </view>
  118. <view
  119. class="listText u-border-one-one u-p30 u-flex-center-sb"
  120. v-if="sureDataAll.givePoint && sureDataAll.givePoint * 1 > 0"
  121. >
  122. <view class="u-font28 u-181818">下单送积分</view>
  123. <view class="u-font30 c-da4f4f">
  124. {{ sureDataAll.givePoint || 0 }}积分
  125. </view>
  126. </view>
  127. <view class="listText u-p30">
  128. <view class="u-font28 u-181818 title">
  129. <span>购买备注</span>
  130. <span class="num"
  131. >{{ dataJson.buyerRemark ? dataJson.buyerRemark.length : 0 }} /
  132. 80</span
  133. >
  134. </view>
  135. <textarea
  136. class="textarea u-mt10 u-font28 u-333"
  137. :auto-height="true"
  138. :maxlength="80"
  139. v-model="dataJson.buyerRemark"
  140. placeholder="选填,给商家留言"
  141. />
  142. </view>
  143. <view class="listText u-border-one-one u-p30 u-flex-center-sb">
  144. <view class="u-font28 u-181818"><text>运费</text></view>
  145. <view class="u-font30 c-da4f4f">
  146. {{
  147. sureDataAll.shippingFee && sureDataAll.shippingFee * 1 > 0
  148. ? "+¥" + (sureDataAll.shippingFee || 0) + "元"
  149. : "免运费"
  150. }}
  151. </view>
  152. </view>
  153. <view class="listText u-p30" v-if="!dataJson.exchange && dataJson.marketingType == 0">
  154. <view class="u-flex-center-sb">
  155. <view class="u-font28 u-181818"><text>共减</text></view>
  156. <view class="u-font30 c-da4f4f">
  157. -¥{{ sureDataAll.totalCouponReduced || 0 }}
  158. </view>
  159. </view>
  160. <view
  161. class="u-border-one-one border"
  162. v-if="(sureDataAll.totalCouponReduced || 0) * 1"
  163. >
  164. <view
  165. class="u-flex-center-sb u-mt10 u-mb10"
  166. v-for="(item, i) in sureDataAll.shopOrderUseRecordBoList || []"
  167. :key="i"
  168. >
  169. <view class="u-font28 u-181818 u-flex1"
  170. ><text>{{ item.businessCouponName }}</text></view
  171. >
  172. <view
  173. class="u-flex-center-sb u-ml10"
  174. style="flex-shrink: 0"
  175. @click="useCoupon(item)"
  176. >
  177. <view class="u-font30 c-da4f4f">
  178. -¥{{ item.businessCouponFaceValue }}
  179. </view>
  180. <uv-icon
  181. name="arrow-right"
  182. :color="item.universal ? '#999999' : '#ffffff'"
  183. size="30rpx"
  184. ></uv-icon>
  185. </view>
  186. </view>
  187. </view>
  188. </view>
  189. <view class="listText u-p30" v-if="dataJson.marketingType != 0">
  190. <view class="u-flex-center-sb">
  191. <view class="u-font28 u-181818"><text>{{ dataJson.marketingType == 5 ? '秒杀' : '拼团' }}活动折扣</text></view>
  192. <view class="u-font30 c-da4f4f">
  193. -¥{{ sureDataAll.totalActivityReduced || 0 }}
  194. </view>
  195. </view>
  196. </view>
  197. <view
  198. class="listText u-border-one-one border u-p30 u-flex-center-sb"
  199. v-if="dataJson.exchange"
  200. >
  201. <view class="u-font28 u-181818"><text>需要积分</text></view>
  202. <view class="u-font30 c-da4f4f">
  203. {{ sureDataAll.paymentPoints || 0 }}积分
  204. </view>
  205. </view>
  206. <view class="listText u-border-one-one border u-p30" v-else>
  207. <view class="u-flex-center-sb">
  208. <view class="u-font28 u-181818"><text>积分抵扣</text></view>
  209. <view class="u-font30 c-da4f4f">
  210. <uv-switch
  211. v-model="usePlatformPoint"
  212. @change="changePlatformPoint()"
  213. active-color="#e93534"
  214. ></uv-switch>
  215. </view>
  216. </view>
  217. <view style="color: #808080; font-size: 24rpx"
  218. >共计{{ sureDataAll.paymentPoints || 0
  219. }}<text v-if="usePlatformPoint"
  220. >,可使用{{ sureDataAll.paymentPoints || 0 }}抵扣{{
  221. sureDataAll.pointReduced || 0
  222. }}元</text
  223. >
  224. </view>
  225. </view>
  226. </view>
  227. <!-- 底部 -->
  228. <view class="botfixed u-flex-center-sb">
  229. <view class="leftAll u-flex-center">
  230. <view class="u-flex-center">
  231. <text class="u-mr20 u-font24 u-666">共{{ totaltNum }}件</text>
  232. <text class="u-font28 u-333">合计:</text>
  233. <view class="u-FF0000 u-bold">
  234. <text v-if="dataJson.exchange"
  235. >{{ sureDataAll.paymentPoints || 0 }}积分</text
  236. >
  237. <rich-text
  238. v-else
  239. :nodes="$mUtil.priceBigSmall(sureDataAll.actualPayment)"
  240. ></rich-text>
  241. </view>
  242. </view>
  243. </view>
  244. <view class="rightP u-flex-center" @click="$throttle(submitOrder, 500)">
  245. <view class="u-btn-two btnWidth u-ml30">提交订单</view>
  246. </view>
  247. </view>
  248. <!-- 优惠券选择弹窗 -->
  249. <couponSelectPopup
  250. ref="couponSelectPopupRef"
  251. :list="couponList"
  252. @change="useCouponChange"
  253. />
  254. </view>
  255. </template>
  256. <script setup>
  257. import { ref } from "vue";
  258. import { onLoad, onShow } from "@dcloudio/uni-app";
  259. import { shoporderBuild_Api, shoporderCreate_Api } from "@/api/order";
  260. import {
  261. businessLogisticsConfigInfo,
  262. businessSelfPickupAddressList,
  263. selectUniversal_Api,
  264. } from "@/api/index";
  265. import $mConfig from "@/config/global.config.js";
  266. const totaltNum = ref(0);
  267. const loading = ref(false);
  268. const status = ref(0);
  269. const sureDataAll = ref({});
  270. const dataJson = ref({});
  271. const type = ref(null);
  272. const usePlatformPoint = ref(true);
  273. const shopPickUpAddressList = ref([]);
  274. const pickUpAdress = ref("");
  275. const pickUpAdressDetail = ref("");
  276. const isAbleSelectSelfPickupBo = ref({});
  277. const couponList = ref([]); // 优惠券列表
  278. const couponSelectPopupRef = ref(null);
  279. // 切换优惠
  280. const useCoupon = (item) => {
  281. if (item.universal) {
  282. couponSelectPopupRef.value.open(item.myBusinessCouponId);
  283. }
  284. };
  285. // 切换优惠卷
  286. const useCouponChange = (item) => {
  287. // console.log(item);
  288. dataJson.value.myCouponId = item.id;
  289. changePlatformPoint();
  290. };
  291. // 收货地址或自提切换
  292. const changePlatformPoint = () => {
  293. let objs = {
  294. ...dataJson.value,
  295. userUsePoint: usePlatformPoint.value,
  296. };
  297. uni.setStorageSync("dataJson", objs);
  298. postData(objs);
  299. };
  300. let submitLoading = false;
  301. const orderCreated = () => {
  302. if (submitLoading) return;
  303. submitLoading = true;
  304. uni.showLoading({
  305. title: "正在创建订单",
  306. mask: true,
  307. });
  308. // console.log({
  309. // ...dataJson.value,
  310. // userUsePoint: usePlatformPoint.value,
  311. // })
  312. // return;
  313. shoporderCreate_Api({
  314. ...dataJson.value,
  315. userUsePoint: usePlatformPoint.value,
  316. })
  317. .then((res) => {
  318. submitLoading = false;
  319. uni.hideLoading();
  320. if (res && res.code == 200) {
  321. let target = res.data;
  322. if (target.paymentStatus == 10) {
  323. uni.showToast({
  324. title: "下单成功",
  325. icon: "success",
  326. });
  327. setTimeout(() => {
  328. uni.redirectTo({
  329. url: `/pages/order/mallOrder/orderList?orderType=0`,
  330. });
  331. }, 100);
  332. return false;
  333. } else {
  334. // console.log("支付时间:" + new Date(target.expiredTime).getTime());
  335. let expiredTime = new Date(target.expiredTime).getTime();
  336. uni.redirectTo({
  337. url:
  338. "/pages/order/pay?orderNo=" +
  339. target.orderNo +
  340. "&total_amount=" +
  341. target.actualPayment +
  342. "&expired_pay_time=" +
  343. expiredTime +
  344. "&orderId=" +
  345. target.orderId,
  346. });
  347. }
  348. }
  349. })
  350. .catch(() => {
  351. submitLoading = false;
  352. // uni.hideLoading();
  353. // setTimeout(() => {
  354. // uni.navigateBack();
  355. // }, 500);
  356. });
  357. };
  358. const submitOrder = () => {
  359. if (status.value == 0) {
  360. //快速配送
  361. // dataJson.value.selfPickupBo = null;
  362. // console.log(dataJson.value);
  363. if (
  364. dataJson.value.addressBo.userAddressId == null &&
  365. !sureDataAll.value.addressBo.userAddressId
  366. ) {
  367. uni.$uv.toast("请填写收货地址");
  368. return false;
  369. }
  370. } else {
  371. //自提
  372. if (!dataJson.value.selfPickupBo.receiverName) {
  373. uni.$uv.toast("请填写提货人姓名");
  374. return false;
  375. }
  376. if (!dataJson.value.selfPickupBo.receiverPhone) {
  377. uni.$uv.toast("请填写提货人手机号");
  378. return false;
  379. }
  380. if (!dataJson.value.selfPickupBo.receiverPhone.match($mConfig.telRegex)) {
  381. uni.$uv.toast("请输入正确手机号");
  382. return false;
  383. }
  384. if (!dataJson.value.selfPickupBo.selfPickupId) {
  385. uni.$uv.toast("请选择自提点地址");
  386. return false;
  387. }
  388. }
  389. orderCreated();
  390. };
  391. // 获取可使用优惠卷列表
  392. const getSelectUniversal_Api = (totalAmountDecShopCoupon) => {
  393. selectUniversal_Api({
  394. totalAmountDecShopCoupon,
  395. businessId: dataJson.value.businessId,
  396. marketingType: 0, // 活动字段0:无活动,5:秒杀, 10:拼团
  397. }).then((res) => {
  398. if (res.code == 200) {
  399. couponList.value = res.data || [];
  400. }
  401. });
  402. };
  403. // 构建订单
  404. const postData = (dataJsons) => {
  405. if (dataJsons) {
  406. loading.value = true;
  407. shoporderBuild_Api(
  408. {
  409. ...dataJsons,
  410. },
  411. {
  412. hideToast: true,
  413. }
  414. )
  415. .then((res) => {
  416. if (res && res.code == 200) {
  417. getSelectUniversal_Api(res.data.totalProductAmount);
  418. try {
  419. loading.value = false;
  420. // uni.setStorageSync("sureData", res.data);
  421. if (res.data) {
  422. sureDataAll.value = res.data;
  423. totaltNum.value = res.data.productNumber;
  424. }
  425. dataJson.value.addressBo = res.data.shopOrderAddress || {};
  426. usePlatformPoint.value = res.data.userUsePoint;
  427. } catch (error) {
  428. console.log(error);
  429. }
  430. }
  431. })
  432. .catch(() => {
  433. // uni.hideLoading();
  434. setTimeout(function () {
  435. uni.navigateBack();
  436. }, 1500);
  437. });
  438. }
  439. };
  440. // 切换取货方式
  441. const changeStatus = (val) => {
  442. if (val == 10 && !shopPickUpAddressList.value.length) {
  443. uni.$uv.toast("暂无自提点,请联系商家");
  444. return;
  445. }
  446. dataJson.value.shippingMethod = val;
  447. status.value = val;
  448. pickUpAdress.value = "";
  449. pickUpAdressDetail.value = "";
  450. postData(dataJson.value);
  451. };
  452. // 自提点选择触发
  453. const confirmPickUp = (e) => {
  454. // console.log(e.detail.value);
  455. if (!shopPickUpAddressList.value.length) {
  456. uni.$uv.toast("暂无自提点,请联系商家");
  457. return;
  458. }
  459. const objs = shopPickUpAddressList.value[e.detail.value];
  460. pickUpAdress.value = objs.pointName;
  461. pickUpAdressDetail.value = objs.address;
  462. dataJson.value.selfPickupBo.selfPickupId = objs.id;
  463. };
  464. // 获取自提点
  465. const getPickUpList = () => {
  466. businessSelfPickupAddressList(dataJson.value.businessId).then((res) => {
  467. if (res && res.code == 200) {
  468. shopPickUpAddressList.value = res.data || [];
  469. }
  470. });
  471. };
  472. // 获取商家物流配置信息
  473. const getBusinessLogisticsConfigInfo = () => {
  474. businessLogisticsConfigInfo(dataJson.value.businessId).then((res) => {
  475. if (res && res.code == 200) {
  476. console.log(res.data);
  477. isAbleSelectSelfPickupBo.value = res.data || {};
  478. if (isAbleSelectSelfPickupBo.value.ablePickup) {
  479. dataJson.value.selfPickupBo = {};
  480. getPickUpList();
  481. }
  482. }
  483. });
  484. };
  485. onLoad((options) => {
  486. loading.value = true;
  487. let dataJson1 = uni.getStorageSync("dataJson");
  488. console.log(dataJson1);
  489. if (dataJson1) {
  490. dataJson.value = dataJson1;
  491. }
  492. if (options.type) {
  493. type.value = options.type;
  494. }
  495. if (dataJson.value.businessId) getBusinessLogisticsConfigInfo();
  496. });
  497. onShow(() => {
  498. let orderreminder = uni.getStorageSync("orderreminder");
  499. if (orderreminder) {
  500. uni.$uv.toast("已生成待付款订单");
  501. uni.removeStorageSync("orderreminder");
  502. }
  503. let dataJson = uni.getStorageSync("dataJson");
  504. postData(dataJson);
  505. });
  506. </script>
  507. <style lang="scss" scoped>
  508. :deep(.input-placeholder) {
  509. font-size: 26rpx;
  510. }
  511. </style>
  512. <style lang="scss">
  513. page {
  514. background-color: #f5f5f5;
  515. box-sizing: border-box;
  516. }
  517. .c-da4f4f {
  518. color: #da4f4f;
  519. }
  520. .border {
  521. border-bottom: 3rpx solid #e7e7e7;
  522. }
  523. .textarea {
  524. width: 100%;
  525. height: 80rpx;
  526. background-color: #fafafa;
  527. padding: 22rpx 20rpx;
  528. box-sizing: border-box;
  529. border: 1px solid #ededed;
  530. border-radius: 20rpx;
  531. }
  532. .topStatus {
  533. height: 100rpx;
  534. background-color: #fdeee9;
  535. position: fixed;
  536. z-index: 9;
  537. width: 100%;
  538. box-sizing: border-box;
  539. .item-text {
  540. line-height: 100rpx;
  541. position: relative;
  542. z-index: 2;
  543. text-align: center;
  544. border-radius: 30rpx 30rpx 0 0;
  545. color: #010101;
  546. }
  547. .top-item {
  548. position: relative;
  549. flex: 1;
  550. box-sizing: border-box;
  551. height: 100rpx;
  552. .item-icon {
  553. width: 420rpx;
  554. height: 114rpx;
  555. position: absolute;
  556. top: -4rpx;
  557. left: 0;
  558. z-index: 1;
  559. }
  560. }
  561. .top-item.active-right,
  562. .top-item.active-left {
  563. font-weight: bold;
  564. width: 420rpx;
  565. flex-shrink: 0;
  566. }
  567. .active-left {
  568. padding-left: 64rpx;
  569. }
  570. .active-right {
  571. padding-right: 64rpx;
  572. }
  573. }
  574. .courierAddress {
  575. background-color: #fff;
  576. padding: 36rpx 30rpx;
  577. }
  578. .goHome,
  579. .listText {
  580. background-color: #fff;
  581. .title {
  582. display: flex;
  583. justify-content: space-between;
  584. align-items: center;
  585. .num {
  586. color: #808080;
  587. font-size: 26rpx;
  588. }
  589. }
  590. .freight {
  591. padding: 30rpx;
  592. .u-border-one-one {
  593. padding: 30rpx 0;
  594. }
  595. }
  596. .consumption_value-icon {
  597. font-size: 60rpx;
  598. color: #ff9651;
  599. }
  600. .consumption_value span {
  601. color: #ff6600;
  602. }
  603. }
  604. .btnview {
  605. width: 300rpx;
  606. margin: 30rpx auto 0;
  607. }
  608. .shopList {
  609. background-color: #fff;
  610. padding: 30rpx 30rpx 0;
  611. &:deep(.textWidth) {
  612. $font-size: 28rpx; // scss 变量
  613. height: $font-size * 1.5 * 2; // 计算出两行文本的高度
  614. line-height: 1.5;
  615. font-size: $font-size;
  616. }
  617. }
  618. .changeTabtwo {
  619. padding: 130rpx 0 160rpx 0;
  620. }
  621. .rightText {
  622. justify-content: space-between;
  623. // height: 200rpx;
  624. }
  625. .bottext,
  626. .botPrice {
  627. width: 100%;
  628. box-sizing: border-box;
  629. }
  630. .bottext {
  631. margin-top: 36rpx;
  632. }
  633. .rightAddRes {
  634. width: 172rpx;
  635. height: 50rpx;
  636. border-radius: 8rpx;
  637. border: 1px solid #e5e5e5;
  638. .centertext {
  639. text-align: center;
  640. }
  641. .btnTag {
  642. width: 50rpx;
  643. height: 50rpx;
  644. line-height: 50rpx;
  645. text-align: center;
  646. background-color: #dedede;
  647. font-size: 46rpx;
  648. color: #888;
  649. }
  650. }
  651. .btnWidth {
  652. width: 340rpx;
  653. background: #e93534;
  654. }
  655. .botfixed {
  656. position: fixed;
  657. background-color: #fff;
  658. width: 100%;
  659. height: 138rpx;
  660. bottom: 0;
  661. left: 0;
  662. z-index: 9;
  663. padding: 0 30rpx;
  664. box-sizing: border-box;
  665. }
  666. .z-flex-pick-up {
  667. align-items: start;
  668. .z-pick-up {
  669. flex-shrink: 0;
  670. }
  671. .address-box {
  672. display: -webkit-box;
  673. -webkit-box-orient: vertical;
  674. -webkit-line-clamp: 3;
  675. overflow: hidden;
  676. text-overflow: ellipsis;
  677. }
  678. }
  679. </style>