houseemail.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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: '/houseemail/indexform' //数据接口
  14. , where: {token: csrfToken}
  15. , method: 'post'
  16. , page: true //开启分页
  17. , text: '数据加载中'
  18. , id: 'tablerReload'
  19. , cols: [[ //表头
  20. {type: 'numbers', title: '序号', width: 100},
  21. {field: 'email', title: '邮箱', align: 'center'},
  22. {field: 'name', title: '楼盘', align: 'center'},
  23. {field: 'create_at', title: '添加时间', width: 300, align: 'center'},
  24. {fixed: 'right', title: '操作', width: 200, align: 'center', toolbar: '#operate'}
  25. ]]
  26. });
  27. table.reload('tablerReload'); //重新加载
  28. //列表操作
  29. table.on('tool(' + tableIds + ')', function (obj) {
  30. var layEvent = obj.event,
  31. data = obj.data;
  32. if (layEvent === 'edit') {
  33. var index = layer.open({
  34. type: 2,
  35. title: '修改楼盘邮箱',
  36. area: ['40%', '50%'],
  37. content: '/houseemail/edit?id=' + data.id + '&house_name=' + data.name,
  38. end: function () {
  39. table.reload('tablerReload'); //重新加载
  40. }
  41. });
  42. } else if (layEvent === 'del') {
  43. layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
  44. $.post('/houseemail/delemail', {id: data.id, type: 'del'}, function (data) {
  45. layer.msg(data.msg);
  46. table.reload('tablerReload');
  47. })
  48. })
  49. }
  50. });
  51. // 新增
  52. var $ = layui.$, active = {
  53. addData: function () { //获取选中数据
  54. var index = layui.layer.open({
  55. type: 2,
  56. title: '新增楼盘邮箱',
  57. closeBtn: 1, //不显示关闭按钮
  58. area: ['40%', '50%'],
  59. content: '/houseemail/add' //iframe的url,no代表不显示滚动条
  60. , success: function (layero, index) {
  61. },
  62. end: function () {
  63. table.reload('tablerReload');
  64. }
  65. });
  66. },
  67. reload: function () {//搜索
  68. var form = pfgs_serialize($('form'));
  69. table.reload('tablerReload', {
  70. where: {
  71. text: form.input_house_text,
  72. },
  73. page: {
  74. curr: 1
  75. }
  76. })
  77. },
  78. };
  79. $('.demoTable .layui-btn').on('click', function () {
  80. var type = $(this).data('type');
  81. active[type] ? active[type].call(this) : '';
  82. });
  83. $('.The_house').focus(function () {
  84. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  85. indexOpen = parent.layui.layer.open({
  86. type: 2,
  87. title: '请选择需要添加的楼盘',
  88. area: ['800px', '800px'],
  89. content: '/publicuse/housename',
  90. success: function (layero, index) {
  91. },
  92. end: function () {
  93. }
  94. });
  95. })
  96. //添加页面提交数据
  97. form.on('submit(add)', function (data) {
  98. var formData = new FormData($('form')[0]);
  99. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  100. $.ajax({
  101. cache: false,
  102. type: "post",
  103. url: "/houseemail/addform",
  104. data: formData, // 你的formid
  105. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  106. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  107. error: function (request) {
  108. layer.close(index);
  109. layer.msg("请联系管理员");
  110. },
  111. success: function (data) {
  112. if (data.data != null) {
  113. layer.msg(ReturnInfo(data.data), {icon: 5});
  114. return;
  115. }
  116. layer.msg(data.msg);
  117. TableClose();
  118. }
  119. });
  120. return false;
  121. });
  122. //编辑页面提交数据
  123. form.on('submit(edit)', function (data) {
  124. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  125. // var oindex = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  126. var formData = new FormData($('form')[0]);
  127. $.ajax({
  128. type: "post",
  129. url: "/houseemail/editform",
  130. data: formData,
  131. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  132. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  133. error: function (request) {
  134. layer.close(index);
  135. layer.msg("请联系管理员");
  136. },
  137. success: function (data) {
  138. if (data.data != null) {
  139. layer.msg(ReturnInfo(data.data), {icon: 5});
  140. return;
  141. }
  142. layer.msg(data.msg);
  143. TableClose();
  144. parent.layer.close(oindex); //再执行关闭
  145. }
  146. });
  147. return false;
  148. });
  149. })