index.vue 14 KB

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