renovation.js 6.2 KB

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