index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. <template>
  2. <view class="orderFood">
  3. <view class="shop-info">
  4. <view class="shop-name">
  5. {{shopInfo.shopName}}
  6. </view>
  7. <view class="address">
  8. {{shopInfo.address}}
  9. </view>
  10. </view>
  11. <view class="content">
  12. <scroll-view :scroll-y="true" class="left" :scroll-into-view="scrollTo1" scroll-with-animation>
  13. <!-- <view class="left"> -->
  14. <view class="item" :class="[active == index?'active':'']" v-for="(item,index) in list" :id="'tab'+index" :key="index" @click="handleTab(index)">
  15. <image class="icon" :src="item.imageCnUrl" mode=""></image>
  16. <view class="name">
  17. {{item.topName}}
  18. </view>
  19. </view>
  20. <!-- </view> -->
  21. </scroll-view>
  22. <scroll-view :scroll-y="true" class="right" :scroll-into-view="scrollTo" scroll-with-animation @scroll="scroll">
  23. <!-- <view class="test">
  24. </view> -->
  25. <!-- <view class="right"> -->
  26. <view class="section" v-for="(item,index) in list" :key="index">
  27. <view class="section-name" :class="'title'+index" :id="'title'+index" >
  28. {{item.topName}}
  29. </view>
  30. <!-- <zs-title :title="item.topName" :value="index" :class="'title'+index" :id="'title'+index" @changeTag="chooseTag"></zs-title> -->
  31. <view class="item" v-for="(i,d) in item.menuVoList" :key="d">
  32. <image class="img" :src="i.imageUrl" mode=""></image>
  33. <view class="info">
  34. <view class="title">
  35. {{i.nameCn}}
  36. </view>
  37. <view class="btn-box">
  38. <view class="price-box">
  39. <view class="price">
  40. <view class="unit">
  41. </view>
  42. <view class="num">
  43. {{i.priceHead}}
  44. </view>
  45. </view>
  46. <view class="old-price">
  47. ¥{{i.price}}
  48. </view>
  49. </view>
  50. <image class="btn" @click="add(i,1)" src="../static/add-active.png" mode=""></image>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- </view> -->
  56. </scroll-view>
  57. </view>
  58. <view class="total-box">
  59. <view class="price-box" @click="handleCar">
  60. <view class="car-box">
  61. <image class="icon" src="../static/shop-car.png" mode=""></image>
  62. <view class="num" v-if="totalNum">
  63. {{totalNum}}
  64. </view>
  65. </view>
  66. <view class="price">
  67. <view class="unit">
  68. </view>
  69. <view class="num">
  70. {{total}}
  71. </view>
  72. </view>
  73. </view>
  74. <button class="buy" :class="[!carList.length?'disabled':'']" :disabled="!carList.length" type="default" @click="buy">{{carList.length?'选好了':'未选择商品'}}</button>
  75. </view>
  76. <u-popup :show="show" round="32rpx" mode="bottom" @close="show = false">
  77. <view class="popup-title-box" >
  78. <view class="title">
  79. 已选商品
  80. </view>
  81. <view class="clear" v-if="carList.length" @click="clear">
  82. 清空
  83. </view>
  84. </view>
  85. <u-empty
  86. mode="car"
  87. icon="http://cdn.uviewui.com/uview/empty/car.png"
  88. v-if="!carList.length"
  89. >
  90. </u-empty>
  91. <view class="car-content" v-else>
  92. <view class="item" v-for="(item,index) in carList" :key="index">
  93. <image class="img" :src="item.imageUrl" mode=""></image>
  94. <view class="info">
  95. <view class="title">
  96. {{item.nameCn}}
  97. </view>
  98. <view class="btn-box">
  99. <view class="price-box">
  100. <view class="price">
  101. <view class="unit">
  102. </view>
  103. <view class="num">
  104. {{item.selPrice}}
  105. </view>
  106. </view>
  107. <view class="old-price">
  108. ¥{{item.orgPrice}}
  109. </view>
  110. </view>
  111. <view class="count-box">
  112. <image class="btn" src="../static/remove.png" v-if="item.quantity" @click="add(item,-1)" mode=""></image>
  113. <view class="num">
  114. {{item.quantity}}
  115. </view>
  116. <image class="btn" src="../static/add-active.png" @click="add(item,1)" mode=""></image>
  117. </view>
  118. </view>
  119. </view>
  120. </view>
  121. </view>
  122. <view class="total-box total-box1">
  123. <view class="price-box" @click="handleCar">
  124. <view class="car-box">
  125. <image class="icon" src="../static/shop-car.png" mode=""></image>
  126. <view class="num" v-if="totalNum">
  127. {{totalNum}}
  128. </view>
  129. </view>
  130. <view class="price">
  131. <view class="unit">
  132. </view>
  133. <view class="num">
  134. {{total}}
  135. </view>
  136. </view>
  137. </view>
  138. <button class="buy" :class="[!carList.length?'disabled':'']" :disabled="!carList.length" type="default" @click="buy">{{carList.length?'选好了':'未选择商品'}}</button>
  139. </view>
  140. </u-popup>
  141. </view>
  142. </template>
  143. <script>
  144. import {shopDetail,menuList} from '@/api/orderFood.js'
  145. export default {
  146. data() {
  147. return {
  148. shopId:"63836999-5117-4980-8632-497f007808ef",
  149. show:false,
  150. active:0,
  151. list:[],
  152. shopInfo:{
  153. shopName:'',
  154. address:'',
  155. },
  156. carList:[],
  157. scrollTo:'title0',
  158. scrollTo1:'',
  159. topList:[],
  160. offsetTop:0,//顶部距离
  161. cateName:'',//跳转过来携带的分类名称
  162. };
  163. },
  164. computed: {
  165. totalNum(){
  166. let total = 0
  167. this.carList.map(item=>{
  168. total+=item.quantity
  169. })
  170. return total
  171. },
  172. total() {
  173. let total = 0
  174. this.carList.map(item=>{
  175. total+=(item.selPrice*10000*item.quantity)
  176. })
  177. return total/10000
  178. }
  179. },
  180. methods: {
  181. scroll(val){
  182. if(!this.offsetTop){
  183. this.offsetTop = val.currentTarget.offsetTop
  184. }
  185. this.topList.map((item,index)=>{
  186. if(index!=this.topList.length-1){
  187. if(val.detail.scrollTop>= (item-this.offsetTop)&&(val.detail.scrollTop <=this.topList[index+1]-this.offsetTop)){
  188. this.scrollTo1 = 'tab'+index
  189. this.active = index
  190. }
  191. }else{
  192. if(val.detail.scrollTop>= (item-this.offsetTop)){
  193. this.scrollTo1 = 'tab'+index
  194. this.active = index
  195. }
  196. }
  197. })
  198. },
  199. clear(){
  200. this.carList = []
  201. },
  202. add(item,num){
  203. if(this.carList.some(i=>item.productId == i.productId)){
  204. this.carList.forEach((row,index)=>{
  205. if(item.productId == row.productId){
  206. row.quantity+=num
  207. if(row.quantity == 0){
  208. this.carList.splice(index,1)
  209. }
  210. }
  211. })
  212. }else{
  213. let obj ={
  214. "imageUrl": item.imageUrl,
  215. "nameCn": item.nameCn,
  216. "productId": item.productId,
  217. "quantity": 1,
  218. "selPrice": item.priceHead,
  219. "orgPrice": item.basePrice,
  220. }
  221. this.carList.push(obj)
  222. }
  223. },
  224. handleCar(){
  225. this.show = true
  226. },
  227. handleTab(index){
  228. this.active = index
  229. this.scrollTo = 'title'+index
  230. },
  231. chooseTag(val){
  232. console.log('当前',val);
  233. },
  234. menuList(){
  235. menuList(this.shopId).then(res=>{
  236. if(res.state = 'Success'){
  237. this.list = res.content.data
  238. if(this.cateName){
  239. this.list.map((item,index)=>{
  240. if(item.topName == this.cateName){
  241. this.handleTab(index)
  242. }
  243. })
  244. }
  245. this.$nextTick(()=>{
  246. let query = uni.createSelectorQuery().in(this);
  247. query.selectAll('.section-name').boundingClientRect(data=>{
  248. console.log(data);
  249. this.topList =data.map(item=>{
  250. return item.top
  251. })
  252. }).exec();
  253. })
  254. }
  255. })
  256. },
  257. shopDetail(){
  258. shopDetail({"id": this.shopId,
  259. "lat": "",
  260. "lon": ""}).then(res=>{
  261. if(res.state = 'Success'){
  262. this.shopInfo.shopName = res.content.data.shopName
  263. this.shopInfo.address = res.content.data.address
  264. }
  265. })
  266. },
  267. buy() {
  268. let that = this
  269. if (uni.getStorageSync('token')) {
  270. if(JSON.parse(uni.getStorageSync('userInfo')).setMealCode != 0&&JSON.parse(uni.getStorageSync('userInfo')).setMealCode){
  271. let info ={
  272. shopName:this.shopInfo.shopName,
  273. address:this.shopInfo.address,
  274. shopId:this.shopId,
  275. products:this.carList,
  276. total:this.total,
  277. openTime:this.shopInfo.openTime,
  278. closeTime:this.shopInfo.closeTime,
  279. totalNum:this.totalNum
  280. }
  281. uni.navigateTo({
  282. url:`/orderFood/pay`,
  283. success: function(res) {
  284. // 通过eventChannel向被打开页面传送数据
  285. res.eventChannel.emit('pay', info)
  286. }
  287. })
  288. }else{
  289. uni.showModal({
  290. title:'此商品需要开通会员才能购买',
  291. cancelText:'下次再说',
  292. confirmText:'立即开通',
  293. success(res) {
  294. if(res.confirm){
  295. uni.navigateTo({
  296. url:'/my/memberCenter/index'
  297. })
  298. }
  299. }
  300. })
  301. }
  302. }else{
  303. uni.showModal({
  304. title:'请登录',
  305. confirmText:'去登录',
  306. success(res){
  307. console.log(res);
  308. if(res.confirm){
  309. uni.navigateTo({
  310. url:`/login/login/login?redirect=/orderFood/index&shopId=${that.shopId}`
  311. })
  312. }
  313. }
  314. })
  315. }
  316. }
  317. },
  318. onLoad(options) {
  319. this.cateName = options.cateName
  320. this.shopId = options.id || "63836999-5117-4980-8632-497f007808ef"
  321. // this.shopId = "63836999-5117-4980-8632-497f007808ef"
  322. this.shopDetail()
  323. this.menuList()
  324. },
  325. onReady () {
  326. // this.Observer = uni.createIntersectionObserver(this)
  327. // this.Observer.relativeTo('.test',{bottom: 0}).observe('.title0', (res) => {
  328. // console.log(12312);
  329. // // this.$emit('changeTag',this.value)
  330. // })
  331. }
  332. }
  333. </script>
  334. <style lang="scss" >
  335. .orderFood{
  336. .shop-info{
  337. width: 100%;
  338. height: 130rpx;
  339. padding: 20rpx 24rpx;
  340. box-sizing: border-box;
  341. border-bottom: 2rpx solid #F0F0F0;
  342. // position: fixed;
  343. // top: 0%;
  344. // left: 0%;
  345. // z-index: 9;
  346. background: #fff;
  347. .shop-name{
  348. font-weight: bold;
  349. font-size: 32rpx;
  350. color: #222222;
  351. }
  352. .address{
  353. font-size: 24rpx;
  354. color: #AAAAAA;
  355. margin-top: 16rpx;
  356. }
  357. }
  358. .content{
  359. height: calc(100vh - 130rpx);
  360. display: flex;
  361. overflow: auto;
  362. box-sizing: border-box;
  363. padding-bottom: calc(98rpx + env(safe-area-inset-bottom)) ;
  364. .left{
  365. flex: 0 0 176rpx;
  366. background: #F7F7F7;
  367. .item{
  368. text-align: center;
  369. padding: 16rpx 0;
  370. .icon{
  371. width: 76rpx;
  372. height: 76rpx;
  373. }
  374. .name{
  375. font-size: 24rpx;
  376. color: #AAAAAA;
  377. }
  378. }
  379. .item.active{
  380. background: #FFFFFF;
  381. .name{
  382. color: #222222;
  383. }
  384. }
  385. }
  386. .right{
  387. flex: 1;
  388. padding: 0 24rpx;
  389. overflow: auto;
  390. position: relative;
  391. .test{
  392. width: 100%;
  393. height: 60rpx;
  394. background: red;
  395. position: fixed;
  396. }
  397. .section{
  398. .section-name{
  399. font-weight: bold;
  400. font-size: 28rpx;
  401. color: #222222;
  402. padding-top: 30rpx;
  403. }
  404. .item{
  405. display: flex;
  406. margin-top: 28rpx;
  407. .img{
  408. width: 160rpx;
  409. height: 160rpx;
  410. border-radius: 8rpx 8rpx 8rpx 8rpx;
  411. }
  412. .info{
  413. flex: 1;
  414. margin-left: 26rpx;
  415. display: flex;
  416. flex-direction: column;
  417. justify-content: space-around;
  418. .title{
  419. font-weight: bold;
  420. font-size: 32rpx;
  421. color: #222222;
  422. }
  423. .btn-box{
  424. display: flex;
  425. justify-content: space-between;
  426. .price-box{
  427. display: flex;
  428. align-items: center;
  429. .price{
  430. display: flex;
  431. align-items: flex-end;
  432. color: #FF4D3A;
  433. .unit{
  434. font-size: 20rpx;
  435. }
  436. .num{
  437. font-weight: bold;
  438. font-size: 36rpx;
  439. }
  440. }
  441. .old-price{
  442. font-weight: normal;
  443. font-size: 24rpx;
  444. color: #AAAAAA;
  445. text-decoration: line-through;
  446. margin-left: 16rpx;
  447. }
  448. }
  449. .btn{
  450. width: 40rpx;
  451. height: 40rpx;
  452. }
  453. }
  454. }
  455. }
  456. }
  457. }
  458. }
  459. .total-box1{
  460. position: inherit!important;
  461. padding-bottom: 0!important;
  462. }
  463. .total-box{
  464. position: fixed;
  465. left: 0%;
  466. bottom: 0;
  467. width: 100%;
  468. padding: 10rpx 24rpx env(safe-area-inset-bottom);
  469. box-sizing: border-box;
  470. display: flex;
  471. align-items: center;
  472. justify-content: space-between;
  473. border-top: 1rpx solid #EEEEEE;
  474. .price-box{
  475. display: flex;
  476. .car-box{
  477. position: relative;
  478. display: flex;
  479. align-items: center;
  480. .icon{
  481. width: 48rpx;
  482. height: 48rpx;
  483. }
  484. .num{
  485. position: absolute;
  486. top: -18rpx;
  487. right: -18rpx;
  488. min-width: 36rpx;
  489. height: 36rpx;
  490. line-height: 36rpx;
  491. text-align: center;
  492. border-radius: 18rpx;
  493. background: #222222;
  494. font-weight: bold;
  495. font-size: 24rpx;
  496. color: #FFFFFF;
  497. margin-left: 20rpx;
  498. }
  499. }
  500. .price{
  501. display: flex;
  502. align-items: flex-end;
  503. color: #FF4D3A;
  504. .unit{
  505. font-size: 20rpx;
  506. }
  507. .num{
  508. font-weight: bold;
  509. font-size: 36rpx;
  510. }
  511. }
  512. }
  513. .buy{
  514. width: 200rpx;
  515. height: 80rpx;
  516. line-height: 80rpx;
  517. text-align: center;
  518. background: #EE4320;
  519. border-radius: 40rpx 40rpx 40rpx 40rpx;
  520. font-weight: bold;
  521. font-size: 28rpx;
  522. color: #FFFFFF;
  523. margin: 0;
  524. }
  525. .buy.disabled{
  526. background: #F6F6F6;
  527. color: #AAAAAA;
  528. }
  529. }
  530. .popup-title-box{
  531. display: flex;
  532. justify-content: space-between;
  533. padding: 24rpx;
  534. .title{
  535. font-weight: bold;
  536. font-size: 28rpx;
  537. color: #222222;
  538. }
  539. .clear{
  540. font-size: 28rpx;
  541. color: #AAAAAA;
  542. }
  543. }
  544. .u-empty{
  545. padding: 30rpx 0;
  546. }
  547. .car-content{
  548. padding-bottom: 30rpx;
  549. max-height: 700rpx;
  550. overflow: auto;
  551. .item{
  552. display: flex;
  553. margin-top: 28rpx;
  554. padding: 0 24rpx;
  555. .img{
  556. width: 160rpx;
  557. height: 160rpx;
  558. border-radius: 8rpx 8rpx 8rpx 8rpx;
  559. }
  560. .info{
  561. flex: 1;
  562. margin-left: 26rpx;
  563. display: flex;
  564. flex-direction: column;
  565. justify-content: space-around;
  566. .title{
  567. font-weight: bold;
  568. font-size: 32rpx;
  569. color: #222222;
  570. }
  571. .btn-box{
  572. display: flex;
  573. justify-content: space-between;
  574. .price-box{
  575. display: flex;
  576. align-items: center;
  577. .price{
  578. display: flex;
  579. align-items: flex-end;
  580. color: #FF4D3A;
  581. .unit{
  582. font-size: 20rpx;
  583. }
  584. .num{
  585. font-weight: bold;
  586. font-size: 36rpx;
  587. }
  588. }
  589. .old-price{
  590. font-weight: normal;
  591. font-size: 24rpx;
  592. color: #AAAAAA;
  593. text-decoration: line-through;
  594. margin-left: 16rpx;
  595. }
  596. }
  597. .count-box{
  598. display: flex;
  599. align-items: center;
  600. .num{
  601. width: 100rpx;
  602. text-align: center;
  603. font-size: 28rpx;
  604. color: #222222;
  605. }
  606. .btn{
  607. width: 40rpx;
  608. height: 40rpx;
  609. }
  610. }
  611. }
  612. }
  613. }
  614. }
  615. }
  616. </style>