浏览代码

@zengqiao@优化资源勘查列表

zengqiao 5 年之前
父节点
当前提交
a432d9b576
共有 1 个文件被更改,包括 37 次插入82 次删除
  1. 37 82
      2019/bj-zqzt/biz/js/resource-exploration-list.js

+ 37 - 82
2019/bj-zqzt/biz/js/resource-exploration-list.js

1
require(['jquery', 'ipuUI'], function ($, ipuUI) {
1
require(['jquery', 'ipuUI'], function ($, ipuUI) {
2
  $(function () {
2
  $(function () {
3
3
4
    // 全部列表的刷新组件
5
    var refresh;
4
    // 搜索
5
    var search;
6
6
7
    var initData = {
7
    var initData = {
8
      "全部": "refresh-all",
8
      "全部": "refresh-all",
16
16
17
    // 页面初始化
17
    // 页面初始化
18
    function init() {
18
    function init() {
19
      showAllList(initData["全部"]);
19
      showResList(initData["全部"]);
20
      $(".normal-tab-head>ul>li.active").attr("firstload", 0);
20
      $(".normal-tab-head>ul>li.active").attr("firstload", 0);
21
    }
21
    }
22
22
42
      SELECT_PICKER.show(function (data) {
42
      SELECT_PICKER.show(function (data) {
43
        self.text(data.text);
43
        self.text(data.text);
44
        self.data("value", data.value);
44
        self.data("value", data.value);
45
        search();
45
      });
46
      });
46
    });
47
    });
47
48
56
      let refreshId = $(this).text();
57
      let refreshId = $(this).text();
57
      if (refreshId == "全部") {
58
      if (refreshId == "全部") {
58
        $(".select-search-area").removeClass("ipu-fn-hide");
59
        $(".select-search-area").removeClass("ipu-fn-hide");
59
        if ($(this).attr("firstload") == 1) {
60
          showAllList(initData["全部"]);
61
          $(this).attr("firstload", 0);
62
        }
63
      } else {
60
      } else {
64
        $(".select-search-area").addClass("ipu-fn-hide");
61
        $(".select-search-area").addClass("ipu-fn-hide");
65
        if ($(this).attr("firstload") == 1) {
66
          showExplorationList(initData[refreshId]);
67
          $(this).attr("firstload", 0);
68
        }
69
      }
62
      }
70
63
      if ($(this).attr("firstload") == 1) {
64
        showResList(initData[refreshId]);
65
        $(this).attr("firstload", 0);
66
      }
71
    });
67
    });
72
68
73
    // 全部中的条件搜索事件
69
    // 全部中的条件搜索事件
74
    $(".common-select-search-btn").click(function(){
70
    $(".common-select-search-btn").click(function(){
75
      refresh();
71
      search();
72
    });
73
74
    // 监测输入框按下事件
75
    $(".common-search-input").keyup(function (e) {
76
      var currKey = e.keyCode || e.which || e.charCode;
77
      if (currKey == 13) {// 按下回车进行查询
78
        search();
79
      }
76
    });
80
    });
77
81
78
    // 选项点击事件跳转至详情页
82
    // 选项点击事件跳转至详情页
80
      console.log("跳转至详情页");
84
      console.log("跳转至详情页");
81
    });
85
    });
82
86
83
    // 初始化全部勘察单列表的下拉刷新组件
84
    function showAllList(refreshId) {
87
    // 初始化下拉刷新组件
88
    function showResList(refreshId) {
85
      var totalPage = 5;  // 总页数
89
      var totalPage = 5;  // 总页数
86
      var nowPage = 1;    // 当前显示第几页,因为默认有一些数据了,所以为1
90
      var currentPage = 1;    // 当前显示第几页,因为默认有一些数据了,所以为1
87
      var listObj = $("#" + refreshId + " ul");
91
      var listObj = $("#" + refreshId + " ul");
88
      var contentHtml = $("li:lt(5)", listObj).clone(); // 测试用,复制5条数据
92
      var contentHtml = $("li:lt(5)", listObj).clone(); // 测试用,复制5条数据
89
93
90
      // 移除初始的数据,并初始nowPage=0;
94
      // 移除初始的数据,并初始currentPage=0;
91
      listObj.empty();
95
      listObj.empty();
92
      nowPage = 0;
96
      currentPage = 0;
93
      var countNo = 0; // 重要计数器,以此来判断不需要
97
      var countNo = 0; // 重要计数器,以此来判断不需要
94
98
95
      // 初始化下拉刷新
99
      // 初始化下拉刷新
100
        },
104
        },
101
        topLoadFun: function () { // 刷新
105
        topLoadFun: function () { // 刷新
102
          console.log('刷新数据'); // 手势下拉,内容上滚动
106
          console.log('刷新数据'); // 手势下拉,内容上滚动
103
          refresh();
107
          refreshData();
104
        }
108
        }
105
      });
109
      });
106
110
107
      // 查询数据
111
      // 查询数据
