| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606 |
- <template>
- <view class="menu-box display-flex">
- <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-26 box-border-box align-items-center flex-justify-center"
- v-for="(item,i) in categoryData" :key="i" @click="selectType(item)"
- :class="type === item.type?'bgc-f fc-3 fw-600':'fc-6 fw-400'" :id="'scroll'+ item.type">
- {{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 categoryData" :key="i" :id="'scroll'+ item.type">
- <view class="mb-32 fs-30">{{item.name}}</view>
- <view class="menu-list flex-justify-space" v-for="(info,k) in item.list" :key="k">
- <image class="flex-shrink0 goods_img" :src="info.goods_image" mode="scaleToFill"></image>
- <view class="menu-list-right">
- <view class="mb-4 goods-name text-overflow-ellipsis fs-34 fw-600">{{info.goods_name}}</view>
- <view class="mb-20 fw-400 fc-9 fs-24">月销{{info.sales}}</view>
- <view class="flex-justify-space align-items-flex-end">
- <view class="">
- <span class="fs-24 fw-400 fc-FB3D03">¥</span>
- <span
- class="fs-40 fw-b fc-FB3D03">{{info.seckill_money>0?info.seckill_money:info.price}}</span>
- <view class="">
- <span class="fs-24 fc-9 fw-400 text-line-through">¥{{info.line_price}}</span>
- </view>
- </view>
- <view class="display-flex align-items-center" v-if="info.spec_type == 1">
- <image v-show="info.num > 0" class="wh-44" @click="addred(1,i,k,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,i,k,info)"
- mode=""></image>
- </view>
- <view v-else class="right-only-right text-align-center fw-600 fs-28 fc-f"
- @click="addred(3,i,k,info)">选规格</view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
- <uni-popup ref="popupGG" type="bottom">
- <view class="gg-box flex-index-css">
- <view class="flex-justify-space box-border-box p-32">
- <view class="fs-32 fw-500 fc-0">商品详情规格</view>
- <view class="" @click="addred(4)">
- <uni-icons type="closeempty" size="20"></uni-icons>
- </view>
- </view>
- <view class="goods-info flex-justify-space mb-32 box-border-box plr-32">
- <image v-if="popData.goodsItem.goods_image" :src="popData.goodsItem.goods_image" mode="scaleToFill">
- </image>
- <view class="flex-1">
- <view style="width: 446rpx;" class="fw-600 fs-34 text-overflow-ellipsis-one">
- {{popData.goodsItem.goods_name}}
- </view>
- <view class="fw-400 fc-9 fs-24">月销{{popData.goodsItem.sales}}</view>
- </view>
- </view>
- <view class="scroll-view-css box-border-box plr-32">
- <view class="" v-for="(item,i) in popData.spec_attr" :key="i">
- <view class="fs-32 fw-500 fc-0 mb-32">{{item.group_name}}</view>
- <view class="flex-wrap-wrap">
- <view class="spec-item text-align-center fs-28"
- :class="popData.spec_ids.indexOf(info.item_id)>=0?'s-item':'n-item'"
- v-for="(info,k) in item.spec_items" :key="k" @click="selectSpec(info,i)">
- {{info.spec_value}}
- </view>
- </view>
- </view>
- </view>
- <view class="pop-buttom box-border-box plr-32">
- <view class="flex-justify-space mb-28">
- <view class="pop-buttom-left">
- <view class="">
- <span class="fw-600 fs-32 fc-ED301D">¥</span>
- <span class="fw-600 fs-48 fc-ED301D">{{popData.price}}</span>
- </view>
- <view class="">
- <span class="fw-400 fs-24 fc-9">已选规格:</span>
- <span class="fw-400 fs-24">{{popData.spec_name.join(';')}}</span>
- </view>
- </view>
- <view class="display-flex align-items-center">
- <image class="wh-44" @click.stop="setSpecNum(1)" src="@/static/img/takeout/j.png" mode="">
- </image>
- <view class="right-only-right-2 text-align-center fs-28 fw-400">{{popData.num}}</view>
- <image class="wh-44" src="@/static/img/takeout/add.png" @click.stop="setSpecNum(2)" mode="">
- </image>
- </view>
- </view>
- <view class="pop-buttom-2 text-align-center fs-32 fw-600 fc-f" @click="addred(4)">选好了</view>
- </view>
- </view>
- </uni-popup>
- </view>
- </template>
- <script>
- import tools from "@/service/tools";
- import {
- shopCategory,
- shopGoods,
- shopGoodsSpec
- } from "@/api/shop";
- import {
- getShopIngList,
- setShopIngAdd,
- setShopIngDel,
- setShopIngNumber
- } from "@/api/shopping";
- export default {
- name: 'menu-box',
- props: {
- 'shop_id': {
- default: 0
- }
- },
- data() {
- return {
- idMark: '', //滚动自适应参数
- type: 1, //分类标识
- typeList: [],
- categoryData: [],
- menuList: [],
- cartData: {
- total_price: 0,
- total_num: 0,
- total_goods_money: 0,
- pack_price: 0,
- must_category: 0,
- is_place_order: 0,
- err_msg: 0,
- goods_list: [],
- },
- isAjax: false,
- operate_id: '',
- popData: {
- goodsItem: {},
- price: '0.00',
- line_price: '',
- num: 0,
- goods_id: '',
- spec_key: '',
- goods_spec_id: '',
- spec_name: [],
- spec_ids: [],
- spec_list: [],
- spec_attr: [],
- },
- }
- },
- watch: {
- 'shop_id': function() {
- this.getShopGoods();
- }
- },
- mounted() {
- this.operate_id = uni.getStorageSync('operate_id')
- this.getShopGoods();
- this.getShopIngList(true);
- },
- methods: {
- setSpecNum(type) {
- console.log(this.popData.goods_spec_id)
- if (!this.popData.goods_spec_id) {
- tools.error('请选择规格')
- return;
- }
- if (this.isAjax) {
- return
- }
- this.isAjax = true
- if (type === 1) {
- // 减
- if (this.popData.num > 0) {
- --this.popData.num;
- } else {
- this.isAjax = false
- return
- }
- } else {
- // 加
- ++this.popData.num;
- }
- let cartKey = this.cartData.goods_list.findIndex(row => this.popData.goods_spec_id === row.goods_spec_id)
- console.log(cartKey)
- console.log(type === 2 && cartKey < 0)
- if (type === 2 && cartKey < 0) {
- this.setShopIngAdd(this.popData.goods_id, this.popData.goodsItem.category_id, this.popData
- .goods_spec_id)
- } else {
- this.setShopIngNumber(this.popData.goods_id, this.popData.goodsItem.category_id, type, this.popData
- .goods_spec_id)
- }
- },
- getShopGoodsSpec(item) {
- shopGoodsSpec({
- 'goods_id': item.goods_id
- }).then(res => {
- this.popData.goodsItem = item
- if (this.popData.goods_id !== item.goods_id) {
- this.popData.goods_id = item.goods_id
- this.popData.spec_name = []
- this.popData.price = '0.00'
- this.popData.line_price = ''
- this.popData.spec_key = ''
- this.popData.num = 0
- this.popData.spec_ids = []
- }
- this.popData.spec_list = res.data.spec_list
- this.popData.spec_attr = res.data.spec_attr
- this.$refs.popupGG.open();
- this.setGoodsSpecPrice()
- this.isAjax = false
- }).catch(() => {
- tools.error('规格信息异常')
- this.isAjax = false
- })
- },
- setGoodsSpecPrice() {
- if (this.popData.spec_ids.length > 0) {
- let spec_ids = JSON.parse(JSON.stringify(this.popData.spec_ids))
- spec_ids.sort((a, b) => a - b);
- let spec_key = spec_ids.join('_')
- this.popData.spec_key = spec_key
- console.log(this.popData.spec_list[spec_key])
- if (this.popData.spec_list[spec_key] !== undefined) {
- this.popData.price = this.popData.spec_list[spec_key].seckill_money > 0 ? this.popData.spec_list[
- spec_key].seckill_money : this.popData.spec_list[spec_key].price
- this.popData.line_price = this.popData.spec_list[spec_key].line_price
- this.popData.goods_spec_id = this.popData.spec_list[spec_key].goods_spec_id + ''
- let cartKey = this.cartData.goods_list.findIndex(row => this.popData.goods_spec_id === row
- .goods_spec_id)
- if (cartKey >= 0) {
- this.popData.num = this.cartData.goods_list[cartKey].goods_number
- }
- }
- }
- },
- setShopIngList(cartData) {
- this.cartData = cartData
- this.setGoodsNum()
- },
- getShopIngList(isStart) {
- getShopIngList({
- 'shop_id': this.shop_id,
- }).then(res => {
- if (res.code === 1) {
- this.cartData = res.data
- this.$emit('setCartData', this.cartData)
- if (isStart) this.setGoodsNum()
- }
- })
- },
- setGoodsNum() {
- if (this.cartData.goods_list.length > 0) {
- this.cartData.goods_list.forEach(item => {
- this.categoryData.forEach(categoryItem => {
- if (categoryItem.type === item.category_id) {
- categoryItem.list.forEach(goodsItem => {
- console.log(item.goods_id, goodsItem.goods_id)
- if (item.goods_id === goodsItem.goods_id) {
- goodsItem.num = item.goods_number * 1
- }
- })
- }
- })
- })
- } else {
- //购物车数据清除
- this.categoryData.forEach(categoryItem => {
- categoryItem.list.forEach(goodsItem => {
- goodsItem.num = 0
- })
- })
- }
- },
- getShopGoods() {
- if (this.shop_id < 0 || !this.operate_id) {
- return;
- }
- shopGoods({
- 'shop_id': this.shop_id,
- operate_id: this.operate_id,
- }).then(res => {
- if (res.code === 1) {
- this.categoryData = res.data
- if (this.categoryData.length > 0) {
- this.selectType(this.categoryData[0])
- }
- this.categoryData.forEach(categoryItem => {
- categoryItem.list.forEach(goodsItem => {
- goodsItem.payNum = 0
- goodsItem.spec = []
- })
- })
- // console.log(res)
- }
- })
- },
- selectType(item) {
- if (this.type != item.type) {
- this.type = item.type;
- this.idMark = 'scroll' + item.type
- }
- },
- 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, i, k, item) {
- if (this.isAjax) {
- return
- }
- this.isAjax = true
- if (type === 1) {
- // 减
- if (item.num > 0) {
- --item.num;
- this.setSub(item, type);
- } else {
- this.isAjax = false
- }
- } else if (type === 2) {
- // 加
- if (item.is_infinite === 1 || item.stock > item.num) {
- ++item.num;
- this.setSub(item, type);
- } else {
- this.isAjax = false
- }
- // this.menuList[i].list[k].num += 1;
- // this.setSub(item);
- } else if (type === 3) {
- // 选规格
- this.getShopGoodsSpec(item)
- } else {
- this.$refs.popupGG.close();
- this.isAjax = false
- }
- },
- setSub(item, type) {
- let cartKey = this.cartData.goods_list.findIndex(row => row.goods_id === item.goods_id)
- if (type === 2 && cartKey < 0) {
- this.setShopIngAdd(item.goods_id, item.category_id, '')
- } else {
- this.setShopIngNumber(item.goods_id, item.category_id, type, '')
- }
- },
- setShopIngAdd(goodsId, categoryId, goodsSpecId) {
- setShopIngAdd({
- 'type': 1,
- 'goods_id': goodsId,
- 'shop_id': this.shop_id,
- 'category_id': categoryId,
- 'goods_spec_id': goodsSpecId,
- }).then(res => {
- this.isAjax = false
- this.getShopIngList()
- }).catch(() => {
- this.isAjax = false
- })
- },
- setShopIngNumber(goodsId, categoryId, operation, goodsSpecId) {
- setShopIngNumber({
- 'type': 1,
- 'goods_id': goodsId,
- 'shop_id': this.shop_id,
- 'category_id': categoryId,
- 'goods_spec_id': goodsSpecId,
- 'operation': operation === 2 ? 1 : 2,
- }).then(res => {
- this.isAjax = false
- this.getShopIngList()
- }).catch(() => {
- this.isAjax = false
- })
- },
- setShopIngDel() {},
- // -------弹窗选择规格-----------
- selectSpec(info, groupKey) {
- let specKey = this.popData.spec_ids.indexOf(info.item_id)
- if (specKey >= 0) {
- this.popData.spec_ids.splice(specKey, 1)
- this.popData.spec_name.splice(specKey, 1)
- } else {
- this.popData.spec_ids.push(info.item_id)
- this.popData.spec_name.push(info.spec_value)
- for (const attrKey in this.popData.spec_attr[groupKey].spec_items) {
- if (this.popData.spec_attr[groupKey].spec_items[attrKey].item_id !== info.item_id) {
- let oldKey = this.popData.spec_ids.indexOf(this.popData.spec_attr[groupKey].spec_items[attrKey]
- .item_id)
- if (oldKey >= 0) {
- this.popData.spec_ids.splice(oldKey, 1)
- this.popData.spec_name.splice(oldKey, 1)
- }
- }
- }
- }
- // this.spec_ids = this.popData.spec_list.join('_')
- this.setGoodsSpecPrice()
- },
- },
- }
- </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: 18rpx 28rpx;
- 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;
- width: 100%;
- height: 100%;
- padding: 16rpx 12rpx 16rpx 16rpx;
- box-sizing: border-box;
- .menu-list {
- width: 100%;
- // height: 200rpx;
- margin-bottom: 40rpx;
- .goods_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;
- }
- }
- }
- }
- .gg-box {
- width: 750rpx;
- height: 1208rpx;
- background: #FFFFFF;
- border-radius: 24rpx 24rpx 0rpx 0rpx;
- .goods-info {
- border-bottom: 1rpx solid #EEEEEE;
- image {
- width: 170rpx;
- height: 160rpx;
- border-radius: 8rpx;
- margin-right: 22rpx;
- margin-bottom: 32rpx;
- }
- }
- .pop-buttom {
- width: 100%;
- height: 250rpx;
- box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(51, 51, 51, 0.1);
- .pop-buttom-left {
- padding-top: 12rpx;
- }
- .pop-buttom-2 {
- width: 100%;
- height: 96rpx;
- line-height: 96rpx;
- background: #41ABF5;
- border-radius: 200rpx
- }
- .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;
- }
- }
- .spec-item {
- width: 210rpx;
- height: 66rpx;
- line-height: 66rpx;
- box-sizing: border-box;
- border-radius: 12rpx;
- margin: 0 26rpx 26rpx 0;
- }
- .spec-item:nth-child(3) {
- margin-right: 0rpx !important;
- }
- .s-item {
- background-color: #ECF7FE;
- border: 2rpx solid #41ABF5;
- color: #41ABF5;
- }
- .n-item {
- border: 2rpx solid #EEEEEE;
- color: #000;
- }
- }
- }
- .goods-name {
- max-width: 310rpx;
- }
- </style>
|