goods-order.vue 14 KB

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