index.vue 13 KB

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