Blame view

assets/pages/scripts/home/messagecenter.js 10.7 KB
10646c94   Andy   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
  /*
   ================================
   @作者:andy
   @修改者:andy
   @模块描述:消息中心js
   @创建日期:2018/08/07
   @修改日期:2018/08/07
   ================================
   */
  
  var fun = {
      // 初始化
      init: function () {
          fun.timeInit();
          //需要删除
          //初始化办事处下拉框
          fun.getAreaBlocks("#parkAreaCode", true);
          //默认表格 初始化加载
          fun.createTableData();
          //
          $('#msg-type').selectpicker('render');
      },
      //需要删除
      //获取办事处
      getAreaBlocks: function (domStr, isNeedAll) {
          var plData = fn.getParkBlock();
          var html = "";
          var areaIds = [];
          $.each(plData, function (index, item) {
              areaIds.push(item.code);
              html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
          });
          if (isNeedAll) {
              var areaIdsStr = JSON.stringify(areaIds);
              html = "<option value='" + areaIdsStr + " ' selected>所有办事处</option>" + html;
          }
          $(domStr).append(html);
          $(domStr).selectpicker('render');
          $(domStr).selectpicker('refresh');
      },
  
      //时间初始化
      timeInit: function () {
          //进场时间初始化
          // $('#msg-daterange-btnsta').val(moment().subtract('days', 0).format('YYYY-MM-DD'));
          // $('#msg-daterange-btnend').val(moment().subtract('days', 0).format('YYYY-MM-DD'));
          //开始日期
          $("#msg-daterange-btnsta").datetimepicker({
              endDate: moment().subtract('days', 0).format('YYYY-MM-DD'),
              format: 'yyyy-mm-dd',
              autoclose: true,
              startView: 2,
              //maxDate:moment().subtract('months', 3),
              minView: 2,
              forceParse: false,
              clearBtn: true, //添加清除按钮,可选值:true/false
              locale: "zh-CN",
              language: 'zh-CN',
              pickerPosition: "bottom-right"
          }).on("change", function () {
              $("#msg-daterange-btnend").val('');
          });
          //结束日期
          $("#msg-daterange-btnend").datetimepicker({
              endDate: moment().subtract('days', 0).format('YYYY-MM-DD'),
              //startDate:startVal,
              format: 'yyyy-mm-dd',
              weekStart: 1,
              autoclose: true,
              clearBtn: true, //添加清除按钮,可选值:true/false
              startView: 2,
              minView: 2,
              forceParse: false,
              locale: "zh-CN",
              language: 'zh-CN',
              pickerPosition: "bottom-right"
          }).on("click", function () {
              $("#msg-daterange-btnend").datetimepicker("setStartDate", $("#msg-daterange-btnsta").val())
          });
      },
      //生成表格数据
      createTableData: function () {
          $('#msgcentertable').bootstrapTable('destroy').bootstrapTable({
              striped: true,//表格显示条纹
              rownumbers: true,
              pagination: true, //启动分页
              pageNumber: 1, //当前第几页
              pageSize: 10,  //每页显示的记录数
              pageList: [10, 15, 20],  //记录数可选列表
              sidePagination: 'server',//表示服务端分页
              queryParamsType: 'limit',
              method: 'POST',//请求方法
              paginationPreText: '<',
              paginationNextText: '>',
              ajax: tableLoadRequest,//自定义ajax加载数据
              uniqueId: 'id',
              columns: [
                  {field: 'id', title: '', width: '10%', align: 'left', visible: false},
                  {
                      field: 'adviceType',
                      title: '<span class="manage-icon"></span>通知',
                      width: '10%',
                      align: 'left',
                      formatter: fun.adviceTypeFormatter
                  },
                    {
                      field: 'adviceType',
                      title: '<span class="status-icon"></span>状态',
                      width: '10%',
                      align: 'left',
                      formatter: fun.statusTypeFormatter
                    },
                  {
                      field: 'advice',
                      title: '<span class="business-icon"></span>内容',
  
                      align: 'left',
                      formatter: fun.msgFormatter
                  },
                  {
                      field: 'createDate',
                      title: '<span class="time-icon"></span>时间',
                      width: '20%',
                      align: 'left',
                      formatter: fun.msgTimeFormatter
                  },
              ]
  
          });
  
      },
      /*获取查询参数*/
      getQueryParam: function () {
  
          var req = {
              sysCode: sysComm.sysCode,
              opId: fn.getUserId()
          };
  
  
          var startCreateDate = $('#msg-daterange-btnsta').val();
  
          var endCreateDate = $('#msg-daterange-btnend').val();
  
          if (null != startCreateDate) {
              req.startCreateDate = new Date(startCreateDate.replace(new RegExp(/-/gm), "/"));
          }
  
          if (null != endCreateDate) {
              req.endCreateDate = new Date(endCreateDate.replace(new RegExp(/-/gm), "/"));
          }
  
          var adviceType = $('#msg-type').val();
          if (null != adviceType && adviceType > 0) {
              req.adviceType = adviceType;
          }
  
          var readState = $('#msg-toptab').find('div.ITD-graynav-topbaractive').attr('data-msg');
          if (null != readState && readState != 'all') {
              req.readState = readState;
          }
  
  
          return req;
      },
      //通知类型
      adviceTypeFormatter: function (value, row, index) {
          // 分已读和未读 未读添加类:fontBold 异常添加类:abnormalIco 正常添加类:normalIco
          var opStr = '';
  
          if (row.readState == 10) {
              //未读
              opStr = '<div class="fontBold "><span class="abnormalIco" ></span>';
          } else {
              //已读
              opStr = '<span class="noabnormalIco" ></span><div>'
          }
  
          if (value < 0) {
              opStr += '<span>异常通知</span></div>';
          } else {
              opStr += '<span>待办通知</span></div>';
          }
  
  
          return opStr;
      },
      //内容
      msgFormatter: function (value, row, index) {
          var msgStr = '';
          // 分已读和未读 未读添加类:fontBold 异常添加类:abnormalIcox 正常添加类:abnormalIco
          if (row.readState == 10) {
              //未读
              msgStr = '<div data-toggle="tooltip" class="fontBold ITD-hidden-nowrap msgMaxwidth" title="' + value + '">' + value + '</div>';
          } else {
              //已读
              msgStr = '<div data-toggle="tooltip" class="ITD-hidden-nowrap msgMaxwidth"  title="' + value + '">' + value + '</div>';
          }
  
  
          return msgStr;
      },
    statusTypeFormatter:function(value, row, index){
      var msgStr = '';
      // 分已读和未读 未读添加类:fontBold 异常添加类:abnormalIcox 正常添加类:abnormalIco
      if (row.readState == 10) {
        //未读
        msgStr = "<div class='fontBold noredystatus'> 未读 </div>";
      } else {
        //已读
        msgStr = "<div > 已读 </div>";
      }
  
  
      return msgStr;
    },
  
      //时间
      msgTimeFormatter: function (value, row, index) {
          // 分已读和未读 未读添加类:fontBold 异常添加类:abnormalIcox 正常添加类:abnormalIco
          var msgStr = '';
          // 分已读和未读 未读添加类:fontBold 异常添加类:abnormalIcox 正常添加类:abnormalIco
          if (row.readState == 10) {
              //未读
              msgStr = "<div class='fontBold'>" + fun.DatetimeFormatter(value) + "</div>";
          } else {
              //已读
              msgStr = "<div >" + fun.DatetimeFormatter(value) + "</div>";
          }
  
  
          return msgStr;
  
      },
      //时间
      DatetimeFormatter: function (value, row, index) {
          if (value == null) {
              return "";
          } else {
              return "<div'>" + DateUtils.long2String(value, 7) + "</div>";
          }
      },
  };
  fun.init();
  
  //行点击事件
  $('#msgcentertable').on('click-row.bs.table', function (e, row, element) {
      var ids = [];
      console.log()
    element.find('.fontBold ').removeClass('fontBold ')
    element.find('.abnormalIco ').removeClass('abnormalIco').addClass('noabnormalIco');
    element.find('.noredystatus').text('已读');
      ids.push(row.id);
      if (row.readState == 10) {
          var noReadNum = $('#bar-tzNum').text();
          if(/^[0-9]+$/.test(noReadNum)) {
              noReadNum = parseInt(noReadNum)-1;
              $('#bar-tzNum').text(noReadNum);
              if(noReadNum == 0){
                  $('#bar-tzNum').addClass('display-none');
              }
          }
          console.log(ids)
          console.log(row.readState)
          updateReadState(ids);
      }
  
  });
  
  documentBindFunc.on('click', "#queryBtn", function () {
      fun.createTableData();
  })
  
  //切换 搜索部分 是否生效
  documentBindFunc.on('click', "#msg-toptab div.ITD-graynav-topbar", function () {
      $(this).addClass('ITD-graynav-topbaractive').siblings('div').removeClass('ITD-graynav-topbaractive');
      //切换完后,调用查询表格
      fun.createTableData();
  
  });
  
  // 点击全部已读
  documentBindFunc.on('click', "#readallBtn", function () {
      //消息通知 为0
      $('#bar-tzNum').addClass('display-none').text('0');
      //调用更新函数
      updateReadState();
  
  
  });
  /**
   * 默认收费组列表
   * 自定义table AJAX请求
   * @param {Object} params
   */
  function tableLoadRequest(params) {
      var req = fun.getQueryParam();
      //设置请求参数
      var pageNum = (params.data.offset / params.data.limit) + 1;
  
      //条件查询
      req.baseRequest = {
          pageNum: pageNum,
          pageSize: params.data.limit
      };
      req.sysCode = sysComm.sysCode;
      var opt = {
          method: 'post',
          url: dataUrl.util.querySysOpAdviceForPage(),
          data: JSON.stringify(req),
          contentType: 'application/json; charset=utf-8',
          dataType: 'json',
          success: function (res) {
              if (res.code == '8888') {
                  params.success(res.data);
                $("[data-toggle='tooltip']").tooltip({
                  delay: { show: 500, hide: 100 },
                });
              }
          }
      };
      sysAjax(opt);
  }
  //更新已读消息
  function updateReadState(ids) {
      var req = fun.getQueryParam();
      req.readState = 20;
      if (undefined != ids && ids.length > 0) {
          req.ids = ids;
      }
      var opt = {
          method: 'post',
          url: dataUrl.util.updateOpAdviceReadState(),
          data: JSON.stringify(req),
          contentType: 'application/json; charset=utf-8',
          dataType: 'json',
          success: function (res) {
              if (res.code == '8888') {
                  // fun.createTableData();
  
              }
          }
      };
      sysAjax(opt);
  
  }