| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- <template>
- <view class="menu-box flex-justify-space">
- <scroll-view scroll-y="true" class="menu-box-left" :scroll-into-view="idMark" :scroll-with-animation='true'>
- <view class="menu-type-list-f">
- <view class="menu-type-list fs-28 box-border-box text-align-center flex-justify-center"
- v-for="(item,i) in typeList" :key="i" @click="selectType(item)"
- :class="type === item.id?'bgc-f fc-3 fw-600':'fc-6 fw-400'" :id="'scroll'+ item.id">
- {{item.name}}
- <view class="menu-type-num fc-f" v-show="item.num > 0">{{item.num > 99?'99+':item.num}}</view>
- </view>
- </view>
- </scroll-view>
- <scroll-view scroll-y="true" :scroll-with-animation='true' :scroll-into-view="idMark" @scroll="menuScroll">
- <view class="menu-box-right">
- <view class="menu-box-only" v-for="(item,i) in menuList" :key="i" :id="'scroll'+ item.type">
- <view class="mb-16 fs-32 fw-600">{{item.name}}</view>
- <view class="menu-list flex-justify-space" v-for="(info,k) in item.list" :key="k">
- <image class="info_img" :src="info.image" mode="aspectFill"></image>
- <view class="menu-list-right flex-index-css flex-justify-space">
- <view class="mb-40 text-overflow-ellipsis fs-34 fw-600">{{info.name}}</view>
- <view class="flex-justify-space align-items-flex-end">
- <view class="">
- <span class="fs-24 fw-600 fc-FB3D03">¥</span>
- <span class="fs-40 fw-b fc-FB3D03">{{info.price}}</span>
- <!-- <span class="fs-24 fc-9 fw-400 text-line-through">¥12</span> -->
- </view>
- <view class="display-flex align-items-center">
- <!-- <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> -->
- <image v-show="info.num > 0" class="wh-44" @click="addred(1,item,info)"
- src="@/static/img/takeout/j.png" mode="">
- </image>
- <view v-show="info.num > 0"
- class="right-only-right-2 text-align-center fs-28 fw-400">{{info.num}}</view>
- <image class="wh-44" src="@/static/img/takeout/add.png" @click="addred(2,item,info)"
- mode=""></image>
- <!-- <view class="right-only-right-add fw-500 text-align-center fs-36 fc-f"
- @click="addred(2,item,info)">+</view> -->
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- </template>
- <script>
- import {
- setShopIngAdd,
- setShopIngNumber,
- getShopIngList
- } from '@/api/shopping.js'
- import {
- getLaundry
- } from '@/api/category.js';
- import {
- laundryList
- } from '@/api/laundry.js';
- import tools from "@/service/tools";
- export default {
- name: 'menu-box',
- props: ['cardList'],
- data() {
- return {
- idMark: '', //滚动自适应参数
- type: 1, //分类标识
- typeList: [],
- menuList: [],
- isAJAX: false,
- cardData: {
- goods_list: [],
- total_num: 0,
- total_price: 0,
- },
- }
- },
- mounted() {
- this.getTypeList();
- },
- methods: {
- getTypeList() {
- let school_id = uni.getStorageSync('school_id');
- getLaundry({
- school_id: school_id
- }).then((res) => {
- if (res.code === 1) {
- this.typeList = res.data;
- this.type = this.typeList[0].id;
- this.idMark = 'scroll' + this.type;
- this.typeList.forEach((v) => {
- v.num = 0
- })
- laundryList({
- school_id: school_id
- }).then((res) => {
- if (res.code === 1) {
- this.menuList = res.data
- getShopIngList({
- type: 3,
- school_id: school_id
- }).then((res) => {
- if (res.code === 1) {
- this.cardData = res.data;
- if (this.cardData.goods_list.length > 0) {
- this.cardData.goods_list.forEach(v => {
- this.menuList.forEach(n => {
- n.list.forEach(t => {
- if (v.goods_id == t
- .goods_id) {
- t.num = v
- .number
- }
- })
- })
- })
- this.menuList.forEach(n => {
- n.list.forEach(t => {
- this.typeList.forEach((v) => {
- if (v.id == n
- .type) {
- v.num += t.num
- }
- })
- })
- })
- }
- }
- })
- } else {
- tools.error(res.msg)
- }
- })
- } else {
- tools.error(res.msg)
- }
- })
- },
- selectType(item) {
- if (this.type != item.id) {
- this.type = item.id;
- this.idMark = 'scroll' + item.id
- }
- },
- menuScroll() {
- let _this = this;
- let query = uni.createSelectorQuery().in(this);
- query.selectAll(".menu-box-only").boundingClientRect(data => {
- data.forEach((v) => {
- if (v.top < 329 && v.top > 0) {
- _this.idMark = v.id;
- let arr = v.id.split('scroll');
- _this.type = Number(arr[1]);
- }
- })
- }).exec();
- },
- addred(type, item, info) {
- if (this.isAJAX) {
- return
- }
- this.isAJAX = true;
- if (type === 1) {
- // 减
- let school_id = uni.getStorageSync('school_id');
- setShopIngNumber({
- type: 3,
- goods_id: info.goods_id,
- category_id: item.type,
- operation: 2,
- school_id: school_id
- }).then((res) => {
- if (res.code === 1) {
- this.isAJAX = false;
- info.num -= 1;
- this.setSub(item);
- this.$emit('relCardBuy')
- } else {
- this.isAJAX = false;
- tools.error(res.msg)
- }
- })
- } else if (type === 2) {
- // 加
- let school_id = uni.getStorageSync('school_id');
- setShopIngAdd({
- type: 3,
- goods_id: info.goods_id,
- category_id: item.type,
- school_id: school_id
- }).then((res) => {
- if (res.code === 1) {
- this.isAJAX = false;
- info.num += 1;
- this.setSub(item);
- this.$emit('relCardBuy')
- } else {
- this.isAJAX = false;
- tools.error(res.msg)
- }
- })
- }
- },
- // 设置角标
- setSub(item) {
- console.log(item);
- let num = 0;
- item.list.forEach((n) => {
- num += n.num
- })
- this.typeList.forEach((v) => {
- if (v.id == item.type) {
- v.num = num
- }
- })
- },
- },
- }
- </script>
- <style scoped lang="scss">
- .wh-44 {
- width: 44rpx;
- height: 44rpx;
- }
- .menu-box {
- height: 100%;
- .menu-box-left {
- width: 160rpx;
- height: 100%;
- background-color: #F7F8FA;
- // border-radius: 0rpx 20rpx 0 0rpx;
- .menu-type-list-f {
- width: 160rpx;
- height: 100%;
- .menu-type-list {
- width: 160rpx;
- min-height: 108rpx;
- padding: 32rpx 34rpx;
- position: relative;
- .menu-type-num {
- position: absolute;
- top: 2rpx;
- right: 8rpx;
- padding: 0 6rpx;
- min-width: 20rpx;
- height: 32rpx;
- text-align: center;
- line-height: 32rpx;
- background: #FB3D03;
- border-radius: 50%;
- }
- }
- }
- }
- .menu-box-right {
- flex: 1;
- height: 100%;
- box-sizing: border-box;
- padding: 0 12rpx 0 16rpx;
- .menu-list {
- width: 100%;
- height: 200rpx;
- margin-bottom: 40rpx;
- .info_img {
- width: 200rpx;
- height: 200rpx;
- border-radius: 12rpx;
- margin-right: 16rpx;
- }
- .menu-list-right {
- flex: 1;
- .right-only-right {
- width: 100rpx;
- height: 44rpx;
- background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
- border-radius: 12rpx;
- line-height: 44rpx;
- }
- .right-only-right-red {
- width: 44rpx;
- height: 44rpx;
- line-height: 40rpx;
- border-radius: 12rpx;
- border: 1rpx solid #41ABF5;
- color: #41ABF5;
- }
- .right-only-right-add {
- width: 44rpx;
- height: 44rpx;
- line-height: 40rpx;
- background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
- border-radius: 12rpx;
- }
- .right-only-right-2 {
- min-width: 50rpx;
- }
- }
- }
- }
- }
- </style>
|