facilities.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','upload'], function(){
  2. var layer = layui.layer //弹层
  3. ,table = layui.table //表格
  4. ,element = layui.element //元素操作
  5. ,form = layui.form
  6. ,upload = layui.upload;
  7. //第一个实例
  8. var indexTtable =table.render({
  9. elem: '#housefacilitieslist'
  10. ,url: '/dictionary/facilitiesform' //数据接口
  11. ,where:{token:csrfToken}
  12. ,method:'post'
  13. ,page: true //开启分页
  14. ,text:'数据加载中'
  15. ,id:'tablerReload'
  16. ,cols: [[ //表头
  17. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  18. {type:'numbers'},
  19. {field: 'name', title: '户型',align:'center'}
  20. ,{field: 'sort', title: '排序',width:200, event:'sortData',edit: 'text',align:'center',sort: true,templet:"#sortBox"}
  21. ,{field: 'is_show', title: '审核',align:'center',width:200, templet:function (d) {
  22. if(d.is_show == 2){
  23. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  24. } else {
  25. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  26. }
  27. }}
  28. ,{field: 'create_at', title: '添加时间', width:120,align:'center'}
  29. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  30. ]]
  31. });
  32. indexTtable.reload('tablerReload'); //重新加载
  33. //监听指定开关
  34. form.on('switch(switchTest)', function(data){
  35. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  36. $.post('/dictionary/facilitiesstate',{id:data.value,type:'is_show'},function (data) {
  37. layer.msg(data.msg);
  38. table.reload('tablerReload');
  39. })
  40. },function (aa) {
  41. indexTtable.reload('tablerReload'); //重新加载
  42. })
  43. });
  44. //列表操作
  45. table.on('tool(housefacilitieslist)', function(obj){
  46. var layEvent = obj.event,
  47. data = obj.data;
  48. if(layEvent === 'edit'){
  49. layer.open({
  50. type: 2,
  51. title: '修改配套信息',
  52. closeBtn: 1, //不显示关闭按钮
  53. shade: [0],
  54. area: ['600px', '500px'],
  55. anim: 2,
  56. content: ['/dictionary/facilitiessave?id='+data.id, 'yes'], //iframe的url,no代表不显示滚动条
  57. });
  58. } else if(layEvent === 'del') {
  59. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  60. $.post('/dictionary/facilitiesdel',{'id':data.id},function (data) {
  61. if(data.code == 200)
  62. {
  63. layer.msg(data.msg);
  64. table.reload('tablerReload');
  65. } else if(data.code == 300 ) {
  66. layer.msg(data.msg);
  67. }
  68. })
  69. })
  70. }else if(layEvent === 'sortData'){ //修改排序
  71. table.on('edit(housefacilitieslist)', function(obj){
  72. var data = obj.data;
  73. $.post('/dictionary/facilitiessort',{id:data.id,type:'sort',sort:data.sort},function (data) {
  74. if(data.code == 200)
  75. {
  76. layer.msg(data.msg);
  77. } else if(data.code == 300 ) {
  78. layer.msg(data.msg);
  79. }
  80. })
  81. })
  82. }
  83. });
  84. var $ = layui.$, active = {
  85. addData: function(){ //获取选中数据
  86. layer.open({
  87. type: 2,
  88. title: '添加配套信息',
  89. closeBtn: 1, //不显示关闭按钮
  90. shade: [0],
  91. area: ['600px', '500px'],
  92. anim: 2,
  93. content: ['/dictionary/facilitiesadd', 'yes'], //iframe的url,no代表不显示滚动条
  94. });
  95. // var checkStatus = table.checkStatus('idTest')
  96. // ,data = checkStatus.data;
  97. // layer.alert(JSON.stringify(data));
  98. }
  99. };
  100. $('.demoTable .layui-btn').on('click', function(){
  101. var type = $(this).data('type');
  102. active[type] ? active[type].call(this) : '';
  103. });
  104. //添加图片上传
  105. upload.render({
  106. elem: '#test1'
  107. ,url: '/house/createimg'
  108. ,data:{token:csrfToken}
  109. ,field:'img'
  110. ,size:1000 //限制上传图片的大小,单位为KB
  111. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  112. ,auto:false
  113. ,bindAction:'#addcity'
  114. ,choose: function(obj){
  115. obj.preview(function(index, file, result){
  116. $('#demo1').attr('src', result); //图片链接(base64)
  117. });
  118. }
  119. });
  120. //添加图片上传
  121. upload.render({
  122. elem: '#test2'
  123. ,url: '/house/createimg'
  124. ,data:{token:csrfToken}
  125. ,field:'mobile_img'
  126. ,size:1000 //限制上传图片的大小,单位为KB
  127. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  128. ,auto:false
  129. ,bindAction:'#addcity'
  130. ,choose: function(obj){
  131. obj.preview(function(index, file, result){
  132. $('#demo2').attr('src', result); //图片链接(base64)
  133. });
  134. }
  135. });
  136. //添加图片上传
  137. upload.render({
  138. elem: '#test3'
  139. ,url: '/house/createimg'
  140. ,data:{token:csrfToken}
  141. ,field:'map_img'
  142. ,size:1000 //限制上传图片的大小,单位为KB
  143. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  144. ,auto:false
  145. ,bindAction:'#addcity'
  146. ,choose: function(obj){
  147. obj.preview(function(index, file, result){
  148. $('#demo3').attr('src', result); //图片链接(base64)
  149. });
  150. }
  151. });
  152. //修改
  153. form.on('submit(save_form)', function(data){
  154. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  155. var formData = new FormData($('#facilities_form')[0]);
  156. $.ajax({
  157. cache : true,
  158. type : "post",
  159. url : '/dictionary/facilitiessaveform',
  160. data : formData, // 你的formid
  161. // async : false, //async 默认为true异步,修改为false为同步
  162. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  163. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  164. error : function(request) {
  165. layer.close(index); //关闭数据提交信息
  166. layer.alert("网络超时");
  167. },
  168. success : function(data) {
  169. if (data.code == 200) {
  170. layer.msg(data.msg);
  171. parent.layui.table.reload('housefacilitieslist');
  172. TableClose();
  173. } else if(data.code == 300){
  174. layer.msg(data.msg);
  175. layer.msg(ReturnInfo(data.data));
  176. }
  177. }
  178. });
  179. return false;
  180. });
  181. // 点击放大图片
  182. $('.layui_magnify').on('click', function(){
  183. var _src = $(this).attr('src');
  184. layui.layer.open({
  185. type: 1,
  186. title: false, //是否显示标题
  187. area: ['60%', '80%'],
  188. shade: 0.6, //透明度
  189. closeBtn: 1, //按钮 1有,0无
  190. shadeClose: true,
  191. content: '<img style="width:100%;height:100%" src="'+_src+'">',
  192. });
  193. });
  194. //添加
  195. form.on('submit(add_form)', function(data){
  196. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  197. var formData = new FormData($('#facilities_form')[0]);
  198. $.ajax({
  199. cache : true,
  200. type : "post",
  201. url : '/dictionary/facilitiesaddform',
  202. data : formData, // 你的formid
  203. // async : false, //async 默认为true异步,修改为false为同步
  204. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  205. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  206. error : function(request) {
  207. layer.close(index); //关闭数据提交信息
  208. layer.alert("网络超时");
  209. },
  210. success : function(data) {
  211. if (data.code == 200) {
  212. layer.msg(data.msg);
  213. parent.layui.table.reload('tablerReload');
  214. // TableClose();
  215. } else if(data.code == 300){
  216. layer.msg(data.msg);
  217. layer.msg(ReturnInfo(data.data),{icon:5});
  218. }
  219. }
  220. });
  221. return false;
  222. });
  223. });