astrict.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. var tableIds = 'astrictList';
  15. //第一个实例
  16. table.render({
  17. elem: '#'+tableIds
  18. ,url: '/usersignup/astrictform' //数据接口
  19. ,where:{token:csrfToken}
  20. ,method:'post'
  21. ,page: true //开启分页
  22. ,text:'数据加载中'
  23. ,id:'tablereload'
  24. ,cols: [[ //表头
  25. {type:'numbers'},
  26. {field: 'mobile', title: '电话', align:'center',width:200}
  27. // ,{field: 'astrict_start', title: '限制开始', align:'center',width:100}
  28. // ,{field: 'astrict_end', title: '限制结束',align:'center',width:100}
  29. ,{field: 'astrict_msg', title: '限制提示',align:'center'}
  30. ,{field: 'state', title: '状态',align:'center',width:150,templet:function (d) {
  31. switch (d.state){
  32. case '2':
  33. return '<input type="checkbox" value="'+d.id+'" data-state="1" lay-skin="switch" lay-filter="switchTest" lay-text="|暂停">'
  34. break;
  35. case '1':
  36. return '<input type="checkbox" checked value="'+d.id+'" data-state="2" lay-skin="switch" lay-filter="switchTest" lay-text="使用|">'
  37. break;
  38. }
  39. }}
  40. ,{field: 'create_at', title: '添加时间', align:'center',width:250}
  41. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#astrictfunc'}
  42. ]]
  43. });
  44. //列表操作
  45. table.on('tool('+tableIds+')', function(obj){
  46. var layEvent = obj.event,
  47. data = obj.data;
  48. if(layEvent === 'del') {
  49. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  50. $.post('/usersignup/astrictdel',{'id':data.id},function (data) {
  51. table.reload('tablereload');
  52. })
  53. })
  54. }
  55. });
  56. var $ = layui.$, active = {
  57. addData: function(){ //获取选中数据
  58. layer.open({
  59. type: 2,
  60. title: '添加限制号码',
  61. closeBtn: 1, //不显示关闭按钮
  62. shade: [0],
  63. area: ['600px', '500px'],
  64. anim: 2,
  65. content: '/usersignup/astrictadd', //iframe的url,no代表不显示滚动条
  66. end:function () {
  67. table.reload('tablereload');
  68. }
  69. });
  70. // var checkStatus = table.checkStatus('idTest')
  71. // ,data = checkStatus.data;
  72. // layer.alert(JSON.stringify(data));
  73. }, reload:function () {
  74. var form = pfgs_serialize($('form'));
  75. var name = '';
  76. var source_id = '';
  77. if(form.input_house == 'name'){
  78. name = form.input_house_text;
  79. } else if(form.input_house == 'source_id'){
  80. source_id = form.input_house_text;
  81. }
  82. table.reload('tablereload',{
  83. where:{
  84. source_id:source_id,
  85. name:name,
  86. type:form.type
  87. },
  88. page:{ //重载分页
  89. curr:1
  90. }
  91. })
  92. }
  93. };
  94. $('.demoTable .layui-btn').on('click', function(){
  95. var type = $(this).data('type');
  96. active[type] ? active[type].call(this) : '';
  97. });
  98. //添加
  99. form.on('submit(addnews)', function(data){
  100. layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8});
  101. $.post('/usersignup/astrictaddto',{'data':data.field,'token':csrfToken},function (data) {
  102. if(data.data != null){
  103. layer.msg(ReturnInfo(data.data),{icon:5});
  104. return ;
  105. }
  106. layer.msg(data.msg);
  107. TableClose();
  108. })
  109. return false;
  110. });
  111. //监听指定开关
  112. form.on('switch(switchTest)', function(data){
  113. var id = $(this).val();
  114. var state = $(this).data('state')
  115. layer.confirm('确定修改吗?',{btn: ['确定', '取消']},function () {
  116. $.post('/usersignup/astrictstate',{'id':id,'state':state,'token':csrfToken},function (data) {
  117. if(data.data != null){
  118. layer.msg(ReturnInfo(data.data),{icon:5});
  119. return ;
  120. }
  121. layer.msg(data.msg);
  122. table.reload('tablereload');
  123. })
  124. },function () {
  125. table.reload('tablereload');
  126. })
  127. });
  128. });