confirm-order.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <template>
  2. <view class="confirm-order-box iPhone-bottom flex-common-css box-border-box">
  3. <view class="bg-box"></view>
  4. <Nav title='提交订单' bgckgroundBox='transparent'></Nav>
  5. <view class="scroll-view-css box-border-box p-24">
  6. <view class="box-card box-border-box mb-20 bgc-f">
  7. <view class="box-input box-border-box p-b-20 mb-20" @click="selectFun(2)">
  8. <view class="flex-justify-space mb-12">
  9. <view v-if="addressData.id" class="fs-36 fw-600 text-overflow-ellipsis w570">
  10. {{addressData.address||''}}{{addressData.school_name||''}}{{addressData.dorm_name||''}}
  11. </view>
  12. <view v-else class="fs-36 fw-600 text-overflow-ellipsis w570">请选择地址</view>
  13. <image class="right-icon" src="@/static/img/toRight.png" mode=""></image>
  14. </view>
  15. <view class="" v-if="addressData.id">
  16. <span class="mr-24 fs-28 fc-9">{{addressData.consignee||''}}</span><span
  17. class="fs-28 fc-9">{{addressData.phone||''}}</span>
  18. </view>
  19. </view>
  20. <view class="p-b-20">
  21. <view class=" flex-justify-space box-border-box p-b-20">
  22. <view class="fs-28 fw-600">取件码</view>
  23. <!-- <view class="align-items-center" @click="selectFun(4)">
  24. <view class="fs-24 fw-400 fc-9">修改</view>
  25. <image class="right-icon" src="@/static/img/toRight.png" mode=""></image>
  26. </view> -->
  27. </view>
  28. <view class="code-box box-border-box flex-wrap-wrap">
  29. <view class="code-item fs-28 text-overflow-ellipsis-one"
  30. v-for="(item,i) in fromData.pickup_code" :key="i">{{item}}</view>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="box-card box-border-box bgc-f mb-20">
  35. <view class="mb-32 b-b-F9F9F9">
  36. <view class="flex-justify-space mb-28" v-for="(item,i) in cardData.goods_list" :key="i">
  37. <image class="goods-img" :src="item.serve_image" mode="aspectFill"></image>
  38. <view class="w376">
  39. <view class="fs-28 fw-400 mb-4">
  40. {{item.serve_name}}
  41. </view>
  42. <view class="fs-24 fc-9 mb-4">{{item.serve_desc}}</view>
  43. <view class="fs-24 fc-9">x{{item.number}}</view>
  44. </view>
  45. <view class="fs-32 fw-600">¥{{Number(item.number * Number(item.price)).toFixed(2)}}</view>
  46. </view>
  47. </view>
  48. <view class="flex-justify-space mb-24 p-b-20 b-b-F9F9F9" @click="selectFun(1)">
  49. <view class="fs-28 fw-400">优惠券</view>
  50. <view class="align-items-center">
  51. <view class="" v-if="!fromData.coupon_id && (receiveLength>0 || CouponLength>0)">
  52. <view class="fs-28 fc-ED301D" v-if="CouponLength>0">
  53. 有{{CouponLength}}张优惠券可用
  54. </view>
  55. <view class="fs-28 fc-ED301D" v-else>
  56. 可领{{receiveLength}}张优惠券
  57. </view>
  58. </view>
  59. <view v-else :class="fromData.coupon_id?'fc-FB3D03 fw-600 fs-32':'fw-400 fs-28'">
  60. {{fromData.coupon_id?'-¥'+ quanMoney:'暂无可用优惠券'}}
  61. </view>
  62. <image class="right-icon" src="@/static/img/toRight.png" mode=""></image>
  63. </view>
  64. </view>
  65. <view class="text-align-right p-b-20">
  66. <span class="fc-9 fs-28">共{{cardData.total_num||0}}件,</span>
  67. <span class="fw-400 fc-0 fs-28">合计¥</span>
  68. <span
  69. class="fw-600 fc-0 fs-44">{{((cardData.total_price - quanMoney) < 0?'0':(cardData.total_price - quanMoney)||0).toFixed(2)}}</span>
  70. </view>
  71. </view>
  72. <view class="box-card box-border-box bgc-f mb-20">
  73. <view class="flex-justify-space b-b-F9F9F9 mb-24">
  74. <view class="fs-28 fw-600 w158 mr-12">备注</view>
  75. <input v-model="fromData.note" class="flex-1 text-align-right fs-28" type="text"
  76. placeholder="请填写你的备注">
  77. </view>
  78. <!-- <view class="p-b-20"></view> -->
  79. </view>
  80. <!-- <view class="box-card box-border-box mb-20 bgc-f flex-justify-space">
  81. <view class="fs-28 fw-600 w158">支付方式</view>
  82. <view class="wx-box display-flex">
  83. <image src="@/static/img/common/wx-zf.png" mode="scaleToFill"></image>
  84. <view class="fs-28 fw-400 ml-10">微信支付</view>
  85. </view>
  86. </view> -->
  87. </view>
  88. <view class="bottom-box box-border-box p-24">
  89. <view class="flex-justify-space">
  90. <view class="align-items-flex-end box-1">
  91. <span class="fs-28 fc-f fw-600">¥</span>
  92. <span
  93. class="fs-44 fc-f fw-600">{{((cardData.total_price - quanMoney) < 0?'0':(cardData.total_price - quanMoney)||0).toFixed(2)}}</span>
  94. </view>
  95. <view class="text-align-center box-2 fs-32 fc-f fw-600" @click="toSave()">立即支付</view>
  96. </view>
  97. </view>
  98. <Coupon ref="coupon" @giveCouPon='giveCouPon' @gbCouopnPop='getExpressCoupon'></Coupon>
  99. <SelectAddress ref="selectAddress" @giveAddress='giveAddress'></SelectAddress>
  100. <Time ref="selectTime" @giveTime='giveTime'></Time>
  101. <EditCode ref='editCode' v-model="fromData.pickup_code"></EditCode>
  102. </view>
  103. </template>
  104. <script>
  105. import {
  106. getExpressCoupon,
  107. getExpressCreate,
  108. getExpressPay
  109. } from '@/api/express.js';
  110. import {
  111. getAddressDefault
  112. } from '@/api/member.js'
  113. import {
  114. getShopIngList
  115. } from '@/api/shopping.js'
  116. import tools from "@/service/tools";
  117. import Coupon from './confirm-mod/dryClean-coupon.vue';
  118. import SelectAddress from './confirm-mod/select-address.vue';
  119. import Time from './confirm-mod/time.vue';
  120. import EditCode from './confirm-mod/edit-code.vue';
  121. export default {
  122. components: {
  123. Coupon,
  124. SelectAddress,
  125. Time,
  126. EditCode
  127. },
  128. data() {
  129. return {
  130. type: 2, //1外卖 2代取 3干洗
  131. fromData: {
  132. school_id: '',
  133. site_id: '',
  134. address_id: '',
  135. coupon_id: '',
  136. note: '',
  137. // is_default:0,
  138. pickup_code: [],
  139. },
  140. addressData: {},
  141. cardData: {
  142. goods_list: [],
  143. },
  144. quanMoney: "",
  145. isAJAX: false,
  146. CouponLength: 0, // 可用优惠券数量
  147. receiveLength: 0 // 可领优惠券数量
  148. }
  149. },
  150. onLoad(e) {
  151. this.type = Number(e.type)
  152. if (this.type == 2) {
  153. this.fromData.pickup_code = e.pickup_code.split(',').map(String)
  154. this.getCard();
  155. }
  156. this.getAddressDefault();
  157. },
  158. onShow() {
  159. let isConfirmAddressFlag = uni.getStorageSync('isConfirmAddressFlag');
  160. if (isConfirmAddressFlag.flag) {
  161. this.selectFun(2, isConfirmAddressFlag);
  162. }
  163. this.getExpressCoupon()
  164. },
  165. onUnload() {
  166. uni.removeStorageSync('isConfirmAddressFlag')
  167. },
  168. methods: {
  169. getExpressCoupon() {
  170. let operate_id = uni.getStorageSync('operate_id');
  171. let school_id = uni.getStorageSync('school_id');
  172. getExpressCoupon({
  173. operate_id: operate_id,
  174. school_id: school_id
  175. }).then((res) => {
  176. if (res.code === 1) {
  177. if (res.data.coupon.length > 0) {
  178. this.CouponLength = res.data.coupon.length
  179. } else {
  180. this.CouponLength = 0
  181. }
  182. if (res.data.receive.length > 0) {
  183. this.receiveLength = res.data.receive.length
  184. } else {
  185. this.receiveLength = 0
  186. }
  187. }
  188. })
  189. },
  190. // 获取购物车
  191. getCard() {
  192. let school_id = uni.getStorageSync('school_id');
  193. getShopIngList({
  194. type: this.type,
  195. school_id: school_id
  196. }).then((res) => {
  197. if (res.code === 1) {
  198. this.cardData = res.data;
  199. }
  200. })
  201. },
  202. // 获取默认地址
  203. getAddressDefault() {
  204. getAddressDefault().then((res) => {
  205. if (res.code === 1) {
  206. this.addressData = res.data
  207. if (this.addressData.id) {
  208. this.fromData.address_id = this.addressData.id;
  209. }
  210. }
  211. })
  212. },
  213. selectFun(type, addressData) {
  214. if (type === 1) {
  215. // 选择优惠券
  216. this.$refs.coupon.getList(this.type, this.fromData.coupon_id);
  217. } else if (type === 2) {
  218. // 选择地址
  219. if (this.addressData.id) {
  220. this.$refs.selectAddress.id = this.addressData.id;
  221. }
  222. if (addressData && addressData.is_default == 1) {
  223. this.$refs.selectAddress.id = addressData.id;
  224. this.$refs.selectAddress.getList(addressData.id);
  225. } else {
  226. this.$refs.selectAddress.getList();
  227. }
  228. } else if (type === 3) {
  229. // 选择时间
  230. this.$refs.selectTime.getList();
  231. } else if (type === 4) {
  232. // 编辑code
  233. this.$refs.editCode.getList();
  234. }
  235. },
  236. giveCouPon(e) {
  237. if (e.id) {
  238. this.quanMoney = Number(e.money);
  239. this.fromData.coupon_id = e.id;
  240. } else {
  241. this.quanMoney = ''
  242. this.fromData.coupon_id = 0
  243. }
  244. },
  245. giveAddress(e) {
  246. this.addressData = e;
  247. this.fromData.address_id = this.addressData.id;
  248. },
  249. giveTime(e) {
  250. console.log(e);
  251. },
  252. toSave() {
  253. if (!this.fromData.address_id) {
  254. return tools.error('请先选择地址')
  255. }
  256. let flag = false;
  257. flag = this.fromData.pickup_code.every(item => item)
  258. if (!flag) {
  259. return tools.error('请先输入取件码')
  260. }
  261. let codeRule = /^[A-Za-z0-9-]+$/
  262. let flagRule = this.fromData.pickup_code.every((item) => {
  263. return codeRule.test(item)
  264. });
  265. if (!flagRule) {
  266. return tools.error('请输入正确的取件码')
  267. }
  268. if (this.isAJAX) {
  269. return
  270. }
  271. this.isAJAX = true;
  272. this.fromData.school_id = uni.getStorageSync('school_id');
  273. this.fromData.site_id = uni.getStorageSync('site_id');
  274. getExpressCreate(this.fromData).then((res) => {
  275. if (res.code === 1) {
  276. uni.redirectTo({
  277. url: `/pages-takeout/pick-up-pay?orderId=${res.data.order_id}`
  278. });
  279. // getExpressPay({
  280. // order_id: res.data.order_id
  281. // }).then((ret) => {
  282. // if (ret.code === 1) {
  283. // uni.requestPayment({
  284. // provider: "wxpay", //支付类型-固定值
  285. // timeStamp: ret.data.wx_pay.timeStamp + "", // 时间戳(单位:秒)
  286. // nonceStr: ret.data.wx_pay.nonceStr, // 随机字符串
  287. // package: ret.data.wx_pay.package, // 固定值
  288. // signType: ret.data.wx_pay.signType, //固定值
  289. // paySign: ret.data.wx_pay.paySign, //签名
  290. // success: (ren) => {
  291. // uni.removeStorageSync('isConfirmAddressFlag')
  292. // tools.success("支付成功");
  293. // this.isAJAX = false;
  294. // setTimeout(() => {
  295. // uni.switchTab({
  296. // url: "/pages/order/index"
  297. // })
  298. // uni.setStorageSync('orderPayType', 2)
  299. // uni.setStorageSync('saveData', false)
  300. // }, 1000)
  301. // },
  302. // fail: (err) => {
  303. // uni.removeStorageSync('isConfirmAddressFlag')
  304. // this.isAJAX = false;
  305. // tools.error("支付失败");
  306. // setTimeout(() => {
  307. // uni.switchTab({
  308. // url: "/pages/order/index"
  309. // })
  310. // uni.setStorageSync('orderPayType', 2)
  311. // uni.setStorageSync('saveData', false)
  312. // }, 1000)
  313. // },
  314. // });
  315. // } else {
  316. // uni.removeStorageSync('isConfirmAddressFlag')
  317. // this.isAJAX = false;
  318. // tools.error("支付失败");
  319. // setTimeout(() => {
  320. // uni.switchTab({
  321. // url: "/pages/order/index"
  322. // })
  323. // uni.setStorageSync('orderPayType', 2)
  324. // uni.setStorageSync('saveData', false)
  325. // }, 1000)
  326. // }
  327. // })
  328. } else {
  329. this.isAJAX = false;
  330. tools.error(res.msg);
  331. }
  332. })
  333. },
  334. },
  335. }
  336. </script>
  337. <style scoped lang="scss">
  338. .code-box {
  339. min-height: 100rpx;
  340. background-color: #F3F4F6;
  341. border-radius: 12rpx;
  342. padding: 24rpx 24rpx 0 24rpx;
  343. .code-item {
  344. width: 156rpx;
  345. margin-right: 52rpx;
  346. margin-bottom: 16rpx;
  347. }
  348. .code-item:nth-child(3n) {
  349. margin-right: 0 !important;
  350. }
  351. }
  352. .tz-an-f {
  353. position: relative;
  354. .tz-an {
  355. position: absolute;
  356. right: 16rpx;
  357. top: 0;
  358. }
  359. }
  360. .r-right {
  361. margin-top: 24rpx;
  362. width: 88rpx;
  363. height: 52rpx;
  364. border-radius: 200rpx;
  365. position: relative;
  366. .r-y {
  367. width: 44rpx;
  368. height: 44rpx;
  369. background: #FFFFFF;
  370. border-radius: 200rpx;
  371. position: absolute;
  372. top: 4rpx;
  373. }
  374. }
  375. .s-r {
  376. background-color: #41ABF5;
  377. transition: all 1s;
  378. .r-y {
  379. right: 4rpx !important;
  380. transition: all 1s;
  381. }
  382. }
  383. .n-r {
  384. background-color: #ccc;
  385. transition: all 1s;
  386. .r-y {
  387. left: 4rpx !important;
  388. transition: all 1s;
  389. }
  390. }
  391. .goods-img {
  392. width: 108rpx;
  393. height: 108rpx;
  394. border-radius: 8rpx;
  395. margin-right: 16rpx;
  396. }
  397. .right-icon {
  398. width: 32rpx;
  399. height: 32rpx;
  400. }
  401. .w376 {
  402. width: 376rpx;
  403. }
  404. .w570 {
  405. width: 570rpx;
  406. }
  407. .sd-box {
  408. padding: 3rpx 16rpx;
  409. height: 40rpx;
  410. line-height: 40rpx;
  411. background: rgba(251, 61, 3, 0.1);
  412. border-radius: 8rpx 8rpx 8rpx 8rpx;
  413. }
  414. .confirm-order-box {
  415. position: relative;
  416. .bg-box {
  417. width: 100%;
  418. height: 448rpx;
  419. filter: blur(80rpx);
  420. background: linear-gradient(to right, rgba(176, 252, 250, 0.6), rgba(249, 246, 224, 0.87), rgba(249, 246, 224, 0.87));
  421. position: absolute;
  422. top: 0;
  423. left: 0;
  424. z-index: -1;
  425. }
  426. .bottom-box {
  427. background-color: #fff;
  428. .box-1 {
  429. flex: 1;
  430. height: 100rpx;
  431. background: #333;
  432. border-radius: 200rpx 0rpx 0rpx 200rpx;
  433. box-sizing: border-box;
  434. padding-left: 32rpx;
  435. padding-bottom: 20rpx;
  436. }
  437. .box-2 {
  438. width: 200rpx;
  439. height: 100rpx;
  440. line-height: 100rpx;
  441. background: #41ABF5;
  442. border-radius: 0rpx 200rpx 200rpx 0rpx;
  443. text-align: center;
  444. }
  445. }
  446. .box-card {
  447. width: 100%;
  448. min-height: 88rpx;
  449. border-radius: 20rpx;
  450. padding: 24rpx 24rpx 0 24rpx;
  451. }
  452. .wx-box {
  453. image {
  454. width: 40rpx;
  455. height: 40rpx;
  456. }
  457. }
  458. .box-input {
  459. border-bottom: 2rpx solid #F9F9F9;
  460. }
  461. }
  462. </style>