截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lists.html 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. {layout name="layout1" /}
  2. <div class="wrapper">
  3. <div class="layui-card">
  4. <div class="layui-card-body">
  5. <div class="layui-collapse like-layui-collapse" lay-accordion="" style="border:1px dashed #c4c4c4">
  6. <div class="layui-colla-item">
  7. <h2 class="layui-colla-title like-layui-colla-title" style="background-color: #fff">操作提示</h2>
  8. <div class="layui-colla-content layui-show">
  9. <p>*平台需要先设置好秒杀时段,商家可以选择需要参与的秒杀时段。</p>
  10. <p>*删除时段会移除所有参与该时段的商品,请谨慎操作。</p>
  11. </div>
  12. </div>
  13. </div>
  14. <button class="layui-btn layui-btn-normal layui-btn-sm" style="margin-top:15px;" id="add_time">新增秒杀时段</button>
  15. <table id="seckill-lists" lay-filter="seckill-lists"></table>
  16. <script type="text/html" id="time-operation">
  17. <a class="layui-btn {$view_theme_color} layui-btn-sm" lay-event="edit_time">编辑</a>
  18. <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del_time">删除时段</a>
  19. </script>
  20. </div>
  21. </div>
  22. </div>
  23. <style>
  24. .layui-table-cell {
  25. height: auto;
  26. }
  27. </style>
  28. <script>
  29. layui.config({
  30. version:"{$front_version}",
  31. base: '/static/lib/' //静态资源所在路径
  32. }).use(['table','form'], function(){
  33. var $ = layui.$
  34. ,form = layui.form
  35. ,table = layui.table
  36. ,element = layui.element;
  37. $('#add_time').click(function() {
  38. var index = layer.open({
  39. type: 2
  40. ,title: '新增秒杀时间段'
  41. ,content: '{:url("seckill.seckill_time/addTime")}'
  42. ,area: ['60%', '60%']
  43. ,btn: ['保存', '取消']
  44. ,maxmin: true
  45. ,yes: function(index, layero){
  46. var iframeWindow = window['layui-layer-iframe'+ index]
  47. ,submitID = 'add-submit'
  48. ,submit = layero.find('iframe').contents().find('#'+ submitID);
  49. //监听提交
  50. iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
  51. var field = data.field;
  52. like.ajax({
  53. url:'{:url("seckill.seckill_time/addTime")}',
  54. data:field,
  55. type:"post",
  56. success:function(res)
  57. {
  58. if(res.code == 1)
  59. {
  60. layui.layer.msg(res.msg, {
  61. offset: '15px'
  62. , icon: 1
  63. , time: 1000
  64. });
  65. layer.close(index); //关闭弹层
  66. table.reload('seckill-lists'); //数据刷新
  67. }
  68. }
  69. });
  70. });
  71. submit.trigger('click');
  72. }
  73. });
  74. });
  75. table.render({
  76. id:'seckill-lists'
  77. ,elem: '#seckill-lists'
  78. ,url: '{:url("seckill.seckill_time/timeLists")}' //模拟接口
  79. ,cols: [[
  80. {field: 'time',align: 'center',title: '秒杀时段'}
  81. ,{field: 'start_time',align: 'center', title:'开始时间'}
  82. ,{field: 'end_time',align: 'center', title:'结束时间'}
  83. ,{fixed: 'right', title: '操作',width:320, align: 'center', toolbar: '#time-operation'}
  84. ]]
  85. ,page:true
  86. ,text: {none: '暂无数据!'}
  87. ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
  88. return {
  89. "code":res.code,
  90. "msg":res.msg,
  91. "count": res.data.count, //解析数据长度
  92. "data": res.data.list, //解析数据列表
  93. };
  94. },
  95. response: {
  96. statusCode: 1
  97. }
  98. ,done: function(res, curr, count){
  99. // 解决操作栏因为内容过多换行问题
  100. $(".layui-table-main tr").each(function (index, val) {
  101. $($(".layui-table-fixed-l .layui-table-body tbody tr")[index]).height($(val).height());
  102. $($(".layui-table-fixed-r .layui-table-body tbody tr")[index]).height($(val).height());
  103. });
  104. }
  105. });
  106. //监听工具条
  107. table.on('tool(seckill-lists)', function(obj){
  108. var id = obj.data.id;
  109. if(obj.event === 'del_time'){
  110. var time = obj.data.time;
  111. layer.confirm('确定删除秒杀时段:'+'<span style="color: red">'+time+'</span>'+'。该秒杀时段的商品将会全部移除,请谨慎操作。', function(index){
  112. like.ajax({
  113. url:'{:url("seckill.seckill_time/delTime")}',
  114. data:{id:id},
  115. type:"post",
  116. success:function(res)
  117. {
  118. if(res.code == 1)
  119. {
  120. layui.layer.msg(res.msg, {
  121. offset: '15px'
  122. , icon: 1
  123. , time: 1000
  124. });
  125. layer.close(index); //关闭弹层
  126. table.reload('seckill-lists'); //数据刷新
  127. }
  128. }
  129. });
  130. layer.close(index);
  131. })
  132. }
  133. if(obj.event === 'edit_time'){
  134. layer.open({
  135. type: 2
  136. ,title: '编辑秒杀时间段'
  137. ,content: '{:url("seckill.seckill_time/editTime")}?id='+id
  138. ,area: ['60%', '60%']
  139. ,btn: ['保存', '取消']
  140. ,maxmin: true
  141. ,yes: function(index, layero){
  142. var iframeWindow = window['layui-layer-iframe'+ index]
  143. ,submitID = 'edit-submit'
  144. ,submit = layero.find('iframe').contents().find('#'+ submitID);
  145. //监听提交
  146. iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
  147. var field = data.field;
  148. like.ajax({
  149. url:'{:url("seckill.seckill_time/editTime")}',
  150. data:field,
  151. type:"post",
  152. success:function(res)
  153. {
  154. if(res.code == 1)
  155. {
  156. layui.layer.msg(res.msg, {
  157. offset: '15px'
  158. , icon: 1
  159. , time: 1000
  160. });
  161. layer.close(index); //关闭弹层
  162. table.reload('seckill-lists'); //数据刷新
  163. }
  164. }
  165. });
  166. });
  167. submit.trigger('click');
  168. }
  169. });
  170. }
  171. });
  172. });
  173. </script>