| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906 |
- <template>
- <view class="content">
- <view class="store-info flex">
- <image :src="storeInfo.logo" mode="" class="store-logo"></image>
- <view class="info">
- <view class="name">
- {{storeInfo.name}}
- </view>
- <view class="dis">
- {{storeInfo.range}}km
- </view>
- </view>
- </view>
- <scroll-view scroll-x="true" class="nav" style="background-color: #fff;">
- <view class="flex">
- <view class="nav-item" v-for="(item,index) in cateList" :key="index" @click="navClick(index)"
- :class="{'action': index == current}">
- <image :src="item.big_pic" mode="" class="cate-img"></image>
- <view class="">
- {{item.cate_name}}
- </view>
- </view>
- </view>
- </scroll-view>
- <view class="bom flex" :style="{height: height}">
- <scroll-view scroll-y class="left-aside">
- <view v-for="(item,indexs) in flist" :key="item.id" class="f-item b-b"
- :class="{ active: indexs === currents }" @click="tabtap(indexs)">{{ item.cate_name }}</view>
- </scroll-view>
- <scroll-view scroll-with-animation scroll-y class="right-aside" @scroll="asideScroll"
- :scroll-top="tabScrollTop">
- <view class="good-wrap">
- <view class="good flex" v-for="(good,gindex) in cateList[current].children[currents].list">
- <image :src="good.image" class="good-img" mode=""></image>
- <view class="info">
- <view class="name clamp2">
- {{good.store_name}}
- </view>
- <view class="price">
- ¥{{good.specs[0].price}}
- </view>
- </view>
- <image src="/static/index/cart.png" mode="" class="btn" @click="openTc(good)"></image>
- </view>
- </view>
- </scroll-view>
- </view>
- <view class="tc" style="height: 114rpx;">
- </view>
- <view class="cart-wrap cart-wraps flex">
- <uni-badge :text="cart_num" absolute="rightTop">
- <image src="/static/index/cart-a.png" mode="" class="btn-cart" @click="openCart"></image>
- </uni-badge>
- <view class="price">
- ¥{{totalPirce}}
- </view>
- <view class="btn" @click="createOrder()" :class="{'enaction': cart_num == 0}">
- 去结算
- </view>
- </view>
- <view class="js">
-
- </view>
- <uni-popup type="center" ref="specs">
- <view class="specs-wrap">
- <view class="good-info flex">
- <image :src="checkGg.img" mode="" class="good-logo"></image>
- <view class="info">
- <view class="name">
- {{good.store_name}}
- </view>
- <view class="dis">
- {{checkGg.price}}
- </view>
- </view>
- </view>
- <view class="tit">
- 选择规格分类
- </view>
- <view class="gg-wrap flex">
- <view class="gg" v-for="(gg,gndex) in good.specs" :class="{'actions': gg.id == checkGg.id}" @click="changeGg(gg)">
- {{gg.name}}
- </view>
- </view>
- <view class="buy-num">
- <view class="">
- 购买数量
- </view>
- <uni-number-box v-model="buyNum" :max="maxNum"></uni-number-box>
- </view>
- <view class="buy-now" @click="addNow">
- 加入购物车
- </view>
- <image src="/static/icon/close.png" class="close-btn" mode="" @click="closeTc"></image>
- </view>
- </uni-popup>
- <uni-popup type="bottom" ref="cartList">
- <view class="cart_wrap">
- <view class="cart-top flex">
- <image src="/static/icon/bin.png" mode="" @click="clearCart"></image>
- <view class="" @click="clearCart">
- 清空购物车
- </view>
- </view>
- <scroll-view scroll-y="true" style="height: 500rpx;">
- <view class="cart-list-wrap">
- <view class="good flex" v-for="(good,gindex) in cartList">
- <image :src="good.product.image" class="good-img" mode=""></image>
- <view class="info">
- <view class="name clamp">
- {{good.product.store_name}}
- </view>
- <view class="gg">
- {{good.specs.name}}
- </view>
- <view class="price">
- ¥{{good.specs.price}}
- </view>
-
- </view>
- <view class="munbox flex">
- <image src="../../static/icon/reduce.png" mode="" @click="reduce(good,gindex)"></image>
- <input type="number" v-model="good.cart_num" disabled />
- <image src="../../static/icon/add.png" mode="" @click="add(good)"></image>
- </view>
- </view>
- </view>
- </scroll-view>
- <view class="cart-wrap flex">
- <uni-badge :text="cart_num" absolute="rightTop">
- <image src="/static/index/cart-a.png" mode="" class="btn-cart" @click="closeCart"></image>
- </uni-badge>
- <view class="price">
- ¥{{totalPirce}}
- </view>
- <view class="btn" @click="createOrder()" :class="{'enaction': cart_num == 0}">
- 去结算
- </view>
- </view>
- </view>
- </uni-popup>
- </view>
- </template>
- <script>
- import {
- mapState,
- mapMutations
- } from 'vuex';
- import {
- getCategoryList,
- getCateList,
- getProducts,
- getCartlist,
- cartAdd,
- cartNum,
- delCart,
- cartCompute
- } from '@/api/product.js';
- // #ifdef H5
- import {
- shareLoad
- } from '@/utils/wxAuthorized';
- // #endif
- export default {
- data() {
- return {
- totalPirce: 0,
- cartList: [],
- cart_num: 0,
- buyNum: 1,
- maxNum: 1,
- checkGg: {},
- good: {},
- storeInfo: {},
- store_id: 0,
- goods: [],
- height: '',
- current: 0,
- currents: 0,
- sizeCalcState: false,
- tabScrollTop: 0,
- currentId: 9,
- flist: [],
- cateList: [{
- children: [{
- list: []
- }]
- }],
- limit: 20
- };
- },
- computed: {
- ...mapState('user', ['userInfo'])
- },
- onReady(res) {
- var that = this;
- uni.getSystemInfo({
- success: resu => {
- const query = uni.createSelectorQuery();
- query.select('.js').boundingClientRect();
- query.exec(function(res) {
- that.height = resu.windowHeight - res[0].top + 'px';
- console.log(that.height)
- });
- },
- fail: res => {}
- });
- },
- onLoad(opt) {
- this.store_id = opt.id
- this.storeInfo = uni.getStorageSync('storeInfo') || {}
- this.getCateList()
- // #ifdef H5
- // shareLoad()
- // #endif
- this.getCartList()
- },
- // 监听导航栏输入框点击事件
- onNavigationBarSearchInputClicked(e) {
- uni.navigateTo({
- url: '/pages/product/search'
- });
- },
- methods: {
- cartCompute() {
- let cart_ids = this.cartList.map(item => {
- return item.id
- })
- cartCompute({
- store_id: this.storeInfo.id,
- uid: this.userInfo.uid,
- cart_ids: cart_ids
- }).then(res => {
- this.totalPirce = res.data.data.group_price.total_price
- })
- },
- //删除
- deleteCartItem(index) {
- let list = this.cartList;
- let row = list[index];
- let id = row.id;
- delCart({
- cart_ids: [id],
- store_id: this.storeInfo.id
- }).then(res => {
- this.cartList.splice(index, 1);
- uni.hideLoading();
- this.getCartList();
- })
-
- },
- //清空
- clearCart() {
- let that = this
- uni.showModal({
- content: '清空购物车?',
- success: e => {
- if (e.confirm) {
- let st = this.cartList.map(e => {
- return e.id;
- });
- delCart({
- cart_ids: st,
- store_id: that.storeInfo.id
- }).then(e => {
- console.log(e);
- this.getCartList();
- });
- this.cartList = [];
- }
- }
- });
- },
- reduce(item, index) {
- if (item.cart_num == 1) {
- uni.showModal({
- content: '删除该商品?',
- success: e => {
- if (e.confirm) {
- this.deleteCartItem(index);
- }
- }
- });
- } else {
- item.cart_num--;
- this.newNumberChange(item);
- }
- },
- add(item) {
- console.log(item);
- if (item.specs.num*1 > item.cart_num) {
- item.cart_num++;
- this.newNumberChange(item);
- } else {
- return;
- }
- },
- newNumberChange(item) {
- let that = this
- cartNum({
- id: item.id,
- cart_num: item.cart_num,
- store_id: that.storeInfo.id,
- is_gift: 0
- })
- .then(e => {
- console.log(e);
- this.getCartList()
- })
- .catch(function(e) {
- console.log(e);
- });
- },
- openCart() {
- this.$refs.cartList.open()
- },
- closeCart() {
- this.$refs.cartList.close()
- },
- //创建订单
- createOrder() {
- let goodsData = [];
- this.cartList.forEach(item => {
- goodsData.push(item.id);
- });
- if(goodsData.length == 0) return;
- uni.navigateTo({
- url: '/pages/order/createOrder?id=' + goodsData.join(',')
- });
- },
- getCartList() {
- getCartlist({
- store_id: this.storeInfo.id
- }).then(res => {
- let data = res.data
- if(data.cart_num) {
- this.cartList = data.group_price.valid.map(items => {
- items.cart_num = items.cart_num*1
- return items
- })
- this.cart_num = data.cart_num
- this.cartCompute()
- }else {
- this.cartList = []
- this.cart_num = 0
- this.totalPirce = 0
- }
-
-
- })
- },
- addNow() {
- let that = this
- console.log(this.buyNum,that.good)
- cartAdd({
- type: 0,
- product_type: 0,
- store_id: that.storeInfo.id,
- product_id: that.good.id,
- specs_id: that.checkGg.id,
- cart_num: that.buyNum,
- is_gift: 0,
- is_new: 0,//0加入购物车 1直接购买
- }).then(res => {
- uni.showToast({
- title:'添加成功',
- duration:1500
- });
- that.getCartList()
- that.closeTc()
- })
- },
- closeTc() {
- this.$refs.specs.close()
- this.checkGg = {}
- this.good = {}
- this.buyNum = 1
- },
- changeGg(item) {
- this.checkGg = item
- this.maxNum = item.num*1
-
- },
- openTc(item) {
- this.good = item
- this.checkGg = item.specs[0]
- this.buyNum = 1
- this.maxNum = item.specs[0].num*1
- this.$refs.specs.open()
- },
- getProducts(type) {
- let that = this
- let item = that.cateList[that.current].children[that.currents]
- if (type == 'tab' && item.loaded) return;
- console.log(item.loadType,'loadtype')
- if (item.loadType == 'loading' || item.loadType == 'noMore') return;
- item.loadType = 'loading'
- getProducts({
- cate_id: item.id,
- page: 1,
- limit: that.limit,
- store_id: that.store_id
- }).then(res => {
- let arr = res.data.data.map(item => {
- item.buyNum = 0
- return item
- })
- console.log(arr,'arr',item);
- // this.goods = res.data.data
- item.list = item.list.concat(arr)
- item.page++
- if (arr.length == that.limit) {
- item.loadType = 'more'
- } else {
- item.loadType = 'noMore'
- }
- item.loaded = true
- })
- },
- navClick(index) {
- this.current = index
- this.currents = 0
- this.flist = this.cateList[index].children
- },
- getCateList() {
- getCateList().then(res => {
- console.log();
- this.cateList = res.data.map(item => {
- item.children.forEach(items => {
- items.page = 1
- items.loaded = false
- items.loadType = 'more'
- items.list = []
- })
- return item
- })
- this.flist = this.cateList[0].children
- this.getProducts()
- })
- },
- // 载入数据
- async loadData() {
- let obj = this;
- getCategoryList({})
- .then(({
- data
- }) => {
- obj.flist = data.map(function(s) {
- return s;
- });
- })
- .catch(err => {
- console.log(err);
- });
- },
- //一级分类点击
- tabtap(index) {
- this.currents = index
- this.getProducts('tab')
- },
- //右侧栏滚动
- asideScroll(e) {
- // 判断有没有初始化页面高度对象数据
- if (!this.sizeCalcState) {
- this.calcSize();
- }
- let scrollTop = e.detail.scrollTop;
- let box = 0; //列表包裹框高度初始化
- let bottom = 10; //距离页面底部多少像素左侧列表切换到最后一个一级分类
- // 查询当前页面对象
- let view = uni.createSelectorQuery().select('.content');
- view.fields({
- id: true,
- dataset: true,
- rect: true,
- size: true,
- scrollOffset: true
- },
- function(e) {
- // 保存包裹框高度
- box = e.height;
- }
- ).exec();
- // 获取所有距离顶部大于滚轮距离页面高度的所有分类
- let tabs = this.flist.filter(item => (item.top - 10) <= scrollTop).reverse();
- if (tabs.length > 0) {
- // 判断是否已经到达滚轮底部
- if (box + scrollTop + bottom >= e.detail.scrollHeight) {
- this.currentId = this.flist[this.flist.length - 1].id;
- } else {
- this.currentId = tabs[0].id;
- }
- }
- },
- //计算右侧栏每个tab的高度等信息
- calcSize() {
- let h = 0;
- this.flist.forEach(item => {
- let view = uni.createSelectorQuery().select('#main-' + item.id);
- view.fields({
- size: true
- },
- data => {
- item.top = h;
- h += data.height;
- item.bottom = h;
- }
- ).exec();
- });
- this.sizeCalcState = true;
- },
- navToList(sid, tid) {
- // 点击导航跳转到详细页面
- uni.navigateTo({
- url: '/pages/product/list?fid=' + this.currentId + '&sid=' + sid + '&tid=' + tid
- });
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- page,
- .content {
- height: 100%;
- background-color: #f8f8f8;
- }
- .content {
- // display: flex;
- }
- .left-aside {
- flex-shrink: 0;
- width: 200rpx;
- height: 100%;
- background: #f8f8f8;
- }
- .f-item {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 100%;
- height: 100rpx;
- font-size: 32rpx;
- color: $font-color-base;
- position: relative;
- &.active {
- color: $base-color;
- background-color: #fff;
- &:before {
- content: '';
- position: absolute;
- left: 0;
- top: 50%;
- transform: translateY(-50%);
- height: 36rpx;
- width: 8rpx;
- background-color: $base-color;
- border-radius: 0 4px 4px 0;
- opacity: 0.8;
- }
- }
- }
- .right-aside {
- flex: 1;
- overflow: hidden;
- padding-left: 20rpx;
- padding-right: 20rpx;
- height: 100%;
- }
- .s-item {
- display: flex;
- align-items: center;
- height: 70rpx;
- padding-top: 8rpx;
- font-size: 32rpx;
- color: $font-color-dark;
- }
- .t-list {
- display: flex;
- flex-wrap: wrap;
- border-radius: 15rpx;
- width: 100%;
- background: #fff;
- padding-top: 12rpx;
- &:after {
- content: '';
- flex: 99;
- height: 0;
- }
- }
- .t-item {
- flex-shrink: 0;
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- width: 171rpx;
- font-size: 28rpx;
- color: #666;
- padding-bottom: 20rpx;
- image {
- width: 140rpx;
- height: 140rpx;
- }
- }
- .nav {
- height: 160rpx;
- flex-wrap: wrap;
- width: 100%;
- padding-top: 20rpx;
- border-radius: 20rpx 20rpx 0 0;
- }
- .nav-item {
- height: 140rpx;
- width: 20%;
- flex-shrink: 0;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- font-weight: 500;
- font-size: 23rpx;
- color: #000000;
-
- .cate-img {
- // border: 1px solid red;
- margin-bottom: 10rpx;
- width: 95rpx;
- height: 95rpx;
- border-radius: 50%;
- }
- }
- .action {
- color: $base-color;
- .cate-img {
- border: 1rpx solid $base-color;
- }
- }
-
- .cart-wrap {
- width: 100%;
- height: 114rpx;
- background: #FFFFFF;
- box-shadow: 0rpx 3rpx 16rpx 0rpx rgba(11, 4, 7, 0.17);
- }
- .cart-wraps {
- position: fixed;
- bottom: 0;
- }
- .good {
- height: 154rpx;
- width: 100%;
- margin-bottom: 20rpx;
- position: relative;
- .good-img {
- width: 145rpx;
- height: 154rpx;
- border-radius: 15rpx;
- flex-shrink: 0;
- }
- .info {
- height: 100%;
- margin-right: auto;
- padding-left: 10rpx;
- position: relative;
- .name {
- font-weight: bold;
- font-size: 30rpx;
- color: #323232;
- }
- .price {
- position: absolute;
- bottom: 0;
- left: 10rpx;
- font-size: 34rpx;
- color: #FF4300;
- }
- .gg {
- color: #999999;
- }
-
-
- }
- .btn {
- flex-shrink: 0;
- width: 50rpx;
- height: 50rpx;
- border-radius: 50%;
- align-self: flex-end;
- }
- }
- .bom {
- padding-top: 20rpx;
- background-color: #fff;
- }
- .store-info {
- justify-content: flex-start;
- background-color: #e07756;
- padding: 30rpx 20rpx;
- color: #fff;
- .store-logo {
- width: 100rpx;
- height: 100rpx;
- }
- .info {
- margin-left: 20rpx;
- .name {
- font-size: 32rpx;
- font-weight: bold;
- padding-bottom: 10rpx;
- }
- .dis {
- font-size: 24rpx;
- }
- }
-
- }
-
- .cart-wrap {
- padding: 0 20rpx 0 35rpx;
- .btn-cart {
- width: 60rpx;
- height: 55rpx;
- }
- .price {
- margin-right: auto;
- font-weight: bold;
- font-size: 38rpx;
- color: #FF6B11;
- margin-left: 30rpx;
- }
- .btn {
- width: 218rpx;
- height: 80rpx;
- background: #FF6602;
- border-radius: 10rpx;
- font-weight: bold;
- font-size: 32rpx;
- color: #FFFFFF;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- }
- .specs-wrap {
- width: 670rpx;
- min-height: 659rpx;
- border-radius: 20rpx;
- background-color: #fff;
- padding: 43rpx 24rpx;
- position: relative;
- .tit {
- font-weight: 500;
- font-size: 28rpx;
- color: #333333;
- margin: 47rpx 0 30rpx;
- }
- }
- .good-info {
- height: 140rpx;
- .good-logo {
- width: 140rpx;
- height: 140rpx;
- border-radius: 10rpx;
- }
- .info {
- margin-right: auto;
- padding-left:20rpx;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- height: 100%;
- .name {
- font-weight: bold;
- font-size: 36rpx;
- color: #1C2023;
- }
- .dis {
- font-weight: 500;
- font-size: 42rpx;
- color: #FF6602;
- &::before {
- content: '¥';
- font-size: 22rpx;
- }
- }
- }
- }
- .gg-wrap {
- justify-content: flex-start;
- flex-wrap: wrap;
- border-bottom: 1px solid #EEEEEE;
- padding-bottom:30rpx;
- .gg {
- margin-right: 20rpx;
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 0 50rpx;
- height: 64rpx;
- background: #F6F6F6;
- border-radius: 10rpx;
- }
- }
- .actions {
- background: #ffeff1;
- border: 1px solid #FF5263;
- color: #FF5263 ;
- }
- .buy-num {
- display: flex;
- justify-content: space-between;
- padding-top: 20rpx;
- font-weight: bold;
- font-size: 28rpx;
- color: #333333;
- }
- .buy-now {
- width: 279rpx;
- height: 84rpx;
- background: #FF6602;
- border-radius: 42rpx;
-
- font-weight: bold;
- font-size: 32rpx;
- color: #FFFFFF;
- display: flex;
- justify-content: center;
- align-items: center;
- margin:50rpx auto 0;
- }
- .close-btn {
- position: absolute;
- bottom: -125rpx;
- height: 83rpx;
- width: 83rpx;
- right: 0;
- left: 0;
- margin: auto;
- }
- .cart_wrap {
- background-color: #fff;
- border-radius: 20rpx 20rpx 0 0;
-
- .cart-top {
- font-weight: 500;
- font-size: 27rpx;
- color: #999999;
- justify-content: flex-end;
- height: 90rpx;
- border-bottom: 1px solid #EEEEEE;
- padding-right: 30rpx;
- image {
- width: 28rpx;
- height: 28rpx ;
- margin-right: 15rpx;
- }
- }
- }
- .cart-list-wrap {
- padding: 20rpx;
- }
- .munbox {
- width: 144rpx;
- height: 44rpx;
- position: absolute;
- bottom: 0;
- right: 0;
-
- input {
- display: inline-block;
- text-align: center;
- }
-
- image {
- flex-shrink: 0;
- width: 44rpx;
- height: 44rpx;
- }
- }
- .enaction {
- background-color: #bcbcbc !important;
- }
- </style>
|