key1_beacon_xcx/pages/home/home.js
2023-11-24 22:54:48 +08:00

257 lines
4.7 KiB
JavaScript

import {
getbannerList
} from '~/services/home/getbannerList';
import {
getNoticeList
} from '~/services/home/getNoticeList';
import {
getSearchRecList
} from '~/services/home/getSearchRecList';
import {
TableDataList
} from '~/services/home/getTableDataList';
import {
getProductsInvolvedList
} from '~/services/table-data/getProductsInvolvedList';
import Toast from 'tdesign-miniprogram/toast/index';
Page({
data: {
imgSrcs: [],
tableDataList: [],
noticeList: [],
popularWords: [],
params: {
pageSize: 10,
pageNum: 1,
isLastUpdate: true,
search: "",
type: 0,
order: "default"
},
pageLoading: false,
current: 0,
autoplay: true,
duration: '500',
interval: 5000,
navigation: {
type: 'dots',
},
swiperImageProps: {
mode: 'scaleToFill',
},
categoryGuid: 0,
loadMoreStatus: 0,
product: {
value: '0',
options: [],
},
sorter: {
value: 'default',
options: [{
value: 'default',
label: '默认排序',
},
{
value: 'date-down',
label: '日期降序',
},
{
value: 'date-up',
label: '日期升序',
},
{
value: 'price-up',
label: '价格从高到低',
},
{
value: 'price-down',
label: '价格从低到高',
},
],
},
},
page: {
size: 10,
num: 1,
},
privateData: {
tabIndex: 0,
},
onShow() {
this.getTabBar().init();
},
onLoad() {
this.init();
},
// 划到底部触发
onReachBottom() {
this.getTableDataList()
},
onPullDownRefresh() {
this.init();
},
init() {
this.loadHomePage();
},
loadHomePage() {
wx.stopPullDownRefresh();
this.setData({
pageLoading: true,
});
this.getTableDataList(false, "")
this.getProductsInvolvedListFun()
// this.getBanner()
// this.getNotice()
},
getBanner() {
// 获取轮播图列表
getbannerList().then((res) => {
if (res.code == 200) {
this.setData({
imgSrcs: res.data.map((v) => v.bannerImg),
});
}
});
},
// 获取涉及产品类别
getProductsInvolvedListFun() {
getProductsInvolvedList().then((res) => {
if (res.code == 200) {
res.data.unshift({
value: '0',
label: '全部类别',
});
this.setData({
"product.value": "0",
"product.options": res.data,
});
console.log(this.data);
}
});
},
// 获取列表
getTableDataList(isInit = false) {
if (isInit) {
this.page.num = 1
}
else{
this.setData({
"params.pageSize": this.page.size,
"params.pageNum": this.page.num
})
}
// const params = {
// pageSize: this.page.size,
// pageNum: this.page.num,
// isLastUpdate: true,
// search,
// type,
// order
// };
this.setData({
loadMoreStatus: 1,
});
TableDataList(this.data.params).then((res) => {
if (res.code == 200) {
if (!isInit) {
this.page.num++;
this.setData({
tableDataList: this.data.tableDataList.concat(res.data.result),
loadMoreStatus: 0,
pageLoading: false
});
} else {
this.setData({
tableDataList: res.data.result,
loadMoreStatus: 0,
pageLoading: false
});
}
console.log(this.data);
} else {}
});
},
getNotice() {
// 获取公告列表
getNoticeList().then((res) => {
if (res.code == 200) {
const _noticeData = res.data.map((v) => {
return {
...v,
visible: true
};
});
this.setData({
noticeList: _noticeData,
pageLoading: false
});
}
});
},
gotoDetail(e) {
const {
dataset
} = e.currentTarget;
const id = dataset?.id;
wx.navigateTo({
url: `/pages/table-data/index?id=${id}`,
});
},
// 搜索
search(e) {
this.setData({
"params.search" : e.detail.value
})
this.getTableDataList(true);
},
onChange(e) {
this.setData({
'product.value': e.detail.value,
});
if(e.detail.value == 0){
this.init()
}
else{
this.setData({
"params.type" : e.detail.value
})
this.getTableDataList(true);
}
},
onChangeOrder(e) {
// this.setData({
// 'product.value': e.detail.value,
// });
if(e.detail.value == 0){
this.init()
}
else{
this.setData({
"params.order" : e.detail.value
})
this.getTableDataList(true);
}
},
});