index.vue 13 KB

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