signup.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. layui.use(['laypage', 'layer', 'table', 'element', 'form', 'laydate'], function () {
  2. var laypage = layui.laypage //分页
  3. , layer = layui.layer //弹层
  4. , table = layui.table //表格
  5. , element = layui.element //元素操作
  6. , form = layui.form,
  7. laydate = layui.laydate;
  8. laydate.render({
  9. elem: '#date1'
  10. });
  11. laydate.render({
  12. elem: '#date2'
  13. });
  14. //第一个实例
  15. var tableIns = table.render({
  16. elem: '#userlist'
  17. , url: '/usersignup/homeform' //数据接口
  18. , where: {token: csrfToken}
  19. , method: 'post'
  20. , id: 'tablerReload'
  21. , page: true //开启分页
  22. ,height:600
  23. , limit: 20
  24. , text: '数据加载中'
  25. , cols: [[ //表头
  26. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  27. {type: 'numbers', fixed: "left", title: '序号'},
  28. {type: "checkbox", width: 50},
  29. {
  30. field: 'equipment',
  31. title: '设备',
  32. width: 110,
  33. align: 'center',
  34. templet: "#equipment",
  35. templet: function (d) {
  36. if (d.equipment == 'PC') {
  37. return '<div class="layui-table-cell" style="color:red;">' + d.equipment + '</div>'
  38. } else {
  39. return '<div class="layui-table-cell" style="color:#009688;">' + d.equipment + '</div>'
  40. }
  41. }
  42. }
  43. , {field: 'ip', title: 'ip', width: 150, align: 'center'}
  44. , {field: 'source', title: '来源', align: 'center'}
  45. // ,{field: 'name', title: '姓名',width:100,align:'center'}
  46. , {field: 'mobile', title: '手机号码', width: 150, align: 'center'}
  47. , {
  48. field: 'city_name', title: '区域', width: 150, align: 'center', templet: function (d) {
  49. if (d.city_name != null) {
  50. return '<div class="layui-table-cell" style="color:#c8601f;font-weight:600">' + d.city_name + '</div>'
  51. } else {
  52. return '<div class="layui-table-cell" style="font-weight:600">-----</div>'
  53. }
  54. }
  55. }
  56. , {
  57. field: 'house_name', title: '归属', width: 200, align: 'center', templet: function (d) {
  58. if (d.house_name != null) {
  59. return '<div class="layui-table-cell" style="font-weight:600">' + d.house_name + '</div>'
  60. } else {
  61. return '<div class="layui-table-cell" style="font-weight:600">-----</div>'
  62. }
  63. }
  64. }
  65. , {field: 'state', title: '发送状态', width: 150, align: 'center'}
  66. , {field: 'send_email', title: '发送邮箱', width: 150, align: 'center'}
  67. , {field: 'create_at', title: '日期', width: 150, align: 'center'}
  68. // ,{field: 'city', title: '用户区域',width:80,align:'center'}
  69. // ,{field: 'send_email', title: '发送邮箱',width:180,align:'center'}
  70. // ,{field: 'state', title: '发送状态',width:100,align:'center',templet:"#state",templet:function(d){
  71. // if(d.state == '成功'){
  72. // return '<div class="layui-table-cell" style="color:#00960b;font-weight:600">'+d.state+'</div>'
  73. // }else {
  74. // return '<div class="layui-table-cell" style="color:red;font-weight:600">'+d.state+'</div>'
  75. // }
  76. // }}
  77. , {fixed: 'right', title: '操作', width: 150, align: 'center', toolbar: '#signupBar'}
  78. ]]
  79. });
  80. // tableIns.reload('tablerReload'); //重新加载
  81. //列表操作
  82. table.on('tool(userlist)', function (obj) {
  83. var layEvent = obj.event,
  84. data = obj.data;
  85. if (layEvent === 'edit') {
  86. layer.open({
  87. type: 2,
  88. title: '用户详情',
  89. area: ['600px', '500px'],
  90. anim: 2,
  91. content: '/usersignup/userdetails?id=' + data.id,
  92. end: function () {
  93. table.reload('tablerReload');
  94. }//iframe的url,no代表不显示滚动条
  95. });
  96. } else if (layEvent === 'del') {
  97. layer.confirm('您确认要删除吗?', {btn: ['确认', '取消']}, function () {
  98. console.log(data.id)
  99. $.post('/usersignup/signupdel', {id: data.id}, function (data) {
  100. layer.msg(data.msg);
  101. // parent.layui.
  102. table.reload('tablerReload');
  103. })
  104. })
  105. }
  106. });
  107. var $ = layui.$, active = {
  108. addData: function () { //获取选中数据
  109. layer.open({
  110. type: 2,
  111. title: '添加账号',
  112. closeBtn: 1, //不显示关闭按钮
  113. shade: [0],
  114. area: ['600px', '500px'],
  115. anim: 2,
  116. content: ['/user/adduser', 'no'], //iframe的url,no代表不显示滚动条
  117. });
  118. },
  119. sendEmail: function () {
  120. var checkStatus = table.checkStatus('tablerReload');
  121. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  122. if (typeof checkStatus.data[0] == 'object') {
  123. layer.confirm('确定要发送吗?', {btn: ['确认', '取消']}, function () {
  124. var formdat = new FormData();
  125. $.each(checkStatus.data, function (key, val) {
  126. formdat.append('hid[]', val.id);
  127. })
  128. $.ajax({
  129. cache: true,
  130. type: "post",
  131. url: "/usersignup/emailsend",
  132. data: formdat, // 你的formid
  133. // async : false, //async 默认为true异步,修改为false为同步
  134. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  135. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  136. error: function (request) {
  137. layer.close(index); //关闭数据提交信息
  138. layer.alert("网络超时");
  139. },
  140. success: function (data) {
  141. if (data.code == 200) {
  142. layer.msg(data.msg);
  143. reloadTable(reloadId);
  144. } else {
  145. layer.msg(data.msg);
  146. }
  147. }
  148. });
  149. })
  150. return false;
  151. }
  152. layer.msg('请选择需要重新发送的报名信息', {icon: 5});
  153. return false;
  154. },
  155. reload: function () {
  156. var form = pfgs_serialize($('form'));
  157. var a = compareTime(form.start_time, form.end_time);
  158. if (a === false) {
  159. layer.msg('开始时间不能大于结束时间');
  160. return;
  161. }
  162. table.reload('tablerReload', {
  163. where: {
  164. equipment: form.equipment,
  165. start_time: form.start_time,
  166. end_time: form.end_time,
  167. source_id: form.source,
  168. state: form.state
  169. },
  170. page: { //重载分页
  171. curr: 1
  172. }
  173. })
  174. }
  175. };
  176. function compareTime(a, b) {
  177. var arr = a.split("-"); //log [2016,04,06]
  178. var start = new Date(arr[0], (arr[1] - 1), arr[2]);
  179. var starts = start.getTime(); //输出时间戳进行对比
  180. var arrs = b.split("-");
  181. var end = new Date(arrs[0], (arrs[1] - 1), arrs[2]);
  182. var ends = end.getTime();
  183. if (starts > ends) return false;
  184. }
  185. $('.demoTable .layui-btn').on('click', function () {
  186. var type = $(this).data('type');
  187. active[type] ? active[type].call(this) : '';
  188. });
  189. });