import { mapState } from "vuex"; var app = getApp(); export const myMixin = { data() { return { loading: false, // 2. 商品 内容 shopSelPro: [], // 精选商品 nodata: false, nomore: false, pagenum: 1, field: "sort", order: "desc", cpid: 0, } }, props: { hearHeight: { type: String, default: "0px", }, }, computed: { ...mapState(['opt']) }, mounted() { this.getData(); }, methods: { getData: function () { const that = this; that.getprolist(); }, // 获取商品列表 getprolist(loadmore) { const that = this; that.loading = true; that.nodata = false; that.nomore = false; if (!loadmore) { that.pagenum = 1; that.shopSelPro = []; } app.post( "/ApiShop/getprolist", { bid: that.opt.bid, field: that.field, order: that.order, pagenum: that.pagenum, }, function (res) { console.log("ApiShop/getprolist=接口返回数据===", res); that.loading = false; if (that.pagenum == 1) { res.data.map((item) => { if (item.id) { item.proid = item.id; } that.shopSelPro.push(item); }); if (res.data.length == 0) { that.nodata = true; } } else { if (res.data.length == 0) { that.nomore = true; } else { console.log("that.pagenum++++++----", that.pagenum); res.data.map((item) => { if (item.id) { item.proid = item.id; } that.shopSelPro = that.shopSelPro.concat(item); }); } } } ); }, // 滚动 getmorecomment() { this.pagenum = this.pagenum + 1; if (!this.nomore && !this.nodata) { this.getprolist(true); } }, // 切换 -商品 sortClick(e) { this.field = e.currentTarget.dataset.field; this.order = e.currentTarget.dataset.order; // 每次切换之前先把商品列表清空 this.shopSelPro = []; this.getprolist(); }, }, beforeDestroy() { clearTimeout(this.watchTimer); }, }