You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
264 lines
6.6 KiB
264 lines
6.6 KiB
|
|
import { mapState } from "vuex";
|
|
|
|
var app = getApp();
|
|
export const myMixin = {
|
|
data() {
|
|
return {
|
|
loading: false,
|
|
|
|
// 3. 活动 内容
|
|
menuindex: -1,
|
|
event_rul: app.globalData.event_url,
|
|
shopTuangou: [], // 团购活动
|
|
pagenum: 1,
|
|
nomore: false,
|
|
nodata: false,
|
|
field: "sort",
|
|
order: "desc",
|
|
cpid: "",
|
|
isActivity: true, // 是否有活动
|
|
saixuan: false, // 是否选中筛选
|
|
|
|
visibleSync: false,
|
|
showDrawer: false,
|
|
rightMode: false,
|
|
watchTimer: null,
|
|
drawerWidth: 70,
|
|
mask: true,
|
|
maskClick: true,
|
|
mode: "right",
|
|
|
|
selectAll: true,
|
|
boltingList: [],
|
|
boltingListIndex: 0,
|
|
timestamp: 0, // 当前时间戳
|
|
|
|
}
|
|
},
|
|
props: {
|
|
hearHeight: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
},
|
|
computed: {
|
|
...mapState(['opt'])
|
|
},
|
|
mounted() {
|
|
this.getData();
|
|
},
|
|
|
|
methods: {
|
|
gettimestamp() {
|
|
this.timestamp = Date.parse(new Date()) / 1000
|
|
},
|
|
getData: function () {
|
|
this.loading = true;
|
|
this.getprolist();
|
|
},
|
|
// 获取活动商品列表
|
|
getprolist(loadmore) {
|
|
this.gettimestamp()
|
|
const that = this;
|
|
that.loading = true;
|
|
that.nodata = false;
|
|
that.nomore = false;
|
|
if (!loadmore) {
|
|
that.pagenum = 1;
|
|
that.shopTuangou = [];
|
|
}
|
|
console.log("打印最开始的cpid", that.cpid);
|
|
app.post(
|
|
"/ApiTuangou/getprolist",
|
|
{
|
|
bid: that.opt.bid,
|
|
cpid: that.cpid,
|
|
field: that.field,
|
|
order: that.order,
|
|
pagenum: that.pagenum,
|
|
},
|
|
function (res) {
|
|
console.log("ApiShop/getprolist=接口返回数据===", res);
|
|
that.loading = false;
|
|
if (that.pagenum == 1) {
|
|
// console.log("that.pagenum-------", that.pagenum);
|
|
that.isActivity = true;
|
|
res.data.map((item) => {
|
|
if (item.id) {
|
|
item.proid = item.id;
|
|
}
|
|
that.shopTuangou.push(item);
|
|
});
|
|
// 如果没有团购活动就返回店铺商品
|
|
if (res.data.length == 0) {
|
|
that.isActivity = false;
|
|
that.getAllProList(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.shopTuangou = that.shopTuangou.concat(item);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
);
|
|
},
|
|
// 获取全部商品
|
|
getAllProList(loadmore) {
|
|
this.gettimestamp()
|
|
const that = this;
|
|
that.loading = true;
|
|
that.nodata = false;
|
|
that.nomore = false;
|
|
if (!loadmore) {
|
|
that.pagenum = 1;
|
|
that.shopTuangou = [];
|
|
}
|
|
console.log("this.cpid-------------", that.cpid);
|
|
app.post(
|
|
"/ApiShop/getprolist",
|
|
{
|
|
bid: that.opt.bid,
|
|
field: that.field,
|
|
order: that.order,
|
|
pagenum: that.pagenum,
|
|
},
|
|
function (res) {
|
|
that.loading = false;
|
|
if (that.pagenum == 1) {
|
|
res.data.map((item) => {
|
|
if (item.id) {
|
|
item.proid = item.id;
|
|
}
|
|
that.shopTuangou.push(item);
|
|
});
|
|
if (res.data.length == 0) {
|
|
that.nodata = true;
|
|
}
|
|
} else {
|
|
if (res.data.length == 0) {
|
|
that.nomore = true;
|
|
} else {
|
|
res.data.map((item) => {
|
|
if (item.id) {
|
|
item.proid = item.id;
|
|
}
|
|
that.shopTuangou = that.shopTuangou.concat(item);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
);
|
|
},
|
|
// 获取活动分类
|
|
getclassify() {
|
|
const that = this;
|
|
app.get("/ApiTuangou/prolist", { bid: that.opt.bid }, function (res) {
|
|
console.log("团购活动筛选", res);
|
|
const NewboltingList = [];
|
|
res.clist.map((item) => {
|
|
NewboltingList.push({
|
|
id: item.id,
|
|
name: item.name,
|
|
});
|
|
});
|
|
that.boltingList = NewboltingList;
|
|
});
|
|
},
|
|
// 滚动
|
|
getmorecomment() {
|
|
this.pagenum = this.pagenum + 1;
|
|
if (!this.nomore && !this.nodata) {
|
|
if(this.isActivity) {
|
|
this.getprolist(true);
|
|
}else {
|
|
this.getAllProList(true)
|
|
}
|
|
}
|
|
},
|
|
// 切换 -活动
|
|
sortClick(e) {
|
|
this.saixuan = false
|
|
this.field = e.currentTarget.dataset.field;
|
|
this.order = e.currentTarget.dataset.order;
|
|
// 每次跳转之前先把商品列表清空
|
|
this.shopTuangou = [];
|
|
if(this.isActivity) {
|
|
this.getprolist();
|
|
}else {
|
|
this.getAllProList()
|
|
}
|
|
},
|
|
|
|
// 筛选
|
|
close(type) {
|
|
// fixed by mehaotian 抽屉尚未完全关闭或遮罩禁止点击时不触发以下逻辑
|
|
if ((type === "mask" && !this.maskClick) || !this.visibleSync) return;
|
|
this._change("showDrawer", "visibleSync", false);
|
|
this.boltingList = [];
|
|
},
|
|
open() {
|
|
this.saixuan = true
|
|
const that = this;
|
|
// fixed by mehaotian 处理重复点击打开的事件
|
|
if (that.visibleSync) return;
|
|
that._change("visibleSync", "showDrawer", true);
|
|
that.getclassify();
|
|
},
|
|
_change(param1, param2, status) {
|
|
this[param1] = status;
|
|
if (this.watchTimer) {
|
|
clearTimeout(this.watchTimer);
|
|
}
|
|
this.watchTimer = setTimeout(
|
|
() => {
|
|
this[param2] = status;
|
|
this.$emit("change", status);
|
|
},
|
|
status ? 50 : 300
|
|
);
|
|
},
|
|
filterConfirm(cpid) {
|
|
this._change("showDrawer", "visibleSync", false);
|
|
this.cpid = cpid;
|
|
console.log("点击确定打印cpid", this.cpid);
|
|
this.shopTuangou = [];
|
|
this.getprolist();
|
|
this.boltingList = [];
|
|
},
|
|
bolting(n) {
|
|
const that = this;
|
|
that.boltingListIndex = n;
|
|
console.log("点击tab打印boltingList", that.boltingList);
|
|
that.boltingList.map((item, index) => {
|
|
if (that.boltingListIndex === index + 1) {
|
|
that.cpid = item.id;
|
|
console.log("点击tab打印cpid", that.cpid);
|
|
} else {
|
|
that.cpid = "";
|
|
console.log("点击tab打印cpid", that.cpid);
|
|
}
|
|
});
|
|
},
|
|
boltingAll() {
|
|
this.boltingListIndex = 0;
|
|
this.cpid = "";
|
|
console.log("点击all打印cpid", this.cpid);
|
|
},
|
|
},
|
|
beforeDestroy() {
|
|
clearTimeout(this.watchTimer);
|
|
},
|
|
}
|
|
|
|
|
|
|
|
|
|
|