sync.js 6.0 KB

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