discount.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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: '/pusha/indexform' //数据接口
  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: 'name', title: '所属楼盘', align: 'center'},
  23. {field: 'create_at', title: '添加时间', width: 200, align: 'center'},
  24. {
  25. field: 'sort',
  26. title: '排序',
  27. width: 150,
  28. event: 'sortData',
  29. edit: 'text',
  30. align: 'center',
  31. sort: true,
  32. templet: "#sortBox"
  33. }
  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: 165, align: 'center', toolbar: '#operate'}
  44. ]]
  45. });
  46. table.reload('tablerReload'); //重新加载
  47. //监听指定开关
  48. form.on('switch(switchTest)', function (data) {
  49. layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
  50. $.post('/pusha/setrow', {id: data.value, type: 'show'}, function (data) {
  51. layer.msg(data.msg);
  52. table.reload('tablerReload');
  53. })
  54. }, function (aa) {
  55. table.reload('tablerReload'); //重新加载
  56. })
  57. });
  58. //列表操作
  59. table.on('tool(' + tableIds + ')', function (obj) {
  60. var layEvent = obj.event,
  61. data = obj.data;
  62. if (layEvent === 'edit') {
  63. var index = layer.open({
  64. type: 2,
  65. title: '编辑',
  66. area: ['50%', '50%'],
  67. content: '/pusha/edit?id=' + data.id + '&house_name=' + data.name + '&status=edit',
  68. end: function () {
  69. table.reload('tablerReload'); //重新加载
  70. }
  71. });
  72. } else if (layEvent === 'del') {
  73. layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
  74. $.post('/pusha/setrow', {id: data.id, type: 'del'}, function (data) {
  75. layer.msg(data.msg);
  76. table.reload('tablerReload');
  77. })
  78. })
  79. } else if (layEvent === 'sortData') { //修改排序
  80. table.on('edit(' + tableIds + ')', function (obj) {
  81. var data = obj.data;
  82. // console.log(data)
  83. $.post('/pusha/setrow', {id: data.id, type: 'sort', sort: data.sort}, function (data) {
  84. if (data.code == 200) {
  85. layer.msg(data.msg);
  86. } else if (data.code == 300) {
  87. layer.msg(data.msg);
  88. }
  89. })
  90. })
  91. }
  92. });
  93. // 新增
  94. var $ = layui.$, active = {
  95. addData: function () { //获取选中数据
  96. var index = layui.layer.open({
  97. type: 2,
  98. title: '添加',
  99. closeBtn: 1, //不显示关闭按钮
  100. area: ['50%', '50%'],
  101. content: '/pusha/edit?type=' + type_id + '&status=add'//iframe的url,no代表不显示滚动条
  102. , success: function (layero, index) {
  103. },
  104. end: function () {
  105. table.reload('tablerReload');
  106. }
  107. });
  108. },
  109. reload: function () {//搜索
  110. var form = pfgs_serialize($('form'));
  111. table.reload('tablerReload', {
  112. where: {}
  113. })
  114. },
  115. };
  116. $('.demoTable .layui-btn').on('click', function () {
  117. var type = $(this).data('type');
  118. active[type] ? active[type].call(this) : '';
  119. });
  120. $('.The_house').focus(function () {
  121. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  122. indexOpen = parent.layui.layer.open({
  123. type: 2,
  124. title: '选择需要添加的楼盘',
  125. area: ['', '100%'],
  126. content: '/publicuse/housename',
  127. success: function (layero, index) {
  128. },
  129. end: function () {
  130. }
  131. });
  132. parent.layui.layer.full(indexOpen);
  133. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  134. $(window).on("resize", function () {
  135. parent.layui.layer.full(indexOpen);
  136. })
  137. })
  138. //添加页面提交数据
  139. form.on('submit(edit-row)', function (data) {
  140. var formData = new FormData($('form')[0]);
  141. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  142. $.ajax({
  143. cache: false,
  144. type: "post",
  145. url: "/pusha/editform",
  146. data: formData, // 你的formid
  147. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  148. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  149. error: function (request) {
  150. layer.close(index);
  151. layer.msg("请联系管理员");
  152. },
  153. success: function (data) {
  154. if (data.data != null) {
  155. layer.msg(ReturnInfo(data.data), {icon: 5});
  156. return;
  157. }
  158. layer.msg(data.msg);
  159. }
  160. });
  161. return false;
  162. });
  163. })