sync.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. layui.use(['layer', 'table', 'element','form'], function(){
  2. var laypage = layui.laypage //分页
  3. ,layer = layui.layer //弹层
  4. ,table = layui.table //表格
  5. ,element = layui.element //元素操作
  6. ,form = layui.form;
  7. //第一个实例
  8. table.render({
  9. elem: '#menulist'
  10. ,url: '/othersync/indexform' //数据接口
  11. ,where:{token:csrfToken}
  12. ,method:'post'
  13. ,page: true //开启分页
  14. ,id:'tablerReload'
  15. ,limit:20
  16. ,text:'数据加载中'
  17. ,cols: [[ //表头
  18. {type:'numbers',title:'序号'}
  19. ,{field: 'name', title: '楼盘名称', align:'center',width:200}
  20. ,{field: 'city_name', title: '区域', align:'center',width:150}
  21. ,{field: 'create_at', title: '添加时间', align:'left',width: 200}
  22. ,{field: 'update_at', title: '修改时间', align:'left',width: 200}
  23. ,{fixed: 'right',title:'操作', align:'center', toolbar: '#operate'}
  24. ]]
  25. });
  26. //列表操作
  27. table.on('tool(menulist)', function(obj){
  28. var layEvent = obj.event,
  29. data = obj.data;
  30. if(layEvent === 'edit'){
  31. var index = layui.layer.open({
  32. title : '同步 [<span style="color:red">'+data.name+'</span>] 楼盘',
  33. type : 2,
  34. area:['','100%'],
  35. maxmin: true,
  36. content : "/othersync/houseinfo?hid="+data.id,
  37. })
  38. layui.layer.full(index);
  39. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  40. $(window).on("resize",function(){
  41. layui.layer.full(index);
  42. })
  43. }else if(layEvent === 'house_album'){
  44. var index = layui.layer.open({
  45. title : '同步 [<span style="color:red">'+data.name+'</span>] 楼盘-相册',
  46. type : 2,
  47. area:['','100%'],
  48. maxmin: true,
  49. content : "/othersync/housealbum?hid="+data.id,
  50. })
  51. layui.layer.full(index);
  52. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  53. $(window).on("resize",function(){
  54. layui.layer.full(index);
  55. })
  56. }else if(layEvent === 'house_type'){
  57. }else if(layEvent === 'house_peitao'){
  58. }
  59. });
  60. table.on('tool(citytellist)', function(obj){
  61. var layEvent = obj.event,
  62. data = obj.data;
  63. if(layEvent === 'tel_city'){
  64. layer.open({
  65. type: 2,
  66. title: '添加区域',
  67. closeBtn: 1, //不显示关闭按钮
  68. shade: [0],
  69. area: ['600px', '500px'],
  70. anim: 2,
  71. content:'/othertel/cityascription?id='+data.id, //iframe的url,no代表不显示滚动条
  72. });
  73. }
  74. });
  75. var $ = layui.$, active = {
  76. addData: function(){ //获取选中数据
  77. layer.open({
  78. type: 2,
  79. title: '添加电话',
  80. closeBtn: 1, //不显示关闭按钮
  81. shade: [0],
  82. area: ['600px', '500px'],
  83. anim: 2,
  84. content: '/othertel/add', //iframe的url,no代表不显示滚动条
  85. end: function(){ //此处用于演示
  86. table.reload('tablerReload');
  87. }
  88. });
  89. }
  90. };
  91. $('.demoTable .layui-btn').on('click', function(){
  92. var type = $(this).data('type');
  93. active[type] ? active[type].call(this) : '';
  94. });
  95. form.on('submit(edittel)', function(data){
  96. $.post('/othertel/editform',{'data':data.field},function (data) {
  97. if(data.code == 200)
  98. {
  99. layer.msg(data.msg);
  100. parent.layui.table.reload('menulist');
  101. } else if(data.code == 300 ) {
  102. layer.msg(data.msg);
  103. layer.msg(ReturnInfo(data.data),{icon:5});
  104. }
  105. })
  106. return false;
  107. });
  108. form.on('submit(tijiao)', function(data){
  109. $.post('/othertel/addform',{'data':data.field},function (data) {
  110. if(data.code == 200)
  111. {
  112. layer.msg(data.msg);
  113. parent.layui.table.reload('menulist');
  114. // TableClose();
  115. } else if(data.code == 300 ) {
  116. layer.msg(data.msg);
  117. layer.msg(ReturnInfo(data.data),{icon:5});
  118. }
  119. })
  120. return false;
  121. });
  122. form.on('submit(unload_tel)', function(data){
  123. var index = top.layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  124. var formData = new FormData($('#cityForm')[0]);
  125. $.ajax({
  126. cache : true,
  127. type : "post",
  128. url : "/othertel/addcityascription",
  129. data : formData, // 你的formid
  130. async : false,
  131. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  132. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  133. error : function(request) {
  134. top.layer.close(index); //关闭数据提交信息
  135. layer.alert("网络超时");
  136. },
  137. success : function(data) {
  138. top.layer.close(index); //关闭数据提交信息
  139. if (data.code == 200) {
  140. layer.msg(data.msg);
  141. parent.layui.table.reload('menulist');
  142. // TableClose();
  143. } else if(data.code == 300){
  144. layer.msg(data.msg);
  145. if(data.data.length > 0){
  146. layer.msg(ReturnInfo(data.data),{icon:5});
  147. }
  148. }
  149. }
  150. });
  151. return false;
  152. });
  153. });