source_index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. {extend name="public/container"}
  2. {block name="content"}
  3. <div class="layui-fluid">
  4. <div class="layui-row layui-col-space15">
  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-row layui-col-space15">
  10. <div class="layui-col-md12">
  11. <form class="layui-form layui-form-pane" action="">
  12. <div class="layui-form-item">
  13. <div class="layui-inline">
  14. <label class="layui-form-label">是否显示</label>
  15. <div class="layui-input-inline">
  16. <select name="is_show">
  17. <option value="">是否显示</option>
  18. <option value="1">显示</option>
  19. <option value="0">不显示</option>
  20. </select>
  21. </div>
  22. </div>
  23. <div class="layui-inline">
  24. <label class="layui-form-label">素材分类</label>
  25. <div class="layui-input-inline">
  26. <select name="pid" lay-search="">
  27. <option value="">全部</option>
  28. {volist name='category' id='vo'}
  29. <option value="{$vo.id}">{$vo.html}{$vo.title}</option>
  30. {/volist}
  31. </select>
  32. </div>
  33. </div>
  34. <div class="layui-inline">
  35. <label class="layui-form-label">素材名称</label>
  36. <div class="layui-input-inline">
  37. <input type="text" name="title" class="layui-input" placeholder="请输入素材名称">
  38. </div>
  39. </div>
  40. <div class="layui-inline">
  41. <div class="layui-input-inline">
  42. <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search" lay-filter="search">
  43. <i class="layui-icon">&#xe615;</i>搜索
  44. </button>
  45. </div>
  46. </div>
  47. </div>
  48. </form>
  49. </div>
  50. <div class="layui-col-md12">
  51. <div class="layui-btn-group">
  52. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" data-type="add" onclick="action.open_add('{:Url('special.special_type/addSources')}','添加素材')">
  53. <i class="layui-icon">&#xe608;</i>添加素材
  54. </button>
  55. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" data-type="refresh" onclick="window.location.reload()">
  56. <i class="layui-icon">&#xe669;</i>刷新
  57. </button>
  58. </div>
  59. <table id="List" lay-filter="List"></table>
  60. <script type="text/html" id="image">
  61. <img width="89" height="50" lay-event='open_image' src="{{d.image}}">
  62. </script>
  63. <script type="text/html" id="recommend">
  64. <div class="layui-btn-container">
  65. {{# layui.each(d.recommend, function(index, item){ }}
  66. <button type="button" class="layui-btn layui-btn-normal layui-btn-xs" data-type="recommend" data-id="{{index}}" data-pid="{{d.id}}">{{item}}</button>
  67. {{# }); }}
  68. </div>
  69. </script>
  70. <script type="text/html" id="is_pay_status_c">
  71. {{# if(d.is_pay_status>0){ }}
  72. <a onclick="$eb.createModalFrame('设置收费专题','{:Url('is_pay_status_c')}?id='+{{d.id}},{w:800})" class="layui-btn layui-btn-normal layui-btn-xs">已设置</a>
  73. {{# }else if(d.use>0){ }}
  74. <span class="layui-badge">未设置</span>
  75. {{# }else{ }}
  76. <span class="layui-badge">未使用</span>
  77. {{# } }}
  78. </script>
  79. <script type="text/html" id="is_show">
  80. <input type='checkbox' name='id' lay-skin='switch' value="{{d.id}}" lay-filter='is_show' lay-text='显示|隐藏' {{ d.is_show == 1 ? 'checked' : '' }}>
  81. </script>
  82. <script type="text/html" id="act">
  83. <button type="button" class="layui-btn layui-btn-normal layui-btn-xs" onclick="dropdown(this)">
  84. <i class="layui-icon">&#xe625;</i>操作
  85. </button>
  86. <ul class="layui-nav-child layui-anim layui-anim-upbit">
  87. <li>
  88. <a href="javascript:;" onclick="action.open_add('{:Url('special.special_type/addSources')}?id={{d.id}}','编辑')" >
  89. <i class="iconfont icon-bianji"></i> 编辑素材
  90. </a>
  91. </li>
  92. {{# if(d.is_pay_status==0){ }}
  93. <li>
  94. <a href="javascript:void(0)" onclick="$eb.createModalFrame('{{d.title}}-推荐管理','{:Url('sourceRecommend')}?source_id={{d.id}}',{h:300,w:400})">
  95. <i class="iconfont icon-tuijianshouye"></i> 推荐至首页
  96. </a>
  97. </li>
  98. {{# } }}
  99. <li>
  100. <a lay-event='delete' href="javascript:;">
  101. <i class="iconfont icon-shanchu"></i> 删除素材
  102. </a>
  103. </li>
  104. </ul>
  105. </script>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  114. {/block}
  115. {block name="script"}
  116. <script>
  117. //实例化form
  118. layList.form.render();
  119. //加载列表
  120. layList.tableList({
  121. o: 'List',
  122. done: function () {
  123. $('.layui-btn').on('mouseover', function (event) {
  124. var target = event.target;
  125. var type = target.dataset.type;
  126. if ('recommend' === type) {
  127. layer.tips('点击即可取消此推荐', target, {
  128. tips: [1, '#0093dd']
  129. });
  130. }
  131. });
  132. $('.layui-btn').on('mouseout', function (event) {
  133. var target = event.target;
  134. var type = target.dataset.type;
  135. if ('recommend' === type) {
  136. layer.closeAll();
  137. }
  138. });
  139. $('.layui-btn').on('click', function (event) {
  140. var target = event.target;
  141. var type = target.dataset.type;
  142. if ('recommend' === type) {
  143. var id = target.dataset.id;
  144. var pid = target.dataset.pid;
  145. var url = layList.U({ a: 'cancel_recommendation', q: { id: id, special_id: pid } });
  146. $eb.$swal(
  147. 'delete',
  148. function () {
  149. $eb.axios
  150. .get(url)
  151. .then(function (res) {
  152. if (res.data.code == 200) {
  153. $eb.$swal('success', res.data.msg);
  154. layList.reload();
  155. } else {
  156. return Promise.reject(res.data.msg || '取消失败');
  157. }
  158. })
  159. .catch(function (err) {
  160. $eb.$swal('error', err);
  161. });
  162. },
  163. {
  164. title: '确定取消此推荐?',
  165. text: '取消后无法撤销,请谨慎操作!',
  166. confirm: '确定取消'
  167. }
  168. );
  169. }
  170. });
  171. }
  172. },"{:Url('get_source_list')}",function (){
  173. return [
  174. {field: 'id', title: '编号', align: 'center',width:'6%'},
  175. {field: 'title', title: '素材名称',align: 'center',width:'16%'},
  176. {field: 'types', title: '素材类型',align: 'center',width:'8%'},
  177. {field: 'image', title: '素材封面',templet:'#image',align: 'center',minWidth:119},
  178. {field: 'use', title: '应用次数',align: 'center',width:'8%'},
  179. {field: 'is_pay_status_c', title: '是否设置收费',align: 'center',templet:'#is_pay_status_c',width:'8.3%'},
  180. {field: 'recommend', title: '移动端推荐',templet:'#recommend',align: 'center',width:'16%'},
  181. {field: 'is_show', title: '状态',templet:'#is_show',align: 'center',minWidth:92},
  182. {field: 'sort', title: '排序',sort: true,event:'sort',edit:'sort',align: 'center',width:'10%'},
  183. {field: 'right', title: '操作',align:'center',toolbar:'#act',minWidth:81}
  184. ];
  185. });
  186. //下拉框
  187. $(document).click(function (e) {
  188. $('.layui-nav-child').hide();
  189. });
  190. function dropdown(that){
  191. var oEvent = arguments.callee.caller.arguments[0] || event;
  192. oEvent.stopPropagation();
  193. var offset = $(that).offset();
  194. var top=offset.top-$(window).scrollTop();
  195. var index = $(that).parents('tr').data('index');
  196. $('.layui-nav-child').each(function (key) {
  197. if (key != index) {
  198. $(this).hide();
  199. }
  200. })
  201. if($(document).height() < top+$(that).next('ul').height()){
  202. $(that).next('ul').css({
  203. 'padding': 10,
  204. 'top': - ($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height()/2),
  205. 'min-width': 'inherit',
  206. 'position': 'absolute'
  207. }).toggle();
  208. }else{
  209. $(that).next('ul').css({
  210. 'padding': 10,
  211. 'top':$(that).parent('td').height() / 2 + $(that).height(),
  212. 'min-width': 'inherit',
  213. 'position': 'absolute'
  214. }).toggle();
  215. }
  216. }
  217. //自定义方法
  218. var action= {
  219. set_value: function (field, id, value, model_type) {
  220. layList.baseGet(layList.Url({
  221. a: 'set_value',
  222. q: {field: field, id: id, value: value, model_type:model_type}
  223. }), function (res) {
  224. layList.msg(res.msg,function () {
  225. location.reload();
  226. });
  227. },function (res) {
  228. layList.msg(res.msg,function () {
  229. location.reload();
  230. });
  231. });
  232. },
  233. //打开新添加页面
  234. open_add: function (url,title) {
  235. layer.open({
  236. type: 2 //Page层类型
  237. ,area: ['100%', '100%']
  238. ,title: title
  239. ,shade: 0.6 //遮罩透明度
  240. ,maxmin: true //允许全屏最小化
  241. ,anim: 1 //0-6的动画形式,-1不开启
  242. ,content: url
  243. ,end:function () {
  244. location.reload();
  245. }
  246. });
  247. }
  248. };
  249. //查询
  250. layList.search('search',function(where){
  251. layList.reload(where,true);
  252. });
  253. layList.switch('is_show',function (odj,value) {
  254. var is_show_value = 0
  255. if(odj.elem.checked==true){
  256. is_show_value = 1
  257. }
  258. action.set_value('is_show',value,is_show_value,'task');
  259. });
  260. //快速编辑
  261. layList.edit(function (obj) {
  262. var id=obj.data.id,value=obj.value;
  263. switch (obj.field) {
  264. case 'title':
  265. action.set_value('title',id,value,'task');
  266. break;
  267. case 'sort':
  268. if (value.trim()) {
  269. if (isNaN(value.trim())) {
  270. layList.msg('请输入正确的数字');
  271. } else {
  272. if (value.trim() < 0) {
  273. layList.msg('排序不能小于0');
  274. } else if (value.trim() > 9999) {
  275. layList.msg('排序不能大于9999');
  276. } else if (parseInt(value.trim()) != value.trim()) {
  277. layList.msg('排序不能为小数');
  278. } else {
  279. action.set_value('sort', id, value.trim(), 'task');
  280. }
  281. }
  282. } else {
  283. layList.msg('排序不能为空');
  284. }
  285. break;
  286. }
  287. });
  288. //监听并执行排序
  289. layList.sort(['id','sort'],true);
  290. //点击事件绑定
  291. layList.tool(function (event,data,obj) {
  292. switch (event) {
  293. case 'delete':
  294. var url=layList.U({a:'delete',q:{id:data.id, model_type:'task'}});
  295. $eb.$swal('delete',function(){
  296. $eb.axios.get(url).then(function(res){
  297. if(res.status == 200 && res.data.code == 200) {
  298. $eb.$swal('success','删除成功!');
  299. obj.del();
  300. }else{
  301. return Promise.reject(res.data.msg || '删除失败');
  302. }
  303. }).catch(function(err){
  304. $eb.$swal('error',err);
  305. });
  306. });
  307. break;
  308. case 'open_image':
  309. layer.photos({
  310. photos: {
  311. data: [
  312. {
  313. src: data.image
  314. }
  315. ]
  316. },
  317. anim: 5
  318. });
  319. break;
  320. }
  321. })
  322. </script>
  323. {/block}