renovation.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','upload'], function(){
  2. var laypage = layui.laypage //分页
  3. ,layer = layui.layer //弹层
  4. ,table = layui.table //表格
  5. ,element = layui.element //元素操作
  6. ,form = layui.form
  7. ,upload = layui.upload;
  8. var tableIds = 'Renovation'; //表格ID
  9. var reloadId = 'tablerReload';
  10. //第一个实例
  11. var tableIns = table.render({
  12. elem: '#'+tableIds
  13. ,url: '/dictionarya/renovationform' //数据接口
  14. ,where:{token:csrfToken,type:4}
  15. ,method:'post'
  16. ,page: true //开启分页
  17. ,height:600
  18. ,text:'数据加载中'
  19. ,id:reloadId
  20. ,limit:20
  21. ,cols: [[ //表头
  22. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  23. {type:'numbers'},
  24. {field: 'name', title: '品鉴栏目', align:'center'}
  25. ,{fixed: 'right',title:'操作', width: 180, align:'center', toolbar: '#operate'}
  26. ]]
  27. });
  28. table.reload('tablerReload'); //重新加载
  29. //列表操作
  30. table.on('tool('+tableIds+')', function(obj){
  31. var layEvent = obj.event,
  32. data = obj.data;
  33. if(layEvent === 'edit'){
  34. layer.open({
  35. type: 2,
  36. title: '修改标签',
  37. area: ['600px', '500px'],
  38. content: '/dictionarya/renovationedit?id='+data.id, //iframe的url,no代表不显示滚动条
  39. end:function(){
  40. table.reload('tablerReload');
  41. }
  42. });
  43. } else if(layEvent === 'del') {
  44. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  45. $.post('/dictionarya/labeldel',{'id':data.id},function (data) {
  46. if(data.code == 200)
  47. {
  48. layer.msg(data.msg);
  49. table.reload('tablerReload');
  50. } else if(data.code == 300 ) {
  51. layer.msg(data.msg);
  52. }
  53. })
  54. })
  55. }
  56. });
  57. var $ = layui.$, active = {
  58. addData: function(){ //获取选中数据
  59. layer.open({
  60. type: 2,
  61. title: '添加装修品鉴栏目',
  62. area: ['600px', '500px'],
  63. content: '/dictionarya/renovationadd', //iframe的url,no代表不显示滚动条
  64. end:function(){
  65. table.reload('tablerReload');
  66. }
  67. });
  68. // var checkStatus = table.checkStatus('idTest')
  69. // ,data = checkStatus.data;
  70. // layer.alert(JSON.stringify(data));
  71. }
  72. };
  73. $('.demoTable .layui-btn').on('click', function(){
  74. var type = $(this).data('type');
  75. active[type] ? active[type].call(this) : '';
  76. });
  77. //添加图片上传
  78. upload.render({
  79. elem: '#test1'
  80. ,url: '/house/createimg'
  81. ,data:{token:csrfToken}
  82. ,field:'img'
  83. ,size:1000 //限制上传图片的大小,单位为KB
  84. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  85. ,auto:false
  86. ,bindAction:'#addcity'
  87. ,choose: function(obj){
  88. obj.preview(function(index, file, result){
  89. $('#breviary_img').attr('src', result); //图片链接(base64)
  90. });
  91. }
  92. });
  93. //添加图片上传
  94. upload.render({
  95. elem: '#test2'
  96. ,url: '/house/createimg'
  97. ,data:{token:csrfToken}
  98. ,field:'img1'
  99. ,size:1000 //限制上传图片的大小,单位为KB
  100. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  101. ,auto:false
  102. ,bindAction:'#addcity'
  103. ,choose: function(obj){
  104. obj.preview(function(index, file, result){
  105. $('#breviary_img1').attr('src', result); //图片链接(base64)
  106. });
  107. }
  108. });
  109. //修改
  110. form.on('submit(edittheme)', function(data){
  111. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  112. var formData = new FormData($('form')[0]);
  113. $.ajax({
  114. type : "post",
  115. url :'/dictionarya/renovationeditform',
  116. data : formData,
  117. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  118. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  119. error : function(request) {
  120. layer.close(index);
  121. layer.msg("请联系管理员");
  122. },
  123. success : function(data) {
  124. if(data.data != null){
  125. layer.msg(ReturnInfo(data.data),{icon:5});
  126. return ;
  127. }
  128. layer.msg(data.msg);
  129. parent.layer.close(oindex); //再执行关闭
  130. }
  131. });
  132. return false;
  133. });
  134. //添加
  135. form.on('submit(addtheme)', function(data){
  136. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  137. var formData = new FormData($('form')[0]);
  138. $.ajax({
  139. type : "post",
  140. url :'/dictionarya/renovationaddform',
  141. data : formData,
  142. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  143. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  144. error : function(request) {
  145. layer.close(index);
  146. layer.msg("请联系管理员");
  147. },
  148. success : function(data) {
  149. if(data.data != null){
  150. layer.msg(ReturnInfo(data.data),{icon:5});
  151. return ;
  152. }
  153. layer.msg(data.msg);
  154. parent.layer.close(oindex); //再执行关闭
  155. }
  156. });
  157. return false;
  158. });
  159. });