adpositioncategory.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 = 'adCategoryList';
  9. //第一个实例
  10. table.render({
  11. elem: '#'+tableIds
  12. ,url: '/dictionary/adpositionform' //数据接口
  13. ,where:{token:csrfToken}
  14. ,method:'post'
  15. ,page: true //开启分页
  16. ,height:600
  17. ,text:'数据加载中'
  18. ,cols: [[ //表头
  19. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  20. {field: 'news_name', title: '资讯名称', width:200,align:'center'}
  21. ,{field: 'sort', title: '排序', width:80,align:'center'}
  22. ,{field: 'state', title: '状态', width:80,align:'center'}
  23. ,{field: 'recommend', title: '是否推荐', width:120,align:'center'}
  24. ,{field: 'update_at', title: '更新时间', width:150,align:'center'}
  25. ,{field: 'create_at', title: '添加时间', width:150,align:'center'}
  26. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  27. ]]
  28. });
  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. closeBtn: 1, //不显示关闭按钮
  38. shade: [0],
  39. area: ['600px', '500px'],
  40. anim: 2,
  41. content: ['/dictionary/adpositionedit?id='+data.id, 'yes'], //iframe的url,no代表不显示滚动条
  42. });
  43. } else if(layEvent === 'del') {
  44. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  45. $.post('/dictionary/adpositiondel',{'id':data.id},function (data) {
  46. if(data.code == 200)
  47. {
  48. layer.msg(data.msg);
  49. table.reload(tableIds);
  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. closeBtn: 1, //不显示关闭按钮
  63. shade: [0],
  64. area: ['600px', '500px'],
  65. anim: 2,
  66. content: ['/dictionary/adpositionadd', 'yes'], //iframe的url,no代表不显示滚动条
  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. form.on('submit(editnews)', function(data){
  79. var formData = new FormData($('form')[0]);
  80. $.ajax({
  81. cache : true,
  82. type : "post",
  83. url : '/dictionary/adpositioneditform',
  84. data : formData, // 你的formid
  85. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  86. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  87. error : function(request) {
  88. layer.close(index); //关闭数据提交信息
  89. layer.alert("网络超时");
  90. },
  91. success : function(data) {
  92. if(data.data != null){
  93. layer.msg(ReturnInfo(data.data),{icon:5});
  94. return ;
  95. }
  96. layer.msg(data.msg);
  97. }
  98. });
  99. // $.post('/dictionary/newseditform',{'data':data.field,'token':csrfToken},function (data) {
  100. // if(data.code == 200)
  101. // {
  102. // layer.msg(data.msg);
  103. // parent.layui.table.reload(tableIds);
  104. // TableClose();
  105. // } else if(data.code == 300 ) {
  106. // layer.msg(data.msg);
  107. // }
  108. // })
  109. return false;
  110. });
  111. //添加
  112. form.on('submit(addnews)', function(data){
  113. var formData = new FormData($('form')[0]);
  114. $.ajax({
  115. cache : true,
  116. type : "post",
  117. url : '/dictionary/adpositionaddform',
  118. data : formData, // 你的formid
  119. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  120. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  121. error : function(request) {
  122. layer.close(index); //关闭数据提交信息
  123. layer.alert("网络超时");
  124. },
  125. success : function(data) {
  126. if(data.data != null){
  127. layer.msg(ReturnInfo(data.data),{icon:5});
  128. return ;
  129. }
  130. layer.msg(data.msg);
  131. }
  132. });
  133. return false;
  134. // $.post('/dictionary/newsaddform',{'data':data.field,'token':csrfToken},function (data) {
  135. // if(data.code == 200)
  136. // {
  137. // layer.msg(data.msg);
  138. // parent.layui.table.reload(tableIds);
  139. // } else if(data.code == 300 ) {
  140. // layer.msg(data.msg);
  141. // }
  142. // })
  143. // return false;
  144. });
  145. //上传图片
  146. upload.render({
  147. elem: '#test1'
  148. ,url: '/house/createimg'
  149. ,data:{token:csrfToken}
  150. ,field:'img'
  151. ,size:1000 //限制上传图片的大小,单位为KB
  152. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  153. ,auto:false
  154. ,bindAction:'#addcity'
  155. ,choose: function(obj){
  156. obj.preview(function(index, file, result){
  157. $('#demo1').attr('src', result); //图片链接(base64)
  158. });
  159. }
  160. });
  161. });