goods-order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view class="flex-common-css iPhone-bottom box-border-box bgc-F5F4F9">
  3. <image class="order-bg" src="@/static/img/order-food/order-bg.png" mode=""></image>
  4. <newNav textName="提交订单" class="mb-20"></newNav>
  5. <view class="scroll-view-css plr-24 box-border-box z-3">
  6. <view class="way-box bgc-f b-rad-20 mb-20 p-24 box-border-box">
  7. <view class="fc-6 fw-400 fs-28 mb-24">
  8. 请选择就餐方式
  9. </view>
  10. <view class="align-items-center">
  11. <view class="pl-32 pr-24 box-border-box align-items-center flex-justify-space flex-1 mr-18 b-rad-16"
  12. :class="cartData.order_type === 1?'bgc-FFF3F3 b-FF3333':'b-b-d'" @click="wayTypeStyle(1)">
  13. <view class="fw-600 fs-32" :class="cartData.order_type === 1?'fc-FF3333':'fc-3'">
  14. 堂食
  15. </view>
  16. <image class="ts-img" src="/static/img/order-food/ts-img.png" mode="aspectFill"></image>
  17. </view>
  18. <view class="pl-32 pr-24 box-border-box align-items-center flex-justify-space flex-1 b-rad-16"
  19. :class="cartData.order_type === 2?'bgc-FFF3F3 b-FF3333':'b-b-d'" @click="wayTypeStyle(2)">
  20. <view class="fw-600 fs-32" :class="cartData.order_type === 2?'fc-FF3333':'fc-3'">
  21. 打包
  22. </view>
  23. <image class="ts-img" src="/static/img/order-food/db-img.png" mode="aspectFill"></image>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="align-items-center b-rad-16 bgc-f mb-20 p-20 box-border-box">
  28. <uni-icons type="notification" size="15" color="#FF8D28" class="mr-12"></uni-icons>
  29. <view class="fs-24 fc-FF8D28">
  30. 依据法律规定,18周岁以下未成年人限制购买酒类商品
  31. </view>
  32. </view>
  33. <view class="box-card bgc-f b-rad-16 p-24 box-border-box mb-16">
  34. <view class="align-items-center flex-justify-space pb-24 b-b-F9F9F9">
  35. <view class="fs-28 fc-6">
  36. 店内点单
  37. </view>
  38. <view class="align-items-center">
  39. <image class="zz-icon mr-4" src="@/static/img/order-food/zz-icon.png" mode=""></image>
  40. <view class="fs-28 fc-6">
  41. 桌号:{{cartData.table_number}}
  42. </view>
  43. </view>
  44. </view>
  45. <view class="mb-24 b-b-F9F9F9">
  46. <view class="flex-justify-space mb-28" v-for="(item,i) in cartData.shopping_cart.goods_list"
  47. :key="i">
  48. <image class="goods-img" :src="item.goods_image" mode="aspectFill"></image>
  49. <view class="w376">
  50. <view class="fs-28 fw-600 mb-2 text-overflow-ellipsis-one">
  51. {{item.goods_name}}
  52. </view>
  53. <view class="fs-24 fc-9 mb-2">{{item.goods_attr}}</view>
  54. <view class="fs-24 fc-9">x{{item.goods_number}}</view>
  55. </view>
  56. <view class="fs-32 fw-600 fc-3">¥{{item.price}}</view>
  57. </view>
  58. </view>
  59. <view class="flex-justify-space mb-30" v-if="cartData.order_type === 2">
  60. <view class="fs-28 fw-400">打包费</view>
  61. <view class="fs-32 fw-600 fc-3">¥{{cartData.shopping_cart.pack_price}}</view>
  62. </view>
  63. <view class="flex-justify-space mb-30" v-if="cartData.order_type === 1">
  64. <view class="fs-28 fw-400">就餐人数</view>
  65. <view class="align-items-center" @click="openPop">
  66. <view class="fs-32 fw-600 fc-3 mr-4">{{cartData.diner_number}}人</view>
  67. <image class="right-b" src="@/static/img/order-food/right-b.png" mode=""></image>
  68. </view>
  69. </view>
  70. <!-- <view class="flex-justify-space mb-30">
  71. <view class="fs-28 fw-400">餐位费</view>
  72. <view class="fs-32 fw-600 fc-3">¥4</view>
  73. </view> -->
  74. <!-- <view class="flex-justify-space mb-30">
  75. <view class="fs-28 fw-400">店铺优惠</view>
  76. <view class="fs-32 fw-600">¥{{cardData.pack_price}}</view>
  77. </view> -->
  78. <view class="align-items-center flex-justify-end pt-20 b-t-F9F9F9">
  79. <view class="fs-28 fc-0 fw-400 mr-4">
  80. 应付
  81. </view>
  82. <span class="fw-600 fc-0 fs-28">¥</span>
  83. <span
  84. class="fw-600 fc-0 fs-44">{{cartData.order_type === 1 ?cartData.shopping_cart.total_goods_money:cartData.shopping_cart.total_price}}</span>
  85. </view>
  86. </view>
  87. <view class="p-24 box-border-box bgc-f mb-20 b-rad-20 flex-justify-space">
  88. <view class="fs-28 fw-600">备注</view>
  89. <input v-model="fromData.note" class="flex-1 text-align-right fs-28" type="text" placeholder="请填写你的需求">
  90. </view>
  91. <view class="p-24 box-border-box bgc-f mb-20 b-rad-20 flex-justify-space">
  92. <view class="fs-28 fw-600">备注</view>
  93. <view class="align-items-center">
  94. <image class="wx-zf mr-6" src="@/static/img/common/wx-zf.png" mode=""></image>
  95. <view class="fs-28 fc-3">
  96. 微信支付
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. <view class="plr-24 box-border-box">
  102. <view class="bottom-box flex-justify-space align-items-center pl-24 box-border-box pr-8 b-rad-200 bgc-f">
  103. <view class="align-items-baseline">
  104. <view class="fs-28 fc-3 fw-600">¥</view>
  105. <view class="fs-44 fc-3 fw-600">
  106. {{cartData.order_type === 1 ?cartData.shopping_cart.total_goods_money:cartData.shopping_cart.total_price}}
  107. </view>
  108. </view>
  109. <view class="box-2 text-align-center fc-f fs-32 fw-600 b-rad-200" @click="toSave()">立即支付</view>
  110. </view>
  111. </view>
  112. <uni-popup ref="popup" type="bottom" background-color="transparent" borderRadius='10px 10px 0 0'>
  113. <view class="b-rad-20-20-0-0 bgc-f popup_diner_number p-32 box-border-box">
  114. <view class="fc-3 fw-600 fs-36 mb-32">
  115. 请选择用餐人数
  116. </view>
  117. <view class="align-items-center flex-justify-space flex-wrap-wrap mb-50">
  118. <view @click="dinerNumber(index+1)"
  119. class="w-25-100 b-rad-12 text-align-center flex-justify-center fs-36 fc-3 fw-500 mb-20"
  120. :class="cartData.diner_number === index+1 && !customizeType?'b-FF3333 bgc-FFF3F3':'b-FFF3F3 bgc-F2F2F2'"
  121. v-for="(item,index) in 10">
  122. {{index + 1}}
  123. </view>
  124. <view class="bgc-F2F2F2 b-rad-12 customize-box mb-20"
  125. :class="customizeType?'b-FF3333 bgc-FFF3F3':'b-FFF3F3 bgc-F2F2F2'">
  126. <input class="customize-input fs-32" type="number" v-model="customize_num" @focus='focusInput'
  127. @input='input' placeholder="请输入数量" placeholder-class="fc-9 fs-32" />
  128. </view>
  129. </view>
  130. <view class="pop-but fs-32 fc-f fw-500 text-align-center b-rad-200" @click="okPop">
  131. 确认选择
  132. </view>
  133. </view>
  134. </uni-popup>
  135. </view>
  136. </template>
  137. <script>
  138. import {
  139. getShopIngList
  140. } from '@/api/shopping.js'
  141. import {
  142. getDeliveryMoney
  143. } from '@/api/common.js'
  144. import {
  145. orderCreateVtwo,
  146. orderCreate,
  147. orderPay
  148. } from '@/api/order.js'
  149. import cartStore from '@/utils/cartStore.js';
  150. import tools from "@/service/tools";
  151. export default {
  152. components: {},
  153. data() {
  154. return {
  155. customize_num: '',
  156. customizeType: false,
  157. shop_id: '',
  158. wayType: 1,
  159. fromData: {
  160. school_id: '',
  161. shop_id: '',
  162. // site_id:'',
  163. type: '',
  164. time: '',
  165. address_id: '',
  166. coupon_id: '',
  167. note: '',
  168. },
  169. addressData: {},
  170. deliverText: '',
  171. delivery_money: '',
  172. quanMoney: "",
  173. total_price: '',
  174. isAJAX: false,
  175. cartData: {
  176. shopping_cart: {},
  177. order_type: 1, //1堂食 2打包
  178. table_number: 1,
  179. diner_number: 1,
  180. note: ''
  181. },
  182. CouponLength: 0, // 可用优惠券数量
  183. receiveLength: 0 // 可领优惠券数量
  184. }
  185. },
  186. onLoad(e) {
  187. this.cartData.table_number = uni.getStorageSync('table_number')
  188. this.getCartData()
  189. },
  190. onShow() {},
  191. onUnload() {},
  192. methods: {
  193. okPop() {
  194. if (this.cartData.diner_number === 0) {
  195. tools.error("选择就餐人数")
  196. return
  197. }
  198. this.$refs.popup.close()
  199. // if(this.customizeType) {
  200. // this.cartData.diner_number = this.customize_diner_number
  201. // }
  202. },
  203. input(e) {
  204. this.cartData.diner_number = e.detail.value
  205. },
  206. focusInput() {
  207. this.customizeType = true
  208. this.cartData.diner_number = 0
  209. },
  210. dinerNumber(num) {
  211. if (this.cartData.diner_number === num) {
  212. return
  213. } else {
  214. this.cartData.diner_number = num
  215. }
  216. this.customizeType = false
  217. this.customize_num = ''
  218. },
  219. getCartData() {
  220. cartStore.setShopId();
  221. const shopCart = cartStore.getShopCart();
  222. this.cartData.shopping_cart = shopCart
  223. console.log(this.cartData, '11111111');
  224. },
  225. orderCreateVtwo() {
  226. orderCreateVtwo(shopCart).then((res) => {
  227. if (res.code === 1) {
  228. console.log(res, '11111');
  229. }
  230. })
  231. },
  232. openPop() {
  233. if (this.cartData.diner_number > 10) {
  234. this.customize_num = this.cartData.diner_number
  235. }
  236. this.$refs.popup.open()
  237. },
  238. wayTypeStyle(type) {
  239. if (type === this.cartData.order_type) {
  240. return
  241. } else {
  242. this.cartData.order_type = type
  243. }
  244. },
  245. getDeliveryMoney(shop_id) {
  246. // 获取外卖配送费
  247. this.fromData.school_id = uni.getStorageSync('school_id');
  248. getDeliveryMoney({
  249. shop_id: shop_id,
  250. school_id: this.fromData.school_id
  251. }).then((res) => {
  252. if (res.code == 1) {
  253. this.delivery_money = res.data.delivery_money
  254. this.total_price = (Number(this.total_price) + Number(this.delivery_money)).toFixed(2)
  255. }
  256. })
  257. },
  258. giveCouPon(e) {
  259. if (e.id) {
  260. this.quanMoney = Number(e.money);
  261. this.fromData.coupon_id = e.id;
  262. } else {
  263. this.quanMoney = ''
  264. this.fromData.coupon_id = 0
  265. }
  266. },
  267. toSave() {
  268. console.log(this.cartData, "111111");
  269. if (this.isAJAX) {
  270. return
  271. }
  272. this.isAJAX = true;
  273. orderCreateVtwo(this.cartData).then((res) => {
  274. if (res.code === 1) {
  275. orderPay({
  276. order_id: res.data.order_id
  277. }).then((ret) => {
  278. if (ret.code === 1) {
  279. uni.requestPayment({
  280. provider: "wxpay", //支付类型-固定值
  281. timeStamp: ret.data.wx_pay.timeStamp + "", // 时间戳(单位:秒)
  282. nonceStr: ret.data.wx_pay.nonceStr, // 随机字符串
  283. package: ret.data.wx_pay.package, // 固定值
  284. signType: ret.data.wx_pay.signType, //固定值
  285. paySign: ret.data.wx_pay.paySign, //签名
  286. success: (ren) => {
  287. tools.success("支付成功");
  288. this.isAJAX = false;
  289. setTimeout(() => {
  290. uni.redirectTo({
  291. url: `/pages-order/takeout-info?orderId=` + res.data.order_id
  292. })
  293. cartStore.clearCurrentShopCart();
  294. }, 1000)
  295. },
  296. fail: (err) => {
  297. this.isAJAX = false;
  298. tools.error("支付失败");
  299. setTimeout(() => {
  300. uni.redirectTo({
  301. url: `/pages/order/index`
  302. })
  303. cartStore.clearCurrentShopCart();
  304. }, 1000)
  305. },
  306. });
  307. } else {
  308. this.isAJAX = false;
  309. tools.error("支付失败");
  310. setTimeout(() => {
  311. uni.redirectTo({
  312. url: `/pages/order/index`
  313. })
  314. cartStore.clearCurrentShopCart();
  315. }, 1000)
  316. }
  317. })
  318. } else {
  319. this.isAJAX = false;
  320. tools.error(res.msg);
  321. }
  322. })
  323. },
  324. setShopIngDel() {
  325. // 清除购物车
  326. cartStore.clearCurrentShopCart();
  327. }
  328. },
  329. }
  330. </script>
  331. <style scoped lang="scss">
  332. .pop-but {
  333. width: 100%;
  334. height: 96rpx;
  335. line-height: 96rpx;
  336. background: linear-gradient(270deg, #FF3333 0%, #FE6122 100%);
  337. }
  338. .customize-input {
  339. width: 100%;
  340. height: 100%;
  341. text-align: center;
  342. }
  343. .customize-box {
  344. width: 48%;
  345. height: 92rpx;
  346. }
  347. .w-25-100 {
  348. width: 22%;
  349. height: 92rpx;
  350. line-height: 92rpx;
  351. }
  352. .popup_diner_number {
  353. width: 100%;
  354. height: 42vh;
  355. position: fixed;
  356. left: 0;
  357. bottom: 0;
  358. }
  359. .wx-zf {
  360. width: 40rpx;
  361. height: 40rpx;
  362. }
  363. .zz-icon {
  364. width: 32rpx;
  365. height: 32rpx;
  366. }
  367. .right-b {
  368. width: 32rpx;
  369. height: 32rpx;
  370. }
  371. .ts-img {
  372. width: 128rpx;
  373. height: 128rpx;
  374. }
  375. .way-box {
  376. box-shadow: 0rpx 8rpx 56rpx 0rpx rgba(154, 152, 152, 0.34);
  377. }
  378. .z-3 {
  379. position: relative;
  380. z-index: 3;
  381. }
  382. .order-bg {
  383. width: 100%;
  384. height: 15vh;
  385. position: fixed;
  386. left: 0;
  387. top: 0;
  388. }
  389. .goods-img {
  390. width: 108rpx;
  391. height: 108rpx;
  392. border-radius: 8rpx;
  393. margin-right: 16rpx;
  394. }
  395. .right-icon {
  396. width: 32rpx;
  397. height: 32rpx;
  398. }
  399. .w376 {
  400. width: 376rpx;
  401. }
  402. .w570 {
  403. width: 570rpx;
  404. }
  405. .sd-box {
  406. padding: 3rpx 16rpx;
  407. height: 40rpx;
  408. line-height: 40rpx;
  409. background: rgba(251, 61, 3, 0.1);
  410. border-radius: 8rpx 8rpx 8rpx 8rpx;
  411. }
  412. .box-2 {
  413. width: 200rpx;
  414. height: 80rpx;
  415. line-height: 80rpx;
  416. background: linear-gradient(270deg, #FF3333 0%, #FE6122 100%);
  417. }
  418. .bottom-box {
  419. width: 100%;
  420. height: 96rpx;
  421. }
  422. </style>