index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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. 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.channelPrice,
  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. }
  278. uni.navigateTo({
  279. url:`/orderFood/pay`,
  280. success: function(res) {
  281. // 通过eventChannel向被打开页面传送数据
  282. res.eventChannel.emit('pay', info)
  283. }
  284. })
  285. }else{
  286. uni.showModal({
  287. title:'此商品需要开通会员才能购买',
  288. cancelText:'下次再说',
  289. confirmText:'立即开通',
  290. success(res) {
  291. if(res.confirm){
  292. uni.navigateTo({
  293. url:'/my/memberCenter/index'
  294. })
  295. }
  296. }
  297. })
  298. }
  299. }else{
  300. uni.showModal({
  301. title:'请登录',
  302. confirmText:'去登录',
  303. success(res){
  304. console.log(res);
  305. if(res.confirm){
  306. uni.navigateTo({
  307. url:`/login/login/login?redirect=/orderFood/index&shopId=${that.shopId}`
  308. })
  309. }
  310. }
  311. })
  312. }
  313. }
  314. },
  315. onLoad(options) {
  316. this.cateName = options.cateName
  317. this.shopId = options.id || "63836999-5117-4980-8632-497f007808ef"
  318. this.shopDetail()
  319. this.menuList()
  320. },
  321. onReady () {
  322. // this.Observer = uni.createIntersectionObserver(this)
  323. // this.Observer.relativeTo('.test',{bottom: 0}).observe('.title0', (res) => {
  324. // console.log(12312);
  325. // // this.$emit('changeTag',this.value)
  326. // })
  327. }
  328. }
  329. </script>
  330. <style lang="scss" >
  331. .orderFood{
  332. .shop-info{
  333. width: 100%;
  334. height: 130rpx;
  335. padding: 20rpx 24rpx;
  336. box-sizing: border-box;
  337. border-bottom: 2rpx solid #F0F0F0;
  338. // position: fixed;
  339. // top: 0%;
  340. // left: 0%;
  341. // z-index: 9;
  342. background: #fff;
  343. .shop-name{
  344. font-weight: bold;
  345. font-size: 32rpx;
  346. color: #222222;
  347. }
  348. .address{
  349. font-size: 24rpx;
  350. color: #AAAAAA;
  351. margin-top: 16rpx;
  352. }
  353. }
  354. .content{
  355. height: calc(100vh - 130rpx);
  356. display: flex;
  357. overflow: auto;
  358. box-sizing: border-box;
  359. padding-bottom: calc(98rpx + env(safe-area-inset-bottom)) ;
  360. .left{
  361. flex: 0 0 176rpx;
  362. background: #F7F7F7;
  363. .item{
  364. text-align: center;
  365. padding: 16rpx 0;
  366. .icon{
  367. width: 76rpx;
  368. height: 76rpx;
  369. }
  370. .name{
  371. font-size: 24rpx;
  372. color: #AAAAAA;
  373. }
  374. }
  375. .item.active{
  376. background: #FFFFFF;
  377. .name{
  378. color: #222222;
  379. }
  380. }
  381. }
  382. .right{
  383. flex: 1;
  384. padding: 0 24rpx;
  385. overflow: auto;
  386. position: relative;
  387. .test{
  388. width: 100%;
  389. height: 60rpx;
  390. background: red;
  391. position: fixed;
  392. }
  393. .section{
  394. .section-name{
  395. font-weight: bold;
  396. font-size: 28rpx;
  397. color: #222222;
  398. padding-top: 30rpx;
  399. }
  400. .item{
  401. display: flex;
  402. margin-top: 28rpx;
  403. .img{
  404. width: 160rpx;
  405. height: 160rpx;
  406. border-radius: 8rpx 8rpx 8rpx 8rpx;
  407. }
  408. .info{
  409. flex: 1;
  410. margin-left: 26rpx;
  411. display: flex;
  412. flex-direction: column;
  413. justify-content: space-around;
  414. .title{
  415. font-weight: bold;
  416. font-size: 32rpx;
  417. color: #222222;
  418. }
  419. .btn-box{
  420. display: flex;
  421. justify-content: space-between;
  422. .price-box{
  423. display: flex;
  424. align-items: center;
  425. .price{
  426. display: flex;
  427. align-items: flex-end;
  428. color: #FF4D3A;
  429. .unit{
  430. font-size: 20rpx;
  431. }
  432. .num{
  433. font-weight: bold;
  434. font-size: 36rpx;
  435. }
  436. }
  437. .old-price{
  438. font-weight: normal;
  439. font-size: 24rpx;
  440. color: #AAAAAA;
  441. text-decoration: line-through;
  442. margin-left: 16rpx;
  443. }
  444. }
  445. .btn{
  446. width: 40rpx;
  447. height: 40rpx;
  448. }
  449. }
  450. }
  451. }
  452. }
  453. }
  454. }
  455. .total-box1{
  456. position: inherit!important;
  457. padding-bottom: 0!important;
  458. }
  459. .total-box{
  460. position: fixed;
  461. left: 0%;
  462. bottom: 0;
  463. width: 100%;
  464. padding: 10rpx 24rpx env(safe-area-inset-bottom);
  465. box-sizing: border-box;
  466. display: flex;
  467. align-items: center;
  468. justify-content: space-between;
  469. border-top: 1rpx solid #EEEEEE;
  470. .price-box{
  471. display: flex;
  472. .car-box{
  473. position: relative;
  474. display: flex;
  475. align-items: center;
  476. .icon{
  477. width: 48rpx;
  478. height: 48rpx;
  479. }
  480. .num{
  481. position: absolute;
  482. top: -18rpx;
  483. right: -18rpx;
  484. min-width: 36rpx;
  485. height: 36rpx;
  486. line-height: 36rpx;
  487. text-align: center;
  488. border-radius: 18rpx;
  489. background: #222222;
  490. font-weight: bold;
  491. font-size: 24rpx;
  492. color: #FFFFFF;
  493. margin-left: 20rpx;
  494. }
  495. }
  496. .price{
  497. display: flex;
  498. align-items: flex-end;
  499. color: #FF4D3A;
  500. .unit{
  501. font-size: 20rpx;
  502. }
  503. .num{
  504. font-weight: bold;
  505. font-size: 36rpx;
  506. }
  507. }
  508. }
  509. .buy{
  510. width: 200rpx;
  511. height: 80rpx;
  512. line-height: 80rpx;
  513. text-align: center;
  514. background: #EE4320;
  515. border-radius: 40rpx 40rpx 40rpx 40rpx;
  516. font-weight: bold;
  517. font-size: 28rpx;
  518. color: #FFFFFF;
  519. margin: 0;
  520. }
  521. .buy.disabled{
  522. background: #F6F6F6;
  523. color: #AAAAAA;
  524. }
  525. }
  526. .popup-title-box{
  527. display: flex;
  528. justify-content: space-between;
  529. padding: 24rpx;
  530. .title{
  531. font-weight: bold;
  532. font-size: 28rpx;
  533. color: #222222;
  534. }
  535. .clear{
  536. font-size: 28rpx;
  537. color: #AAAAAA;
  538. }
  539. }
  540. .u-empty{
  541. padding: 30rpx 0;
  542. }
  543. .car-content{
  544. padding-bottom: 30rpx;
  545. max-height: 700rpx;
  546. overflow: auto;
  547. .item{
  548. display: flex;
  549. margin-top: 28rpx;
  550. padding: 0 24rpx;
  551. .img{
  552. width: 160rpx;
  553. height: 160rpx;
  554. border-radius: 8rpx 8rpx 8rpx 8rpx;
  555. }
  556. .info{
  557. flex: 1;
  558. margin-left: 26rpx;
  559. display: flex;
  560. flex-direction: column;
  561. justify-content: space-around;
  562. .title{
  563. font-weight: bold;
  564. font-size: 32rpx;
  565. color: #222222;
  566. }
  567. .btn-box{
  568. display: flex;
  569. justify-content: space-between;
  570. .price-box{
  571. display: flex;
  572. align-items: center;
  573. .price{
  574. display: flex;
  575. align-items: flex-end;
  576. color: #FF4D3A;
  577. .unit{
  578. font-size: 20rpx;
  579. }
  580. .num{
  581. font-weight: bold;
  582. font-size: 36rpx;
  583. }
  584. }
  585. .old-price{
  586. font-weight: normal;
  587. font-size: 24rpx;
  588. color: #AAAAAA;
  589. text-decoration: line-through;
  590. margin-left: 16rpx;
  591. }
  592. }
  593. .count-box{
  594. display: flex;
  595. align-items: center;
  596. .num{
  597. width: 100rpx;
  598. text-align: center;
  599. font-size: 28rpx;
  600. color: #222222;
  601. }
  602. .btn{
  603. width: 40rpx;
  604. height: 40rpx;
  605. }
  606. }
  607. }
  608. }
  609. }
  610. }
  611. }
  612. </style>