confirm-order.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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) {
  149. this.selectFun(2);
  150. }
  151. },
  152. methods: {
  153. // 获取购物车
  154. getCard() {
  155. let school_id = uni.getStorageSync('school_id');
  156. getShopIngList({
  157. type: this.type,
  158. school_id: school_id
  159. }).then((res) => {
  160. if (res.code === 1) {
  161. this.cardData = res.data;
  162. }
  163. })
  164. },
  165. // 获取默认地址
  166. getAddressDefault() {
  167. getAddressDefault().then((res) => {
  168. if (res.code === 1) {
  169. this.addressData = res.data
  170. if (this.addressData.id) {
  171. this.fromData.address_id = this.addressData.id;
  172. }
  173. }
  174. })
  175. },
  176. selectFun(type) {
  177. if (type === 1) {
  178. // 选择优惠券
  179. this.$refs.coupon.getList(this.type, this.fromData.coupon_id);
  180. } else if (type === 2) {
  181. // 选择地址
  182. if (this.addressData.id) {
  183. this.$refs.selectAddress.id = this.addressData.id;
  184. }
  185. this.$refs.selectAddress.getList(this.addressData.id);
  186. } else if (type === 3) {
  187. // 选择时间
  188. this.$refs.selectTime.getList();
  189. } else if (type === 4) {
  190. // 编辑code
  191. this.$refs.editCode.getList();
  192. }
  193. },
  194. giveCouPon(e) {
  195. this.quanMoney = Number(e.money);
  196. this.fromData.coupon_id = e.id;
  197. },
  198. giveAddress(e) {
  199. this.addressData = e;
  200. this.fromData.address_id = this.addressData.id;
  201. },
  202. giveTime(e) {
  203. console.log(e);
  204. },
  205. toSave() {
  206. if (!this.fromData.address_id) {
  207. return tools.error('请先选择地址')
  208. }
  209. let flag = false;
  210. flag = this.fromData.pickup_code.every(item => item)
  211. if (!flag) {
  212. return tools.error('请先输入取件码')
  213. }
  214. let codeRule = /^[A-Za-z0-9-]+$/
  215. let flagRule = this.fromData.pickup_code.every((item) => {return codeRule.test(item)});
  216. if(!flagRule){
  217. return tools.error('请输入正确的取件码')
  218. }
  219. if (this.isAJAX) {
  220. return
  221. }
  222. this.isAJAX = true;
  223. this.fromData.school_id = uni.getStorageSync('school_id');
  224. this.fromData.site_id = uni.getStorageSync('site_id');
  225. getExpressCreate(this.fromData).then((res) => {
  226. if (res.code === 1) {
  227. getExpressPay({
  228. order_id: res.data.order_id
  229. }).then((ret) => {
  230. if (ret.code === 1) {
  231. uni.requestPayment({
  232. provider: "wxpay", //支付类型-固定值
  233. timeStamp: ret.data.wx_pay.timeStamp + "", // 时间戳(单位:秒)
  234. nonceStr: ret.data.wx_pay.nonceStr, // 随机字符串
  235. package: ret.data.wx_pay.package, // 固定值
  236. signType: ret.data.wx_pay.signType, //固定值
  237. paySign: ret.data.wx_pay.paySign, //签名
  238. success: (ren) => {
  239. tools.success("支付成功");
  240. this.isAJAX = false;
  241. setTimeout(() => {
  242. uni.switchTab({
  243. url: "/pages/order/index"
  244. })
  245. uni.setStorageSync('orderPayType', 2)
  246. uni.setStorageSync('saveData', false)
  247. }, 1000)
  248. },
  249. fail: (err) => {
  250. this.isAJAX = false;
  251. tools.error("支付失败");
  252. setTimeout(() => {
  253. uni.switchTab({
  254. url: "/pages/order/index"
  255. })
  256. uni.setStorageSync('orderPayType', 2)
  257. uni.setStorageSync('saveData', false)
  258. }, 1000)
  259. },
  260. });
  261. } else {
  262. this.isAJAX = false;
  263. tools.error("支付失败");
  264. setTimeout(() => {
  265. uni.switchTab({
  266. url: "/pages/order/index"
  267. })
  268. uni.setStorageSync('orderPayType', 2)
  269. uni.setStorageSync('saveData', false)
  270. }, 1000)
  271. }
  272. })
  273. } else {
  274. this.isAJAX = false;
  275. tools.error(res.msg);
  276. }
  277. })
  278. },
  279. },
  280. }
  281. </script>
  282. <style scoped lang="scss">
  283. .code-box {
  284. min-height: 100rpx;
  285. background-color: #F3F4F6;
  286. border-radius: 12rpx;
  287. padding: 24rpx 24rpx 0 24rpx;
  288. .code-item {
  289. width: 156rpx;
  290. margin-right: 52rpx;
  291. margin-bottom: 16rpx;
  292. }
  293. .code-item:nth-child(3n) {
  294. margin-right: 0 !important;
  295. }
  296. }
  297. .tz-an-f {
  298. position: relative;
  299. .tz-an {
  300. position: absolute;
  301. right: 16rpx;
  302. top: 0;
  303. }
  304. }
  305. .r-right {
  306. margin-top: 24rpx;
  307. width: 88rpx;
  308. height: 52rpx;
  309. border-radius: 200rpx;
  310. position: relative;
  311. .r-y {
  312. width: 44rpx;
  313. height: 44rpx;
  314. background: #FFFFFF;
  315. border-radius: 200rpx;
  316. position: absolute;
  317. top: 4rpx;
  318. }
  319. }
  320. .s-r {
  321. background-color: #41ABF5;
  322. transition: all 1s;
  323. .r-y {
  324. right: 4rpx !important;
  325. transition: all 1s;
  326. }
  327. }
  328. .n-r {
  329. background-color: #ccc;
  330. transition: all 1s;
  331. .r-y {
  332. left: 4rpx !important;
  333. transition: all 1s;
  334. }
  335. }
  336. .goods-img {
  337. width: 108rpx;
  338. height: 108rpx;
  339. border-radius: 8rpx;
  340. margin-right: 16rpx;
  341. }
  342. .right-icon {
  343. width: 32rpx;
  344. height: 32rpx;
  345. }
  346. .w376 {
  347. width: 376rpx;
  348. }
  349. .w570 {
  350. width: 570rpx;
  351. }
  352. .sd-box {
  353. padding: 3rpx 16rpx;
  354. height: 40rpx;
  355. line-height: 40rpx;
  356. background: rgba(251, 61, 3, 0.1);
  357. border-radius: 8rpx 8rpx 8rpx 8rpx;
  358. }
  359. .confirm-order-box {
  360. position: relative;
  361. .bg-box {
  362. width: 100%;
  363. height: 448rpx;
  364. filter: blur(80rpx);
  365. background: linear-gradient(to right, rgba(176, 252, 250, 0.6), rgba(249, 246, 224, 0.87), rgba(249, 246, 224, 0.87));
  366. position: absolute;
  367. top: 0;
  368. left: 0;
  369. z-index: -1;
  370. }
  371. .bottom-box {
  372. background-color: #fff;
  373. .box-1 {
  374. flex: 1;
  375. height: 100rpx;
  376. background: #333;
  377. border-radius: 200rpx 0rpx 0rpx 200rpx;
  378. box-sizing: border-box;
  379. padding-left: 32rpx;
  380. padding-bottom: 20rpx;
  381. }
  382. .box-2 {
  383. width: 200rpx;
  384. height: 100rpx;
  385. line-height: 100rpx;
  386. background: #41ABF5;
  387. border-radius: 0rpx 200rpx 200rpx 0rpx;
  388. text-align: center;
  389. }
  390. }
  391. .box-card {
  392. width: 100%;
  393. min-height: 88rpx;
  394. border-radius: 20rpx;
  395. padding: 24rpx 24rpx 0 24rpx;
  396. }
  397. .wx-box {
  398. image {
  399. width: 40rpx;
  400. height: 40rpx;
  401. }
  402. }
  403. .box-input {
  404. border-bottom: 2rpx solid #F9F9F9;
  405. }
  406. }
  407. </style>