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.
 

320 lines
7.3 KiB

var app = getApp();
var WXAPI = require('../../utils/server.js');
Page({
data: {
current: 0,
shopList: [],
ptype: '',
title: '',
page: 1,
catId: 0,
cont: 1,
remind: '加载中',//进来加载
brandId: 0,
heng:'xs',//控制显示方式
shu:'bxs',
logoUrl: "https://cz-hl-shop.oss-cn-shanghai.aliyuncs.com/239/1/20230227/",
xianshi:'icon-yduipaibanleixingliebiao',
imageurl1: "../../images/mo.png",//默认排序图
daindex1: 0,
imageurl2: "../../images/mo.png",
daindex2: 0,
loading: false,//显示加载
period: false,//显示无数据
select:0,//选中
sort: 0,// 1 asc 升序 0 desc 降序
},
onPullDownRefresh: function () {
var that = this;
var objectId = that.data.objectId;
var select = that.data.select;
var sort = that.data.sort;
that.getMore();
},
/* tab */
choosesort1: function (e) {
var that =this;
if (this.data.daindex1 == 0) {
this.setData({
imageurl1: "../../images/shang.png",
daindex1: 1,
imageurl2: "../../images/mo.png",
})
} else {
this.setData({
imageurl1: "../../images/xia.png",
daindex1: 0,
imageurl2: "../../images/mo.png",
})
}
this.setData({
select: 1,
sort: that.data.daindex1,
page: 1,
period: false,
});
that.sort();
},
choosesort2: function (e) {
var that = this;
if (this.data.daindex2 == 0) {
this.setData({
imageurl2: "../../images/shang.png",
daindex2: 1,
imageurl1: "../../images/mo.png",
})
} else {
this.setData({
imageurl2: "../../images/xia.png",
imageurl1: "../../images/mo.png",
daindex2: 0
})
}
this.setData({
select: 2,
sort: that.data.daindex2,
page: 1,
period: false,
});
that.sort();
},
default: function (e) {
var that = this;
this.setData({
select: 0,
sort: 1,
imageurl1: "../../images/mo.png",
imageurl2: "../../images/mo.png",
page: 1,
period: false,
})
that.sort();
},
tabchage: function () {
if (this.data.heng == 'xs'){
this.setData({
heng: 'bxs',
shu: 'xs',
xianshi: 'icon-yduipaibanleixingduicheng'
})
}else{
this.setData({
heng: 'xs',
shu: 'bxs',
xianshi: 'icon-yduipaibanleixingliebiao'
})
}
},
showModal: function () {
// 显示遮罩层
var animation = wx.createAnimation({
duration: 200,
timingFunction: "linear",
delay: 0
})
this.animation = animation
animation.translateY(300).step()
this.setData({
animationData: animation.export(),
showModalStatus: true
})
setTimeout(function () {
animation.translateY(0).step()
this.setData({
animationData: animation.export()
})
}.bind(this), 200)
},
hideModal: function () {
// 隐藏遮罩层
var animation = wx.createAnimation({
duration: 200,
timingFunction: "linear",
delay: 0
})
this.animation = animation
animation.translateY(300).step()
this.setData({
animationData: animation.export(),
})
setTimeout(function () {
animation.translateY(0).step()
this.setData({
animationData: animation.export(),
showModalStatus: false
})
}.bind(this), 200)
},
//上拉事件
onReachBottom: function () {
var that = this;
that.setData({
loading: true,
});
that.getMore();
},
//排序
sort:function (){
//页面初始化 options为页面跳转所带来的参数
var that = this;
var select = that.data.select;
var sort = that.data.sort;
var page = that.data.page;
WXAPI.newArrival({
accessId: app.globalData.accessId,
storeId: 239,
storeType: 1,
// page: page,
}).then(res => {
if (res.code == 200) {
var data = res.data;
that.setData({
shopList: data.list,
page: page+1
})
}
});
},
//页面加载完成函数
onReady: function () {
var that = this;
},
// 点击加载更多
getMore: function (e) {
var that = this;
var page = that.data.page;
var objectId = that.data.objectId;
var select = that.data.select;
var sort = that.data.sort;
that.setData({
page: page+1
});
if (that.data.title == '新品上市') {
that.getNewArrival()
} else {
that.getRecommend()
}
},
//新品上市
getNewArrival() {
var that = this;
wx.showNavigationBarLoading() //在标题栏中显示加载
WXAPI.newArrival({
accessId: app.globalData.accessId,
storeId: 239,
storeType: 1,
}).then(res => {
if (res.code == 200) {
var data = res.data;
//成功返回设置数据
if (data == '') {
that.setData({
loading: false,
});
return;
} else {
that.setData({
remind: '',
loading:false,
shopList: data.list
// shopList: that.data.shopList.concat(data.list)
});
}
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
}
});
},
//好物优选
getRecommend() {
var that = this;
wx.showNavigationBarLoading() //在标题栏中显示加载
WXAPI.recommend({
accessId: app.globalData.accessId,
storeId: 239,
storeType: 1,
}).then(res => {
if (res.code == 200) {
var data = res.data;
//成功返回设置数据
if (data == '') {
that.setData({
loading: false,
});
return;
} else {
that.setData({
remind: '',
loading:false,
shopList: data.list
// shopList: that.data.shopList.concat(data.list)
});
}
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
}
});
},
onShow: function () {
},
onLoad: function (options) {
wx.setNavigationBarTitle({
title: options.title,
})
this.setData({
title: options.title,
});
//页面初始化 options为页面跳转所带来的参数
this.getMore();
},
//详情页跳转
lookdetail: function (e) {
var lookid = e.currentTarget.dataset;
wx.navigateTo({
url: "../index/detail?id=" + lookid.id
})
},
switchSlider: function (e) {
this.setData({
current: e.target.dataset.index
})
},
changeSlider: function (e) {
this.setData({
current: e.detail.current
})
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
// 获取滚动条当前位置
onPageScroll: function (e) {
if (e.scrollTop > 300) {
this.setData({
floorstatus: true
});
} else {
this.setData({
floorstatus: false
});
}
},
//回到顶部
goTop: function (e) { // 一键回到顶部
if (wx.pageScrollTo) {
wx.pageScrollTo({
scrollTop: 0
})
} else {
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
},
})