signup.js 8.1 KB

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