index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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">
  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. that.$set(that, `marketList`, res.data)
  202. })
  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 !== e._id)
  218. if (cart) that.$set(that, `buyList`, cart)
  219. } else {
  220. for (let val of that.buyList) {
  221. if (val._id == e._id) val.num = e.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. let list = that.buyList.filter(i => i.num !== 0)
  254. that.$set(that, `buyList`, list)
  255. that.$set(that, `popupShow`, '1')
  256. that.$refs.specShow.open();
  257. },
  258. // 去购买
  259. async toBuy() {
  260. const that = this;
  261. let res;
  262. let list = that.buyList.filter(i => i.num !== 0)
  263. if (list.length > 0) {
  264. if (that.id) {
  265. res = await that.$api(`cart/${that.id}`, 'GET', {});
  266. if (res.errcode == '0') {
  267. let obj = {
  268. list: [...list, ...res.data.list],
  269. total: that.$plus(that.cartNum.total, res.data.total),
  270. }
  271. let cart = await that.$api(`cart/${res.data._id}`, 'POST', obj);
  272. if (cart.errcode == '0') {
  273. uni.navigateTo({
  274. url: `/pagesHome/order/add?id=${cart.data._id}&order=${that.order}`
  275. })
  276. }
  277. }
  278. } else {
  279. let obj = {
  280. list: list,
  281. total: that.cartNum.total,
  282. table: '63dc6a6b6a22ff30c8a11470'
  283. }
  284. res = await that.$api(`cart`, 'POST', obj);
  285. if (res.errcode == '0') {
  286. uni.navigateTo({
  287. url: `/pagesHome/order/index?id=${res.data._id}`
  288. })
  289. }
  290. }
  291. }
  292. },
  293. //清空购物车
  294. toDelete() {
  295. const that = this;
  296. for (let val of that.typeList) val.num = 0
  297. that.$set(that, `buyList`, [])
  298. that.$set(that.cartNum, `num`, 0)
  299. that.$set(that.cartNum, `total`, 0)
  300. that.searchMarket()
  301. that.$refs.specShow.close();
  302. },
  303. // 左侧一级选择
  304. toChange(index, e) {
  305. const that = this;
  306. that.$set(that, `marketList`, []);
  307. that.$set(that, `active`, index);
  308. that.$set(that.tags, `code`, e.code);
  309. that.searchMarket();
  310. },
  311. }
  312. }
  313. </script>
  314. <style lang="scss">
  315. .content {
  316. font-family: 12px/1 Tahoma, Helvetica, Arial, "\5b8b\4f53", sans-serif;
  317. .info {
  318. display: flex;
  319. flex-direction: column;
  320. position: relative;
  321. flex-grow: 1;
  322. .one {
  323. .one_1 {
  324. padding: 2vw;
  325. display: flex;
  326. justify-content: space-between;
  327. font-size: 18px;
  328. font-weight: bold;
  329. .name {
  330. display: flex;
  331. align-items: center;
  332. }
  333. }
  334. .one_2 {
  335. display: flex;
  336. justify-content: space-between;
  337. align-items: center;
  338. padding: 2vw;
  339. .left {
  340. text:first-child {
  341. font-size: 14px;
  342. margin: 0 1vw 0 0;
  343. font-weight: 600;
  344. }
  345. .left_1 {
  346. font-size: 12px;
  347. padding: 1vw;
  348. margin: 0 1vw 0 0;
  349. color: #FF7800;
  350. border: 1px solid #FF7800;
  351. border-radius: 2vw;
  352. }
  353. .left_2 {
  354. font-size: 12px;
  355. color: #808080;
  356. }
  357. }
  358. .right {
  359. font-size: 12px;
  360. color: #808080;
  361. }
  362. }
  363. .one_3 {
  364. padding: 2vw;
  365. text-align: center;
  366. background-color: #f1f1f1;
  367. image {
  368. width: 100%;
  369. border-radius: 2vw;
  370. height: 15vh;
  371. }
  372. }
  373. }
  374. .two {
  375. height: 61vh;
  376. display: flex;
  377. .two_1 {
  378. position: relative;
  379. width: 25vw;
  380. background-color: #fafafa;
  381. display: flex;
  382. flex-direction: column;
  383. .list {
  384. text-align: center;
  385. padding: 3vw 0;
  386. border-bottom: 1px solid #f1f1f1;
  387. .name {
  388. color: #858585;
  389. font-size: 12px;
  390. }
  391. }
  392. .listActive {
  393. background-color: #ffffff;
  394. }
  395. }
  396. .two_2 {
  397. flex-grow: 1;
  398. position: relative;
  399. display: flex;
  400. flex-direction: column;
  401. .theme {
  402. padding: 2vw;
  403. color: #858585;
  404. font-size: 12px;
  405. }
  406. .list {
  407. display: flex;
  408. width: 70vw;
  409. margin: 0 0 2vw 0;
  410. padding: 2vw;
  411. box-shadow: 0 0 5px #f1f1f1;
  412. border-radius: 5px;
  413. .img {
  414. width: 30vw;
  415. .image {
  416. width: 30vw;
  417. height: 20vw;
  418. border-radius: 5px;
  419. }
  420. }
  421. .info {
  422. display: flex;
  423. flex-direction: column;
  424. justify-content: space-between;
  425. width: 40vw;
  426. padding: 0 0 0 2vw;
  427. .name {
  428. font-size: 16px;
  429. }
  430. .spec {
  431. font-size: 12px;
  432. color: #858585;
  433. }
  434. .money {
  435. display: flex;
  436. justify-content: space-between;
  437. align-items: center;
  438. font-size: 16px;
  439. color: #FF8C00;
  440. margin: 0 0 1vw 0;
  441. }
  442. }
  443. }
  444. }
  445. }
  446. }
  447. .foot {
  448. display: flex;
  449. justify-content: space-between;
  450. padding: 0 2vw;
  451. background-color: #ffffff;
  452. border-top: 1px solid #f1f1f1;
  453. z-index: 99999 !important;
  454. .foot_1 {
  455. display: flex;
  456. justify-content: space-between;
  457. align-items: center;
  458. font-size: 14px;
  459. .type {
  460. color: #FF8C00;
  461. }
  462. .money {
  463. font-size: 25px;
  464. color: #FF8C00;
  465. }
  466. }
  467. .foot_2 {
  468. .button {
  469. background-color: #FF8C00;
  470. color: #ffffff;
  471. border-radius: 5vw;
  472. font-size: 16px;
  473. }
  474. }
  475. }
  476. .uni-popup {
  477. z-index: 9999 !important;
  478. }
  479. .popup {
  480. display: flex;
  481. flex-direction: column;
  482. width: 100vw;
  483. height: 60vh;
  484. .close {
  485. text-align: right;
  486. padding: 2vw;
  487. .name {
  488. font-size: 14px;
  489. color: #858585;
  490. }
  491. }
  492. .info_1 {
  493. position: relative;
  494. display: flex;
  495. flex-direction: column;
  496. height: 54vh;
  497. margin-bottom: 12vw;
  498. .list {
  499. display: flex;
  500. width: 96vw;
  501. margin: 0 0 2vw 0;
  502. padding: 2vw;
  503. box-shadow: 0 0 5px #f1f1f1;
  504. border-radius: 5px;
  505. .img {
  506. width: 30vw;
  507. .image {
  508. width: 30vw;
  509. height: 20vw;
  510. border-radius: 5px;
  511. }
  512. }
  513. .info {
  514. display: flex;
  515. flex-direction: column;
  516. justify-content: space-between;
  517. width: 60vw;
  518. padding: 0 0 0 2vw;
  519. .name {
  520. font-size: 16px;
  521. }
  522. .spec {
  523. font-size: 12px;
  524. color: #858585;
  525. }
  526. .money {
  527. display: flex;
  528. justify-content: space-between;
  529. align-items: center;
  530. font-size: 16px;
  531. color: #FF8C00;
  532. margin: 0 0 1vw 0;
  533. }
  534. }
  535. }
  536. }
  537. }
  538. }
  539. .scroll-view {
  540. position: absolute;
  541. top: 0;
  542. left: 0;
  543. right: 0;
  544. bottom: 0;
  545. .list-scroll-view {
  546. display: flex;
  547. flex-direction: column;
  548. }
  549. }
  550. </style>