surePay.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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">
  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
  190. class="listText u-border-one-one border u-p30 u-flex-center-sb"
  191. v-if="dataJson.exchange"
  192. >
  193. <view class="u-font28 u-181818"><text>需要积分</text></view>
  194. <view class="u-font30 c-da4f4f">
  195. {{ sureDataAll.paymentPoints || 0 }}积分
  196. </view>
  197. </view>
  198. <view class="listText u-border-one-one border u-p30" v-else>
  199. <view class="u-flex-center-sb">
  200. <view class="u-font28 u-181818"><text>积分抵扣</text></view>
  201. <view class="u-font30 c-da4f4f">
  202. <uv-switch
  203. v-model="usePlatformPoint"
  204. @change="changePlatformPoint()"
  205. active-color="#e93534"
  206. ></uv-switch>
  207. </view>
  208. </view>
  209. <view style="color: #808080; font-size: 24rpx"
  210. >共计{{ sureDataAll.paymentPoints || 0
  211. }}<text v-if="usePlatformPoint"
  212. >,可使用{{ sureDataAll.paymentPoints || 0 }}抵扣{{
  213. sureDataAll.pointReduced || 0
  214. }}元</text
  215. >
  216. </view>
  217. </view>
  218. </view>
  219. <!-- 底部 -->
  220. <view class="botfixed u-flex-center-sb">
  221. <view class="leftAll u-flex-center">
  222. <view class="u-flex-center">
  223. <text class="u-mr20 u-font24 u-666">共{{ totaltNum }}件</text>
  224. <text class="u-font28 u-333">合计:</text>
  225. <view class="u-FF0000 u-bold">
  226. <text v-if="dataJson.exchange"
  227. >{{ sureDataAll.paymentPoints || 0 }}积分</text
  228. >
  229. <rich-text
  230. v-else
  231. :nodes="$mUtil.priceBigSmall(sureDataAll.actualPayment)"
  232. ></rich-text>
  233. </view>
  234. </view>
  235. </view>
  236. <view class="rightP u-flex-center" @click="$throttle(submitOrder, 500)">
  237. <view class="u-btn-two btnWidth u-ml30">提交订单</view>
  238. </view>
  239. </view>
  240. <!-- 优惠券选择弹窗 -->
  241. <couponSelectPopup
  242. ref="couponSelectPopupRef"
  243. :list="couponList"
  244. @change="useCouponChange"
  245. />
  246. </view>
  247. </template>
  248. <script setup>
  249. import { ref } from "vue";
  250. import { onLoad, onShow } from "@dcloudio/uni-app";
  251. import { shoporderBuild_Api, shoporderCreate_Api } from "@/api/order";
  252. import {
  253. businessLogisticsConfigInfo,
  254. businessSelfPickupAddressList,
  255. selectUniversal_Api,
  256. } from "@/api/index";
  257. import $mConfig from "@/config/global.config.js";
  258. const totaltNum = ref(0);
  259. const loading = ref(false);
  260. const status = ref(0);
  261. const sureDataAll = ref({});
  262. const dataJson = ref({});
  263. const type = ref(null);
  264. const usePlatformPoint = ref(true);
  265. const shopPickUpAddressList = ref([]);
  266. const pickUpAdress = ref("");
  267. const pickUpAdressDetail = ref("");
  268. const isAbleSelectSelfPickupBo = ref({});
  269. const couponList = ref([]); // 优惠券列表
  270. const couponSelectPopupRef = ref(null);
  271. // 切换优惠
  272. const useCoupon = (item) => {
  273. if (item.universal) {
  274. couponSelectPopupRef.value.open(item.myBusinessCouponId);
  275. }
  276. };
  277. // 切换优惠卷
  278. const useCouponChange = (item) => {
  279. // console.log(item);
  280. dataJson.value.myCouponId = item.id;
  281. changePlatformPoint();
  282. };
  283. // 收货地址或自提切换
  284. const changePlatformPoint = () => {
  285. let objs = {
  286. ...dataJson.value,
  287. userUsePoint: usePlatformPoint.value,
  288. };
  289. uni.setStorageSync("dataJson", objs);
  290. postData(objs);
  291. };
  292. let submitLoading = false;
  293. const orderCreated = () => {
  294. if (submitLoading) return;
  295. submitLoading = true;
  296. uni.showLoading({
  297. title: "正在创建订单",
  298. mask: true,
  299. });
  300. shoporderCreate_Api({
  301. ...dataJson.value,
  302. userUsePoint: usePlatformPoint.value,
  303. })
  304. .then((res) => {
  305. submitLoading = false;
  306. uni.hideLoading();
  307. if (res && res.code == 200) {
  308. let target = res.data;
  309. if (target.paymentStatus == 10) {
  310. uni.showToast({
  311. title: "下单成功",
  312. icon: "success",
  313. });
  314. setTimeout(() => {
  315. uni.redirectTo({
  316. url: `/pages/order/mallOrder/orderList?orderType=0`,
  317. });
  318. }, 100);
  319. return false;
  320. } else {
  321. // console.log("支付时间:" + new Date(target.expiredTime).getTime());
  322. let expiredTime = new Date(target.expiredTime).getTime();
  323. uni.redirectTo({
  324. url:
  325. "/pages/order/pay?orderNo=" +
  326. target.orderNo +
  327. "&total_amount=" +
  328. target.actualPayment +
  329. "&expired_pay_time=" +
  330. expiredTime +
  331. "&orderId=" +
  332. target.orderId,
  333. });
  334. }
  335. }
  336. })
  337. .catch(() => {
  338. submitLoading = false;
  339. // uni.hideLoading();
  340. setTimeout(() => {
  341. uni.navigateBack();
  342. }, 500);
  343. });
  344. };
  345. const submitOrder = () => {
  346. if (status.value == 0) {
  347. //快速配送
  348. // dataJson.value.selfPickupBo = null;
  349. // console.log(dataJson.value);
  350. if (
  351. dataJson.value.addressBo.userAddressId == null &&
  352. !sureDataAll.value.addressBo.userAddressId
  353. ) {
  354. uni.$uv.toast("请填写收货地址");
  355. return false;
  356. }
  357. } else {
  358. //自提
  359. if (!dataJson.value.selfPickupBo.receiverName) {
  360. uni.$uv.toast("请填写提货人姓名");
  361. return false;
  362. }
  363. if (!dataJson.value.selfPickupBo.receiverPhone) {
  364. uni.$uv.toast("请填写提货人手机号");
  365. return false;
  366. }
  367. if (!dataJson.value.selfPickupBo.receiverPhone.match($mConfig.telRegex)) {
  368. uni.$uv.toast("请输入正确手机号");
  369. return false;
  370. }
  371. if (!dataJson.value.selfPickupBo.selfPickupId) {
  372. uni.$uv.toast("请选择自提点地址");
  373. return false;
  374. }
  375. }
  376. orderCreated();
  377. };
  378. // 获取可使用优惠卷列表
  379. const getSelectUniversal_Api = (totalAmountDecShopCoupon) => {
  380. selectUniversal_Api({
  381. totalAmountDecShopCoupon,
  382. businessId: dataJson.value.businessId,
  383. marketingType: 0, // 活动字段0:无活动,5:秒杀, 10:拼团
  384. }).then((res) => {
  385. if (res.code == 200) {
  386. couponList.value = res.data || [];
  387. }
  388. });
  389. };
  390. // 构建订单
  391. const postData = (dataJsons) => {
  392. if (dataJsons) {
  393. loading.value = true;
  394. shoporderBuild_Api(
  395. {
  396. ...dataJsons,
  397. },
  398. {
  399. hideToast: true,
  400. }
  401. )
  402. .then((res) => {
  403. if (res && res.code == 200) {
  404. getSelectUniversal_Api(res.data.totalProductAmount);
  405. try {
  406. loading.value = false;
  407. // uni.setStorageSync("sureData", res.data);
  408. if (res.data) {
  409. sureDataAll.value = res.data;
  410. totaltNum.value = res.data.productNumber;
  411. }
  412. dataJson.value.addressBo = res.data.shopOrderAddress || {};
  413. usePlatformPoint.value = res.data.userUsePoint;
  414. } catch (error) {
  415. console.log(error);
  416. }
  417. }
  418. })
  419. .catch(() => {
  420. // uni.hideLoading();
  421. setTimeout(function () {
  422. uni.navigateBack();
  423. }, 1500);
  424. });
  425. }
  426. };
  427. // 切换取货方式
  428. const changeStatus = (val) => {
  429. if (val == 10 && !shopPickUpAddressList.value.length) {
  430. uni.$uv.toast("暂无自提点,请联系商家");
  431. return;
  432. }
  433. dataJson.value.shippingMethod = val;
  434. status.value = val;
  435. pickUpAdress.value = "";
  436. pickUpAdressDetail.value = "";
  437. postData(dataJson.value);
  438. };
  439. // 自提点选择触发
  440. const confirmPickUp = (e) => {
  441. // console.log(e.detail.value);
  442. if (!shopPickUpAddressList.value.length) {
  443. uni.$uv.toast("暂无自提点,请联系商家");
  444. return;
  445. }
  446. const objs = shopPickUpAddressList.value[e.detail.value];
  447. pickUpAdress.value = objs.pointName;
  448. pickUpAdressDetail.value = objs.address;
  449. dataJson.value.selfPickupBo.selfPickupId = objs.id;
  450. };
  451. // 获取自提点
  452. const getPickUpList = () => {
  453. businessSelfPickupAddressList(dataJson.value.businessId).then((res) => {
  454. if (res && res.code == 200) {
  455. shopPickUpAddressList.value = res.data || [];
  456. }
  457. });
  458. };
  459. // 获取商家物流配置信息
  460. const getBusinessLogisticsConfigInfo = () => {
  461. businessLogisticsConfigInfo(dataJson.value.businessId).then((res) => {
  462. if (res && res.code == 200) {
  463. console.log(res.data);
  464. isAbleSelectSelfPickupBo.value = res.data || {};
  465. if (isAbleSelectSelfPickupBo.value.ablePickup) {
  466. dataJson.value.selfPickupBo = {};
  467. getPickUpList();
  468. }
  469. }
  470. });
  471. };
  472. onLoad((options) => {
  473. loading.value = true;
  474. let dataJson1 = uni.getStorageSync("dataJson");
  475. console.log(dataJson1);
  476. if (dataJson1) {
  477. dataJson.value = dataJson1;
  478. }
  479. if (options.type) {
  480. type.value = options.type;
  481. }
  482. if (dataJson.value.businessId) getBusinessLogisticsConfigInfo();
  483. });
  484. onShow(() => {
  485. let orderreminder = uni.getStorageSync("orderreminder");
  486. if (orderreminder) {
  487. uni.$uv.toast("已生成待付款订单");
  488. uni.removeStorageSync("orderreminder");
  489. }
  490. let dataJson = uni.getStorageSync("dataJson");
  491. postData(dataJson);
  492. });
  493. </script>
  494. <style lang="scss" scoped>
  495. :deep(.input-placeholder) {
  496. font-size: 26rpx;
  497. }
  498. </style>
  499. <style lang="scss">
  500. page {
  501. background-color: #f5f5f5;
  502. box-sizing: border-box;
  503. }
  504. .c-da4f4f {
  505. color: #da4f4f;
  506. }
  507. .border {
  508. border-bottom: 3rpx solid #e7e7e7;
  509. }
  510. .textarea {
  511. width: 100%;
  512. height: 80rpx;
  513. background-color: #fafafa;
  514. padding: 22rpx 20rpx;
  515. box-sizing: border-box;
  516. border: 1px solid #ededed;
  517. border-radius: 20rpx;
  518. }
  519. .topStatus {
  520. height: 100rpx;
  521. background-color: #fdeee9;
  522. position: fixed;
  523. z-index: 9;
  524. width: 100%;
  525. box-sizing: border-box;
  526. .item-text {
  527. line-height: 100rpx;
  528. position: relative;
  529. z-index: 2;
  530. text-align: center;
  531. border-radius: 30rpx 30rpx 0 0;
  532. color: #010101;
  533. }
  534. .top-item {
  535. position: relative;
  536. flex: 1;
  537. box-sizing: border-box;
  538. height: 100rpx;
  539. .item-icon {
  540. width: 420rpx;
  541. height: 114rpx;
  542. position: absolute;
  543. top: -4rpx;
  544. left: 0;
  545. z-index: 1;
  546. }
  547. }
  548. .top-item.active-right,
  549. .top-item.active-left {
  550. font-weight: bold;
  551. width: 420rpx;
  552. flex-shrink: 0;
  553. }
  554. .active-left {
  555. padding-left: 64rpx;
  556. }
  557. .active-right {
  558. padding-right: 64rpx;
  559. }
  560. }
  561. .courierAddress {
  562. background-color: #fff;
  563. padding: 36rpx 30rpx;
  564. }
  565. .goHome,
  566. .listText {
  567. background-color: #fff;
  568. .title {
  569. display: flex;
  570. justify-content: space-between;
  571. align-items: center;
  572. .num {
  573. color: #808080;
  574. font-size: 26rpx;
  575. }
  576. }
  577. .freight {
  578. padding: 30rpx;
  579. .u-border-one-one {
  580. padding: 30rpx 0;
  581. }
  582. }
  583. .consumption_value-icon {
  584. font-size: 60rpx;
  585. color: #ff9651;
  586. }
  587. .consumption_value span {
  588. color: #ff6600;
  589. }
  590. }
  591. .btnview {
  592. width: 300rpx;
  593. margin: 30rpx auto 0;
  594. }
  595. .shopList {
  596. background-color: #fff;
  597. padding: 30rpx 30rpx 0;
  598. &:deep(.textWidth) {
  599. $font-size: 28rpx; // scss 变量
  600. height: $font-size * 1.5 * 2; // 计算出两行文本的高度
  601. line-height: 1.5;
  602. font-size: $font-size;
  603. }
  604. }
  605. .changeTabtwo {
  606. padding: 130rpx 0 160rpx 0;
  607. }
  608. .rightText {
  609. justify-content: space-between;
  610. // height: 200rpx;
  611. }
  612. .bottext,
  613. .botPrice {
  614. width: 100%;
  615. box-sizing: border-box;
  616. }
  617. .bottext {
  618. margin-top: 36rpx;
  619. }
  620. .rightAddRes {
  621. width: 172rpx;
  622. height: 50rpx;
  623. border-radius: 8rpx;
  624. border: 1px solid #e5e5e5;
  625. .centertext {
  626. text-align: center;
  627. }
  628. .btnTag {
  629. width: 50rpx;
  630. height: 50rpx;
  631. line-height: 50rpx;
  632. text-align: center;
  633. background-color: #dedede;
  634. font-size: 46rpx;
  635. color: #888;
  636. }
  637. }
  638. .btnWidth {
  639. width: 340rpx;
  640. background: #e93534;
  641. }
  642. .botfixed {
  643. position: fixed;
  644. background-color: #fff;
  645. width: 100%;
  646. height: 138rpx;
  647. bottom: 0;
  648. left: 0;
  649. z-index: 9;
  650. padding: 0 30rpx;
  651. box-sizing: border-box;
  652. }
  653. .z-flex-pick-up {
  654. align-items: start;
  655. .z-pick-up {
  656. flex-shrink: 0;
  657. }
  658. .address-box {
  659. display: -webkit-box;
  660. -webkit-box-orient: vertical;
  661. -webkit-line-clamp: 3;
  662. overflow: hidden;
  663. text-overflow: ellipsis;
  664. }
  665. }
  666. </style>