index.vue 14 KB

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