confirm-order.vue 12 KB

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