facilities.js 9.3 KB

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