index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <template>
  2. <view class="content">
  3. <view class="info">
  4. <view class="one">
  5. <view class="one_1">
  6. <view class="name">
  7. {{shopInfo.name}}
  8. <!-- <uni-icons type="forward" size="20"></uni-icons> -->
  9. </view>
  10. <view class="num">
  11. 桌号:{{shopInfo.table}}
  12. </view>
  13. </view>
  14. <!-- <view class="one_2">
  15. <view class="left">
  16. <text>领劵</text>
  17. <text class="left_1" v-for="(item,index) in shopInfo.coupon">{{item.name}}</text>
  18. </view>
  19. <view class="right">
  20. <text>去领劵</text>
  21. <uni-icons color="#C0C0C0" type="forward" size="14"></uni-icons>
  22. </view>
  23. </view> -->
  24. <view class="one_2">
  25. <view class="left">
  26. <text>公告</text>
  27. <text class="left_2">{{shopInfo.notice}}</text>
  28. </view>
  29. </view>
  30. <view class="one_3">
  31. <image :src="shopInfo.logo" mode="scaleToFill"></image>
  32. </view>
  33. </view>
  34. <view class="two">
  35. <view class="two_1">
  36. <scroll-view scroll-y="true" class="scroll-view">
  37. <view class="list-scroll-view">
  38. <view class="list" :class="[active==index?'listActive':'']" v-for="(item,index) in typeList"
  39. :key="index" @tap="toChange(index,item)">
  40. <uni-badge :text="item.num" absolute="rightTop" size="small">
  41. <uni-icons color="#FF8C00" :type="item.icon" size="15"></uni-icons>
  42. <text class="name">{{item.name}}</text>
  43. </uni-badge>
  44. </view>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. <view class="two_2">
  49. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  50. <view class="list-scroll-view">
  51. <view class="theme">{{tags.name}}</view>
  52. <view class="list" v-for="(tag,index) in marketList" :key="index">
  53. <view class="img">
  54. <image class="image" :src="tag.file" mode=""></image>
  55. </view>
  56. <view class="info">
  57. <view class="name textOver">
  58. <text>{{tag.name}}</text>
  59. </view>
  60. <view class="spec" v-if="tag.spec">
  61. <text>{{tag.spec}}</text>
  62. </view>
  63. <view class="money">
  64. <text>¥{{tag.price}}</text>
  65. <uni-number-box @change="bindChange(tag)" :min="0" :max="tag.stock" value="tag"
  66. background="#FF8C00" color="#fff" v-model="tag.num" />
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. <view class="is_bottom" v-if="is_bottom">
  72. <text>已经到底了!</text>
  73. </view>
  74. </scroll-view>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="foot" @tap="toView">
  79. <view class="foot_1">
  80. <uni-badge :text="cartNum.num" absolute="rightTop" size="small">
  81. <uni-icons color="#FF8C00" type="cart-filled" size="45"></uni-icons>
  82. </uni-badge>
  83. <text>合计</text>
  84. <text class="type">¥</text>
  85. <text class="money">{{cartNum.total||0}}</text>
  86. </view>
  87. <view class="foot_2">
  88. <button class="button" @tap.stop="toBuy">去结算</button>
  89. </view>
  90. </view>
  91. <!-- 规格 -->
  92. <uni-popup ref="specShow" background-color="#fff" type="bottom">
  93. <view class="popup">
  94. <view class="close">
  95. <view @click="toDelete">
  96. <uni-icons color="#858585" type="trash" size="17"></uni-icons>
  97. <text class="name">清空购物车</text>
  98. </view>
  99. </view>
  100. <view class="info_1" v-if="popupShow=='1'">
  101. <scroll-view scroll-y="true" class="scroll-view">
  102. <view class="list-scroll-view">
  103. <view class="list" v-for="(tag,index) in buyList" :key="index">
  104. <view class="img">
  105. <image class="image" :src="tag.file" mode=""></image>
  106. </view>
  107. <view class="info">
  108. <view class="name textOver">
  109. <text>{{tag.name}}</text>
  110. </view>
  111. <view class="spec" v-if="tag.spec">
  112. <text>{{tag.spec}}</text>
  113. </view>
  114. <view class="money">
  115. <text>¥{{tag.price}}</text>
  116. <uni-number-box @change="bindChange(tag)" :min="0" :max="tag.stock" value="tag"
  117. background="#FF8C00" color="#fff" v-model="tag.num" />
  118. </view>
  119. </view>
  120. </view>
  121. </view>
  122. </scroll-view>
  123. </view>
  124. </view>
  125. </uni-popup>
  126. </view>
  127. </template>
  128. <script>
  129. export default {
  130. data() {
  131. return {
  132. id: '',
  133. shopInfo: {
  134. name: '德轩美食',
  135. table: '1',
  136. coupon: [{
  137. name: '满100减10'
  138. },
  139. {
  140. name: '满200减30'
  141. }
  142. ],
  143. notice: '您好,欢迎进店选购',
  144. logo: require("../../static/foods_1.webp")
  145. },
  146. list: [{
  147. _id: '1',
  148. code: '0',
  149. name: '三文鱼',
  150. file: require("../../static/foods_1.webp"),
  151. price: 126,
  152. spec: '300g',
  153. stock: 100
  154. },
  155. {
  156. _id: '2',
  157. code: '0',
  158. name: '蜜汁扇贝',
  159. file: require("../../static/foods_2.webp"),
  160. price: 68,
  161. spec: '400g',
  162. stock: 140
  163. },
  164. {
  165. _id: '3',
  166. code: '0',
  167. name: '意大利牛排',
  168. file: require("../../static/foods_3.webp"),
  169. price: 128,
  170. spec: '600g',
  171. stock: 200
  172. },
  173. {
  174. _id: '4',
  175. code: '0',
  176. name: '糖醋里脊',
  177. file: require("../../static/foods_4.webp"),
  178. price: 58,
  179. spec: '500g',
  180. stock: 140
  181. },
  182. {
  183. _id: '5',
  184. code: '2',
  185. name: '黑糖珍珠奶茶',
  186. file: require("../../static/foods_1.webp"),
  187. price: 18,
  188. spec: '500g',
  189. stock: 120
  190. },
  191. {
  192. _id: '6',
  193. code: '2',
  194. name: '雪碧',
  195. file: require("../../static/foods_2.webp"),
  196. price: 5,
  197. spec: '500g',
  198. stock: 34
  199. },
  200. {
  201. _id: '7',
  202. code: '2',
  203. name: '可口可乐',
  204. file: require("../../static/foods_3.webp"),
  205. price: 5,
  206. spec: '500g',
  207. stock: 50
  208. },
  209. {
  210. _id: '8',
  211. code: '1',
  212. name: '芝士小蛋糕',
  213. file: require("../../static/foods_2.webp"),
  214. price: 12,
  215. spec: '260g',
  216. stock: 10
  217. },
  218. {
  219. _id: '9',
  220. code: '1',
  221. name: '草莓千层',
  222. file: require("../../static/foods_3.webp"),
  223. price: 15,
  224. spec: '350g',
  225. stock: 40
  226. }
  227. ],
  228. active: '0',
  229. tags: {},
  230. // 数据是否触底
  231. is_bottom: false,
  232. scrollTop: 0,
  233. typeList: [],
  234. marketList: [],
  235. // 购物车
  236. buyList: [],
  237. // 购物车数量
  238. cartNum: {},
  239. is_show: false,
  240. // 规格弹框
  241. popupShow: '1',
  242. }
  243. },
  244. onLoad: async function(e) {
  245. const that = this;
  246. that.$set(that, `id`, e.id);
  247. that.search();
  248. },
  249. onShow() {
  250. const that = this;
  251. },
  252. methods: {
  253. // 查询左侧一级列表
  254. async search() {
  255. const that = this;
  256. let type = [{
  257. icon: 'vip',
  258. name: '主食',
  259. code: '0'
  260. },
  261. {
  262. icon: 'fire',
  263. name: '甜品',
  264. code: '1'
  265. },
  266. {
  267. icon: '',
  268. name: '饮料',
  269. code: '2'
  270. }
  271. ]
  272. that.$set(that, `typeList`, type);
  273. // 查询产品
  274. that.$set(that, `tags`, type[0])
  275. that.searchMarket()
  276. },
  277. // 查询产品
  278. async searchMarket() {
  279. const that = this;
  280. let list = that.list.filter(i => i.code == that.tags.code)
  281. if (list) that.$set(that, `marketList`, list)
  282. },
  283. // 改变数量
  284. async bindChange(e) {
  285. const that = this;
  286. that.$nextTick(async () => {
  287. let list = that.buyList.find(i => i._id == e._id)
  288. if (list) {
  289. if (list.num == 0) {
  290. let cart = that.buyList.filter(i => i._id !== list._id)
  291. if (cart) that.$set(that, `buyList`, cart)
  292. } else {
  293. for (let val of that.buyList) {
  294. if (val._id == list._id) val.num = list.num
  295. }
  296. }
  297. } else {
  298. if (e.num != 0) that.buyList.push(e)
  299. }
  300. for (let s of that.typeList) {
  301. let num = that.buyList.filter(i => i.code == s.code)
  302. let buy = num.filter(i => i.num !== 0)
  303. if (buy) s.num = buy.length
  304. }
  305. await that.countMoney()
  306. })
  307. },
  308. // 计算总额
  309. countMoney() {
  310. const that = this;
  311. let list = that.buyList.filter(i => i.num !== 0)
  312. let totalMoney = 0;
  313. // 渲染结束执行下面方法
  314. that.$nextTick(() => {
  315. for (const val of list) {
  316. let total = that.$multiply(val.price, val.num);
  317. totalMoney += Number(total);
  318. }
  319. that.$set(that.cartNum, `num`, list.length)
  320. that.$set(that.cartNum, `total`, totalMoney)
  321. })
  322. },
  323. // 查看选择商品详情
  324. toView() {
  325. const that = this;
  326. that.$set(that, `popupShow`, '1')
  327. that.$refs.specShow.open();
  328. },
  329. // 去购买
  330. toBuy() {
  331. const that = this;
  332. let key = '1'
  333. if (that.buyList.length > 0) {
  334. if (that.id) {
  335. uni.navigateTo({
  336. url: `/pagesHome/order/add?key=${key}`
  337. })
  338. } else {
  339. uni.navigateTo({
  340. url: `/pagesHome/order/index?key=${key}`
  341. })
  342. }
  343. }
  344. },
  345. // 关闭弹框
  346. toDelete() {
  347. const that = this;
  348. for (let val of that.typeList) val.num = 0
  349. that.$set(that, `buyList`, [])
  350. that.$set(that.cartNum, `num`, 0)
  351. that.$set(that.cartNum, `total`, 0)
  352. that.searchMarket()
  353. that.$refs.specShow.close();
  354. },
  355. // 分页
  356. toPage() {
  357. const that = this;
  358. },
  359. // 触底
  360. toScroll(e) {
  361. const that = this;
  362. let up = that.scrollTop;
  363. that.$set(that, `scrollTop`, e.detail.scrollTop);
  364. let num = Math.sign(up - e.detail.scrollTop);
  365. if (num == 1) that.$set(that, `is_bottom`, false);
  366. },
  367. // 左侧一级选择
  368. toChange(index, e) {
  369. const that = this;
  370. that.$set(that, `marketList`, []);
  371. that.$set(that, `active`, index);
  372. that.$set(that, `tags`, e);
  373. that.searchMarket();
  374. },
  375. }
  376. }
  377. </script>
  378. <style lang="scss">
  379. .content {
  380. font-family: 12px/1 Tahoma, Helvetica, Arial, "\5b8b\4f53", sans-serif;
  381. .info {
  382. display: flex;
  383. flex-direction: column;
  384. position: relative;
  385. flex-grow: 1;
  386. .one {
  387. .one_1 {
  388. padding: 2vw;
  389. display: flex;
  390. justify-content: space-between;
  391. font-size: 18px;
  392. font-weight: bold;
  393. .name {
  394. display: flex;
  395. align-items: center;
  396. }
  397. }
  398. .one_2 {
  399. display: flex;
  400. justify-content: space-between;
  401. align-items: center;
  402. padding: 2vw;
  403. .left {
  404. text:first-child {
  405. font-size: 14px;
  406. margin: 0 1vw 0 0;
  407. font-weight: 600;
  408. }
  409. .left_1 {
  410. font-size: 12px;
  411. padding: 1vw;
  412. margin: 0 1vw 0 0;
  413. color: #FF7800;
  414. border: 1px solid #FF7800;
  415. border-radius: 2vw;
  416. }
  417. .left_2 {
  418. font-size: 12px;
  419. color: #808080;
  420. }
  421. }
  422. .right {
  423. font-size: 12px;
  424. color: #808080;
  425. }
  426. }
  427. .one_3 {
  428. padding: 2vw;
  429. text-align: center;
  430. background-color: #f1f1f1;
  431. image {
  432. width: 100%;
  433. border-radius: 2vw;
  434. height: 15vh;
  435. }
  436. }
  437. }
  438. .two {
  439. height: 61vh;
  440. display: flex;
  441. .two_1 {
  442. position: relative;
  443. width: 25vw;
  444. background-color: #fafafa;
  445. display: flex;
  446. flex-direction: column;
  447. .list {
  448. text-align: center;
  449. padding: 3vw 0;
  450. border-bottom: 1px solid #f1f1f1;
  451. .name {
  452. color: #858585;
  453. font-size: 12px;
  454. }
  455. }
  456. .listActive {
  457. background-color: #ffffff;
  458. }
  459. }
  460. .two_2 {
  461. flex-grow: 1;
  462. position: relative;
  463. display: flex;
  464. flex-direction: column;
  465. .theme {
  466. padding: 2vw;
  467. color: #858585;
  468. font-size: 12px;
  469. }
  470. .list {
  471. display: flex;
  472. width: 70vw;
  473. margin: 0 0 2vw 0;
  474. padding: 2vw;
  475. box-shadow: 0 0 5px #f1f1f1;
  476. border-radius: 5px;
  477. .img {
  478. width: 30vw;
  479. .image {
  480. width: 30vw;
  481. height: 20vw;
  482. border-radius: 5px;
  483. }
  484. }
  485. .info {
  486. display: flex;
  487. flex-direction: column;
  488. justify-content: space-between;
  489. width: 40vw;
  490. padding: 0 0 0 2vw;
  491. .name {
  492. font-size: 16px;
  493. }
  494. .spec {
  495. font-size: 12px;
  496. color: #858585;
  497. }
  498. .money {
  499. display: flex;
  500. justify-content: space-between;
  501. align-items: center;
  502. font-size: 16px;
  503. color: #FF8C00;
  504. margin: 0 0 1vw 0;
  505. }
  506. }
  507. }
  508. }
  509. }
  510. }
  511. .foot {
  512. display: flex;
  513. justify-content: space-between;
  514. padding: 0 2vw;
  515. background-color: #ffffff;
  516. border-top: 1px solid #f1f1f1;
  517. z-index: 99999 !important;
  518. .foot_1 {
  519. display: flex;
  520. justify-content: space-between;
  521. align-items: center;
  522. font-size: 14px;
  523. .type {
  524. color: #FF8C00;
  525. }
  526. .money {
  527. font-size: 25px;
  528. color: #FF8C00;
  529. }
  530. }
  531. .foot_2 {
  532. .button {
  533. background-color: #FF8C00;
  534. color: #ffffff;
  535. border-radius: 5vw;
  536. font-size: 16px;
  537. }
  538. }
  539. }
  540. .uni-popup {
  541. z-index: 9999 !important;
  542. }
  543. .popup {
  544. display: flex;
  545. flex-direction: column;
  546. width: 100vw;
  547. height: 60vh;
  548. .close {
  549. text-align: right;
  550. padding: 2vw;
  551. .name {
  552. font-size: 14px;
  553. color: #858585;
  554. }
  555. }
  556. .info_1 {
  557. position: relative;
  558. display: flex;
  559. flex-direction: column;
  560. height: 54vh;
  561. margin-bottom: 12vw;
  562. .list {
  563. display: flex;
  564. width: 96vw;
  565. margin: 0 0 2vw 0;
  566. padding: 2vw;
  567. box-shadow: 0 0 5px #f1f1f1;
  568. border-radius: 5px;
  569. .img {
  570. width: 30vw;
  571. .image {
  572. width: 30vw;
  573. height: 20vw;
  574. border-radius: 5px;
  575. }
  576. }
  577. .info {
  578. display: flex;
  579. flex-direction: column;
  580. justify-content: space-between;
  581. width: 60vw;
  582. padding: 0 0 0 2vw;
  583. .name {
  584. font-size: 16px;
  585. }
  586. .spec {
  587. font-size: 12px;
  588. color: #858585;
  589. }
  590. .money {
  591. display: flex;
  592. justify-content: space-between;
  593. align-items: center;
  594. font-size: 16px;
  595. color: #FF8C00;
  596. margin: 0 0 1vw 0;
  597. }
  598. }
  599. }
  600. }
  601. }
  602. }
  603. .scroll-view {
  604. position: absolute;
  605. top: 0;
  606. left: 0;
  607. right: 0;
  608. bottom: 0;
  609. .list-scroll-view {
  610. display: flex;
  611. flex-direction: column;
  612. }
  613. }
  614. </style>