confirm-order.vue 12 KB

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