facilities.js 9.7 KB

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