192 lines
3.6 KiB
JavaScript
192 lines
3.6 KiB
JavaScript
/* eslint-disable no-param-reassign */
|
|
import {
|
|
getEmotionCategoryList,
|
|
getEmoticonDataList,
|
|
} from '~/services/emoticon/index';
|
|
import Toast from 'tdesign-miniprogram/toast/index';
|
|
|
|
const initFilters = {
|
|
overall: 1,
|
|
sorts: '',
|
|
};
|
|
|
|
Page({
|
|
data: {
|
|
emoticonDataList: [],
|
|
tabList: [{
|
|
text: "全部",
|
|
key: 0,
|
|
}],
|
|
categoryGuid: 0,
|
|
overall: 1,
|
|
show: false,
|
|
hasLoaded: false,
|
|
keywords: '',
|
|
loadMoreStatus: 0,
|
|
loading: true,
|
|
},
|
|
|
|
privateData: {
|
|
tabIndex: 0,
|
|
},
|
|
|
|
total: 0,
|
|
pageNum: 1,
|
|
pageSize: 10,
|
|
|
|
onLoad(options) {
|
|
const {
|
|
searchValue = ''
|
|
} = options || {};
|
|
this.setData({
|
|
keywords: searchValue,
|
|
},
|
|
() => {
|
|
this.getCategotyList()
|
|
this.init(true);
|
|
},
|
|
);
|
|
},
|
|
|
|
OnShow() {
|
|
this.getCategotyList()
|
|
},
|
|
|
|
generalQueryData(reset = false) {
|
|
const {
|
|
keywords,
|
|
categoryGuid
|
|
} = this.data;
|
|
const {
|
|
pageNum,
|
|
pageSize
|
|
} = this;
|
|
|
|
const params = {
|
|
pageNum: 1,
|
|
pageSize: 10,
|
|
search: keywords,
|
|
emoticonCategoryGuid: categoryGuid
|
|
};
|
|
|
|
if (reset) return params;
|
|
return {
|
|
...params,
|
|
pageNum: pageNum + 1,
|
|
pageSize,
|
|
};
|
|
|
|
},
|
|
|
|
getCategotyList() {
|
|
// 获取表情包分类列表
|
|
getEmotionCategoryList().then((res) => {
|
|
if (res.code == 200) {
|
|
this.setData({
|
|
tabList: this.data.tabList.concat(res.data),
|
|
});
|
|
} else {}
|
|
});
|
|
},
|
|
|
|
// 点击分类
|
|
async tabChangeHandle(e) {
|
|
this.setData({
|
|
categoryGuid: e.detail.value,
|
|
keywords: ""
|
|
});
|
|
// 刷新列表
|
|
await this.init()
|
|
},
|
|
|
|
async init(reset = true) {
|
|
const {
|
|
loadMoreStatus,
|
|
emoticonDataList = []
|
|
} = this.data;
|
|
const params = this.generalQueryData(reset);
|
|
if (loadMoreStatus !== 0) return;
|
|
this.setData({
|
|
loadMoreStatus: 1,
|
|
loading: true,
|
|
});
|
|
try {
|
|
const result = await getEmoticonDataList(params);
|
|
const data = result.data;
|
|
if (result.code == 200) {
|
|
const {
|
|
result,
|
|
totalPage = 0
|
|
} = data;
|
|
if (totalPage === 0 && reset) {
|
|
this.total = totalPage;
|
|
this.setData({
|
|
emptyInfo: {
|
|
tip: '抱歉,未找到相关表情包',
|
|
},
|
|
hasLoaded: true,
|
|
loadMoreStatus: 0,
|
|
loading: false,
|
|
emoticonDataList: [],
|
|
});
|
|
return;
|
|
}
|
|
|
|
const _emoticonDataList = reset ? result : emoticonDataList.concat(result);
|
|
const _loadMoreStatus = _emoticonDataList.length === totalPage ? 2 : 0;
|
|
this.pageNum = params.pageNum || 1;
|
|
this.total = totalPage;
|
|
this.setData({
|
|
emoticonDataList: _emoticonDataList,
|
|
loadMoreStatus: _loadMoreStatus,
|
|
});
|
|
} else {
|
|
this.setData({
|
|
loading: false,
|
|
});
|
|
wx.showToast({
|
|
title: '查询失败,请稍候重试',
|
|
});
|
|
}
|
|
} catch (error) {
|
|
this.setData({
|
|
loading: false,
|
|
});
|
|
}
|
|
this.setData({
|
|
hasLoaded: true,
|
|
loading: false,
|
|
});
|
|
},
|
|
|
|
handleSubmit(e) {
|
|
this.setData({
|
|
emoticonDataList: [],
|
|
loadMoreStatus: 0,
|
|
keywords: e.detail.value
|
|
},
|
|
() => {
|
|
this.init(true);
|
|
},
|
|
);
|
|
},
|
|
|
|
onReachBottom() {
|
|
const {
|
|
emoticonDataList
|
|
} = this.data;
|
|
const {
|
|
total = 0
|
|
} = this;
|
|
if (emoticonDataList.length === total) {
|
|
this.setData({
|
|
loadMoreStatus: 2,
|
|
});
|
|
return;
|
|
}
|
|
this.init(false);
|
|
},
|
|
|
|
|
|
|
|
}); |