index.vue 14 KB

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