const app = getApp(); Page({ /** * 页面的初始数据 */ data: { barHeight: '', navBarHeight: '', searchValue: '', path: '', pathList: [], pageCount: { page: 1, total: 0, }, isMore: null, assortCheck: { name: '', code: '', }, bookList: [], stairList: { value: '', options: [ { value: '', label: '一级', }, ], }, secondList: { value: [], options: [], }, majorProjectList: { value: [], options: [], }, newTextBook: { value: [], options: [], }, stairCode: '', // 一级分类选中项 secondCode: '', // 二级分类选中项 sort: '', // 排序 enable: false, loadingProps: { size: '50rpx' }, loading: false, noData: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { const systInfo = wx.getSystemInfoSync(); const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息 const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度 this.setData({ barHeight: systInfo.statusBarHeight, navBarHeight: navBarHeight, }); // 搜索赋值 if (options.searchValue) { this.setData({ searchValue: options.searchValue, }); } // 高级分类赋值 this.setData({ assortCheck: { name: options.assorName, code: options.assortCode, }, }); if (this.data.assortCheck.code) { this.setData({}); } // 获取一级分类 this.getStairList(options.assortCode); // 一级分类和path赋值 if (options.stairCode) { this.setData({ 'stairList.value': options.stairCode, stairCode: options.stairCode, path: `${options.assortCode}\\${options.stairCode}`, }); } // 二级分类赋值 if (options.secondCode) { this.setData({ secondCode: options.secondCode, pathList: [{ Path: options.secondCode, Type: '*', StoreRefCode: app.config.goodsStore, } ], }) } // 获取二级分类 this.getSecondList(`${options.assortCode}\\${options.stairCode}`); this.getBookList(`${options.assortCode}\\${options.stairCode}`); // 获取重点项目 this.getProjectList('bookClassification'); this.getProjectList('newFormsTextbooks'); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { console.log('下拉'); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom(e) { const flag = this.data.bookList.length < this.data.pageCount.total if (flag) { this.setData({ isMore: true, "pageCount.page": this.data.pageCount.page + 1 }) this.getBookList(this.data.path) } else { this.setData({ isMore: true, }) setTimeout(() => { this.setData({ isMore: false }) }, 100) console.log('没有更多了'); } }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, goBack() { wx.navigateBack(); }, // 获取一级列表 getStairList(path) { const query = { path, filterList: [], queryType: '\\', searchList: [], size: '30', start: '0', storeRefCode: app.config.goodsStore, sort: { type: 'Asc', field: 'LinkOrder' }, }; app.MG.store.getStoreChannelList(query).then(async (res) => { const options = [ { value: '', label: '一级', }, ]; for (let index = 0; index < res.datas.length; index++) { const item = res.datas[index]; options.push({ value: item.refCode, label: item.name, }); } this.setData({ 'stairList.options': options, 'stairList.value': this.data.stairCode, }); }); }, // 获取一级分类下二级分类 getSecondList(path) { const options = []; const query = { path, filterList: [], queryType: '\\', searchList: [], size: '30', start: '0', storeRefCode: app.config.goodsStore, sort: { type: 'Asc', field: 'LinkOrder' }, }; app.MG.store.getStoreChannelList(query).then((res) => { for (let index = 0; index < res.datas.length; index++) { const item = res.datas[index]; options.push({ value: `${item.pathLinks[0].linkPath}\\${item.id}`, label: item.name, }); } this.setData({ 'secondList.options': options, }); const second = [this.data.secondCode] this.setData({ 'secondList.value': second }) }); }, // 获取重点项目 getProjectList(type) { const options = []; const arr = []; let array = []; const query = { refCodes: [type], }; app.MG.store.getProductTypeField(query).then((res) => { array = JSON.parse(res[0].config).option; for (let index = 0; index < array.length; index++) { const element = array[index]; if (element.child) { for (let index = 0; index < element.child.length; index++) { const item = element.child[index]; arr.push(item); } } } if (type == 'bookClassification') { for (let index = 0; index < arr.length; index++) { const element = arr[index]; options.push({ value: element.value, label: element.name, }); } this.setData({ 'majorProjectList.options': options, }); } else if (type == 'newFormsTextbooks') { for (let index = 0; index < arr.length; index++) { const element = arr[index]; options.push({ value: element.value, label: element.name, }); } this.setData({ 'newTextBook.options': options, }); console.log('重点项目', this.data.newTextBook); } }); }, // 获取图书列表 getBookList(path) { this.setData({ loading: true, noData: false }) let sort; let pathObj = {}; if (this.data.pathList.length) { pathObj = { subAccess: this.data.pathList, }; } else { pathObj = { path, queryType: '*', }; } if (this.data.sort) { sort = { Name: this.data.sort, BaseType: '', }; } else { sort = { type: 'Desc', field: 'ViewCount', }; } // 搜索 let searchObj = {}; if (this.data.searchValue) { searchObj = { 'Name*': this.data.searchValue, '||author*': this.data.searchValue, '||isbn*': this.data.searchValue, '||seriesName*': this.data.searchValue, }; } const query = { ...pathObj, filterList: [ { value: 'Normal', field: 'state', }, ], sort, paging: { start: 0, size: this.data.pageCount.page * 8, }, fields: { author: [], publicationDate: [], ...searchObj, 'bookClassification*': this.data.majorProjectList.value, 'newFormsTextbooks*': this.data.newTextBook.value, }, }; app.MG.store.getProductList(query).then((res) => { this.setData({ bookList: res.datas, enable: false, "pageCount.total": res.total, loading: false }); console.log('图书列表', res.datas); if (!res.datas.length) { this.setData({ noData: true }) } }); }, // 一级分类切换 onChangeStair(e) { const path = e.detail.value.length ? `${this.data.assortCheck.code}\\${e.detail.value}` : this.data.assortCheck.code; this.setData({ pathList: [], stairCode: e.detail.value, secondCode: '', path: path, 'stairList.value': e.detail.value, }); this.getBookList(path); this.getSecondList(path); }, // 二级分类切换 onChangeSecond(e) { const pathList = []; for (let index = 0; index < e.detail.value.length; index++) { const element = e.detail.value[index]; pathList.push({ Path: element, Type: '*', StoreRefCode: app.config.goodsStore, }); } this.setData({ pathList: pathList, 'secondList.value': e.detail.value, }); }, // onConfirmSecond() { this.getBookList(this.data.path); }, // 重点项目改变 changeMajorProject(e) { this.setData({ 'majorProjectList.value': e.detail.value, }); this.getBookList(this.data.path); }, // 重点项目重置 resetMajorProject() { this.setData({ 'majorProjectList.value': [], }); this.getBookList(this.data.path); }, changeNewText(e) { this.setData({ 'newTextBook.value': e.detail.value, }); this.getBookList(this.data.path); }, resetNewText() { this.setData({ 'newTextBook.value': [], }); this.getBookList(this.data.path); }, // 排序按钮 sortClick() { if (!this.data.sort.length) { this.setData({ sort: 'Desc', }); } else if (this.data.sort == 'Desc') { this.setData({ sort: 'Asc', }); } else if (this.data.sort == 'Asc') { this.setData({ sort: '', }); } let path; if (this.data.secondCode) { path = this.data.secondCode; } else if (this.data.stairCode) { path = `${this.data.assortCheck.code}\\${this.data.stairCode}`; } else { path = this.data.assortCheck.code; } this.setData({ path: path, }); this.getBookList(path); }, // 搜索图书 searchBook(e) { console.log(e.detail.value); this.setData({ searchValue: e.detail.value, }); this.getBookList(this.data.path); }, // 跳转图书详情 goDetail(e) { const { book } = e.currentTarget.dataset; wx.navigateTo({ url: `/packageBookService/pages/bookServices/detail/index?id=${book.id}&name=${book.name}`, }); }, onRefresh() { this.setData({ enable: true }); this.getBookList(this.data.path) }, });