setsite.js 8.2 KB

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