import { mapState } from "vuex"; var app = getApp(); export const myMixin = { data() { return { flag: false, shopData: uni.getStorageSync('header_data') || {}, // 店铺信息 shopProduct: [], // 商品列表 shopCategory: [], // 商品类别 shopCategorychild: [], // 分类二级列表 cid2: "", // 类别id currentIndex: "", curidx: "", nodata: false, loading: false, nomore: false, loadmore: true, pagenum: 1, navHeight: 0, hearHeight: 0, isSelectAll: true, event_rul: app.globalData.event_url, }; }, computed: { ...mapState([ 'opt' ]) }, mounted() { let elemetn; // #ifdef MP-WEIXIN let menuButtonInfo = uni.getMenuButtonBoundingClientRect(); uni.getSystemInfo({ success: (res) => { if (res) { elemetn = res.statusBarHeight; } }, }); // #endif // #ifdef MP-WEIXIN this.navHeight = menuButtonInfo.bottom + menuButtonInfo.top - elemetn; // console.log(menuButtonInfo,elemetn, 'navheight') // #endif // #ifndef MP this.navHeight = 60; // #endif this.getData(); this.flag = true; }, methods: { getData: function () { const that = this; // const cid = that.opt.cid; that.loading = true; that.getCategory(); that.getprolist(); }, // 获取类别列表 getCategory() { const that = this; that.loading = true; that.shopCategorychild = []; that.shopCategory = []; console.log(that.opt, "打印opt"); app.post( "/ApiShop/classify", { bid: that.opt.bid, }, function (res) { if (res.data.length > 0) { const shopCategoryArr = []; res.data.map((item, index) => { shopCategoryArr.push({ aid: item.aid, createtime: item.createtime, id: item.id, name: item.name, pic: item.pic, pid: item.pid, }); that.shopCategory.push(item); if (item.id == that.opt.cid) { that.currentIndex = index; if (item.child != []) { item.child.map((item) => { that.shopCategorychild.push(item); }); } console.log(that.shopCategorychild, "打印二级类别"); } }); } } ); }, // 获取商品列表 getprolist(loadmore) { const that = this; that.loading = true; that.nodata = false; that.nomore = false; that.cid2 = that.opt.cid; console.log("打印cid2:", that.cid2, "打印bid:", that.opt.bid); if (!loadmore) { that.pagenum = 1; that.shopProduct = []; } app.post( "/ApiShop/getprolist", { bid: that.opt.bid, cid2: that.cid2, field: "sort", order: "desc", pagenum: that.pagenum, }, function (res) { that.loading = false; if (that.pagenum == 1) { res.data.map((item) => { if (item.id) { item.proid = item.id; } that.shopProduct.push(item); }); if (res.data.length == 0) { that.nodata = true; } } else { if (res.data.length == 0) { that.nomore = true; } else { that.loadmore = false; res.data.map((item) => { if (item.id) { item.proid = item.id; } that.shopProduct = that.shopProduct.concat(item); }); } } } ); }, // 类别跳转 categoryHandle(cid, index) { this.isSelectAll = true; this.currentIndex = index; this.opt.cid = cid; this.getCategory(); this.getprolist(); }, // 二级类别跳转 categoryChildHandle(cid, idx) { this.curidx = idx; this.isSelectAll = false; console.log(cid, "打印cid"); this.opt.cid = cid; // this.getCategory(); this.getprolist(); }, // 滚动 getmorecomment() { this.pagenum = this.pagenum + 1; if (!this.nomore && !this.nodata) { this.getprolist(true); } }, // 获取全部商品 selectAll() { this.currentIndex = ""; this.isSelectAll = true; this.opt.cid = ""; this.getCategory(); this.getprolist(); }, // 获取类别全部商品 selectCategoryAll() { this.isSelectAll = true; this.curidx = ""; console.log( "this.currentIndex:", this.currentIndex, "打印this.shopCategory:", this.shopCategory ); this.shopCategory.map((item, index) => { if (this.currentIndex === index) { this.opt.cid = item.id; } }); this.getCategory(); this.getprolist(); }, }, };