searchs_task.php 7.4 KB

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