hotcity.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. layui.use(['laypage', 'layer', 'table', 'element', 'form', 'upload'], function () {
  2. var laypage = layui.laypage //分页
  3. , $ = layui.jquery
  4. , layer = layui.layer //弹层
  5. , table = layui.table //表格
  6. , element = layui.element //元素操作
  7. , form = layui.form
  8. , upload = layui.upload;
  9. var tableIds = 'videolist'; //表格ID
  10. var type_id = $('input[name="typeid"]').val();
  11. //第一个实例
  12. table.render({
  13. elem: '#' + tableIds
  14. , url: '/miniprograms/rotationform' //数据接口
  15. , where: {token: csrfToken, type: type_id}
  16. , method: 'post'
  17. , page: true //开启分页
  18. , text: '数据加载中'
  19. , id: 'tablerReload'
  20. , cols: [[ //表头
  21. {type: 'numbers', title: '序号', width: 50},
  22. {field: 'title', title: '区域', align: 'center'},
  23. {
  24. field: 'img', title: '图片', width: 200, align: 'center', templet: function (d) {
  25. return '<img class="layui_magnify" src="' + d.img + '"/>'
  26. }
  27. }
  28. , {
  29. field: 'url', title: '地址', width: 200, align: 'center', templet: function (d) {
  30. return '<a href="' + d.url + '" target="_blank">' + d.url + '</a>';
  31. }
  32. }
  33. , {field: 'create_at', title: '添加时间', width: 150, align: 'center'}
  34. , {
  35. field: 'is_show', title: '审核', align: 'center', width: 100, templet: function (d) {
  36. if (d.is_show == 2) {
  37. return '<input type="checkbox" value="' + d.id + '" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  38. } else {
  39. return '<input type="checkbox" checked value="' + d.id + '" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  40. }
  41. }
  42. }
  43. , {fixed: 'right', title: '操作', width: 180, align: 'center', toolbar: '#operate'}
  44. ]]
  45. });
  46. table.reload('tablerReload'); //重新加载
  47. // 列表点击放大图片
  48. $('.layui-table-main').on('click', '.layui_magnify', function () {
  49. var _src = $(this).attr('src');
  50. layui.layer.open({
  51. type: 1,
  52. title: false, //是否显示标题
  53. area: ['95%', '55%'],
  54. shade: 0.6, //透明度
  55. closeBtn: 1, //按钮 1有,0无
  56. shadeClose: true,
  57. content: '<img style="width:100%;height:100%" src="' + _src + '">',
  58. });
  59. });
  60. //监听指定开关
  61. form.on('switch(switchTest)', function (data) {
  62. layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
  63. $.post('/miniprograms/imgdelshow', {id: data.value, type: 'show'}, function (data) {
  64. layer.msg(data.msg);
  65. table.reload('tablerReload');
  66. })
  67. }, function (aa) {
  68. table.reload('tablerReload'); //重新加载
  69. })
  70. });
  71. //列表操作
  72. table.on('tool(' + tableIds + ')', function (obj) {
  73. var layEvent = obj.event,
  74. data = obj.data;
  75. if (layEvent === 'edit') {
  76. var index = layer.open({
  77. type: 2,
  78. title: '修改',
  79. area: ['800px', '500px'],
  80. content: '/miniprograms/hotcityedit?id=' + data.id + '&house_name=' + data.name,
  81. end: function () {
  82. table.reload('tablerReload'); //重新加载
  83. }
  84. });
  85. } else if (layEvent === 'del') {
  86. layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
  87. $.post('/miniprograms/imgdelshow', {id: data.id, type: 'del'}, function (data) {
  88. layer.msg(data.msg);
  89. table.reload('tablerReload');
  90. })
  91. })
  92. } else if (layEvent === 'expirationData') {
  93. table.on('edit(' + tableIds + ')', function (obj) {
  94. var data = obj.data;
  95. $.post('/miniprograms/imgdelshow', {
  96. id: data.id,
  97. type: 'expiration',
  98. expiration: data.expiration_date
  99. }, function (data) {
  100. if (data.code == 200) {
  101. layer.msg(data.msg);
  102. } else if (data.code == 300) {
  103. layer.msg(data.msg);
  104. }
  105. })
  106. })
  107. }
  108. });
  109. //添加图片上传
  110. upload.render({
  111. elem: '#test1'
  112. , url: '/house/createimg'
  113. , data: {token: csrfToken}
  114. , field: 'img'
  115. , size: 300 //限制上传图片的大小,单位为KB
  116. , exts: 'png|jpg|jpeg' //只允许上传压缩文件
  117. , auto: false
  118. , bindAction: '#addcity'
  119. , choose: function (obj) {
  120. obj.preview(function (index, file, result) {
  121. $('#breviary_img').attr('src', result); //图片链接(base64)
  122. });
  123. }
  124. });
  125. // 图片放大浏览
  126. $('.layui_magnify').click(function () {
  127. var _src = $(this).attr('src');
  128. layui.layer.open({
  129. type: 1,
  130. title: false, //是否显示标题
  131. area: ['60%', '80%'],
  132. shade: 0.6, //透明度
  133. closeBtn: 1, //按钮 1有,0无
  134. shadeClose: true,
  135. content: '<img style="width:100%;height:100%" src="' + _src + '">',
  136. });
  137. })
  138. // 新增
  139. var $ = layui.$, active = {
  140. addData: function () { //获取选中数据
  141. var index = layui.layer.open({
  142. type: 2,
  143. title: '添加',
  144. closeBtn: 1, //不显示关闭按钮
  145. area: ['800px', '500px'],
  146. content: '/miniprograms/hotcityadd?type=' + type_id //iframe的url,no代表不显示滚动条
  147. , success: function (layero, index) {
  148. },
  149. end: function () {
  150. table.reload('tablerReload');
  151. }
  152. });
  153. },
  154. reload: function () {//搜索
  155. var form = pfgs_serialize($('form'));
  156. var name = '';
  157. var house_name = '';
  158. if (form.input_house == 'name') {
  159. name = form.input_house_text;
  160. } else if (form.input_house == 'house_name') {
  161. house_name = form.input_house_text;
  162. }
  163. table.reload('tablerReload', {
  164. where: {
  165. title: name,
  166. house_name: house_name,
  167. city: form.input_city,
  168. type_name: form.type_name
  169. }
  170. })
  171. },
  172. };
  173. $('.demoTable .layui-btn').on('click', function () {
  174. var type = $(this).data('type');
  175. active[type] ? active[type].call(this) : '';
  176. });
  177. $('.The_house').focus(function () {
  178. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  179. indexOpen = parent.layui.layer.open({
  180. type: 2,
  181. title: '选择需要添加的楼盘',
  182. area: ['', '100%'],
  183. content: '/publicuse/housename',
  184. success: function (layero, index) {
  185. },
  186. end: function () {
  187. }
  188. });
  189. parent.layui.layer.full(indexOpen);
  190. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  191. $(window).on("resize", function () {
  192. parent.layui.layer.full(indexOpen);
  193. })
  194. })
  195. //添加页面提交数据
  196. form.on('submit(adds)', function (data) {
  197. var formData = new FormData($('form')[0]);
  198. if (formData.getAll('img')[0].size == 0) {
  199. layer.msg('请选择图片');
  200. return false;
  201. }
  202. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  203. $.ajax({
  204. cache: false,
  205. type: "post",
  206. url: "/miniprograms/rotationaddform",
  207. data: formData, // 你的formid
  208. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  209. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  210. error: function (request) {
  211. layer.close(index);
  212. layer.msg("请联系管理员");
  213. },
  214. success: function (data) {
  215. if (data.data != null) {
  216. layer.msg(ReturnInfo(data.data), {icon: 5});
  217. return;
  218. }
  219. layer.msg(data.msg);
  220. }
  221. });
  222. return false;
  223. });
  224. form.on('submit(edit)', function (data) {
  225. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  226. // var oindex = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  227. var formData = new FormData($('form')[0]);
  228. $.ajax({
  229. type: "post",
  230. url: "/miniprograms/rotationeditform",
  231. data: formData,
  232. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  233. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  234. error: function (request) {
  235. layer.close(index);
  236. layer.msg("请联系管理员");
  237. },
  238. success: function (data) {
  239. if (data.data != null) {
  240. layer.msg(ReturnInfo(data.data), {icon: 5});
  241. return;
  242. }
  243. layer.msg(data.msg);
  244. parent.layer.close(oindex); //再执行关闭
  245. }
  246. });
  247. return false;
  248. });
  249. })