index.php 16 KB

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