setsite.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','upload'], function(){
  2. var laypage = layui.laypage //分页
  3. ,layer = layui.layer //弹层
  4. ,table = layui.table //表格
  5. ,element = layui.element //元素操作
  6. ,form = layui.form
  7. ,upload = layui.upload;
  8. //第一个实例
  9. table.render({
  10. elem: '#menulist'
  11. ,url: '/othertel/homeform' //数据接口
  12. ,where:{token:csrfToken}
  13. ,method:'post'
  14. ,page: true //开启分页
  15. ,text:'数据加载中'
  16. ,cols: [[ //表头
  17. {type:'numbers'}
  18. ,{field: 'name', title: '方案名称', align:'center'}
  19. ,{field: 'tel', title: '内容', align:'center'}
  20. ,{fixed: 'right',title:'操作', width: 200, align:'center', toolbar: '#operate'}
  21. ]]
  22. });
  23. //添加图片上传
  24. upload.render({
  25. elem: '#weixin'
  26. ,url: '/house/createimg'
  27. ,data:{token:csrfToken}
  28. ,field:'wechat'
  29. ,size:1000 //限制上传图片的大小,单位为KB
  30. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  31. ,auto:false
  32. ,bindAction:'#addcity'
  33. ,choose: function(obj){
  34. obj.preview(function(index, file, result){
  35. $('#weixin_img').attr('src', result); //图片链接(base64)
  36. });
  37. }
  38. });
  39. //添加图片上传
  40. upload.render({
  41. elem: '#logo'
  42. ,url: '/house/createimg'
  43. ,data:{token:csrfToken}
  44. ,field:'logo'
  45. ,size:1000 //限制上传图片的大小,单位为KB
  46. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  47. ,auto:false
  48. ,bindAction:'#addcity'
  49. ,choose: function(obj){
  50. obj.preview(function(index, file, result){
  51. $('#logo_img').attr('src', result); //图片链接(base64)
  52. });
  53. }
  54. });
  55. //列表操作
  56. table.on('tool(menulist)', function(obj){
  57. var layEvent = obj.event,
  58. data = obj.data;
  59. if(layEvent === 'edit'){
  60. layer.open({
  61. type: 2,
  62. title: '修改方案',
  63. closeBtn: 1, //不显示关闭按钮
  64. shade: [0],
  65. area: ['600px', '500px'],
  66. anim: 2,
  67. content:'/othertel/edit?id='+data.id, //iframe的url,no代表不显示滚动条
  68. });
  69. } else if(layEvent === 'del') {
  70. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  71. $.post('/othertel/del',{'id':data.id},function (data) {
  72. if(data.code == 200)
  73. {
  74. layer.msg(data.msg);
  75. table.reload('menulist');
  76. } else if(data.code == 300 ) {
  77. layer.msg(data.msg);
  78. }
  79. })
  80. })
  81. }else if(layEvent === 'tel_city'){
  82. layer.open({
  83. type: 2,
  84. title: '添加区域',
  85. closeBtn: 1, //不显示关闭按钮
  86. shade: [0],
  87. area: ['600px', '500px'],
  88. anim: 2,
  89. content:'/othertel/cityascription?id='+data.id, //iframe的url,no代表不显示滚动条
  90. });
  91. }
  92. });
  93. var $ = layui.$, active = {
  94. addData: function(){ //获取选中数据
  95. layer.open({
  96. type: 2,
  97. title: '添加电话',
  98. closeBtn: 1, //不显示关闭按钮
  99. shade: [0],
  100. area: ['600px', '500px'],
  101. anim: 2,
  102. content: '/othertel/add' //iframe的url,no代表不显示滚动条
  103. // end: function(){ //此处用于演示
  104. // layer.open({
  105. // type: 2,
  106. // title: '很多时候,我们想最大化看,比如像这个页面。',
  107. // shadeClose: true,
  108. // shade: false,
  109. // maxmin: true, //开启最大化最小化按钮
  110. // area: ['893px', '600px'],
  111. // content: '//fly.layui.com/'
  112. // });
  113. // }
  114. });
  115. // var checkStatus = table.checkStatus('idTest')
  116. // ,data = checkStatus.data;
  117. // layer.alert(JSON.stringify(data));
  118. }
  119. };
  120. $('.demoTable .layui-btn').on('click', function(){
  121. var type = $(this).data('type');
  122. active[type] ? active[type].call(this) : '';
  123. });
  124. form.on('submit(edittel)', function(data){
  125. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  126. $.post('/othertel/editform',{'data':data.field},function (data) {
  127. if(data.code == 200)
  128. {
  129. layer.msg(data.msg);
  130. parent.layui.table.reload('menulist');
  131. } else if(data.code == 300 ) {
  132. layer.msg(data.msg);
  133. layer.msg(ReturnInfo(data.data),{icon:5});
  134. }
  135. })
  136. return false;
  137. });
  138. form.on('submit(tijiao)', function(data){
  139. var formData = new FormData($('form')[0]);
  140. $.ajax({
  141. cache : true,
  142. type : "post",
  143. url : "/othersiteset/editform",
  144. data : formData, // 你的formid
  145. // async : false, //async 默认为true异步,修改为false为同步,
  146. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  147. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  148. error : function(request) {
  149. layer.close(index); //关闭数据提交信息
  150. layer.alert("网络超时");
  151. },
  152. success : function(data) {
  153. if (data.code == 200) {
  154. layer.msg(data.msg);
  155. } else if(data.code == 300){
  156. layer.msg(data.msg);
  157. if(data.data.length > 0){
  158. layer.msg(ReturnInfo(data.data),{icon:5});
  159. }
  160. }
  161. }
  162. });
  163. return false;
  164. });
  165. form.on('submit(unload_tel)', function(data){
  166. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  167. var formData = new FormData($('#cityForm')[0]);
  168. $.ajax({
  169. cache : true,
  170. type : "post",
  171. url : "/othertel/addcityascription",
  172. data : formData, // 你的formid
  173. // async : false, //async 默认为true异步,修改为false为同步,
  174. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  175. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  176. error : function(request) {
  177. layer.close(index); //关闭数据提交信息
  178. layer.alert("网络超时");
  179. },
  180. success : function(data) {
  181. if (data.code == 200) {
  182. layer.msg(data.msg);
  183. parent.layui.table.reload('menulist');
  184. // TableClose();
  185. } else if(data.code == 300){
  186. layer.msg(data.msg);
  187. if(data.data.length > 0){
  188. layer.msg(ReturnInfo(data.data),{icon:5});
  189. }
  190. }
  191. }
  192. });
  193. return false;
  194. });
  195. });
  196. $(function(){
  197. //选项卡切换
  198. $('.layui-tab-title .site-demo-active').on('click', function(){
  199. $(this).addClass('layui-this').siblings().removeClass('layui-this');
  200. var lay_id = $(this).attr('lay-id');
  201. $('.layui-tab-item').removeClass('layui-show')
  202. $('.layui-tab-content #'+lay_id).addClass('layui-show')
  203. });
  204. })