static

resource-exploration-list.js 5.4KB

    require(['jquery', 'ipuUI'], function ($, ipuUI) { $(function () { // 搜索 var search; var initData = { "全部": "refresh-all", "申请传输资源": "refresh-apply", "待处理": "refresh-handle", "已竣工": "refresh-success", "已作废": "refresh-fail" } init(); // 页面初始化 function init() { showResList(initData["全部"]); $(".normal-tab-head>ul>li.active").attr("firstload", 0); } // 筛选条件 var SELECT_DATA = [ { text: '客户名称', value: 'CUST_NAME', }, { text: '勘查地址', value: 'CHECKPOINT1ADD' } ]; var SELECT_PICKER = ipuUI.popPicker({ layer: 1 }); SELECT_PICKER.setData(SELECT_DATA); $(".sort-condition").click(function () { var self = $(".sort-type",this) SELECT_PICKER.show(function (data) { self.text(data.text); self.data("value", data.value); search(); }); }); //tab状态 var STATE = ""; // tab项切换 $(".agreement-sheet-list-area").on("click", ".normal-tab-head>ul>li", function () { $(this).addClass("active").siblings(".active").removeClass("active"); var index = $(this).index(".normal-tab-head li"); $(".normal-tab-body>ul>li.normal-tab-item:eq(" + index + ")").addClass("active").siblings(".active").removeClass("active"); STATE = $(this).data("type"); let refreshId = $(this).text(); if (refreshId == "全部") { $(".select-search-area").removeClass("ipu-fn-hide"); } else { $(".select-search-area").addClass("ipu-fn-hide"); } if ($(this).attr("firstload") == 1) { showResList(initData[refreshId]); $(this).attr("firstload", 0); } }); // 全部中的条件搜索事件 $(".common-select-search-btn").click(function(){ search(); }); // 监测输入框按下事件 $(".common-search-input").keyup(function (e) { var currKey = e.keyCode || e.which || e.charCode; if (currKey == 13) {// 按下回车进行查询 search(); } }); // 选项点击事件跳转至详情页 $(".agreement-sheet-list-area").on("click", ".agreement-sheet-item", function () { console.log("跳转至详情页"); }); // 初始化下拉刷新组件 function showResList(refreshId) { var totalPage = 5; // 总页数 var currentPage = 1; // 当前显示第几页,因为默认有一些数据了,所以为1 var listObj = $("#" + refreshId + " ul"); var contentHtml = $("li:lt(5)", listObj).clone(); // 测试用,复制5条数据 // 移除初始的数据,并初始currentPage=0; listObj.empty(); currentPage = 0; var countNo = 0; // 重要计数器,以此来判断不需要 // 初始化下拉刷新 var myRefresh = ipuUI.refresh("#" + refreshId, { bottomLoadFun: function () { // 加载更多 console.log('加载更多'); // 手势上拉,内容下滚动动 addData(); }, topLoadFun: function () { // 刷新 console.log('刷新数据'); // 手势下拉,内容上滚动 refreshData(); } }); // 查询数据 function addData(refresh) {// 0搜索,1刷新,2加载更多 $("#" + refreshId + " .no-result-msg").hide(); currentPage++; var localCountNo = ++countNo; // 执行查询前,保留当前计数器,当查询返回时进行检查是否最新查询,不是则抛弃查询结果 setTimeout(function () { // 模拟延时加载 if (localCountNo == countNo) { // 检查是否最新查询返回数据,不是则抛弃查询结果 // 此处先更新togalPage等信息 myRefresh.enableTop(totalPage != 0); // 假设totalPage为0时表示没数据,此时停用刷新功能,也可不停用,强行刷新 myRefresh.enableBottom(currentPage < totalPage); // enable应该总是先于endBottom/TopLoading方法执行 if (totalPage == 0) { $("#" + refreshId + " .no-result-msg").hide(); } else { if (refresh) { // 顶部刷新,刷新也可能已经没有数据了,待处理 listObj.empty(); // 清空已有内容 contentHtml.clone().appendTo(listObj); myRefresh.endTopLoading(); //最后调用 } else { // 底部加载更多,或查询 contentHtml.clone().appendTo(listObj); myRefresh.endBottomLoading(); //最后调用 } } } }, 1000); } // 刷新 function refreshData() { // 刷新数据 currentPage = 0; // 底部加载时,停用底部加载功能和底部加载 addData(true); myRefresh.enableBottom(false); if (myRefresh.bottomLoading) { myRefresh.endBottomLoading(); } addData(true); } // 搜索 search = function searchData() { // 刷新数据 myRefresh.enableBottom(false); if (myRefresh.bottomLoading) { myRefresh.endBottomLoading(); } myRefresh.enableTop(false); if (myRefresh.topLoading) { myRefresh.endTopLoading(); } currentPage = 0; listObj.empty(); myRefresh.enableBottom(true); myRefresh.refresh(); } } }); });