index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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.channelPrice}}
  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. };
  162. },
  163. computed: {
  164. totalNum(){
  165. let total = 0
  166. this.carList.map(item=>{
  167. total+=item.quantity
  168. })
  169. return total
  170. },
  171. total() {
  172. let total = 0
  173. this.carList.map(item=>{
  174. total+=(item.selPrice*10000*item.quantity)
  175. })
  176. return total/10000
  177. }
  178. },
  179. methods: {
  180. scroll(val){
  181. if(!this.offsetTop){
  182. this.offsetTop = val.currentTarget.offsetTop
  183. }
  184. this.topList.map((item,index)=>{
  185. if(index!=this.topList.length-1){
  186. if(val.detail.scrollTop>= (item-this.offsetTop)&&(val.detail.scrollTop <=this.topList[index+1]-this.offsetTop)){
  187. this.scrollTo1 = 'tab'+index
  188. this.active = index
  189. }
  190. }else{
  191. if(val.detail.scrollTop>= (item-this.offsetTop)){
  192. this.scrollTo1 = 'tab'+index
  193. this.active = index
  194. }
  195. }
  196. })
  197. },
  198. clear(){
  199. this.carList = []
  200. },
  201. add(item,num){
  202. if(this.carList.some(i=>item.productId == i.productId)){
  203. this.carList.forEach((i,index)=>{
  204. if(item.productId == i.productId){
  205. item.quantity+=num
  206. if(item.quantity == 0){
  207. this.carList.splice(index,1)
  208. }
  209. }
  210. })
  211. }else{
  212. let obj ={
  213. "imageUrl": item.imageUrl,
  214. "nameCn": item.nameCn,
  215. "productId": item.productId,
  216. "quantity": 1,
  217. "selPrice": item.channelPrice,
  218. "orgPrice": item.basePrice,
  219. }
  220. this.carList.push(obj)
  221. }
  222. },
  223. handleCar(){
  224. this.show = true
  225. },
  226. handleTab(index){
  227. this.active = index
  228. this.scrollTo = 'title'+index
  229. },
  230. chooseTag(val){
  231. console.log('当前',val);
  232. },
  233. menuList(){
  234. menuList(this.shopId).then(res=>{
  235. if(res.state = 'Success'){
  236. this.list = res.content.data
  237. this.$nextTick(()=>{
  238. let query = uni.createSelectorQuery().in(this);
  239. query.selectAll('.section-name').boundingClientRect(data=>{
  240. console.log(data);
  241. this.topList =data.map(item=>{
  242. return item.top
  243. })
  244. }).exec();
  245. })
  246. }
  247. })
  248. },
  249. shopDetail(){
  250. shopDetail({"id": this.shopId,
  251. "lat": "",
  252. "lon": ""}).then(res=>{
  253. if(res.state = 'Success'){
  254. this.shopInfo.shopName = res.content.data.shopName
  255. this.shopInfo.address = res.content.data.address
  256. }
  257. })
  258. },
  259. buy() {
  260. let that = this
  261. if (uni.getStorageSync('token')) {
  262. if(JSON.parse(uni.getStorageSync('userInfo')).setMealCode != 0){
  263. let info ={
  264. shopName:this.shopInfo.shopName,
  265. address:this.shopInfo.address,
  266. shopId:this.shopId,
  267. products:this.carList,
  268. total:this.total
  269. }
  270. uni.navigateTo({
  271. url:`/orderFood/pay`,
  272. success: function(res) {
  273. // 通过eventChannel向被打开页面传送数据
  274. res.eventChannel.emit('pay', info)
  275. }
  276. })
  277. }else{
  278. uni.showModal({
  279. title:'此商品需要开通会员才能购买',
  280. cancelText:'下次再说',
  281. confirmText:'立即开通',
  282. success(res) {
  283. if(res.confirm){
  284. uni.navigateTo({
  285. url:'/my/memberCenter/index'
  286. })
  287. }
  288. }
  289. })
  290. }
  291. }else{
  292. uni.showModal({
  293. title:'请登录',
  294. confirmText:'去登录',
  295. success(res){
  296. console.log(res);
  297. if(res.confirm){
  298. uni.navigateTo({
  299. url:`/login/login/login?redirect=/orderFood/index&shopId=${that.shopId}`
  300. })
  301. }
  302. }
  303. })
  304. }
  305. }
  306. },
  307. onLoad(options) {
  308. this.shopId = options.shopId || "63836999-5117-4980-8632-497f007808ef"
  309. this.shopDetail()
  310. this.menuList()
  311. },
  312. onReady () {
  313. // this.Observer = uni.createIntersectionObserver(this)
  314. // this.Observer.relativeTo('.test',{bottom: 0}).observe('.title0', (res) => {
  315. // console.log(12312);
  316. // // this.$emit('changeTag',this.value)
  317. // })
  318. }
  319. }
  320. </script>
  321. <style lang="scss" >
  322. .orderFood{
  323. .shop-info{
  324. width: 100%;
  325. height: 130rpx;
  326. padding: 20rpx 24rpx;
  327. box-sizing: border-box;
  328. border-bottom: 2rpx solid #F0F0F0;
  329. // position: fixed;
  330. // top: 0%;
  331. // left: 0%;
  332. // z-index: 9;
  333. background: #fff;
  334. .shop-name{
  335. font-weight: bold;
  336. font-size: 32rpx;
  337. color: #222222;
  338. }
  339. .address{
  340. font-size: 24rpx;
  341. color: #AAAAAA;
  342. margin-top: 16rpx;
  343. }
  344. }
  345. .content{
  346. height: calc(100vh - 130rpx);
  347. display: flex;
  348. overflow: auto;
  349. box-sizing: border-box;
  350. padding-bottom: calc(98rpx + env(safe-area-inset-bottom)) ;
  351. .left{
  352. flex: 0 0 176rpx;
  353. background: #F7F7F7;
  354. .item{
  355. text-align: center;
  356. padding: 16rpx 0;
  357. .icon{
  358. width: 76rpx;
  359. height: 76rpx;
  360. }
  361. .name{
  362. font-size: 24rpx;
  363. color: #AAAAAA;
  364. }
  365. }
  366. .item.active{
  367. background: #FFFFFF;
  368. .name{
  369. color: #222222;
  370. }
  371. }
  372. }
  373. .right{
  374. flex: 1;
  375. padding: 0 24rpx;
  376. overflow: auto;
  377. position: relative;
  378. .test{
  379. width: 100%;
  380. height: 60rpx;
  381. background: red;
  382. position: fixed;
  383. }
  384. .section{
  385. .section-name{
  386. font-weight: bold;
  387. font-size: 28rpx;
  388. color: #222222;
  389. padding-top: 30rpx;
  390. }
  391. .item{
  392. display: flex;
  393. margin-top: 28rpx;
  394. .img{
  395. width: 160rpx;
  396. height: 160rpx;
  397. border-radius: 8rpx 8rpx 8rpx 8rpx;
  398. }
  399. .info{
  400. flex: 1;
  401. margin-left: 26rpx;
  402. display: flex;
  403. flex-direction: column;
  404. justify-content: space-around;
  405. .title{
  406. font-weight: bold;
  407. font-size: 32rpx;
  408. color: #222222;
  409. }
  410. .btn-box{
  411. display: flex;
  412. justify-content: space-between;
  413. .price-box{
  414. display: flex;
  415. align-items: center;
  416. .price{
  417. display: flex;
  418. align-items: flex-end;
  419. color: #FF4D3A;
  420. .unit{
  421. font-size: 20rpx;
  422. }
  423. .num{
  424. font-weight: bold;
  425. font-size: 36rpx;
  426. }
  427. }
  428. .old-price{
  429. font-weight: normal;
  430. font-size: 24rpx;
  431. color: #AAAAAA;
  432. text-decoration: line-through;
  433. margin-left: 16rpx;
  434. }
  435. }
  436. .btn{
  437. width: 40rpx;
  438. height: 40rpx;
  439. }
  440. }
  441. }
  442. }
  443. }
  444. }
  445. }
  446. .total-box1{
  447. position: inherit!important;
  448. padding-bottom: 0!important;
  449. }
  450. .total-box{
  451. position: fixed;
  452. left: 0%;
  453. bottom: 0;
  454. width: 100%;
  455. padding: 10rpx 24rpx env(safe-area-inset-bottom);
  456. box-sizing: border-box;
  457. display: flex;
  458. align-items: center;
  459. justify-content: space-between;
  460. border-top: 1rpx solid #EEEEEE;
  461. .price-box{
  462. display: flex;
  463. .car-box{
  464. position: relative;
  465. display: flex;
  466. align-items: center;
  467. .icon{
  468. width: 48rpx;
  469. height: 48rpx;
  470. }
  471. .num{
  472. position: absolute;
  473. top: -18rpx;
  474. right: -18rpx;
  475. min-width: 36rpx;
  476. height: 36rpx;
  477. line-height: 36rpx;
  478. text-align: center;
  479. border-radius: 18rpx;
  480. background: #222222;
  481. font-weight: bold;
  482. font-size: 24rpx;
  483. color: #FFFFFF;
  484. margin-left: 20rpx;
  485. }
  486. }
  487. .price{
  488. display: flex;
  489. align-items: flex-end;
  490. color: #FF4D3A;
  491. .unit{
  492. font-size: 20rpx;
  493. }
  494. .num{
  495. font-weight: bold;
  496. font-size: 36rpx;
  497. }
  498. }
  499. }
  500. .buy{
  501. width: 200rpx;
  502. height: 80rpx;
  503. line-height: 80rpx;
  504. text-align: center;
  505. background: #EE4320;
  506. border-radius: 40rpx 40rpx 40rpx 40rpx;
  507. font-weight: bold;
  508. font-size: 28rpx;
  509. color: #FFFFFF;
  510. margin: 0;
  511. }
  512. .buy.disabled{
  513. background: #F6F6F6;
  514. color: #AAAAAA;
  515. }
  516. }
  517. .popup-title-box{
  518. display: flex;
  519. justify-content: space-between;
  520. padding: 24rpx;
  521. .title{
  522. font-weight: bold;
  523. font-size: 28rpx;
  524. color: #222222;
  525. }
  526. .clear{
  527. font-size: 28rpx;
  528. color: #AAAAAA;
  529. }
  530. }
  531. .u-empty{
  532. padding: 30rpx 0;
  533. }
  534. .car-content{
  535. padding-bottom: 30rpx;
  536. max-height: 700rpx;
  537. overflow: auto;
  538. .item{
  539. display: flex;
  540. margin-top: 28rpx;
  541. padding: 0 24rpx;
  542. .img{
  543. width: 160rpx;
  544. height: 160rpx;
  545. border-radius: 8rpx 8rpx 8rpx 8rpx;
  546. }
  547. .info{
  548. flex: 1;
  549. margin-left: 26rpx;
  550. display: flex;
  551. flex-direction: column;
  552. justify-content: space-around;
  553. .title{
  554. font-weight: bold;
  555. font-size: 32rpx;
  556. color: #222222;
  557. }
  558. .btn-box{
  559. display: flex;
  560. justify-content: space-between;
  561. .price-box{
  562. display: flex;
  563. align-items: center;
  564. .price{
  565. display: flex;
  566. align-items: flex-end;
  567. color: #FF4D3A;
  568. .unit{
  569. font-size: 20rpx;
  570. }
  571. .num{
  572. font-weight: bold;
  573. font-size: 36rpx;
  574. }
  575. }
  576. .old-price{
  577. font-weight: normal;
  578. font-size: 24rpx;
  579. color: #AAAAAA;
  580. text-decoration: line-through;
  581. margin-left: 16rpx;
  582. }
  583. }
  584. .count-box{
  585. display: flex;
  586. align-items: center;
  587. .num{
  588. width: 100rpx;
  589. text-align: center;
  590. font-size: 28rpx;
  591. color: #222222;
  592. }
  593. .btn{
  594. width: 40rpx;
  595. height: 40rpx;
  596. }
  597. }
  598. }
  599. }
  600. }
  601. }
  602. }
  603. </style>