index.vue 14 KB

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