108
      function addData(refresh) {// 0搜索,1刷新,2加载更多
112
      function addData(refresh) {// 0搜索,1刷新,2加载更多
109
        $("#" + refreshId + " .no-result-msg").hide();
113
        $("#" + refreshId + " .no-result-msg").hide();
110
        nowPage++;
114
        currentPage++;
111
        var localCountNo = ++countNo;  // 执行查询前,保留当前计数器,当查询返回时进行检查是否最新查询,不是则抛弃查询结果
115
        var localCountNo = ++countNo;  // 执行查询前,保留当前计数器,当查询返回时进行检查是否最新查询,不是则抛弃查询结果
112
116
113
        setTimeout(function () { // 模拟延时加载
117
        setTimeout(function () { // 模拟延时加载
115
            // 此处先更新togalPage等信息
119
            // 此处先更新togalPage等信息
116
120
117
            myRefresh.enableTop(totalPage != 0); // 假设totalPage为0时表示没数据,此时停用刷新功能,也可不停用,强行刷新
121
            myRefresh.enableTop(totalPage != 0); // 假设totalPage为0时表示没数据,此时停用刷新功能,也可不停用,强行刷新
118
            myRefresh.enableBottom(nowPage < totalPage); // enable应该总是先于endBottom/TopLoading方法执行
122
            myRefresh.enableBottom(currentPage < totalPage); // enable应该总是先于endBottom/TopLoading方法执行
119
123
120
            if (totalPage == 0) {
124
            if (totalPage == 0) {
121
              $("#" + refreshId + " .no-result-msg").hide();
125
              $("#" + refreshId + " .no-result-msg").hide();
134
      }
138
      }
135
139
136
      // 刷新
140
      // 刷新
137
      refresh = function refreshData() {   // 刷新数据
138
        nowPage = 0; // 底部加载时,停用底部加载功能和底部加载
139
        listObj.empty(); // 清空已有内容
141
      function refreshData() {   // 刷新数据
142
        currentPage = 0; // 底部加载时,停用底部加载功能和底部加载
140
        addData(true);
143
        addData(true);
141
        myRefresh.enableBottom(false);
144
        myRefresh.enableBottom(false);
142
        if (myRefresh.bottomLoading) {
145
        if (myRefresh.bottomLoading) {
144
        }
147
        }
145
        addData(true);
148
        addData(true);
146
      }
149
      }
147
    }
148
149
    // 初始化全部以外勘察单列表的下拉刷新组件
150
    function showExplorationList(refreshId) {
151
      var totalPage = 5;  // 总页数
152
      var nowPage = 1;    // 当前显示第几页,因为默认有一些数据了,所以为1
153
      var listObj = $("#" + refreshId + " ul");
154
      var contentHtml = $("li:lt(5)", listObj).clone(); // 测试用,复制5条数据
155
156
      // 移除初始的数据,并初始nowPage=0;
157
      listObj.empty();
158
      nowPage = 0;
159
      var countNo = 0; // 重要计数器,以此来判断不需要
160
161
      // 初始化下拉刷新
162
      var myRefresh = ipuUI.refresh("#" + refreshId, {
163
        bottomLoadFun: function () { // 加载更多
164
          console.log('加载更多'); // 手势上拉,内容下滚动动
165
          addData();
166
        },
167
        topLoadFun: function () { // 刷新
168
          console.log('刷新数据'); // 手势下拉,内容上滚动
169
          refreshData();
170
        }
171
      });
172
173
      // 查询数据
174
      function addData(refresh) {// 0搜索,1刷新,2加载更多
175
        $("#" + refreshId + " .no-result-msg").hide();
176
        nowPage++;
177
        var localCountNo = ++countNo;  // 执行查询前,保留当前计数器,当查询返回时进行检查是否最新查询,不是则抛弃查询结果
178
179
        setTimeout(function () { // 模拟延时加载
180
          if (localCountNo == countNo) { // 检查是否最新查询返回数据,不是则抛弃查询结果
181
            // 此处先更新togalPage等信息
182
183
            myRefresh.enableTop(totalPage != 0); // 假设totalPage为0时表示没数据,此时停用刷新功能,也可不停用,强行刷新
184
            myRefresh.enableBottom(nowPage < totalPage); // enable应该总是先于endBottom/TopLoading方法执行
185
186
            if (totalPage == 0) {
187
              $("#" + refreshId + " .no-result-msg").hide();
188
            } else {
189
              if (refresh) {                    // 顶部刷新,刷新也可能已经没有数据了,待处理
190
                listObj.empty(); // 清空已有内容
191
                contentHtml.clone().appendTo(listObj);
192
                myRefresh.endTopLoading(); //最后调用
193
              } else {  // 底部加载更多,或查询
194
                contentHtml.clone().appendTo(listObj);
195
                myRefresh.endBottomLoading();  //最后调用
196
              }
197
            }
198
          }
199
        }, 1000);
200
      }
201
150
202
      // 刷新
203
      function refreshData() {   // 刷新数据
204
        nowPage = 0; // 底部加载时,停用底部加载功能和底部加载
151
      // 搜索
152
      search = function searchData() {   // 刷新数据
205
        myRefresh.enableBottom(false);
153
        myRefresh.enableBottom(false);
206
        if (myRefresh.bottomLoading) {
154
        if (myRefresh.bottomLoading) {
207
          myRefresh.endBottomLoading();
155
          myRefresh.endBottomLoading();
208
        }
156
        }
209
        addData(true);
157
        myRefresh.enableTop(false);
158
        if (myRefresh.topLoading) {
159
          myRefresh.endTopLoading();
160
        }
161
        currentPage = 0;
162
        listObj.empty();
163
        myRefresh.enableBottom(true);
164
        myRefresh.refresh();
210
      }
165
      }
211
    }
166
    }
212
167