special_task.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. {extend name="public/container"}
  2. {block name="content"}
  3. <div class="layui-fluid">
  4. <div class="layui-row layui-col-space15" id="app">
  5. <div class="layui-col-md12">
  6. <div class="layui-card">
  7. <div class="layui-card-header">搜索条件</div>
  8. <div class="layui-card-body">
  9. <div class="layui-form layui-form-pane">
  10. <div class="layui-form-item">
  11. 专题名称:
  12. <div class="layui-inline">
  13. <input class="layui-input" name="title" id="demoReload" placeholder="请输入专题名称">
  14. </div>
  15. <div class="layui-inline">
  16. <label class="layui-form-label">专题类型</label>
  17. <div class="layui-input-block">
  18. <select name="type" id="test">
  19. <option value="">全部</option>
  20. <option value="3">视频专题</option>
  21. <option value="2">音频专题</option>
  22. <option value="1">图文专题</option>
  23. <option value="7">轻专题</option>
  24. </select>
  25. </div>
  26. </div>
  27. <button class="layui-btn layui-btn-normal layui-btn-sm" data-type="reload">搜索</button>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <!--产品列表-->
  34. <div class="layui-col-md12">
  35. <div class="layui-card">
  36. <div class="layui-card-header">专题列表</div>
  37. <div class="layui-card-body">
  38. <div class="layui-btn-container">
  39. <button class="layui-btn layui-btn-normal layui-btn-sm" onclick="window.location.reload()"><i class="layui-icon layui-icon-refresh"></i> 刷新</button>
  40. </div>
  41. <table class="layui-hide" id="List" lay-filter="List"></table>
  42. <script type="text/html" id="image">
  43. <img style="cursor: pointer;width: 80px;height: 40px;" lay-event='open_image' src="{{d.image}}">
  44. </script>
  45. <script type="text/html" id="is_light">
  46. {{# if(d.is_light==1){ }}
  47. 轻专题
  48. {{# }else{ }}
  49. 普通专题
  50. {{# }; }}
  51. </script>
  52. <script type="text/html" id="is_show">
  53. <input type='checkbox' name='id' lay-skin='switch' value="{{d.id}}" lay-filter='is_show' lay-text='显示|隐藏' {{ d.is_show == 1 ? 'checked' : '' }}>
  54. </script>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  61. {/block}
  62. {block name="script"}
  63. <script>
  64. var special_id = <?=isset($special_id) ? $special_id : ""?>;
  65. var table_date=new Array();//用于保存当前页数据
  66. var ids=new Array(); //用于保存选中的数据
  67. //实例化form
  68. layList.form.render();
  69. var table = layui.table;
  70. table.render({
  71. elem: '#List'
  72. ,url:"{:Url('source_list')}?special_id={$special_id}&special_type={$special_type}"
  73. ,cols: [[
  74. {type: 'checkbox'},
  75. {field: 'id', title: '编号', width:60,align:'center'},
  76. {field: 'types', title: '类型',align:'center'},
  77. {field: 'is_light', title: '专题类别',templet:'#is_light',align:'center'},
  78. {field: 'title', title: '专题标题',align:'center'},
  79. {field: 'image', title: '封面',templet:'#image',align:'center'},
  80. ]]
  81. ,id: 'testReload'
  82. ,page: {
  83. theme: '#0092dc'
  84. }
  85. ,limit:10
  86. ,done:function (res,curr,count) {
  87. table_date=res.data;
  88. for(var i=0;i< res.data.length;i++){
  89. for (var j = 0; j < ids.length; j++) {
  90. if(res.data[i].id == ids[j].id) {
  91. res.data[i]["LAY_CHECKED"]='true';/*设置勾选*/
  92. /*找到对应数据改变勾选样式*/
  93. var index= res.data[i]['LAY_TABLE_INDEX'];
  94. $('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
  95. $('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
  96. }
  97. }
  98. if(res.data[i]["LAY_CHECKED"]){
  99. ids.push(res.data[i]);
  100. }
  101. }
  102. var checkStatus = table.checkStatus('List');/*获得选中的值 和判断是否是全选 isAll true全选 isAlL false 没有全选*/
  103. if(checkStatus.isAll){
  104. $('.layui-table-header th[data-field="0"] input[type="checkbox"]').prop('checked', true);
  105. $('.layui-table-header th[data-field="0"] div[class="layui-unselect layui-form-checkbox"]').addClass('layui-form-checked');
  106. }
  107. removeArrayRepElement(ids);
  108. $("#check_source_tmp",window.parent.document).val(JSON.stringify(ids));
  109. }
  110. });
  111. var $ = layui.$, active = {
  112. reload: function(){
  113. var demoReload = $('#demoReload');
  114. //执行重载
  115. table.reload('testReload', {
  116. page: {
  117. curr: 1 //重新从第 1 页开始
  118. }
  119. ,where: {
  120. title: demoReload.val(),
  121. type:$('#test option:selected').val()
  122. }
  123. }, 'data');
  124. }
  125. };
  126. $('.layui-btn').on('click', function(){
  127. var type = $(this).data('type');
  128. active[type] ? active[type].call(this) : '';
  129. });
  130. //删除重复
  131. function removeArrayRepElement(arr) {
  132. for (var i = 0; i < arr.length; i++) {
  133. for (var j = 0; j < arr.length; j++) {
  134. if (arr[i].id == arr[j].id && i != j) {
  135. arr.splice(j, 1);
  136. }
  137. }
  138. }
  139. return arr;
  140. }
  141. table.on('checkbox(List)', function (obj) {
  142. if(obj.checked==true){
  143. if(obj.type=='one'){
  144. ids.push(obj.data);
  145. }else{
  146. for(var i=0;i<table_date.length;i++){
  147. ids.push(table_date[i]);
  148. }
  149. }
  150. ids=removeArrayRepElement(ids);
  151. }else{
  152. if(obj.type=='one'){
  153. for(var i=0;i<ids.length;i++){
  154. if(ids[i].id==obj.data.id){
  155. ids.remove(i);
  156. }
  157. }
  158. }else{
  159. for(var i=0;i<ids.length;i++){
  160. for(var j=0;j<table_date.length;j++){
  161. if(ids[i].id==table_date[j].id){
  162. ids.remove(i);
  163. }
  164. }
  165. }
  166. }
  167. }
  168. $("#check_source_tmp",window.parent.document).val(JSON.stringify(ids));
  169. });
  170. Array.prototype.remove=function(dx){
  171. if(isNaN(dx)||dx>this.length){return false;}
  172. for(var i=0,n=0;i<this.length;i++)
  173. {
  174. if(this[i]!=this[dx]){
  175. this[n++]=this[i];
  176. }
  177. }
  178. this.length-=1;
  179. };
  180. //自定义方法
  181. var action= {
  182. //打开新添加页面
  183. open_add: function (url,title) {
  184. layer.open({
  185. type: 2 //Page层类型
  186. ,area: ['100%', '100%']
  187. ,title: title
  188. ,shade: 0.6 //遮罩透明度
  189. ,maxmin: true //允许全屏最小化
  190. ,anim: 1 //0-6的动画形式,-1不开启
  191. ,content: url
  192. ,end:function() {
  193. location.reload();
  194. }
  195. });
  196. }
  197. }
  198. </script>
  199. {/block}