search_task.php 6.9 KB

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