menu.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. school_id: school_id
  103. }).then((res) => {
  104. if (res.code === 1) {
  105. this.cardData = res.data;
  106. if (this.cardData.goods_list.length > 0) {
  107. this.cardData.goods_list.forEach(v => {
  108. this.menuList.forEach(n => {
  109. n.list.forEach(t => {
  110. if (v.goods_id == t
  111. .goods_id) {
  112. t.num = v
  113. .number
  114. }
  115. })
  116. })
  117. })
  118. this.menuList.forEach(n => {
  119. n.list.forEach(t => {
  120. this.typeList.forEach((v) => {
  121. if (v.id == n
  122. .type) {
  123. v.num += t.num
  124. }
  125. })
  126. })
  127. })
  128. }
  129. }
  130. })
  131. } else {
  132. tools.error(res.msg)
  133. }
  134. })
  135. } else {
  136. tools.error(res.msg)
  137. }
  138. })
  139. },
  140. selectType(item) {
  141. if (this.type != item.id) {
  142. this.type = item.id;
  143. this.idMark = 'scroll' + item.id
  144. }
  145. },
  146. menuScroll() {
  147. let _this = this;
  148. let query = uni.createSelectorQuery().in(this);
  149. query.selectAll(".menu-box-only").boundingClientRect(data => {
  150. data.forEach((v) => {
  151. if (v.top < 329 && v.top > 0) {
  152. _this.idMark = v.id;
  153. let arr = v.id.split('scroll');
  154. _this.type = Number(arr[1]);
  155. }
  156. })
  157. }).exec();
  158. },
  159. addred(type, item, info) {
  160. if (this.isAJAX) {
  161. return
  162. }
  163. this.isAJAX = true;
  164. if (type === 1) {
  165. // 减
  166. let school_id = uni.getStorageSync('school_id');
  167. setShopIngNumber({
  168. type: 3,
  169. goods_id: info.goods_id,
  170. category_id: item.type,
  171. operation: 2,
  172. school_id: school_id
  173. }).then((res) => {
  174. if (res.code === 1) {
  175. this.isAJAX = false;
  176. info.num -= 1;
  177. this.setSub(item);
  178. this.$emit('relCardBuy')
  179. } else {
  180. this.isAJAX = false;
  181. tools.error(res.msg)
  182. }
  183. })
  184. } else if (type === 2) {
  185. // 加
  186. let school_id = uni.getStorageSync('school_id');
  187. setShopIngAdd({
  188. type: 3,
  189. goods_id: info.goods_id,
  190. category_id: item.type,
  191. school_id: school_id
  192. }).then((res) => {
  193. if (res.code === 1) {
  194. this.isAJAX = false;
  195. info.num += 1;
  196. this.setSub(item);
  197. this.$emit('relCardBuy')
  198. } else {
  199. this.isAJAX = false;
  200. tools.error(res.msg)
  201. }
  202. })
  203. }
  204. },
  205. // 设置角标
  206. setSub(item) {
  207. console.log(item);
  208. let num = 0;
  209. item.list.forEach((n) => {
  210. num += n.num
  211. })
  212. this.typeList.forEach((v) => {
  213. if (v.id == item.type) {
  214. v.num = num
  215. }
  216. })
  217. },
  218. },
  219. }
  220. </script>
  221. <style scoped lang="scss">
  222. .wh-44 {
  223. width: 44rpx;
  224. height: 44rpx;
  225. }
  226. .menu-box {
  227. height: 100%;
  228. .menu-box-left {
  229. width: 160rpx;
  230. height: 100%;
  231. background-color: #F7F8FA;
  232. // border-radius: 0rpx 20rpx 0 0rpx;
  233. .menu-type-list-f {
  234. width: 160rpx;
  235. height: 100%;
  236. .menu-type-list {
  237. width: 160rpx;
  238. min-height: 108rpx;
  239. padding: 32rpx 34rpx;
  240. position: relative;
  241. .menu-type-num {
  242. position: absolute;
  243. top: 2rpx;
  244. right: 8rpx;
  245. padding: 0 6rpx;
  246. min-width: 20rpx;
  247. height: 32rpx;
  248. text-align: center;
  249. line-height: 32rpx;
  250. background: #FB3D03;
  251. border-radius: 50%;
  252. }
  253. }
  254. }
  255. }
  256. .menu-box-right {
  257. flex: 1;
  258. height: 100%;
  259. box-sizing: border-box;
  260. padding: 0 12rpx 0 16rpx;
  261. .menu-list {
  262. width: 100%;
  263. height: 200rpx;
  264. margin-bottom: 40rpx;
  265. .info_img {
  266. width: 200rpx;
  267. height: 200rpx;
  268. border-radius: 12rpx;
  269. margin-right: 16rpx;
  270. }
  271. .menu-list-right {
  272. flex: 1;
  273. .right-only-right {
  274. width: 100rpx;
  275. height: 44rpx;
  276. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  277. border-radius: 12rpx;
  278. line-height: 44rpx;
  279. }
  280. .right-only-right-red {
  281. width: 44rpx;
  282. height: 44rpx;
  283. line-height: 40rpx;
  284. border-radius: 12rpx;
  285. border: 1rpx solid #41ABF5;
  286. color: #41ABF5;
  287. }
  288. .right-only-right-add {
  289. width: 44rpx;
  290. height: 44rpx;
  291. line-height: 40rpx;
  292. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  293. border-radius: 12rpx;
  294. }
  295. .right-only-right-2 {
  296. min-width: 50rpx;
  297. }
  298. }
  299. }
  300. }
  301. }
  302. </style>