menu.vue 7.0 KB

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