index.vue 13 KB

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