电风扇第三方

都是

var util = require('../../../utils/util.js') var app = getApp() Page({ data: { showsearch: false, //显示搜索按钮 searchtext: '', //搜索文字 showfilter: false, //是否显示下拉筛选 showfilterindex: null, //显示哪个筛选类目 subjectName: "全部学科", schoolName: "所属院校", sujectList: [], //学科 schoolList: [], //学校 selectedSubjectId: "", //当前选中学科id selectedSchoolId: "", //当前选中学校id recCourseList: [], searchList: [], //放置返回数据的数组 isFromSearch: true, // 用于判断searchList数组是不是空数组,默认true,空的数组 pageIndex: 1, // 设置加载的第几次,默认是第一次 pageSize: 5, //返回数据的个数 searchLoading: false, //"上拉加载"的变量,默认false,隐藏 searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏 noResSatic: false //"暂无数据"的变量,默认false,隐藏 }, onLoad: function(options) { //加载数据渲染页面 this.setPar(options); this.fetchFilterData();
this.setData({ searchLoading: true, //把"上拉加载"的变量设为false,隐藏 searchLoadingComplete: false //把“没有数据”设为true,显示 }); this.fetchServiceData(); }, setPar: function(options) { var subjectid = options.subjectid; var schoolguid = options.schoolguid; if (subjectid != undefined && subjectid != "undefined") { this.setData({ selectedSubjectId: options.subjectid, subjectName: options.subjectname, }) } if (schoolguid != undefined && schoolguid != "undefined") { this.setData({ selectedSchoolId: options.schoolguid, //当前选中学校id schoolName: options.schoolname.length > 8 ? options.schoolname.substring(0, 8) : options.schoolname }) } }, fetchServiceData: function() { //获取课程列表 let that = this; let keywords = that.data.searchtext, //输入框字符串作为参数 pageIndex = that.data.pageIndex, //把第几次加载次数作为参数 pageSize = that.data.pageSize, //返回数据的个数 subjectGuid = that.data.selectedSubjectId, schoolGuid = that.data.selectedSchoolId //console.log(subjectGuid) //console.log(pageIndex) var url = app.apiUrl + "/api/MyCourse/GetSearchCourseList"; var data = { courseNature: "", subjectGuid: subjectGuid == undefined ? "" : subjectGuid, schoolGuid: schoolGuid == undefined ? "" : schoolGuid, collegeGuid: "", majorGuid: "", time: "", keywords: keywords == undefined ? "" : keywords.trim(), orderby: "1", publicCourseTuijian: "", pageIndex: pageIndex, pageSize: pageSize }; util.httpGet(url, data, this.callbackServiceData); }, callbackServiceData: function(data) { //console.log(data) let that = this; if (data.ResultState) { let _searchList = []; //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加 that.data.isFromSearch ? _searchList = data.DataResult : _searchList = that.data.searchList.concat(data.DataResult)
that.setData({ searchList: _searchList, //获取数据数组 }); if (_searchList.length < that.data.pageSize) { console.log("数据小于页数") that.setData({ searchLoadingComplete: true, searchLoading: false, noResSatic: false }); } } else { if (that.data.pageIndex == 1) { //暂无数据 that.setData({ searchLoadingComplete: false, //把“没有数据”设为true,显示 searchLoading: false, //把"上拉加载"的变量设为false,隐藏 noResSatic: true }); } else { //加载尾页 that.setData({ searchLoadingComplete: true, //把“没有数据”设为true,显示 searchLoading: false, //把"上拉加载"的变量设为false,隐藏 noResSatic: false }); } } }, //滚动到底部触发事件 searchScrollLower: function() { let that = this; if (that.data.searchLoading && !that.data.searchLoadingComplete) { that.setData({ pageIndex: that.data.pageIndex + 1, //每次触发上拉事件,把pageIndex+1 isFromSearch: false //触发到上拉事件,把isFromSearch设为为false }); that.fetchServiceData(); } }, fetchFilterData: function() { //获取筛选条件 this.bindSujectList(); this.bindSchoolList(); }, //绑定筛选条件-学科 bindSujectList: function() { var url = app.apiUrl + "/api/MyCourse/GetSubjectList"; util.httpGet(url, {}, this.callbackSujectList); }, callbackSujectList: function(data) { if (data.ResultState) { this.setData({ sujectList: data.DataResult, }) } }, //绑定筛选条件-学校 bindSchoolList: function() { var url = app.apiUrl + "/api/MyCourse/GetSchools"; util.httpGet(url, {}, this.callbackSchoolList); }, callbackSchoolList: function(data) { console.log(data) if (data.ResultState) { var result = data.DataResult; var list = []; for(var index in result){ var temp = result[index]; temp.SchoolName = temp.SchoolName.length > 8 ? temp.SchoolName.substring(0,8):temp.SchoolName list.push(temp); } this.setData({ schoolList: list, }) } }, inputSearch: function(e) { //输入搜索文字 this.setData({ showsearch: e.detail.cursor > 0, searchtext: e.detail.value }) }, resetSearch: function() { //删除搜索 this.setData({ searchtext: "", showsearch: false, pageIndex: 1, //第一次加载,设置1 searchList: [], //放置返回数据的数组,设为空 isFromSearch: true, //第一次加载,设置true searchLoading: true, //把"上拉加载"的变量设为true,显示 searchLoadingComplete: false, noResSatic: false }) this.fetchServiceData(); }, submitSearch: function() { //提交搜索 this.setData({ pageIndex: 1, //第一次加载,设置1 searchList: [], //放置返回数据的数组,设为空 isFromSearch: true, //第一次加载,设置true searchLoading: true, //把"上拉加载"的变量设为true,显示 searchLoadingComplete: false, noResSatic: false }) this.fetchServiceData(); }, setFilterPanel: function(e) { //展开筛选面板 const d = this.data; const i = e.currentTarget.dataset.findex; if (d.showfilterindex == i) { this.setData({ showfilter: false, showfilterindex: null }) } else { this.setData({ showfilter: true, showfilterindex: i, }) } //console.log(d.showfilterindex); }, setSubjectGuid: function(e) { //学科点击 const dataset = e.currentTarget.dataset; this.setData({ selectedSubjectId: dataset.subjectguid, subjectName: dataset.subjectname }) this.setData({ pageIndex: 1, //第一次加载,设置1 searchList: [], //放置返回数据的数组,设为空 isFromSearch: true, //第一次加载,设置true searchLoading: true, //把"上拉加载"的变量设为true,显示 searchLoadingComplete: false, noResSatic: false }) this.hideFilter(); this.fetchServiceData(); //console.log(dataset.subjectguid); }, setSchoolGuid: function(e) { //院校点击 const dataset = e.currentTarget.dataset; this.setData({ selectedSchoolId: dataset.schoolguid, schoolName: dataset.schoolname }) this.setData({ pageIndex: 1, //第一次加载,设置1 searchList: [], //放置返回数据的数组,设为空 isFromSearch: true, //第一次加载,设置true searchLoading: true, //把"上拉加载"的变量设为true,显示 searchLoadingComplete: false, noResSatic: false }) this.hideFilter(); this.fetchServiceData(); //console.log(dataset.schoolguid); }, hideFilter: function() { //关闭筛选面板 this.setData({ showfilter: false, showfilterindex: null }) }, goCouseInfo: function(e) { var courseguid = e.currentTarget.dataset.courseguid; wx.navigateTo({ url: '../courseInfo/courseInfo?courseguid=' + courseguid }) } })
上一篇:组合实体模式


下一篇:微信小程序中setData的key是变量该如何处理?