navi.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. ;
  2. layui.define(['form','table','element','laytpl','upload'], function (e) {
  3. var s = layui.$,
  4. l = (layui.layer, layui.laytpl, layui.setter, layui.view, layui.admin),
  5. table = layui.table,
  6. laytpl = layui.laytpl,
  7. form = layui.form,
  8. upload = layui.upload,
  9. pid = s('input[name=pid]').val(),
  10. position = 'admin';
  11. upload.render({
  12. elem: '.file'
  13. ,url: '/admin/file/upload'
  14. ,done: function(res){
  15. //上传完毕回调
  16. if (!res.code) {
  17. var name = s(this.item).data('name');
  18. s('input[name="'+name+'"]').val(res.data.src);
  19. s(this.item).attr('src',res.data.src);
  20. }
  21. }
  22. })
  23. //导航列表
  24. table.render({
  25. elem:'#navi-table'
  26. ,url:'load.html?level=2'
  27. ,where:{pid:pid,position:position}
  28. ,toolbar:'#topToolbar'
  29. ,cols: [[
  30. {field:'cname', title: '名称'}
  31. ,{field:'sort', title: '排序',edit: 'text'}
  32. ,{field:'action', title: '动作'}
  33. ,{title:'操作', fixed: 'right', width:250, align:'center', toolbar: '#toolbar'}
  34. ]]
  35. ,id: 'navi-table'
  36. ,page: false
  37. ,done:function(){
  38. position = s('select[name=position]').val();
  39. }
  40. });
  41. table.on('toolbar(navi)',function(obj){
  42. switch(obj.event){
  43. case "add":
  44. layer.open({
  45. type: 2,
  46. title: '添加导航',
  47. shadeClose: true,
  48. shade: true,
  49. area: ['80%', '80%'],
  50. content: 'add.html?position='+position+'&pid='+pid
  51. });
  52. break;
  53. }
  54. })
  55. table.on('tool(navi)', function(obj){
  56. var data = obj.data; //获得当前行数据
  57. var tr = obj.tr;
  58. switch(obj.event){
  59. case 'add':
  60. layer.open({
  61. type: 2,
  62. title: '添加导航',
  63. shadeClose: true,
  64. shade: true,
  65. area: ['80%', '80%'],
  66. content: 'add.html?position='+position+'&pid='+data['id']
  67. });
  68. break;
  69. case 'edit':
  70. layer.open({
  71. type: 2,
  72. title: '编辑导航',
  73. shadeClose: true,
  74. shade: true,
  75. area: ['80%', '80%'],
  76. content: 'edit.html?id='+data['id']
  77. });
  78. break;
  79. case 'delete':
  80. layer.confirm('您确定要删除该行数据吗?', {
  81. btn: ['确定','取消'] //按钮
  82. }, function(index){
  83. s.post('delete.html',{id:data['id']},function(r){
  84. if(r.code){
  85. layer.msg(r.msg);
  86. }else{
  87. obj.del();
  88. layer.close(index);
  89. }
  90. });
  91. });
  92. break;
  93. case 'children':
  94. location.href = Think.ADMIN+'/navi/index.html?position='+position+'&pid='+data['id'];
  95. break;
  96. }
  97. });
  98. table.on('edit(navi)', function(obj){
  99. var value = obj.value //得到修改后的值
  100. ,data = obj.data //得到所在行所有键值
  101. ,field = obj.field; //得到字段
  102. s.post(layui.setter.host + 'admin/navi/sort.html',{id:data.id,sort:value},function(r){
  103. if(!r.code){
  104. table.reload('navi-table')
  105. }else{
  106. layer.msg(r.msg);
  107. }
  108. });
  109. });
  110. form.on('select(position)',function(data){
  111. table.reload('navi-table',{
  112. where:{position:s('select[name=position]').val()}
  113. })
  114. })
  115. form.on('submit(LAY-navi-edit)',function(data){
  116. s.post('edit.html',data.field,function(r){
  117. if (!r.code) {
  118. var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  119. parent.layer.close(index); //再执行关闭
  120. parent.layui.table.reload('navi-table')
  121. }else{
  122. layer.msg(r.msg)
  123. }
  124. });
  125. return false;
  126. });
  127. form.on('submit(LAY-navi-add)',function(data){
  128. var index = layer.load();
  129. s.post('add.html',data.field,function(r){
  130. if (!r.code) {
  131. var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  132. parent.layer.close(index); //再执行关闭
  133. parent.layui.table.reload('navi-table')
  134. }else{
  135. layer.msg(r.msg)
  136. }
  137. layer.close(index);
  138. });
  139. return false;
  140. });
  141. e('navi', {})
  142. })