| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600 |
- <template>
- <view class="u-wrap" :style="$isEmpty(goods)?'background-color: #FFFFFF;':''">
- <block v-show="!isLoading">
- <view class="goods_empty" v-if="$isEmpty(goods)">
- <image src="/pagesD/static/icon/goods_empty.png" mode=""></image>
- <text style="font-weight: 400;">该商铺还未上架商品</text>
- </view>
- <block v-else>
- <view class="u-search-box">
- <view class="nav">
- <view class="header">
- <view class="left overflow-hidden">
- <view class="flex align-center overflow-hidden" v-if="takeType == takeTypeGlobal.delivery">
- <image src="/pagesD/static/icon/location1.png" style="width: 30rpx; height: 30rpx;"
- class="margin-right-10">
- </image>
- <text v-if="$isEmpty(vuex_userId)" @tap="showLogin">去登录</text>
- <view class="" v-else @click="$jump('/pagesD/pages/address/address')">
- <text v-if="$isEmpty(address)">请完善地址信息</text>
- <view style="margin-right: 20rpx;" v-else>
- <text class="text-cut-1">{{address.address}}</text>
- </view>
- </view>
- </view>
- <view class="flex align-center overflow-hidden" v-else>
- <image src="/pagesD/static/icon/shop2.png" style="width: 30rpx; height: 30rpx;"
- class="margin-right-10">
- </image>
- <text style="font-size: 36rpx;font-weight: 800;">{{appProperties.shopName}}</text>
- </view>
- </view>
- <view @click="modalCheckedShow" class="cu-btn round sm" style="font-size: 24rpx;">
- <text class="center">{{takeType.substring(2,4)}}</text>
- <text class="cuIcon-order center text-bold"
- style="transform: rotate(90deg);margin-left: 6rpx;"></text>
- </view>
- </view>
- <view class="bg-white" v-if="$isNotEmpty(appProperties.shopNotice)">
- <u-notice-bar mode="horizontal" :list="[appProperties.shopNotice]"></u-notice-bar>
- </view>
- </view>
- </view>
- <view class="u-menu-wrap">
- <scroll-view scroll-y scroll-with-animation class="u-tab-view menu-scroll-view" :scroll-top="scrollTop"
- :scroll-into-view="itemId">
- <view v-for="(item,index) in goods" :key="index" class="u-tab-item"
- :class="[current == index ? 'u-tab-item-active' : '']" @tap.stop="swichMenu(index)">
- <text class="u-line-1">{{item.goodsCategoryName}}</text>
- </view>
- </scroll-view>
- <scroll-view :scroll-top="scrollRightTop" scroll-y scroll-with-animation class="right-box"
- @scroll="rightScroll">
- <view class="page-view">
- <view class="class-item" :id="'item' + index" v-for="(item , index) in goods" :key="index">
- <view class="item-title">
- <text>{{item.goodsCategoryName}}</text>
- </view>
- <view class="item-container">
- <view class="thumb-box" v-for="(goods, index1) in item.goodsList" :key="index1">
- <image @click="$util.preview(goods.image)" class="item-menu-image" :src="goods.image" mode=""></image>
- <view class="item-content">
- <view class="name">{{goods.name}}</view>
- <view class="tips">
- {{ goods.description && goods.description != '' ? goods.description : goods.name }}
- </view>
- <view class="price_and_action">
- <text class="price">¥{{ goods.defaultPrice / 100 }}</text>
- <!-- 商品没有下架 -->
- <view v-if="goods.isSell">
- <!-- 要选商品规格详细信息 -->
- <view class="btn-group"
- v-if="goods.goodsPropertyVos && goods.goodsPropertyVos.length">
- <button type="primary" class="btn property_btn" hover-class="none"
- size="mini" @tap="showGoodDetailModal(goods)">
- 选规格
- </button>
- <view class="dot" v-show="goodsCartNum(goods.id)">
- {{ goodsCartNum(goods.id) }}
- </view>
- </view>
- <!-- 可以直接添加,不用选择商品属性 -->
- <view class="btn-group" v-else>
- <button type="default" v-show="goodsCartNum(goods.id)" plain
- class="btn reduce_btn" size="mini" hover-class="none"
- @tap="handleReduceFromCart(goods)">
- <view class="iconfont iconsami-select"></view>
- </button>
- <view class="number" v-show="goodsCartNum(goods.id)">
- {{ goodsCartNum(goods.id) }}
- </view>
- <button type="primary" class="btn add_btn" size="min" hover-class="none"
- @tap="handleAddToCart(goods)">
- <view class="iconfont iconadd-select"></view>
- </button>
- </view>
- </view>
- <!-- 已经下架了 -->
- <view v-else>
- <view class="btn-group">
- <button type="primary" disabled class="btn property_btn"
- style="text-decoration: line-through;background-color: rgba(255, 148, 71,.6);"
- size="mini">
- 已售空
- </button>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- </block>
- </block>
-
- <view class="" v-show="!isLoading && $isNotEmpty(goods)">
- <!-- 购物车栏 begin -->
- <view class="cart-box" v-if="cart && cart.length">
- <view class="mark" @tap="cartPopupVisible = !cartPopupVisible">
- <image src="/pagesD/static/icon/cart.png" class="cart-img"></image>
- <view class="tag">{{ getCartGoodsNumber }}</view>
- </view>
- <view style="color: #202224;font-size: 34rpx;font-weight: 800;" class="flex-sub" @tap="cartPopupVisible = !cartPopupVisible">¥{{ getCartGoodsPrice / 100 }}</view>
- <view v-if="!appProperties.shopStatus"><button type="primary" class="pay-btn" disabled>商家休息中</button>
- </view>
- <view v-else-if="isBusinessTime">
- <button :style="!disabledPay?'background-color: #FF9447;':''" type="primary" class="pay-btn"
- @tap="toPay()"
- :disabled="disabledPay">{{ disabledPay ? `差${spread / 100}元起送` : '去结算' }}</button>
- </view>
- <view v-else><button type="primary" class="pay-btn" disabled>未在营业时段</button></view>
- </view>
- <!-- 购物车栏 end -->
- <!-- 商品详情模态框 begin -->
- <modal :show="goodDetailModalVisible" class="good-detail-modal" color="#5A5B5C" width="90%" custom
- padding="0rpx" radius="12rpx">
- <view class="cover">
- <image v-if="currentGoods.image" :src="currentGoods.image" class="image"></image>
- <view class="btn-group">
- <image src="/pagesD/static/icon/close.png" @tap="closeGoodDetailModal"></image>
- </view>
- </view>
- <scroll-view class="detail" scroll-y style="padding-bottom: 100px;">
- <view class="wrapper">
- <view class="basic">
- <view class="name">{{ currentGoods.name }}</view>
- <view class="tips">{{ currentGoods.description }}</view>
- </view>
- <!-- 商品的额外属性 -->
- <view class="properties"
- v-if="currentGoods.goodsPropertyVos && currentGoods.goodsPropertyVos.length">
- <view class="property" v-for="(goodsPropertyVo, index) in currentGoods.goodsPropertyVos"
- :key="index">
- <view class="title">
- <text class="name">
- <text v-if="goodsPropertyVo.required" style="color: red">*</text>
- {{ goodsPropertyVo.category }}
- </text>
- </view>
- <view class="values">
- <view class="value" v-for="(property, index2) in goodsPropertyVo.propertyList"
- :key="index2" :class="{ default: property.isDefault }"
- @tap="changePropertyDefault(index, index2)">
- {{ property.propertyOption }}
- {{ property.rebasePrice && property.rebasePrice >=0 ? '¥' + property.rebasePrice / 100 : property.extraPrice / 100 ? '¥' + property.extraPrice / 100 : '' }}
- </view>
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
- <view class="action">
- <!-- 价格和属性 -->
- <view class="left">
- <view class="price">¥{{ currentGoods.realPrice / 100 }}</view>
- <view class="props" v-if="getGoodSelectedProps(currentGoods)">
- {{ getGoodSelectedProps(currentGoods) }}
- </view>
- </view>
- <!-- 模态窗里面增减商品 -->
- <view class="btn-group">
- <button type="default" plain class="btn" size="mini" hover-class="none"
- @tap="changeCurrentGoodsNumber(-1)">
- <view class="iconfont iconsami-select"></view>
- </button>
- <view class="number">{{ currentGoods.number }}</view>
- <button type="primary" class="btn" size="min" hover-class="none"
- @tap="changeCurrentGoodsNumber(1)">
- <view class="iconfont iconadd-select"></view>
- </button>
- </view>
- </view>
- <view class="add-to-cart-btn" @tap="addCurrentGoodsToCart()">
- <view>确认</view>
- </view>
- </modal>
- <!-- 商品详情模态框 end -->
- <!-- 购物车详情popup -->
- <u-popup z-index="99" v-model="cartPopupVisible" mode="bottom">
- <view class="cart-popup">
- <view class="top"><text @tap="handleCartClear">清空</text></view>
- <scroll-view class="cart-list" scroll-y>
- <view class="wrapper">
- <view class="item" v-for="(goods, index) in cart" :key="index">
- <view class="left">
- <view class="name">{{ goods.name }}</view>
- <view class="props">{{ getGoodSelectedProps(goods) }}</view>
- </view>
- <view class="center">
- <text>¥{{ goods.realPrice / 100 }}</text>
- </view>
- <view class="right">
- <!-- 购物车里添加数量 -->
- <button type="default" plain size="mini" class="btn" hover-class="none"
- @tap="handleCartItemReduce(index)">
- <view class="iconfont iconsami-select"></view>
- </button>
- <view class="number">{{ goods.number }}</view>
- <!-- 购物车里减少数量 -->
- <button type="primary" class="btn" size="min" hover-class="none"
- @tap="handleCartItemAdd(index)">
- <view class="iconfont iconadd-select"></view>
- </button>
- </view>
- </view>
- <view class="item" v-if="takeType == takeTypeGlobal.package">
- <view class="left">
- <view class="name">包装费</view>
- </view>
- <view class="center">
- <text>¥{{ appProperties.packingPrice / 100 }}</text>
- </view>
- </view>
- <view class="item" v-if="takeType == takeTypeGlobal.delivery">
- <view class="left">
- <view class="name">包装费</view>
- </view>
- <view class="center">
- <text>¥{{ appProperties.packingPrice / 100 }}</text>
- </view>
- <view class="left">
- <view class="name">配送费</view>
- </view>
- <view class="center">
- <text>¥{{ appProperties.sendingPrice / 100 }}</text>
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- </u-popup>
- <!-- 购物车详情popup -->
- </view>
- <toast ref="toast"></toast>
- <login ref="login" @signIn="signIn"></login>
- <loading ref="loading" type="3" theme="2" />
- <modal-checked @confirm="modalConfirm" ref="modalChecked" :list="checkList"></modal-checked>
- </view>
- </template>
- <script>
- import login from "../../comps/login.vue"
- import modal from '../../comps/modal/modal.vue';
- import modalChecked from "../../comps/modal-checked.vue"
- import popupLayer from '../../comps/popup-layer/popup-layer.vue';
- import global from "@/assets/http/global.js"
- let _this = this
- export default {
- components: {
- modal,
- popupLayer,
- login,
- modalChecked
- },
- data() {
- return {
- isLoading: true,
- shopId: '',
- //是否有必点商品
- hasMustOrder:false,
- address: {},
- cart: [],
- takeType: "店内堂食",
- takeTypeGlobal: global.takeType,
- shopDetail: {},
- appProperties: {
- "shopName": "",
- "sendingPrice": 0, // 商家配送费
- "packingPrice": 0, // 包装费
- "sendingNeedLeastPrice": 0, // 起送需要的最低价格
- "businessStartTime": '', // 营业开始时间, 开始的点必须在结束之前
- "businessEndTime": '', // 营业结束时间
- "shopStatus": true, // 商家营业状态
- "shopNotice": '', // 公告
- },
- goods: {},
- currentCategoryName: '', // 默认分类
- goodDetailModalVisible: false, //是否饮品详情模态框
- currentGoods: {}, // 当前商品
- selectedPropertyList: [], // 当前商品的属性
- cartPopupVisible: false,
- //座位号
- seatNum: 0,
- /**
- * uview菜单begin
- */
- scrollTop: 0, //tab标题的滚动条位置
- oldScrollTop: 0,
- current: 0, // 预设当前项的值
- menuHeight: 0, // 左边菜单的高度
- menuItemHeight: 0, // 左边菜单item的高度
- itemId: '', // 栏目右边scroll-view用于滚动的id
- goods: [],
- menuItemPos: [],
- arr: [],
- scrollRightTop: 0, // 右边栏目scroll-view的滚动条高度
- timer: null, // 定时器
- /**
- * u-view菜单end
- */
- checkList: [{
- //店内堂食
- name: "扫一扫店内下单",
- icon: "/pagesD/static/icon/order.png",
- },
- {
- name: "到店自取",
- icon: "/pagesD/static/icon/pickup.png",
- }
- ]
- }
- },
- onLoad(options) {
- this.$refs.loading.showLoading()
- _this = this
- if (this.$isNotEmpty(options.q)) {
- //获取普通二维码的参数
- let params = this.$util.getUrlParams(options.q)
- this.shopId = params.shopId
- this.seatNum = params.seatNum
- }
- if (this.$isNotEmpty(options.shopId)) {
- this.shopId = options.shopId
- }
- if (this.$isNotEmpty(options.seatNum)) {
- this.seatNum = options.seatNum
- }
- this.init()
- },
- onShow() {
- this.address = this.$util.getBackParams('addressData')
- if (this.$isEmpty(this.address)) {
- this.fetchAddress()
- }
- },
- onReady() {
- this.getMenuItemTop()
- },
- computed: {
- isBusinessTime: {
- get() {
- return this.timeRange(this.appProperties.businessStartTime, this.appProperties.businessEndTime)
- }
- },
- // 计算单个饮品添加到购物车的数量
- goodsCartNum() {
- return id =>
- this.cart.reduce((acc, cur) => {
- if (cur.id === id) {
- return (acc += cur.number);
- }
- return acc;
- }, 0);
- },
- // 计算该类商品的购买总数
- menuCartNum() {
- return goodsCategoryName =>
- this.cart.reduce((acc, cur) => {
- if (cur.goodsCategoryName === goodsCategoryName) {
- return (acc += cur.number);
- }
- return acc;
- }, 0);
- },
- // 计算购物车总数
- getCartGoodsNumber() {
- return this.cart.reduce((acc, cur) => acc + cur.number, 0);
- },
- // 计算购物车总价,
- getCartGoodsPrice() {
- let totalPrice = 0;
- this.cart.forEach(goods => {
- totalPrice += goods.realPrice * goods.number;
- });
- //如果是到店自取,要计算包装费
- if (this.takeType == this.takeTypeGlobal.package) {
- totalPrice += this.appProperties.packingPrice
- }
- //如果是商家配送,要计算配送费和包装费
- if (this.takeType == this.takeTypeGlobal.delivery) {
- totalPrice += this.appProperties.packingPrice + this.appProperties.sendingPrice;
- }
- return totalPrice;
- }, // 是否达到起送价
- disabledPay() {
- return this.takeType == this.takeTypeGlobal.delivery && this.getCartGoodsPrice < this.appProperties
- .sendingNeedLeastPrice ? true : false;
- }, // 差多少元起送
- spread() {
- if (this.takeType != this.takeTypeGlobal.delivery) return;
- return this.appProperties.sendingNeedLeastPrice - this.getCartGoodsPrice;
- }
- },
- watch: {
- cart: {
- handler: (newV, oldV) => {
- _this.putCart()
- },
- deep: true,
- }
- },
- methods: {
- modalCheckedShow() {
- this.$refs.modalChecked.showModal()
- },
- timeRange(beginTime, endTime) { //判断是否在查询时间
- var strb = beginTime.split(":");
- if (strb.length != 3) {
- return false;
- }
- var stre = endTime.split(":");
- if (stre.length != 3) {
- return false;
- }
- var b = new Date();
- var e = new Date();
- var n = new Date();
- if (parseInt(strb[0]) >= parseInt(stre[0])) {
- b.setDate(b.getDate() - 1)
- }
- console.log(b, ",,,");
- console.log(e, ",,,");
- console.log(n, ",,,");
- b.setHours(strb[0]);
- b.setMinutes(strb[1]);
- b.setSeconds(strb[2]);
- e.setHours(stre[0]);
- e.setMinutes(stre[1]);
- e.setSeconds(stre[2]);
- if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
- return true;
- } else {
- return false;
- }
- },
- //页面初始化
- async init() {
- await this.initShop()
- await this.initMenu()
- await this.initCart()
- this.initShopConfig()
- },
- async initShop() {
- let params = {
- id: this.shopId
- }
- let res=await this.$api.shop.detail(params)
- this.shopDetail = res.data
- this.appProperties.shopName=this.shopDetail.name
- },
- initShopConfig(){
- let params={
- shopId:this.shopId
- }
- this.$api.shopConfig.list(params).then(res=>{
- if (this.$isNotEmpty(res.data.records)) {
- this.$util.objectCopy(this.appProperties,res.data.records[0])
- this.appProperties.shopName=this.shopDetail.name
- }
- })
- },
- async initMenu() {
- let res = await this.$api.goods.menu({
- shopId: this.shopId
- })
- this.goods = res.data;
- this.hasMustOrder= this.goods.some(item=>item.goodsCategoryName.includes(this.$global.mustOrder))
- setTimeout(() => {
- _this.$refs.loading.hide()
- _this.isLoading = false
- if (_this.$isNotEmpty(_this.goods) && _this.$isEmpty(_this.seatNum)) {
- _this.$nextTick(function() {
- _this.modalCheckedShow()
- })
- }
- }, 400)
- },
- //初始化购物车
- initCart() {
- this.cartKey = this.$global.cart_prefix + this.shopId
- if (this.$isEmpty(this.$cache.get(this.cartKey))) {
- return
- }
- this.cart = this.$cache.get(this.cartKey)
- },
- putCart() {
- this.$cache.put(this.cartKey, this.cart)
- },
- modalConfirm(index) {
- let takeType = this.checkList[index].name
- if (takeType == '扫一扫店内下单') {
- this.scanCodeOrder()
- this.takeType = this.$global.takeType.dine_in
- return
- }
- this.takeType = this.checkList[index].name
- if (this.takeType == this.takeTypeGlobal.delivery) {
- this.takeout()
- }
- },
- scanCodeOrder() {
- uni.scanCode({
- success: (res) => {
- _this.seatNum = this.$util.getUrlParams(res.result).seatNum
- if (_this.$isEmpty(_this.seatNum)) {
- _this.$dialog.showModal('非点餐二维码!', false)
- _this.modalCheckedShow()
- return
- }
- },
- fail: (err) => {
- _this.modalCheckedShow()
- }
- })
- },
- // 选择商家配送的方式下单
- takeout() {
- if (this.$isEmpty(this.vuex_userId)) {
- this.showLogin()
- return
- }
- if (this.$isEmpty(this.address) && this.$isNotEmpty(this.vuex_userId)) {
- uni.navigateTo({
- url: "../address/address"
- })
- }
- },
- // 显示当前商品的详情信息
- showGoodDetailModal(currentGoods) {
- currentGoods.number = 1;
- currentGoods.realPrice = this.getGoodsRealPrice(currentGoods);
- currentGoods.propertyStr = this.getGoodSelectedProps(currentGoods);
- this.currentGoods = JSON.parse(JSON.stringify(currentGoods)); // 深拷贝
- this.goodDetailModalVisible = true;
- this.selectedPropertyList = [];
- console.log('显示当前商品的详情信息', this.currentGoods);
- },
- // 获取商品具体价格,如大杯商品,小杯商品价格不同
- getGoodsRealPrice(goods) {
- console.log(goods);
- let realPrice = goods.realPrice;
- if (goods.goodsPropertyVos && goods.goodsPropertyVos.length) {
- let vos = goods.goodsPropertyVos;
- for (let i = 0; i < vos.length; i++) {
- let propertyList = vos[i].propertyList;
- for (let j = 0; j < propertyList.length; j++) {
- if (propertyList[j].isDefault && propertyList[j].realPrice) {
- realPrice = propertyList[j].realPrice;
- break;
- }
- }
- }
- }
- return realPrice;
- },
- // 显示当前商品的详情信息
- showGoodDetailModal(currentGoods) {
- currentGoods.number = 1;
- currentGoods.realPrice = this.getGoodsRealPrice(currentGoods);
- currentGoods.propertyStr = this.getGoodSelectedProps(currentGoods);
- this.currentGoods = JSON.parse(JSON.stringify(currentGoods)); // 深拷贝
- this.goodDetailModalVisible = true;
- this.selectedPropertyList = [];
- console.log('显示当前商品的详情信息', this.currentGoods);
- },
- closeGoodDetailModal() {
- // 关闭饮品详情模态框
- this.goodDetailModalVisible = false;
- },
- // 改变商品的某个默认属性值 要区分必选和多选的属性
- changePropertyDefault(categoryIndex, propertyIndex) {
- let propertyCategory = this.currentGoods.goodsPropertyVos[categoryIndex].category;
- let propertyList = this.currentGoods.goodsPropertyVos[categoryIndex].propertyList;
- if (propertyCategory != '加料') {
- // 必须选一个
- propertyList.forEach(property => (property.isDefault = false)); // 重置所有默认选择状态重新选择
- propertyList[propertyIndex].isDefault = true;
- if (propertyCategory == '大小') {
- this.currentGoods.realPrice = this.currentGoods.realPrice - this.currentGoods.defaultPrice +
- propertyList[propertyIndex].rebasePrice;
- this.currentGoods.defaultPrice = propertyList[propertyIndex].rebasePrice;
- this.currentGoods.number = 1;
- this.currentGoods.propertyStr = this.getGoodSelectedProps(this.currentGoods);
- }
- } else {
- // 可选项 加料或减料
- if (propertyList[propertyIndex].isDefault) {
- this.currentGoods.realPrice -= propertyList[propertyIndex].extraPrice;
- propertyList[propertyIndex].isDefault = false;
- } else {
- this.currentGoods.realPrice += propertyList[propertyIndex].extraPrice;
- propertyList[propertyIndex].isDefault = true;
- }
- }
- },
- // 计算当前饮品所选属性,空格隔开
- getGoodSelectedProps(goods) {
- if (goods.goodsPropertyVos) {
- let propertyStr = '';
- goods.goodsPropertyVos.forEach(goodsPropertyVo => {
- goodsPropertyVo.propertyList.forEach(property => {
- if (property.isDefault) {
- propertyStr += property.propertyOption + ' ';
- }
- });
- });
- return propertyStr;
- }
- return '';
- },
- // 改变当前商品数量
- changeCurrentGoodsNumber(number) {
- this.currentGoods.number += number;
- if (this.currentGoods.number < 0) {
- this.currentGoods.number = 0;
- } else if (this.currentGoods.number >= 100) {
- this.currentGoods.number = 100;
- }
- },
- // 将当前商品加入到购物车
- addCurrentGoodsToCart() {
- if (this.currentGoods && this.currentGoods.number) {
- this.handleAddToCart(this.currentGoods);
- }
- this.closeGoodDetailModal();
- },
- // 减少购物车里的商品数量, goodsId和propertyStr去比较
- handleReduceFromCart(goods) {
- let propertyStr = this.getGoodSelectedProps(goods);
- let cart = this.cart;
- for (let i = cart.length - 1; i >= 0; i--) {
- if (cart[i].id == goods.id && cart[i].propertyStr == propertyStr) {
- if (cart[i].number <= 1) cart.splice(i, 1);
- else cart[i].number -= 1;
- return;
- }
- }
- },
- // 添加到购物车
- handleAddToCart(goods) {
- let propertyStr = this.getGoodSelectedProps(goods);
- goods.propertyStr = propertyStr;
- let cart = this.cart;
- for (let i = cart.length - 1; i >= 0; i--) {
- if (cart[i].id == goods.id && cart[i].propertyStr == propertyStr) {
- cart[i].number++;
- return;
- }
- }
- // 购物车里不存在
- if (!goods.number) goods.number = 1;
- this.cart.push(JSON.parse(JSON.stringify(goods)));
- },
- // 清空购物车
- handleCartClear() {
- let that = this;
- uni.showModal({
- title: '提示',
- content: '确定清空购物车么',
- success: ({
- confirm
- }) => {
- if (confirm) {
- that.cartPopupVisible = false;
- this.cart = []
- }
- }
- });
- },
- // 在购物车里操作商品数量
- handleCartItemAdd(index) {
- this.cart[index].number += 1;
- },
- handleCartItemReduce(index) {
- if (this.cart[index].number === 1) {
- this.cart.splice(index, 1);
- } else {
- this.cart[index].number -= 1;
- }
- if (!this.cart.length) {
- this.cartPopupVisible = false;
- }
- },
- toPay() {
- this.cartPopupVisible = false;
- if (this.$isEmpty(this.vuex_userId)) {
- this.showLogin()
- return
- }
- let orderInfo = {
- shopDetail: this.shopDetail,
- shopId: this.shopId,
- cart: this.cart,
- cartKey: this.cartKey,
- takeType: this.takeType,
- address: this.address,
- store: this.appProperties,
- address: this.address,
- seatNum: this.seatNum
- }
- this.$u.vuex('vuex_orderInfo', orderInfo)
- uni.navigateTo({
- url: '../pay/pay'
- })
- },
- fetchAddress() {
- if (this.$isEmpty(this.vuex_userId)) {
- return
- }
- let params = {
- userId: this.vuex_userId,
- isDefault: true
- }
- this.$api.address.list(params).then(res => {
- this.address = res.data.records[0]
- })
- },
- // 登录 begin
- showLogin() {
- this.$refs.login.show()
- },
- showPhoneModal() {
- this.$refs.login.showPhoneModal()
- },
- signIn(resp) {
- //获取手机号
- if (this.$isEmpty(this.vuex_phone)) {
- this.showPhoneModal()
- }
- this.$refs.toast.info('登录成功')
- this.fetchAddress()
- },
- async login(e) {
- if (this.$isEmpty(this.vuex_userId)) {
- this.showLogin()
- return
- } else {
- this.userInfo = this.$cache.get('userInfo')
- }
- //获取手机号
- if (this.$isEmpty(this.vuex_phone)) {
- this.showPhoneModal()
- }
- },
- // 登录 end
- /**
- * u-view 菜单栏 begin
- *
- */
- async swichMenu(index) {
- if (this.arr.length == 0) {
- await this.getMenuItemTop();
- }
- if (index == this.current) return;
- this.scrollRightTop = this.oldScrollTop;
- this.$nextTick(function() {
- this.scrollRightTop = this.arr[index];
- this.current = index;
- this.leftMenuStatus(index);
- })
- },
- // 获取一个目标元素的高度
- getElRect(elClass, dataVal) {
- new Promise((resolve, reject) => {
- const query = uni.createSelectorQuery().in(this);
- query.select('.' + elClass).fields({
- size: true
- }, res => {
- // 如果节点尚未生成,res值为null,循环调用执行
- if (!res) {
- setTimeout(() => {
- this.getElRect(elClass);
- }, 10);
- return;
- }
- this[dataVal] = res.height;
- resolve();
- }).exec();
- })
- },
- // 观测元素相交状态
- async observer() {
- this.goods.map((val, index) => {
- let observer = uni.createIntersectionObserver(this);
- // 检测右边scroll-view的id为itemxx的元素与right-box的相交状态
- // 如果跟.right-box底部相交,就动态设置左边栏目的活动状态
- observer.relativeTo('.right-box', {
- top: 0
- }).observe('#item' + index, res => {
- if (res.intersectionRatio > 0) {
- let id = res.id.substring(4);
- this.leftMenuStatus(id);
- }
- })
- })
- },
- // 设置左边菜单的滚动状态
- async leftMenuStatus(index) {
- this.current = index;
- // 如果为0,意味着尚未初始化
- if (this.menuHeight == 0 || this.menuItemHeight == 0) {
- await this.getElRect('menu-scroll-view', 'menuHeight');
- await this.getElRect('u-tab-item', 'menuItemHeight');
- }
- // 将菜单活动item垂直居中
- this.scrollTop = index * this.menuItemHeight + this.menuItemHeight / 2 - this.menuHeight / 2;
- },
- // 获取右边菜单每个item到顶部的距离
- getMenuItemTop() {
- new Promise(resolve => {
- let selectorQuery = uni.createSelectorQuery();
- selectorQuery.selectAll('.class-item').boundingClientRect((rects) => {
- // 如果节点尚未生成,rects值为[](因为用selectAll,所以返回的是数组),循环调用执行
- if (!rects.length) {
- setTimeout(() => {
- this.getMenuItemTop();
- }, 10);
- return;
- }
- rects.forEach((rect) => {
- // 这里减去rects[0].top,是因为第一项顶部可能不是贴到导航栏(比如有个搜索框的情况)
- this.arr.push(rect.top - rects[0].top);
- resolve();
- })
- }).exec()
- })
- },
- // 右边菜单滚动
- async rightScroll(e) {
- this.oldScrollTop = e.detail.scrollTop;
- if (this.arr.length == 0) {
- await this.getMenuItemTop();
- }
- if (this.timer) return;
- if (!this.menuHeight) {
- await this.getElRect('menu-scroll-view', 'menuHeight');
- }
- setTimeout(() => { // 节流
- this.timer = null;
- // scrollHeight为右边菜单垂直中点位置
- let scrollHeight = e.detail.scrollTop + this.menuHeight / 2;
- for (let i = 0; i < this.arr.length; i++) {
- let height1 = this.arr[i];
- let height2 = this.arr[i + 1];
- // 如果不存在height2,意味着数据循环已经到了最后一个,设置左边菜单为最后一项即可
- if (!height2 || scrollHeight >= height1 && scrollHeight < height2) {
- this.leftMenuStatus(i);
- return;
- }
- }
- }, 10)
- },
- /**
- * u-view 菜单栏 end
- */
- }
- }
- </script>
- <style lang="scss" scoped>
- .goods_empty {
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- margin-top: 300rpx;
- image {
- width: 270rpx;
- height: 160rpx;
- margin-bottom: 50rpx;
- }
- text: {
- font-weight: 400;
- color: #DDDDDD;
- }
- }
- .nav {
- width: 100%;
- flex-shrink: 0;
- display: flex;
- flex-direction: column;
- .header {
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 20rpx;
- background-color: #ffffff;
- height: 100rpx;
- .left {
- flex: 1;
- display: flex;
- flex-direction: column;
- .store-name {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- font-size: $font-size-lg;
- margin-bottom: 10rpx;
- .iconfont {
- margin-left: 10rpx;
- line-height: 100%;
- }
- }
- .store-location {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- color: $text-color-assist;
- font-size: $font-size-sm;
- .iconfont {
- vertical-align: middle;
- display: table-cell;
- color: $color-primary;
- line-height: 100%;
- }
- }
- }
- .right {
- background-color: $bg-color-grey;
- border-radius: 38rpx;
- display: flex;
- align-items: center;
- font-size: $font-size-sm;
- padding: 0 38rpx;
- color: $text-color-assist;
- .dinein,
- .takeout {
- position: relative;
- display: flex;
- align-items: center;
- &.active {
- padding: 14rpx 38rpx;
- color: #ffffff;
- background-color: $color-primary;
- border-radius: 38rpx;
- }
- }
- .takeout {
- margin-left: 20rpx;
- height: 100%;
- flex: 1;
- padding: 14rpx 0;
- }
- .dinein.active {
- margin-left: -38rpx;
- }
- .takeout.active {
- margin-right: -38rpx;
- }
- }
- }
- .coupon {
- flex: 1;
- width: 100%;
- font-size: $font-size-base;
- color: $color-primary;
- padding: 0 20rpx;
- display: flex;
- align-items: center;
- overflow: hidden;
- .title {
- flex: 1;
- margin-left: 10rpx;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- .iconfont {
- line-height: 100%;
- }
- }
- }
- .item-container {
- display: flex;
- flex-wrap: wrap;
- .thumb-box {
- width: 100%;
- display: flex;
- padding: 20rpx 0;
- border-bottom: 1rpx solid #EEEEEE;
- .item-menu-image {
- width: 160rpx;
- height: 160rpx;
- margin-right: 20rpx;
- border-radius: 8rpx;
- }
- .item-content {
- width: calc(100% - 180rpx);
- }
- .name {
- font-size: $font-size-base;
- margin-bottom: 10rpx;
- }
- .tips {
- width: 100%;
- height: 40rpx;
- line-height: 40rpx;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- font-size: $font-size-sm;
- color: $text-color-assist;
- margin-bottom: 10rpx;
- }
- .price_and_action {
- width: 100%;
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-top: 30rpx;
- .price {
- font-size: $font-size-base;
- font-weight: 600;
- }
- .btn-group {
- display: flex;
- justify-content: space-between;
- align-items: center;
- position: relative;
- .btn {
- background-color: $base-color;
- padding: 0 20rpx;
- box-sizing: border-box;
- font-size: $font-size-sm;
- height: 44rpx;
- line-height: 44rpx;
- &.property_btn {
- border-radius: 24rpx;
- }
- &.add_btn,
- &.reduce_btn {
- color: #FFFFFF;
- border: $base-color;
- padding: 0;
- width: 44rpx;
- border-radius: 44rpx;
- }
- }
- .dot {
- position: absolute;
- background-color: #ffffff;
- border: 1px solid $color-primary;
- color: $color-primary;
- font-size: $font-size-sm;
- width: 36rpx;
- height: 36rpx;
- line-height: 36rpx;
- text-align: center;
- border-radius: 100%;
- right: -12rpx;
- top: -10rpx;
- }
- .number {
- width: 44rpx;
- height: 44rpx;
- line-height: 44rpx;
- text-align: center;
- }
- }
- }
- }
- .thumb-box:last-child {
- border: none;
- }
- }
- .good-detail-modal {
- width: 100%;
- height: 100%;
- display: flex;
- flex-direction: column;
- .cover {
- height: 320rpx;
- padding: 30rpx 0;
- display: flex;
- justify-content: center;
- align-items: center;
- position: relative;
- .image {
- width: 260rpx;
- height: 260rpx;
- }
- .btn-group {
- position: absolute;
- right: 10rpx;
- top: 30rpx;
- display: flex;
- align-items: center;
- justify-content: space-around;
- image {
- width: 80rpx;
- height: 80rpx;
- }
- }
- }
- .detail {
- width: 100%;
- min-height: 1vh;
- max-height: calc(90vh - 320rpx - 80rpx - 330rpx);
- .wrapper {
- width: 100%;
- height: 100%;
- overflow: hidden;
- .basic {
- padding: 0 20rpx 30rpx;
- display: flex;
- flex-direction: column;
- .name {
- font-size: $font-size-base;
- color: $text-color-base;
- margin-bottom: 10rpx;
- }
- .tips {
- font-size: $font-size-sm;
- color: $text-color-grey;
- }
- }
- .properties {
- width: 100%;
- border-top: 2rpx solid $bg-color-grey;
- padding: 10rpx 30rpx 0;
- display: flex;
- flex-direction: column;
- .property {
- width: 100%;
- display: flex;
- flex-direction: column;
- margin-bottom: 20rpx;
- padding-bottom: -16rpx;
- .title {
- width: 100%;
- display: flex;
- justify-content: flex-start;
- align-items: center;
- margin-bottom: 20rpx;
- .name {
- font-size: 26rpx;
- color: $text-color-base;
- margin-right: 20rpx;
- }
- .desc {
- flex: 1;
- font-size: $font-size-sm;
- color: $color-primary;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- }
- .values {
- width: 100%;
- display: flex;
- flex-wrap: wrap;
- .value {
- border-radius: 8rpx;
- background-color: $bg-color-grey;
- padding: 16rpx 30rpx;
- font-size: 26rpx;
- color: $text-color-assist;
- margin-right: 16rpx;
- margin-bottom: 16rpx;
- &.default {
- background-color: $color-primary;
- color: $text-color-white;
- }
- }
- }
- }
- }
- }
- }
- .action {
- display: flex;
- align-items: center;
- justify-content: space-between;
- background-color: $bg-color-grey;
- height: 120rpx;
- padding: 0 26rpx;
- .left {
- flex: 1;
- display: flex;
- flex-direction: column;
- justify-content: center;
- margin-right: 20rpx;
- overflow: hidden;
- .price {
- font-size: $font-size-lg;
- color: $text-color-base;
- }
- .props {
- color: $text-color-assist;
- font-size: 24rpx;
- width: 100%;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- }
- .btn-group {
- display: flex;
- align-items: center;
- justify-content: space-around;
- .number {
- font-size: $font-size-base;
- width: 44rpx;
- height: 44rpx;
- line-height: 44rpx;
- text-align: center;
- }
- .btn {
- padding: 0;
- font-size: $font-size-base;
- width: 44rpx;
- height: 44rpx;
- line-height: 44rpx;
- border-radius: 100%;
- }
- }
- }
- .add-to-cart-btn {
- display: flex;
- justify-content: center;
- align-items: center;
- background-color: $color-primary;
- color: $text-color-white;
- font-size: $font-size-base;
- height: 80rpx;
- border-radius: 0 0 12rpx 12rpx;
- }
- }
- .cart-popup {
- .top {
- background-color: #f3ede3;
- color: #ff9447;
- padding: 10rpx 30rpx;
- font-size: 24rpx;
- text-align: right;
- }
- .cart-list {
- background-color: #FFFFFF;
- width: 100%;
- overflow: hidden;
- min-height: 30vh;
- max-height: 70vh;
- margin-bottom: 30rpx;
- .wrapper {
- height: 100%;
- display: flex;
- flex-direction: column;
- padding: 0 30rpx;
- margin-bottom: 156rpx;
- .item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 30rpx 0;
- position: relative;
- &::after {
- content: ' ';
- position: absolute;
- bottom: 0;
- left: 0;
- width: 100%;
- background-color: $border-color;
- height: 2rpx;
- transform: scaleY(.6);
- }
- .left {
- flex: 1;
- display: flex;
- flex-direction: column;
- overflow: hidden;
- margin-right: 30rpx;
- .name {
- font-size: $font-size-sm;
- color: $text-color-base;
- }
- .props {
- color: $text-color-assist;
- font-size: 24rpx;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- }
- .center {
- margin-right: 120rpx;
- font-size: $font-size-base;
- }
- .right {
- display: flex;
- align-items: center;
- justify-content: space-between;
- .btn {
- width: 46rpx;
- height: 46rpx;
- border-radius: 100%;
- padding: 0;
- text-align: center;
- line-height: 46rpx;
- }
- .number {
- font-size: $font-size-base;
- width: 46rpx;
- height: 46rpx;
- text-align: center;
- line-height: 46rpx;
- }
- }
- }
- }
- }
- }
- .cart-box {
- position: fixed;
- bottom: 30rpx;
- left: 30rpx;
- right: 30rpx;
- height: 96rpx;
- border-radius: 48rpx;
- box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.2);
- background-color: #FFFFFF;
- display: flex;
- align-items: center;
- justify-content: space-between;
- z-index: 999;
- .cart-img {
- width: 96rpx;
- height: 96rpx;
- position: relative;
- margin-top: -48rpx;
- }
- .pay-btn {
- height: 100%;
- padding: 0 30rpx;
- color: #FFFFFF;
- border-radius: 0 50rpx 50rpx 0;
- display: flex;
- align-items: center;
- background-color: rgba(255, 148, 71, .6);
- font-size: $font-size-base;
- }
- .mark {
- padding-left: 46rpx;
- margin-right: 30rpx;
- position: relative;
- .tag {
- background-color: #ED302C;
- color: #fff;
- border: 1rpx solid #ED302C;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: $font-size-sm;
- position: absolute;
- right: -10rpx;
- top: -50rpx;
- border-radius: 100%;
- padding: 4rpx;
- width: 36rpx;
- height: 36rpx;
- opacity: .9;
- }
- }
- .price {
- flex: 1;
- color: $text-color-base;
- }
- }
- .u-wrap {
- height: calc(100vh);
- /* #ifdef H5 */
- height: calc(100vh - var(--window-top));
- /* #endif */
- display: flex;
- flex-direction: column;
- width: 100%;
- }
- .u-search-box {
- background-color: #FFFFFF;
- }
- .u-menu-wrap {
- width: 100%;
- flex: 1;
- display: flex;
- overflow: hidden;
- }
- .u-search-inner {
- background-color: rgb(234, 234, 234);
- border-radius: 100rpx;
- display: flex;
- align-items: center;
- padding: 10rpx 16rpx;
- }
- .u-search-text {
- font-size: 26rpx;
- color: $u-tips-color;
- margin-left: 10rpx;
- }
- .u-tab-view {
- width: 200rpx;
- height: 100%;
- }
- .u-tab-item {
- height: 110rpx;
- background: #f6f6f6;
- box-sizing: border-box;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 26rpx;
- color: #444;
- font-weight: 400;
- line-height: 1;
- }
- .u-tab-item-active {
- position: relative;
- color: #000;
- font-size: 30rpx;
- font-weight: 600;
- background: #fff;
- }
- .u-tab-item-active::before {
- content: "";
- position: absolute;
- border-left: 4px solid $base-color;
- height: 32rpx;
- left: 0;
- top: 39rpx;
- }
- .u-tab-view {
- height: 100%;
- }
- .right-box {
- background-color: rgb(250, 250, 250);
- }
- .page-view {
- margin-bottom: 80rpx;
- background-color: #FFFFFF;
- padding: 16rpx;
- }
- .class-item {
- margin-bottom: 30rpx;
- background-color: #fff;
- border-radius: 8rpx;
- }
- .class-item:first-child {
- margin-bottom: 0rpx;
- }
- .class-item:last-child {
- min-height: 100vh;
- }
- .item-title {
- padding: 20rpx;
- font-size: 26rpx;
- color: $u-main-color;
- font-weight: bold;
- }
- </style>
|