signup.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 : 580
  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:140,align:'center'}
  37. ,{field: 'source', title: '来源',align:'center'}
  38. // ,{field: 'name', title: '姓名',width:100,align:'center'}
  39. ,{field: 'mobile', title: '手机号码',width:140,align:'center'}
  40. ,{field: 'city_name', title: '区域',width:120,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:180,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:80,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: 180, 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. } else if (layEvent === 'form') {
  95. layer.open({
  96. type: 2,
  97. title: '来源',
  98. area: ['80%', '80%'],
  99. anim: 2,
  100. content: '/usersignup/userform?id='+data.id,
  101. end:function () {
  102. table.reload('tablerReload');
  103. }//iframe的url,no代表不显示滚动条
  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. reset:function(){
  156. // table.reload('tablerReload');
  157. window.location.reload();
  158. },
  159. reload:function () {
  160. var form = pfgs_serialize($('form'));
  161. var a = compareTime(form.start_time,form.end_time);
  162. if(a === false) {
  163. layer.msg('开始时间不能大于结束时间');
  164. return ;
  165. }
  166. table.reload('tablerReload',{
  167. where:{
  168. equipment:form.equipment,
  169. start_time:form.start_time,
  170. end_time:form.end_time,
  171. source_id:form.source,
  172. source_mobile:form.source_mobile,
  173. state:form.state,
  174. accurate:form.accurate
  175. },
  176. page:{ //重载分页
  177. curr:1
  178. }
  179. })
  180. }
  181. };
  182. function compareTime(a, b) {
  183. var arr = a.split("-"); //log [2016,04,06]
  184. var start = new Date(arr[0], (arr[1] - 1), arr[2]);
  185. var starts = start.getTime(); //输出时间戳进行对比
  186. var arrs = b.split("-");
  187. var end = new Date(arrs[0], (arrs[1] - 1), arrs[2]);
  188. var ends = end.getTime();
  189. if (starts > ends) return false ;
  190. }
  191. $('.demoTable .layui-btn').on('click', function(){
  192. var type = $(this).data('type');
  193. active[type] ? active[type].call(this) : '';
  194. });
  195. });