From 3d73fb33c46aada16a6060adcd4ea14bb33b6b2a Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期二, 09 四月 2024 10:39:11 +0800 Subject: [PATCH] 详情页tabs样式优化,答题添加页面退出拦截,合并代码 --- packageBookService/pages/bookServices/list/index.js | 418 +++++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 292 insertions(+), 126 deletions(-) diff --git a/packageBookService/pages/bookServices/list/index.js b/packageBookService/pages/bookServices/list/index.js index 656c94b..6f9dd50 100644 --- a/packageBookService/pages/bookServices/list/index.js +++ b/packageBookService/pages/bookServices/list/index.js @@ -1,13 +1,14 @@ const app = getApp(); +import { loginInfo } from "../../../../assets/js/login"; Page({ /** * 椤甸潰鐨勫垵濮嬫暟鎹� */ data: { - barHeight: '', - navBarHeight: '', - searchValue: '', - path: '', + barHeight: "", + navBarHeight: "", + searchValue: "", + path: "", pathList: [], pageCount: { page: 1, @@ -15,40 +16,74 @@ }, isMore: null, assortCheck: { - name: '', - code: '', + name: "", + code: "", }, bookList: [], stairList: { - value: '', + value: "", options: [ { - value: '', - label: '涓�绾�', + value: "", + label: "涓�绾�", }, ], }, secondList: { value: [], options: [], + disabled: false, }, majorProjectList: { value: [], options: [], }, + sortList: { + value: "default", + options: [ + { + value: "default", + label: "榛樿鎺掑簭", + }, + { + value: "name-asc", + label: "鍚嶇О姝e簭", + }, + { + value: "name-desc", + label: "鍚嶇О鍊掑彊", + }, + { + value: "time-asc", + label: "鍑虹増鏃堕棿姝e簭", + }, + { + value: "time-desc", + label: "鍑虹増鏃堕棿鍊掑彊", + }, + ], + }, newTextBook: { value: [], options: [], }, - stairCode: '', // 涓�绾у垎绫婚�変腑椤� - secondCode: '', // 浜岀骇鍒嗙被閫変腑椤� - sort: '', // 鎺掑簭 + stairCode: "", // 涓�绾у垎绫婚�変腑椤� + secondCode: "", // 浜岀骇鍒嗙被閫変腑椤� + sort: "", // 鎺掑簭 enable: false, loadingProps: { - size: '50rpx' + size: "50rpx", }, loading: false, - noData: false + noData: false, + showDropdown: false, + isRequesting: false, + disabledStair: false, + disabledSecondList: false, + disabledProject: false, + disabledNewForms: false, + triggered: false, + backTop: "", }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 @@ -56,7 +91,8 @@ onLoad(options) { const systInfo = wx.getSystemInfoSync(); const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅 - const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴� + const navBarHeight = + (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴� this.setData({ barHeight: systInfo.statusBarHeight, navBarHeight: navBarHeight, @@ -82,7 +118,7 @@ // 涓�绾у垎绫诲拰path璧嬪�� if (options.stairCode) { this.setData({ - 'stairList.value': options.stairCode, + "stairList.value": options.stairCode, stairCode: options.stairCode, path: `${options.assortCode}\\${options.stairCode}`, }); @@ -91,99 +127,111 @@ if (options.secondCode) { this.setData({ secondCode: options.secondCode, - pathList: [{ - Path: options.secondCode, - Type: '*', - StoreRefCode: app.config.goodsStore, - } + 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'); + this.getProjectList("bookClassification"); + this.getProjectList("newFormsTextbooks"); }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 */ - onReady() { - }, + onReady() {}, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ - onShow() { - }, + onShow() {}, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 */ - onHide() { }, + onHide() {}, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇 */ - onUnload() { }, + onUnload() {}, /** * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ onPullDownRefresh() { - console.log('涓嬫媺'); + this.setData({ + triggered: true, + }); + this.setData({ + "pageCount.page": 1, + }); + this.getBookList(this.data.path); }, /** * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� */ onReachBottom(e) { - const flag = this.data.bookList.length < this.data.pageCount.total + 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) + if (!this.data.isRequesting) { + 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('娌℃湁鏇村浜�'); + isMore: false, + }); + }, 100); } }, /** * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� */ - onShareAppMessage() { }, + onShareAppMessage() {}, goBack() { wx.navigateBack(); }, // 鑾峰彇涓�绾у垪琛� getStairList(path) { + this.setData({ + disabledStair: false, + }); const query = { path, filterList: [], - queryType: '\\', + queryType: "\\", searchList: [], - size: '30', - start: '0', + size: "30", + start: "0", storeRefCode: app.config.goodsStore, - sort: { type: 'Asc', field: 'LinkOrder' }, + sort: { + type: "Asc", + field: "LinkOrder", + }, }; app.MG.store.getStoreChannelList(query).then(async (res) => { const options = [ { - value: '', - label: '涓�绾�', + value: "", + label: "涓�绾�", }, ]; for (let index = 0; index < res.datas.length; index++) { @@ -194,9 +242,14 @@ }); } this.setData({ - 'stairList.options': options, - 'stairList.value': this.data.stairCode, + "stairList.options": options, + "stairList.value": this.data.stairCode, }); + if (!options.length) { + this.setData({ + disabledStair: true, + }); + } }); }, // 鑾峰彇涓�绾у垎绫讳笅浜岀骇鍒嗙被 @@ -205,14 +258,26 @@ const query = { path, filterList: [], - queryType: '\\', + queryType: "\\", searchList: [], - size: '30', - start: '0', + size: "30", + start: "0", storeRefCode: app.config.goodsStore, - sort: { type: 'Asc', field: 'LinkOrder' }, + sort: { + type: "Asc", + field: "LinkOrder", + }, }; app.MG.store.getStoreChannelList(query).then((res) => { + if (!res.datas.length) { + this.setData({ + disabledSecondList: true, + }); + } else { + this.setData({ + disabledSecondList: false, + }); + } for (let index = 0; index < res.datas.length; index++) { const item = res.datas[index]; options.push({ @@ -221,16 +286,20 @@ }); } this.setData({ - 'secondList.options': options, + "secondList.options": options, }); - const second = [this.data.secondCode] + const second = [this.data.secondCode]; this.setData({ - 'secondList.value': second - }) + "secondList.value": second, + }); }); }, // 鑾峰彇閲嶇偣椤圭洰 getProjectList(type) { + this.setData({ + disabledProject: false, + disabledNewForms: false, + }); const options = []; const arr = []; let array = []; @@ -238,7 +307,9 @@ refCodes: [type], }; app.MG.store.getProductTypeField(query).then((res) => { - array = JSON.parse(res[0].config).option; + array = JSON.parse(res[0].config).option.filter( + (item) => item.value == this.data.assortCheck.code + ); for (let index = 0; index < array.length; index++) { const element = array[index]; if (element.child) { @@ -248,7 +319,7 @@ } } } - if (type == 'bookClassification') { + if (type == "bookClassification") { for (let index = 0; index < arr.length; index++) { const element = arr[index]; options.push({ @@ -256,10 +327,15 @@ label: element.name, }); } + if (!options.length) { + this.setData({ + disabledProject: true, + }); + } this.setData({ - 'majorProjectList.options': options, + "majorProjectList.options": options, }); - } else if (type == 'newFormsTextbooks') { + } else if (type == "newFormsTextbooks") { for (let index = 0; index < arr.length; index++) { const element = arr[index]; options.push({ @@ -267,19 +343,28 @@ label: element.name, }); } + if (!options.length) { + this.setData({ + disabledNewForms: true, + }); + } this.setData({ - 'newTextBook.options': options, + "newTextBook.options": options, }); - console.log('閲嶇偣椤圭洰', this.data.newTextBook); + console.log("閲嶇偣椤圭洰", this.data.newTextBook); } }); }, // 鑾峰彇鍥句功鍒楄〃 getBookList(path) { + if (this.data.isRequesting) { + return false; + } this.setData({ loading: true, - noData: false - }) + noData: false, + isRequesting: true, + }); let sort; let pathObj = {}; if (this.data.pathList.length) { @@ -287,44 +372,67 @@ subAccess: this.data.pathList, }; } else { - pathObj = { + pathObj = { path, - queryType: '*', + queryType: "*", }; } - if (this.data.sort) { + if (this.data.sortList.value == "name-asc") { sort = { - Name: this.data.sort, - BaseType: '', + Name: "Asc", + BaseType: "", }; - } else { + } else if (this.data.sortList.value == "name-desc") { sort = { - type: 'Desc', - field: 'ViewCount', + Name: "Desc", + BaseType: "", + }; + } else if (this.data.sortList.value == "time-asc") { + sort = { + PublicationDate: "Asc", + BaseType: "DateTime", + }; + } else if (this.data.sortList.value == "time-desc") { + sort = { + PublicationDate: "Desc", + BaseType: "DateTime", + }; + } else if (this.data.sortList.value == "default") { + sort = { + field: "order", + type: "Desc", }; } + // 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, + "Name*": this.data.searchValue, + "||author*": this.data.searchValue, + "||isbn*": this.data.searchValue, + "||seriesName*": this.data.searchValue, }; } const query = { ...pathObj, filterList: [ { - value: 'Normal', - field: 'state', + value: "Normal", + field: "state", }, ], sort, - coverSize: { - height: 145, - }, paging: { start: 0, size: this.data.pageCount.page * 8, @@ -333,22 +441,31 @@ author: [], publicationDate: [], ...searchObj, - 'bookClassification*': this.data.majorProjectList.value, - 'newFormsTextbooks*': this.data.newTextBook.value, + "bookClassification*": this.data.majorProjectList.value, + "newFormsTextbooks*": this.data.newTextBook.value, }, }; app.MG.store.getProductList(query).then((res) => { this.setData({ bookList: res.datas, + isMore: null, enable: false, "pageCount.total": res.total, - loading: false + loading: false, + isRequesting: false, }); - console.log('鍥句功鍒楄〃', res.datas); if (!res.datas.length) { this.setData({ - noData: true - }) + noData: true, + }); + } + if (this.data.triggered) { + this.setData({ + triggered: false, + }); + wx.showToast({ + title: "鍒锋柊鎴愬姛", + }); } }); }, @@ -357,15 +474,26 @@ const path = e.detail.value.length ? `${this.data.assortCheck.code}\\${e.detail.value}` : this.data.assortCheck.code; + console.log(this.data.path); + this.setData({ + backTop: "#assort-title", pathList: [], stairCode: e.detail.value, - secondCode: '', + secondCode: "", path: path, - 'stairList.value': e.detail.value, + "stairList.value": e.detail.value, }); + + if (e.detail.value == "") { + this.setData({ + disabledSecondList: true, + }); + } else { + this.getSecondList(path); + } this.getBookList(path); - this.getSecondList(path); + console.log(this.data.disabledSecondList); }, // 浜岀骇鍒嗙被鍒囨崲 onChangeSecond(e) { @@ -374,60 +502,42 @@ const element = e.detail.value[index]; pathList.push({ Path: element, - Type: '*', + Type: "*", StoreRefCode: app.config.goodsStore, }); } this.setData({ + backTop: "#assort-title", pathList: pathList, - 'secondList.value': e.detail.value, + "secondList.value": e.detail.value, }); }, - // + // onConfirmSecond() { this.getBookList(this.data.path); }, // 閲嶇偣椤圭洰鏀瑰彉 changeMajorProject(e) { this.setData({ - 'majorProjectList.value': e.detail.value, + backTop: "#assort-title", + "majorProjectList.value": e.detail.value, }); this.getBookList(this.data.path); }, // 閲嶇偣椤圭洰閲嶇疆 resetMajorProject() { this.setData({ - 'majorProjectList.value': [], + "majorProjectList.value": [], }); this.getBookList(this.data.path); }, - changeNewText(e) { + // 鎺掑簭鍒囨崲 + onSortChange(e) { this.setData({ - 'newTextBook.value': e.detail.value, + backTop: "#assort-title", + "sortList.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; @@ -441,10 +551,52 @@ }); this.getBookList(path); }, + // 鏂板舰鎬佹暀鏉愭敼鍙� + changeNewText(e) { + this.setData({ + backTop: "#assort-title", + "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({ + backTop: "#assort-title", searchValue: e.detail.value, }); this.getBookList(this.data.path); @@ -457,7 +609,21 @@ }); }, onRefresh() { - this.setData({ enable: true }); - this.getBookList(this.data.path) + this.setData({ + enable: true, + }); + this.getBookList(this.data.path); + }, + openDropdown() { + console.log("灞曞紑鍝�"); + this.setData({ + showDropdown: true, + }); + }, + closeDropdown() { + console.log("鍏抽棴"); + this.setData({ + showDropdown: false, + }); }, }); -- Gitblit v1.9.1