userList.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. var tab;
  2. layui.config({
  3. base : "js/"
  4. }).use(['form', 'layer', 'jquery', 'element', 'laypage'], function () {
  5. var form = layui.form(),
  6. layer = parent.layer === undefined ? layui.layer : parent.layer,
  7. laypage = layui.laypage,
  8. $ = layui.jquery;
  9. //加载页面数据
  10. var newsData = '';
  11. var txtkeywords = "";
  12. var myPageSize = 50;
  13. function LoadDataList(pageSize, page, keywords)
  14. {
  15. var index = layer.msg('查询中,请稍候', { icon: 16, time: false, shade: 0.8 });
  16. $.get("/BackgroundProcess.aspx?type=pushuserlist&page=" + page + "&pageSize=" + pageSize + "&keywords=" + keywords, function (data) {
  17. // var newArray = [];
  18. //正常加载信息
  19. var tempDataObj = JSON.parse(data);
  20. // console.log(data);
  21. // console.log(tempDataObj);
  22. if (tempDataObj["code"] == 200) {
  23. //console.log(tempDataObj["data"]);
  24. //执行加载数据的方法
  25. newsData = tempDataObj["data"];
  26. newsList(newsData);
  27. } else {
  28. layer.msg("加载数据失败:" + tempDataObj["info"]);
  29. }
  30. layer.close(index);
  31. })
  32. }
  33. LoadDataList(myPageSize, 1, "");
  34. //查询
  35. $(".search_btn").click(function () {
  36. txtkeywords = $(".search_input").val();
  37. var newArray = [];
  38. LoadDataList(myPageSize, 1, txtkeywords);
  39. //if($(".search_input").val() != ''){
  40. //}else{
  41. // layer.msg("请输入需要查询的内容");
  42. //}
  43. })
  44. function DelData(delIDs)
  45. {
  46. var index = layer.msg('正在删除,请稍候', { icon: 16, time: false, shade: 0.8 });
  47. $.get("/BackgroundProcess.aspx?type=delpushuser&delID=" + delIDs, function (data) {
  48. var tempDataObj = JSON.parse(data);
  49. if (tempDataObj["code"] == 200) {
  50. $('.news_list thead input[type="checkbox"]').prop("checked", false);
  51. form.render();
  52. layer.msg("删除成功");
  53. LoadDataList(myPageSize, 1, "");
  54. } else {
  55. layer.msg("删除数据失败:" + tempDataObj["info"]);
  56. }
  57. layer.close(index);
  58. })
  59. }
  60. //批量删除
  61. $(".batchDel").click(function(){
  62. var $checkbox = $('.news_list tbody input[type="checkbox"][name="checked"]');
  63. var $checked = $('.news_list tbody input[type="checkbox"][name="checked"]:checked');
  64. if($checkbox.is(":checked")){
  65. layer.confirm('确定删除选中的信息?',{icon:3, title:'提示信息'},function(index){
  66. var index = layer.msg('删除中,请稍候',{icon: 16,time:false,shade:0.8});
  67. var delIDList = "";
  68. //删除数据
  69. for (var j = 0; j < $checked.length; j++) {
  70. delIDList+= $checked.eq(j).parents("tr").find(".news_del").attr("data-id")+",";
  71. }
  72. DelData(delIDList);
  73. })
  74. }else{
  75. layer.msg("请选择需要删除的数据");
  76. }
  77. })
  78. //全选
  79. form.on('checkbox(allChoose)', function(data){
  80. var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]:not([name="show"])');
  81. child.each(function(index, item){
  82. item.checked = data.elem.checked;
  83. });
  84. form.render('checkbox');
  85. });
  86. //通过判断文章是否全部选中来确定全选按钮是否选中
  87. form.on("checkbox(choose)",function(data){
  88. var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]:not([name="show"])');
  89. var childChecked = $(data.elem).parents('table').find('tbody input[type="checkbox"]:not([name="show"]):checked')
  90. if(childChecked.length == child.length){
  91. $(data.elem).parents('table').find('thead input#allChoose').get(0).checked = true;
  92. }else{
  93. $(data.elem).parents('table').find('thead input#allChoose').get(0).checked = false;
  94. }
  95. form.render('checkbox');
  96. })
  97. //是否展示
  98. form.on('switch(isShow)', function(data){
  99. var index = layer.msg('修改中,请稍候',{icon: 16,time:false,shade:0.8});
  100. setTimeout(function(){
  101. layer.close(index);
  102. layer.msg("展示状态修改成功!");
  103. },2000);
  104. })
  105. //操作
  106. $("body").on("click", ".news_edit", function () { //编辑
  107. // let dataUrl = $(this).attr("data-url");
  108. // layer.alert('推送消息ID' + dataUrl, { icon: 6, title: '推送消息' });
  109. window.parent.addTab($(this));
  110. // console.log($(this))
  111. })
  112. $("body").on("click",".news_collect",function(){ //收藏.
  113. if($(this).text().indexOf("已收藏") > 0){
  114. layer.msg("取消收藏成功!");
  115. $(this).html("<i class='layui-icon'>&#xe600;</i> 收藏");
  116. }else{
  117. layer.msg("收藏成功!");
  118. $(this).html("<i class='iconfont icon-star'></i> 已收藏");
  119. }
  120. })
  121. $("body").on("click",".news_del",function(){ //删除
  122. var _this = $(this);
  123. layer.confirm('确定删除此信息?',{icon:3, title:'提示信息'},function(index){
  124. //_this.parents("tr").remove();
  125. // _this.attr("data-id");
  126. layer.close(index);
  127. DelData(_this.attr("data-id"));
  128. });
  129. })
  130. function formatDate(now) {
  131. var year = now.getYear();
  132. var month = now.getMonth() + 1;
  133. var date = now.getDate();
  134. var hour = now.getHours();
  135. var minute = now.getMinutes();
  136. var second = now.getSeconds();
  137. return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
  138. }
  139. function formatDate2(now) {
  140. var year = now.getYear();
  141. var month = now.getMonth() + 1;
  142. var date = now.getDate();
  143. return year + "-" + month + "-" + date;
  144. }
  145. Date.prototype.format = function (format) {
  146. var date = {
  147. "M+": this.getMonth() + 1,
  148. "d+": this.getDate(),
  149. "h+": this.getHours(),
  150. "m+": this.getMinutes(),
  151. "s+": this.getSeconds(),
  152. "q+": Math.floor((this.getMonth() + 3) / 3),
  153. "S+": this.getMilliseconds()
  154. };
  155. if (/(y+)/i.test(format)) {
  156. format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  157. }
  158. for (var k in date) {
  159. if (new RegExp("(" + k + ")").test(format)) {
  160. format = format.replace(RegExp.$1, RegExp.$1.length == 1
  161. ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
  162. }
  163. }
  164. return format;
  165. }
  166. //渲染数据
  167. function renderDate(data,curr) {
  168. var dataHtml = '';
  169. //if(!that){
  170. // currData = newsData.concat().splice(curr*nums-nums, nums);
  171. //}else{
  172. // currData = that.concat().splice(curr*nums-nums, nums);
  173. //}
  174. currData = data["ListData"];
  175. //console.log(currData);
  176. if (currData.length != 0) {
  177. for (var i = 0; i < currData.length; i++) {
  178. // console.log(currData[i]);
  179. // console.log(currData[i].EnterpriseName);
  180. dataHtml += '<tr>'
  181. + '<td><input type="checkbox" name="checked" lay-skin="primary" lay-filter="choose"></td>'
  182. + '<td align="left">' + (currData[i].GTType == 0 ? "IOS" : "Android") + ' ['+currData[i].LYFZAPPID+ ']</td>'
  183. dataHtml += '<td>' + currData[i].GTClientID + '</td>';
  184. dataHtml += '<td>' + currData[i].Badge + '</td>';
  185. if (currData[i].GTState == 1)
  186. {
  187. if (currData[i].APPState == 1) {
  188. dataHtml += '<td>正常[Pro生产] V' + currData[i].AppVersion+'</td>'
  189. } else {
  190. dataHtml += '<td>正常[Dev开发] V' + currData[i].AppVersion +'</td>'
  191. }
  192. } else {
  193. if (currData[i].APPState == 1) {
  194. dataHtml += '<td>不可用[Pro生产] V' + currData[i].AppVersion +'</td>'
  195. } else {
  196. dataHtml += '<td>不可用[Dev开发] V' + currData[i].AppVersion +'</td>'
  197. }
  198. }
  199. //var newDate = new Date(currData[i].CreationTime);
  200. // newDate.toLocaleDateString()
  201. //newDate.format('yyyy-MM-dd h:m:s')
  202. dataHtml += '<td>' + new Date(currData[i].CreationTime).format('yyyy-MM-dd h:m') + '</td>'
  203. + '<td>' + new Date(currData[i].UpdateTime).format('yyyy-MM-dd h:m') + '</td>'
  204. + '<td>'
  205. + '<a class="layui-btn layui-btn-mini news_edit" href="javascript:;" data-url="/admin/page/GtMsgList/MsgAdd.html?uid=' + currData[i].EnterpriseID +":"+ currData[i].UserID + '&type=' + currData[i].GTType + '"><i class="iconfont icon-wenben" data-icon="icon-text"></i> <cite>推送消息</cite></a>'
  206. + '<a class="layui-btn layui-btn-danger layui-btn-mini news_del" data-id="' + currData[i].sid + '"><i class="layui-icon">&#xe640;</i> 删除</a>'
  207. + '</td>'
  208. + '</tr>';
  209. }
  210. } else {
  211. dataHtml = '<tr><td colspan="9">暂无数据</td></tr>';
  212. }
  213. $(".news_content").html(dataHtml);
  214. $('.news_list thead input[type="checkbox"]').prop("checked", false);
  215. form.render();
  216. }
  217. function newsList(thatData) {
  218. //分页
  219. var nums = myPageSize; //每页出现的数据量
  220. var TotalCount = 0;
  221. if (thatData)
  222. {
  223. TotalCount = thatData["TotalCount"];
  224. }
  225. $("#SumTotalCount").html(TotalCount);
  226. laypage({
  227. cont : "page",
  228. pages: Math.ceil(TotalCount / nums),
  229. jump: function (obj, first)
  230. {
  231. // console.log(first);
  232. // console.log(obj);
  233. if (first) {
  234. renderDate(thatData, obj.curr);
  235. } else {
  236. var index = layer.msg('查询中,请稍候', { icon: 16, time: false, shade: 0.8 });
  237. $.get("/BackgroundProcess.aspx?type=pushuserlist&page=" + obj.curr + "&pageSize=" + nums + "&keywords=" + txtkeywords, function (data) {
  238. var newArray = [];
  239. //正常加载信息
  240. var tempDataObj = JSON.parse(data);
  241. //console.log(data);
  242. if (tempDataObj["code"] == 200) {
  243. //执行加载数据的方法
  244. newsData = tempDataObj["data"];
  245. renderDate(newsData, obj.curr);
  246. } else {
  247. layer.msg("加载数据失败:" + tempDataObj["info"]);
  248. }
  249. layer.close(index);
  250. })
  251. }
  252. }
  253. })
  254. }
  255. })