pushcity.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. layui.use(['layer', 'table', 'form','upload'], function () {
  2. /*********layui引入参数**********/
  3. var $ = layui.jquery
  4. , layer = layui.layer //弹层
  5. , table = layui.table //表格
  6. , form = layui.form
  7. ,upload = layui.upload
  8. /**********列表参数设置**********/
  9. var list_id = $('#list_id').val();
  10. var tableIds = 'advertisinglist'; //表格节点ID
  11. var rowIds = 'advertisingfunc'; //列操作节点ID
  12. var url = '/listnav/indexpush/pushcityform';//数据接口
  13. var where = {token: csrfToken,list_id:list_id};//参数
  14. /************表格实列************/
  15. table.render({
  16. elem: '#' + tableIds
  17. , url: url //数据接口
  18. , where: where
  19. , method: 'post'
  20. , page: true //开启分页
  21. , text: '数据加载中'
  22. , height: 580
  23. , id: 'tablerReload'
  24. , cols: [[ //表头
  25. {type: 'numbers', title: '序号', width: 50}
  26. , {field: 'city_name', title: '地区名称', align: 'center'}
  27. , {
  28. field: 'sort',
  29. title: '排序',
  30. width: 100,
  31. event: 'sortData',
  32. edit: 'text',
  33. align: 'center',
  34. sort: true,
  35. templet: "#sortBox"
  36. }
  37. , {field: 'state', title: '审核', align: 'center', width: 100,templet: function (d) {
  38. if (d.state == 2) {
  39. return '<input type="checkbox" value="' + d.id + '" res_state="1" lay-skin="switch" lay-filter="switchTest3" lay-text="|">'
  40. } else {
  41. return '<input type="checkbox" checked value="' + d.id + '" res_state="2" lay-skin="switch" lay-filter="switchTest3" lay-text="|">'
  42. }
  43. }}
  44. , {field: 'create_at', title: '添加时间', width: 200, align: 'center'}
  45. , {fixed: 'right', title: '操作', width: 180, align: 'center', toolbar: '#' + rowIds}
  46. ]]
  47. });
  48. /********************************************列操作begin***********************************************************/
  49. table.on('tool(' + tableIds + ')', function (obj) {
  50. var layEvent = obj.event,
  51. data = obj.data;
  52. if (layEvent === 'del') {
  53. var index = layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
  54. setListHouse('del',data.id);
  55. layer.close(index);
  56. })
  57. } else if (layEvent === 'sortData') { //修改排序
  58. table.on('edit(' + tableIds + ')', function (obj) {
  59. var data = obj.data;
  60. setListHouse('sort',data.id,data.sort);
  61. })
  62. }
  63. });
  64. /********************************************列操作end***********************************************************/
  65. /********************************************栏目操作gegin*******************************************************/
  66. var $ = layui.$, active = {
  67. addData: function () { //获取选中数据
  68. var index = layui.layer.open({
  69. type: 2,
  70. title: '添加首页区域主推楼盘推送',
  71. closeBtn: 1, //不显示关闭按钮
  72. area: ['60%', '30%'],
  73. content: '/listnav/indexpush/addpushcity?list_id='+list_id//iframe的url,no代表不显示滚动条
  74. , success: function (layero, index) {
  75. },
  76. end: function () {
  77. table.reload('tablerReload');
  78. }
  79. });
  80. }
  81. };
  82. $('.demoTable .layui-btn').on('click', function () {
  83. var type = $(this).data('type');
  84. active[type] ? active[type].call(this) : '';
  85. });
  86. /********************************************栏目操作end*******************************************************/
  87. /********************************************提交操作begin*****************************************************/
  88. form.on('submit(adds)', function (data) {
  89. var formData = new FormData($('form')[0]);
  90. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  91. $.ajax({
  92. cache: false,
  93. type: "post",
  94. url: "/listnav/indexpush/addpushcityform",
  95. data: formData, // 你的formid
  96. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  97. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  98. error: function (request) {
  99. layer.close(index);
  100. layer.msg("请联系管理员");
  101. },
  102. success: function (data) {
  103. layer.msg(data.msg);
  104. if(data.code == 200){
  105. TableClose();
  106. }
  107. }
  108. });
  109. return false;
  110. });
  111. /********************************************提交操作end*********************************************************/
  112. /********************************************其他操作begin*******************************************************/
  113. //选择区域
  114. $('.The_house').focus(function () {
  115. indexOpen = parent.layui.layer.open({
  116. type: 2,
  117. title: '选择需要添加的区域',
  118. area: ['', '100%'],
  119. content: '/publicuse/city?type=1',
  120. success: function (layero, index) {
  121. }
  122. });
  123. parent.layui.layer.full(indexOpen);
  124. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  125. $(window).on("resize", function () {
  126. parent.layui.layer.full(indexOpen);
  127. })
  128. })
  129. //监听指定开关
  130. form.on('switch(switchTest3)', function (data) {
  131. let id = data.value;
  132. let val = $(this).attr('res_state');
  133. var index = layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
  134. setListHouse('state',id,val)
  135. layer.close(index)
  136. }, function (aa) {
  137. renderTable(); //重新加载
  138. })
  139. });
  140. function setListHouse(code, id, val = null) {
  141. $.post('/listnav/indexpush/set',{code:code,id:id,val:val},function(res){
  142. layer.msg(res.msg)
  143. table.reload('tablerReload'); //重新加载
  144. },'json')
  145. }
  146. /********************************************其他操作end*********************************************************/
  147. })