| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587 |
- <template>
- <view class="u-wrap" :style="$isEmpty(goods)?'background-color: #FFFFFF;':''">
- <view class="" 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>
- <view class="" v-else>
- <login ref="login" @signIn="signIn"></login>
- <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 bg-red 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">
- <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 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 class="">
- <!-- 购物车栏 begin -->
- <view class="cart-box" v-if="cart && cart.length">
- <view class="mark" @tap="cartPopupVisible = !cartPopupVisible">
- <image src="/pagesD/static/icon/cart1.png" class="cart-img"></image>
- <view class="tag">{{ getCartGoodsNumber }}</view>
- </view>
- <view class="price" @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 -->
-
- <modal-checked @confirm="modalConfirm" ref="modalChecked" :list="checkList"></modal-checked>
- <login ref="login" @signIn="signIn"></login>
- </view>
- </view>
-
- <toast ref="toast" ></toast>
- </view>
- </view>
- <loading ref="loading" type="3" theme="2"/>
- </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:'',
- address: {},
- cart: [],
- takeType: "店内堂食",
- takeTypeGlobal:global.takeType,
- shopDetail:{},
- appProperties: {
- "shopName": "",
- "sendingPrice": 100, // 商家配送费
- "packingPrice": 100, // 包装费
- "sendingNeedLeastPrice": 2000, // 起送需要的最低价格
- "businessStartTime": '09:00:00', // 营业开始时间, 开始的点必须在结束之前
- "businessEndTime": '22:00:00', // 营业结束时间
- "shopStatus": true, // 商家营业状态
- "shopNotice": ['10点到22点可以送餐~'], // 公告
- },
- 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()
- },
- initShop(){
- let params={
- id:this.shopId
- }
- this.$api.shop.detail(params).then(res=>{
- this.shopDetail=res.data
- this.appProperties.shopName=this.shopDetail.name
- })
- },
- async initMenu(){
- let res=await this.$api.goods.menu({shopId: this.shopId})
- this.goods = res.data;
-
- setTimeout(()=>{
- _this.$refs.loading.hide()
- _this.isLoading=false
- if (_this.$isNotEmpty(_this.goods)&&_this.$isEmpty(_this.seatNum)) {
- _this.$nextTick(function(){
- _this.modalCheckedShow()
- })
- }
- },200)
-
-
- },
- //初始化购物车
- 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.$u.toast('登录成功')
-
- 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: #FFFFFF;
- color: $base-color;
- border: 1rpx solid $base-color;
- 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: 40rpx;
- height: 40rpx;
- 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>
|