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.
 
 
 
 

194 lines
5.5 KiB

import { mapState, mapActions } from 'vuex'
var app = getApp();
export const myMixin = {
data() {
return {
loading: false,
// 1精选内容
shopData: {},
shopNotice: [], // 店铺公告
shopMenu: [], // 店铺菜单
isShowDots: true,
couponids: [],
shopCoupon: [], // 店铺优惠
shopVideo: [], // 店铺短视频
shopNote: [], // 店铺笔记
shopBanner: [], // 店铺banner
shopTuangou: [], // 团购活动
shopProduct: [], // 店铺商品
shopSelPro: [], // 精选商品
}
},
computed: {
...mapState(['opt', 'pagecontentList']),
},
mounted() {
this.getData()
},
methods: {
...mapActions(['acPagecontent']),
getData() {
const that = this;
that.loading = true;
uni.getStorage({
key: "header_data",
success: function(res){
that.shopData = res.data;
},
})
// 获取state的pagecontentList,不为空就直接使用
if (that.pagecontentList.length != 0) {
that.getPagecontent(that.pagecontentList);
} else {
// 否则重新发送请求获取数据
that.getShopBuiness();
}
},
getShopBuiness() {
const that = this;
app.post('ApiBusiness/ThemeIndex', { bid: that.opt.bid }, function (res) {
if (res.pagecontent) {
console.log('ApiBusiness/ThemeIndex=接口返回数据===', res)
const { pagecontent } = res;
that.acPagecontent(pagecontent);
// 内容处理
that.getPagecontent(pagecontent);
}
})
},
getPagecontent(pagecontent) {
const that = this;
console.log("打印pagecontent===========",pagecontent)
pagecontent.map((item) => {
// 公告
if (item.temp === 'notice') {
that.shopNotice = item.data
}
// 轮播图
if (item.temp == 'banner') {
that.shopBanner = item.data
}
// 店铺菜单
let MetuItem = [];
if (item.temp == 'menu') {
if (item.data.length != 0) {
item.data.map((el, index) => {
MetuItem.push(el);
let idx = index + 1;
let num = Math.ceil(item.data.length / 2);
// console.log("打印num",num);
if(item.data.length >= 10) {
if(idx === num) {
that.shopMenu.push(MetuItem);
MetuItem = [];
}
if(idx === item.data.length) {
that.shopMenu.push(MetuItem);
}
} else {
that.shopMenu[0] = MetuItem;
}
if(item.data.length <= 10) {
that.isShowDots = false;
}
})
}
}
// 优惠立减
if (item.temp == 'coupon') {
that.shopCoupon = item.data
that.shopCoupon.map((items,ind) => {
that.$set(items,'idd',ind);
})
that.getCouponTime();
}
// 短视频
if (item.temp == 'shortvideo') {
that.shopVideo = item.data
}
// 笔记
if (item.temp == 'note') {
that.shopNote = item.data
}
// 团购活动
if (item.temp == 'tuangou') {
that.shopTuangou = item.data
}
// 商品列表
if (item.temp == 'product') {
that.shopProduct = item.data
}
// 精选商品
if (item.temp == 'selected_product') {
that.shopSelPro = item.data
}
that.loading = false;
})
uni.getStorage({
key: "isLogin",
success: function(res) {
if(res.data) {
that.getCoupon();
}
}
})
},
// 获取我的优惠券
getCoupon() {
const that = this;
app.post('ApiCoupon/mycoupon', { bid: that.opt.bid }, function (res) {
let Newcouponids = [];
res.data.map((item) => {
Newcouponids.push({couponid: item.couponid})
})
that.couponids = Newcouponids;
console.log("优惠券id",that.couponids)
that.getCouponTime();
if(that.couponids.length > 0) {
that.couponids.map((item) => {
that.shopCoupon.map((item1) => {
// 我的优惠券列表的优惠券id与店铺所有优惠券id对比,相等的就显示去使用
if(item.couponid === item1.couponid) {
// console.log("打印优惠券id",item.couponid,item1.couponid)
that.$set(item1,"msg","去使用");
that.$set(item1,'isUse',true);
that.$set(item,'isOver',false);
}
})
})
}
})
},
// 优惠券时间(是否已经过期)
getCouponTime() {
let that = this;
for (let i = that.shopCoupon.length - 1; i >= 0; i--) {
let now = new Date(); // 当前时间
let endTime = that.shopCoupon[i].endtime;
let end = new Date(endTime.replace(/-/g,"/")); // 对比时间
if(now.getTime() > end.getTime()) {
that.shopCoupon.splice(i,1);
}else {
// 未过期
that.$set(that.shopCoupon[i],'isUse',false);
that.$set(that.shopCoupon[i],'isOver',false);
}
}
}
}
}