equipallotList.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. layui.use('form', function(){
  2. var form = layui.form;
  3. form.on('checkbox(check)', function(data){
  4. // console.log(data.elem); //得到checkbox原始DOM对象
  5. // console.log(data.elem.checked); //是否被选中,true或者false
  6. // console.log(data.value); //复选框value值,也可以通过data.elem.value得到
  7. // console.log(data.othis); //得到美化后的DOM对象
  8. if(data.elem.checked){
  9. if (!contains(topicid, $(this).parents('tr').find('.itemId').html())) {
  10. topicid.push($(this).parents('tr').find('.itemId').html());
  11. }
  12. if(topicid.length == 10){
  13. $('#checkAll').prop("checked", true);
  14. }
  15. }else{
  16. removeByValue(topicid, $(this).parents('tr').find('.itemId').html())
  17. if(topicid.length < 10){
  18. $('#checkAll').prop("checked", false);
  19. }
  20. }
  21. layui.use('form', function(){
  22. var form = layui.form;
  23. form.render(); //更新全部
  24. });
  25. });
  26. form.on('checkbox(checkAll)', function(data){
  27. if(data.elem.checked){
  28. $('.check').each(function () {
  29. $(this).prop("checked", true);
  30. $(this).parents('tr').addClass('selectedColor');
  31. if (!contains(topicid, $(this).parents('tr').find('.itemId').html())) {
  32. topicid.push($(this).parents('tr').find('.itemId').html());
  33. }
  34. });
  35. }else{
  36. $('.check').each(function () {
  37. $(this).parents('tr').removeClass('selectedColor');
  38. $(this).prop("checked", false);
  39. });
  40. topicid = [];
  41. }
  42. layui.use('form', function(){
  43. var form = layui.form;
  44. form.render(); //更新全部
  45. });
  46. });
  47. });
  48. var topicid = []; //imei数组
  49. //遍历当前是否已经有选中状态
  50. function isCheck(){
  51. $('.check').each(function () {
  52. if($(this).prop("checked") == true){
  53. topicid.push($(this).parents('tr').find('.itemId').html());
  54. }
  55. })
  56. }
  57. //移除数组元素
  58. function removeByValue(arr, val) {
  59. for (var i = 0; i < arr.length; i++) {
  60. if (arr[i] == val) {
  61. arr.splice(i, 1);
  62. break;
  63. }
  64. }
  65. }
  66. //判断数组中是否包含元素
  67. function contains(arr, obj) {
  68. var i = arr.length;
  69. while (i--) {
  70. if (arr[i] === obj) {
  71. return true;
  72. }
  73. }
  74. return false;
  75. }
  76. // 分页初始化
  77. layui.use('laypage', function () {
  78. var laypage = layui.laypage;
  79. var uname = $('#uname').val()
  80. laypage.render({
  81. elem: 'page' //注意,这里的 test1 是 ID,不用加 # 号
  82. // , count: 30
  83. , count: $('#totalPage').val()
  84. ,theme: '#428BCA'
  85. , layout: ['prev', 'page', 'next', 'skip']
  86. , jump: function (obj) {
  87. topicid = [];
  88. $.ajax({
  89. url: 'allot_equip_list?uname=' + uname + '&page=' + obj.curr,
  90. type: 'get',
  91. success: function (data) {
  92. $('#table tbody').html('');
  93. $('#table tbody').html(data);
  94. if ($('#totalPage').val() > 0) {
  95. $('.nullData').hide();
  96. $('#page').parent().show();
  97. } else {
  98. $('.nullData').show();
  99. $('#page').parent().hide();
  100. }
  101. isCheck();
  102. layui.use('form', function(){
  103. var form = layui.form;
  104. form.render(); //更新全部
  105. //各种基于事件的操作,下面会有进一步介绍
  106. });
  107. }
  108. })
  109. }
  110. });
  111. });
  112. //设备筛选:
  113. function sub_filter() {
  114. var uname = $('#uname').val();
  115. var type = $('#type').val();
  116. var f_id = $('#identity').val();
  117. var begin = $('#begin').val();
  118. var end = $('#end').val();
  119. $("#data_table tr:not(:first)").html("");
  120. $.ajax({
  121. url: 'allot_equip_list',
  122. type: 'post',
  123. data: {
  124. req: "filter",
  125. uname: uname,
  126. type: type,
  127. f_id: f_id,
  128. begin: begin,
  129. end: end,
  130. page:1
  131. },
  132. success: function (data) {
  133. $('#table tbody').html('');
  134. $('#table tbody').html(data);
  135. if ($('#total_nums').val() > 0) {
  136. $('.nullData').hide();
  137. $('#page').parent().show();
  138. } else {
  139. $('.nullData').show();
  140. $('#page').parent().hide();
  141. }
  142. layui.use('form', function(){
  143. var form = layui.form;
  144. form.render(); //更新全部
  145. //各种基于事件的操作,下面会有进一步介绍
  146. });
  147. var datas = {
  148. req: "filter",
  149. uname: uname,
  150. type: type,
  151. f_id: f_id,
  152. begin: begin,
  153. end: end
  154. }
  155. initSearchPage($('#total_nums').val(),'allot_equip_list', datas);
  156. }
  157. })
  158. }
  159. //设备搜索分页
  160. function initSearchPage(page, url, datas) {
  161. layui.use('laypage', function () {
  162. var laypage = layui.laypage;
  163. var uname = $('#uname').val()
  164. laypage.render({
  165. elem: 'page' //注意,这里的 test1 是 ID,不用加 # 号
  166. // , count: 30
  167. , count: page
  168. ,theme: '#428BCA'
  169. , layout: ['prev', 'page', 'next', 'skip']
  170. , jump: function (obj, first) {
  171. datas.page = obj.curr;
  172. topicid = [];
  173. if (!first) {
  174. $.ajax({
  175. url: url,
  176. type: 'post',
  177. data: datas,
  178. success: function (data) {
  179. $('#table tbody').html('');
  180. $('#table tbody').html(data);
  181. if ($('#total_nums').val() > 0) {
  182. $('.nullData').hide();
  183. $('#page').parent().show();
  184. } else {
  185. $('.nullData').show();
  186. $('#page').parent().hide();
  187. }
  188. layui.use('form', function(){
  189. var form = layui.form;
  190. form.render(); //更新全部
  191. //各种基于事件的操作,下面会有进一步介绍
  192. });
  193. }
  194. })
  195. }
  196. }
  197. });
  198. });
  199. }
  200. // 返回
  201. function goback(){
  202. var currPage = $('#currPage').val();
  203. var f_name = $('#f_name').val();
  204. window.location.href = 'equipallot?uname='+f_name+'&page='+currPage;
  205. }