homediscount.js 12 KB

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