menu.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. getLaundry().then((res)=>{
  67. if(res.code === 1){
  68. this.typeList = res.data;
  69. this.type = this.typeList[0].id;
  70. this.idMark = 'scroll'+ this.type;
  71. this.typeList.forEach((v)=>{
  72. v.num = 0
  73. })
  74. laundryList().then((res)=>{
  75. if(res.code === 1){
  76. this.menuList = res.data
  77. getShopIngList({type:3}).then((res)=>{
  78. if(res.code === 1){
  79. this.cardData = res.data;
  80. if(this.cardData.goods_list.length > 0){
  81. this.cardData.goods_list.forEach(v=>{
  82. this.menuList.forEach(n=>{
  83. n.list.forEach(t=>{
  84. if(v.goods_id == t.goods_id){
  85. t.num = v.number
  86. }
  87. })
  88. })
  89. })
  90. this.menuList.forEach(n=>{
  91. n.list.forEach(t=>{
  92. this.typeList.forEach((v)=>{
  93. if(v.id == n.type){
  94. v.num += t.num
  95. }
  96. })
  97. })
  98. })
  99. }
  100. }
  101. })
  102. }
  103. })
  104. }
  105. })
  106. },
  107. selectType(item){
  108. if(this.type != item.id){
  109. this.type = item.id;
  110. this.idMark = 'scroll'+ item.id
  111. }
  112. },
  113. menuScroll(){
  114. let _this = this;
  115. let query = uni.createSelectorQuery().in(this);
  116. query.selectAll(".menu-box-only").boundingClientRect(data=>{
  117. data.forEach((v)=>{
  118. if(v.top < 329&&v.top>0){
  119. _this.idMark = v.id;
  120. let arr = v.id.split('scroll');
  121. _this.type = Number(arr[1]);
  122. }
  123. })
  124. }).exec();
  125. },
  126. addred(type,item,info){
  127. if(this.isAJAX){
  128. return
  129. }
  130. this.isAJAX = true;
  131. if(type === 1){
  132. // 减
  133. setShopIngNumber({type:3,goods_id:info.goods_id,category_id:item.type,operation:2}).then((res)=>{
  134. if(res.code === 1){
  135. this.isAJAX = false;
  136. info.num -= 1;
  137. this.setSub(item);
  138. this.$emit('relCardBuy')
  139. }else{
  140. this.isAJAX = false;
  141. tools.error(res.msg)
  142. }
  143. })
  144. }else if(type === 2){
  145. // 加
  146. setShopIngAdd({type:3,goods_id:info.goods_id,category_id:item.type}).then((res)=>{
  147. if(res.code === 1){
  148. this.isAJAX = false;
  149. info.num += 1;
  150. this.setSub(item);
  151. this.$emit('relCardBuy')
  152. }else{
  153. this.isAJAX = false;
  154. tools.error(res.msg)
  155. }
  156. })
  157. }
  158. },
  159. // 设置角标
  160. setSub(item){
  161. console.log(item);
  162. let num = 0;
  163. item.list.forEach((n)=>{
  164. num += n.num
  165. })
  166. this.typeList.forEach((v)=>{
  167. if(v.id == item.type){
  168. v.num = num
  169. }
  170. })
  171. },
  172. },
  173. }
  174. </script>
  175. <style scoped lang="scss">
  176. .menu-box{
  177. height: 100%;
  178. .menu-box-left{
  179. width: 176rpx;
  180. height: 100%;
  181. background-color: #F7F8FA;
  182. border-radius: 0rpx 20rpx 0 0rpx;
  183. .menu-type-list-f{
  184. width: 176rpx;
  185. height: 100%;
  186. .menu-type-list{
  187. width: 176rpx;
  188. min-height: 10rpx;
  189. box-sizing: border-box;
  190. padding: 14rpx 32rpx;
  191. position: relative;
  192. .menu-type-num{
  193. position: absolute;
  194. top: 2rpx;
  195. right: 8rpx;
  196. padding: 0 6rpx;
  197. min-width: 20rpx;
  198. height: 32rpx;
  199. text-align: center;
  200. line-height: 32rpx;
  201. background: #FB3D03;
  202. border-radius: 50%;
  203. }
  204. }
  205. }
  206. }
  207. .menu-box-right{
  208. flex: 1;
  209. height: 100%;
  210. box-sizing: border-box;
  211. padding: 0 16rpx;
  212. .menu-list{
  213. width: 100%;
  214. height: 200rpx;
  215. margin-bottom: 40rpx;
  216. image{
  217. width: 200rpx;
  218. height: 200rpx;
  219. border-radius: 12rpx;
  220. margin-right: 16rpx;
  221. }
  222. .menu-list-right{
  223. flex: 1;
  224. .right-only-right{
  225. width: 100rpx;
  226. height: 44rpx;
  227. background: linear-gradient( 117deg, #57CAFF 0%, #41ABF5 100%);
  228. border-radius: 12rpx;
  229. line-height: 44rpx;
  230. }
  231. .right-only-right-red{
  232. width: 44rpx;
  233. height: 44rpx;
  234. line-height: 40rpx;
  235. border-radius: 12rpx;
  236. border: 1rpx solid #41ABF5;
  237. color: #41ABF5;
  238. }
  239. .right-only-right-add{
  240. width: 44rpx;
  241. height: 44rpx;
  242. line-height: 40rpx;
  243. background: linear-gradient( 117deg, #57CAFF 0%, #41ABF5 100%);
  244. border-radius: 12rpx;
  245. }
  246. .right-only-right-2{
  247. min-width: 50rpx;
  248. }
  249. }
  250. }
  251. }
  252. }
  253. </style>