menu.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <view class="menu-box flex-justify-space">
  3. <scroll-view scroll-y="true" class="menu-box-left" :scroll-into-view="idMark" :scroll-with-animation='true'>
  4. <view class="menu-type-list-f">
  5. <view class="menu-type-list fs-28 box-border-box text-align-center flex-justify-center"
  6. v-for="(item,i) in typeList" :key="i" @click="selectType(item)"
  7. :class="type === item.id?'bgc-f fc-3 fw-600':'fc-6 fw-400'" :id="'scroll'+ item.id">
  8. {{item.name}}
  9. <view class="menu-type-num fc-f" v-show="item.num > 0">{{item.num > 99?'99+':item.num}}</view>
  10. </view>
  11. </view>
  12. </scroll-view>
  13. <scroll-view scroll-y="true" :scroll-with-animation='true' :scroll-into-view="idMark" @scroll="menuScroll">
  14. <view class="menu-box-right">
  15. <view class="menu-box-only" v-for="(item,i) in menuList" :key="i" :id="'scroll'+ item.type">
  16. <view class="mb-16 fs-32 fw-600">{{item.name}}</view>
  17. <view class="menu-list flex-justify-space" v-for="(info,k) in item.list" :key="k">
  18. <image class="info_img" :src="info.image" mode="aspectFill"></image>
  19. <view class="menu-list-right flex-index-css flex-justify-space">
  20. <view class="mb-40 text-overflow-ellipsis fs-34 fw-600">{{info.name}}</view>
  21. <view class="flex-justify-space align-items-flex-end">
  22. <view class="">
  23. <span class="fs-24 fw-600 fc-FB3D03">¥</span>
  24. <span class="fs-40 fw-b fc-FB3D03">{{info.price}}</span>
  25. <!-- <span class="fs-24 fc-9 fw-400 text-line-through">¥12</span> -->
  26. </view>
  27. <view class="display-flex align-items-center">
  28. <!-- <view v-show="info.num > 0"
  29. class="right-only-right-red fw-500 text-align-center fs-36 fc-f"
  30. @click="addred(1,item,info)">-</view> -->
  31. <image v-show="info.num > 0" class="wh-44" @click="addred(1,item,info)"
  32. src="@/static/img/takeout/j.png" mode="">
  33. </image>
  34. <view v-show="info.num > 0"
  35. class="right-only-right-2 text-align-center fs-28 fw-400">{{info.num}}</view>
  36. <image class="wh-44" src="@/static/img/takeout/add.png" @click="addred(2,item,info)"
  37. mode=""></image>
  38. <!-- <view class="right-only-right-add fw-500 text-align-center fs-36 fc-f"
  39. @click="addred(2,item,info)">+</view> -->
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. </template>
  49. <script>
  50. import {
  51. setShopIngAdd,
  52. setShopIngNumber,
  53. getShopIngList
  54. } from '@/api/shopping.js'
  55. import {
  56. getLaundry
  57. } from '@/api/category.js';
  58. import {
  59. laundryList
  60. } from '@/api/laundry.js';
  61. import tools from "@/service/tools";
  62. export default {
  63. name: 'menu-box',
  64. props: ['cardList'],
  65. data() {
  66. return {
  67. idMark: '', //滚动自适应参数
  68. type: 1, //分类标识
  69. typeList: [],
  70. menuList: [],
  71. isAJAX: false,
  72. cardData: {
  73. goods_list: [],
  74. total_num: 0,
  75. total_price: 0,
  76. },
  77. }
  78. },
  79. mounted() {
  80. this.getTypeList();
  81. },
  82. methods: {
  83. getTypeList() {
  84. let school_id = uni.getStorageSync('school_id');
  85. getLaundry({
  86. school_id: school_id
  87. }).then((res) => {
  88. if (res.code === 1) {
  89. this.typeList = res.data;
  90. this.type = this.typeList[0].id;
  91. this.idMark = 'scroll' + this.type;
  92. this.typeList.forEach((v) => {
  93. v.num = 0
  94. })
  95. laundryList({
  96. school_id: school_id
  97. }).then((res) => {
  98. if (res.code === 1) {
  99. this.menuList = res.data
  100. getShopIngList({
  101. type: 3
  102. }).then((res) => {
  103. if (res.code === 1) {
  104. this.cardData = res.data;
  105. if (this.cardData.goods_list.length > 0) {
  106. this.cardData.goods_list.forEach(v => {
  107. this.menuList.forEach(n => {
  108. n.list.forEach(t => {
  109. if (v.goods_id == t
  110. .goods_id) {
  111. t.num = v
  112. .number
  113. }
  114. })
  115. })
  116. })
  117. this.menuList.forEach(n => {
  118. n.list.forEach(t => {
  119. this.typeList.forEach((v) => {
  120. if (v.id == n
  121. .type) {
  122. v.num += t.num
  123. }
  124. })
  125. })
  126. })
  127. }
  128. }
  129. })
  130. } else {
  131. tools.error(res.msg)
  132. }
  133. })
  134. } else {
  135. tools.error(res.msg)
  136. }
  137. })
  138. },
  139. selectType(item) {
  140. if (this.type != item.id) {
  141. this.type = item.id;
  142. this.idMark = 'scroll' + item.id
  143. }
  144. },
  145. menuScroll() {
  146. let _this = this;
  147. let query = uni.createSelectorQuery().in(this);
  148. query.selectAll(".menu-box-only").boundingClientRect(data => {
  149. data.forEach((v) => {
  150. if (v.top < 329 && v.top > 0) {
  151. _this.idMark = v.id;
  152. let arr = v.id.split('scroll');
  153. _this.type = Number(arr[1]);
  154. }
  155. })
  156. }).exec();
  157. },
  158. addred(type, item, info) {
  159. if (this.isAJAX) {
  160. return
  161. }
  162. this.isAJAX = true;
  163. if (type === 1) {
  164. // 减
  165. setShopIngNumber({
  166. type: 3,
  167. goods_id: info.goods_id,
  168. category_id: item.type,
  169. operation: 2
  170. }).then((res) => {
  171. if (res.code === 1) {
  172. this.isAJAX = false;
  173. info.num -= 1;
  174. this.setSub(item);
  175. this.$emit('relCardBuy')
  176. } else {
  177. this.isAJAX = false;
  178. tools.error(res.msg)
  179. }
  180. })
  181. } else if (type === 2) {
  182. // 加
  183. setShopIngAdd({
  184. type: 3,
  185. goods_id: info.goods_id,
  186. category_id: item.type
  187. }).then((res) => {
  188. if (res.code === 1) {
  189. this.isAJAX = false;
  190. info.num += 1;
  191. this.setSub(item);
  192. this.$emit('relCardBuy')
  193. } else {
  194. this.isAJAX = false;
  195. tools.error(res.msg)
  196. }
  197. })
  198. }
  199. },
  200. // 设置角标
  201. setSub(item) {
  202. console.log(item);
  203. let num = 0;
  204. item.list.forEach((n) => {
  205. num += n.num
  206. })
  207. this.typeList.forEach((v) => {
  208. if (v.id == item.type) {
  209. v.num = num
  210. }
  211. })
  212. },
  213. },
  214. }
  215. </script>
  216. <style scoped lang="scss">
  217. .wh-44 {
  218. width: 44rpx;
  219. height: 44rpx;
  220. }
  221. .menu-box {
  222. height: 100%;
  223. .menu-box-left {
  224. width: 160rpx;
  225. height: 100%;
  226. background-color: #F7F8FA;
  227. // border-radius: 0rpx 20rpx 0 0rpx;
  228. .menu-type-list-f {
  229. width: 160rpx;
  230. height: 100%;
  231. .menu-type-list {
  232. width: 160rpx;
  233. min-height: 108rpx;
  234. padding: 32rpx 34rpx;
  235. position: relative;
  236. .menu-type-num {
  237. position: absolute;
  238. top: 2rpx;
  239. right: 8rpx;
  240. padding: 0 6rpx;
  241. min-width: 20rpx;
  242. height: 32rpx;
  243. text-align: center;
  244. line-height: 32rpx;
  245. background: #FB3D03;
  246. border-radius: 50%;
  247. }
  248. }
  249. }
  250. }
  251. .menu-box-right {
  252. flex: 1;
  253. height: 100%;
  254. box-sizing: border-box;
  255. padding: 0 12rpx 0 16rpx;
  256. .menu-list {
  257. width: 100%;
  258. height: 200rpx;
  259. margin-bottom: 40rpx;
  260. .info_img {
  261. width: 200rpx;
  262. height: 200rpx;
  263. border-radius: 12rpx;
  264. margin-right: 16rpx;
  265. }
  266. .menu-list-right {
  267. flex: 1;
  268. .right-only-right {
  269. width: 100rpx;
  270. height: 44rpx;
  271. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  272. border-radius: 12rpx;
  273. line-height: 44rpx;
  274. }
  275. .right-only-right-red {
  276. width: 44rpx;
  277. height: 44rpx;
  278. line-height: 40rpx;
  279. border-radius: 12rpx;
  280. border: 1rpx solid #41ABF5;
  281. color: #41ABF5;
  282. }
  283. .right-only-right-add {
  284. width: 44rpx;
  285. height: 44rpx;
  286. line-height: 40rpx;
  287. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  288. border-radius: 12rpx;
  289. }
  290. .right-only-right-2 {
  291. min-width: 50rpx;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. </style>