steps.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. {extend name="public/container"}
  2. {block name="content"}
  3. <div class="layui-fluid">
  4. <div class="layui-card">
  5. <div class="layui-card-header">学习步骤</div>
  6. <div class="layui-card-body">
  7. <div class="layui-btn-container">
  8. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" data-type="addsteps">
  9. <i class="layui-icon layui-icon-add-1"></i>添加学习步骤
  10. </button>
  11. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" data-type="refresh">
  12. <i class="layui-icon layui-icon-refresh-1"></i>刷新
  13. </button>
  14. </div>
  15. <table id="List" lay-filter="List"></table>
  16. <script type="text/html" id="act">
  17. <button type="button" class="layui-btn layui-btn-normal layui-btn-xs" onclick="dropdown(this)">
  18. <i class="layui-icon">&#xe625;</i>操作
  19. </button>
  20. <ul class="layui-nav-child layui-anim layui-anim-upbit">
  21. <li>
  22. <a href="javascript:void(0)" lay-event="edit">
  23. <i class="iconfont icon-bianji"></i> 编辑
  24. </a>
  25. </li>
  26. <li>
  27. <a lay-event='delstor' href="javascript:void(0)">
  28. <i class="iconfont icon-shanchu"></i> 删除
  29. </a>
  30. </li>
  31. </ul>
  32. </script>
  33. </div>
  34. </div>
  35. </div>
  36. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  37. {/block}
  38. {block name="script"}
  39. <script>
  40. let $eb = parent.parent._mpApi;
  41. let pid = {$pid};
  42. var $ = layui.jquery;
  43. var layer = layui.layer;
  44. //实例化form
  45. layList.form.render();
  46. //加载列表
  47. layList.tableList({o:'List', done:function () {
  48. $('.layui-btn').on('mouseout', function (event) {
  49. var target = event.target;
  50. var type = target.dataset.type;
  51. if ('recommend' === type) {
  52. layer.closeAll();
  53. }
  54. });
  55. }},"{:Url('steps', ['op'=>'getlist', 'pid'=> $pid])}",function (){
  56. return [
  57. {field: 'sort', title: '排序', align: 'center'},
  58. {field: 'stepname', title: '步骤名称',align: 'left'},
  59. {field: 'introduction', title: '步骤介绍',align:'left'},
  60. {field: 'right', title: '操作',align:'center',toolbar:'#act',minWidth:81},
  61. ];
  62. });
  63. //下拉框
  64. $(document).click(function (e) {
  65. $('.layui-nav-child').hide();
  66. })
  67. function dropdown(that){
  68. var oEvent = arguments.callee.caller.arguments[0] || event;
  69. oEvent.stopPropagation();
  70. var offset = $(that).offset();
  71. var top=offset.top-$(window).scrollTop();
  72. var index = $(that).parents('tr').data('index');
  73. $('.layui-nav-child').each(function (key) {
  74. if (key != index) {
  75. $(this).hide();
  76. }
  77. })
  78. if($(document).height() < top+$(that).next('ul').height()){
  79. $(that).next('ul').css({
  80. 'padding': 10,
  81. 'top': - ($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height()/2),
  82. 'min-width': 'inherit',
  83. 'position': 'absolute'
  84. }).toggle();
  85. }else{
  86. $(that).next('ul').css({
  87. 'padding': 10,
  88. 'top':$(that).parent('td').height() / 2 + $(that).height(),
  89. 'min-width': 'inherit',
  90. 'position': 'absolute'
  91. }).toggle();
  92. }
  93. }
  94. //自定义方法
  95. var action= {
  96. set_value: function (field, id, value) {
  97. layList.baseGet(layList.Url({
  98. a: 'set_value',
  99. q: {field: field, id: id, value: value}
  100. }), function (res) {
  101. layList.msg(res.msg);
  102. });
  103. },
  104. }
  105. //查询
  106. layList.search('search',function(where){
  107. layList.reload(where,true);
  108. });
  109. //快速编辑
  110. // layList.edit(function (obj) {
  111. // var id=obj.data.id,value=obj.value;
  112. // switch (obj.field) {
  113. // case 'sort':
  114. // if (value.trim()) {
  115. // if (isNaN(value.trim())) {
  116. // layList.msg('请输入正确的数字');
  117. // } else {
  118. // if (value.trim() < 0) {
  119. // layList.msg('排序不能小于0');
  120. // } else if (value.trim() > 9999) {
  121. // layList.msg('排序不能大于9999');
  122. // } else if (parseInt(value.trim()) != value.trim()) {
  123. // layList.msg('排序不能为小数');
  124. // } else {
  125. // action.set_value('sort', id, value.trim());
  126. // }
  127. // }
  128. // } else {
  129. // layList.msg('排序不能为空');
  130. // }
  131. // break;
  132. // }
  133. // });
  134. //监听并执行排序
  135. //layList.sort(['id','sort'],true);
  136. //点击事件绑定
  137. layList.tool(function (event,data,obj) {
  138. switch (event) {
  139. case 'delstor':
  140. var url=layList.U({a:'deletestep',q:{id:data.id}});
  141. $eb.$swal('delete',function(){
  142. $eb.axios.get(url).then(function(res){
  143. if(res.status == 200 && res.data.code == 200) {
  144. $eb.$swal('success',res.data.msg);
  145. obj.del();
  146. }else
  147. return Promise.reject(res.data.msg || '删除失败')
  148. }).catch(function(err){
  149. $eb.$swal('error',err);
  150. });
  151. })
  152. break;
  153. case 'open_image':
  154. $eb.openImage(data.plan_head);
  155. break;
  156. case 'open_images':
  157. $eb.openImage(data.image);
  158. break;
  159. case 'edit':
  160. layer.open({
  161. type: 2,
  162. title: '编辑学习步骤',
  163. content: '{:Url('createsteps')}?id=' + data.id + "&pid=" + data.pid,
  164. area: ['100%', '100%'],
  165. maxmin: true
  166. });
  167. break;
  168. }
  169. })
  170. //是否显示快捷按钮操作
  171. layList.switch('is_show',function (odj,value) {
  172. if(odj.elem.checked==true){
  173. layList.baseGet(layList.Url({a:'set_show',p:{is_show:1,id:value}}),function (res) {
  174. layList.msg(res.msg);
  175. });
  176. }else{
  177. layList.baseGet(layList.Url({a:'set_show',p:{is_show:0,id:value}}),function (res) {
  178. layList.msg(res.msg);
  179. });
  180. }
  181. });
  182. $(document).on('click', '.layui-btn', function (event) {
  183. var type = $(this).data('type');
  184. var id = $(this).data('id');
  185. if (type === 'addsteps') {
  186. layer.open({
  187. type: 2,
  188. title: '添加学习步骤',
  189. content: "{:Url('createsteps')}?pid=" + pid,
  190. area: ['100%', '100%'],
  191. maxmin: true,
  192. end: function () {
  193. location.reload();
  194. }
  195. });
  196. } else if (type === 'refresh') {
  197. layList.reload();
  198. }
  199. });
  200. </script>
  201. {/block}