zt.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','treetable','upload'], function(){
  2. var laypage = layui.laypage //分页
  3. ,$ = layui.jquery
  4. ,layer = layui.layer //弹层
  5. ,table = layui.table //表格
  6. ,element = layui.element //元素操作
  7. ,form = layui.form
  8. ,treetable = layui.treetable
  9. ,upload = layui.upload;
  10. $('#feng_houseall').on('click','.feng_houseallnamedel a',function () {
  11. var _this = $(this);
  12. _this.parent().parent().remove();
  13. })
  14. //第一个实例
  15. table.render({
  16. elem: '#menulist'
  17. ,url: '/zt/homeform' //数据接口
  18. ,where:{token:csrfToken}
  19. ,method:'post'
  20. ,page: true //开启分页
  21. ,id:'tablerReload'
  22. ,limit:20
  23. ,text:'数据加载中'
  24. ,cols: [[ //表头
  25. {field:'id',title:'专题ID',align:'center'}
  26. ,{field: 'zt_name', title: '专题名称',align:'center'}
  27. ,{field: 'expiration_date', title: '专题有效期',align:'center'}
  28. ,{field: 'pc_img', title: 'PC图',align:'center',templet:function(d){
  29. return '<img class="layui_magnify" src="'+d.pc_img+'"/>';
  30. }}
  31. ,{field: 'm_img', title: 'M图',align:'center',templet:function(d){
  32. return '<img class="layui_magnify" src="'+d.m_img+'"/>';
  33. }}
  34. ,{field: 'hids', title: '楼盘ID',align:'center'}
  35. ,{title:'操作', width: 200 ,align:'center', toolbar: '#operate'}
  36. ]]
  37. });
  38. table.reload('tablerReload'); //重新加载
  39. if($('#citytellist').attr('lay-filter') == 'citytellist'){
  40. var renderTable = function (wheres = {}) {
  41. treetable.render({
  42. treeColIndex: 1,
  43. treeSpid:0,
  44. treeIdName: 'id',
  45. treePidName: 'pid',
  46. treeDefaultClose: true,
  47. treeLinkage: false,
  48. elem: '#citytellist',
  49. url: '/othertel/citytelhomeform',
  50. page: false,
  51. where:wheres,
  52. id:'tablerReload',
  53. cols: [[
  54. {type:'numbers'}
  55. // {field: 'id', title: 'ID', width:80, sort: true,align:'center'}
  56. ,{field: 'city_name', title: '区域名称',align:'center'}
  57. ,{field: 'name', title: '方案名称',align:'center'}
  58. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  59. ]],
  60. done: function () {
  61. layer.closeAll('loading');
  62. }
  63. });
  64. };
  65. renderTable();
  66. }
  67. //列表操作
  68. table.on('tool(menulist)', function(obj){
  69. var layEvent = obj.event,
  70. data = obj.data;
  71. if(layEvent === 'edit'){
  72. layer.open({
  73. type: 2,
  74. title: '修改方案',
  75. closeBtn: 1, //不显示关闭按钮
  76. shade: [0],
  77. area: ['600px', '500px'],
  78. anim: 2,
  79. content:'/zt/edit?id='+data.id,
  80. end:function () {
  81. table.reload('tablerReload');
  82. }
  83. });
  84. } else if(layEvent === 'del') {
  85. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  86. $.post('/zt/del',{'id':data.id},function (data) {
  87. layer.msg(data.msg);
  88. table.reload('tablerReload');
  89. })
  90. })
  91. }else if(layEvent === 'tel_city'){
  92. layer.open({
  93. type: 2,
  94. title: '添加区域',
  95. closeBtn: 1, //不显示关闭按钮
  96. shade: [0],
  97. area: ['600px', '500px'],
  98. anim: 2,
  99. content:'/othertel/cityascription?id='+data.id, //iframe的url,no代表不显示滚动条
  100. });
  101. }
  102. });
  103. $('.The_house').click(function(){
  104. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  105. indexOpen = parent.layui.layer.open({
  106. type: 2,
  107. title: '选择需要添加的楼盘',
  108. area: ['','100%'],
  109. content: '/publicuse/housename',
  110. success:function (layero, index) {
  111. },
  112. end:function(){
  113. }
  114. });
  115. parent.layui.layer.full(indexOpen);
  116. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  117. $(window).on("resize",function(){
  118. parent.layui.layer.full(indexOpen);
  119. })
  120. })
  121. table.on('tool(citytellist)', function(obj){
  122. var layEvent = obj.event,
  123. data = obj.data;
  124. if(layEvent === 'tel_city'){
  125. layer.open({
  126. type: 2,
  127. title: '加载方案',
  128. closeBtn: 1, //不显示关闭按钮
  129. shade: [0],
  130. area: ['600px', '500px'],
  131. anim: 2,
  132. content:'/othertel/cityascription?id='+data.id,
  133. end:function () {
  134. renderTable();
  135. }
  136. });
  137. }
  138. });
  139. var $ = layui.$, active = {
  140. addData: function(){ //获取选中数据
  141. layer.open({
  142. type: 2,
  143. title: '添加专题推送',
  144. closeBtn: 1, //不显示关闭按钮
  145. shade: [0],
  146. area: ['600px', '500px'],
  147. anim: 2,
  148. content: '/zt/add', //iframe的url,no代表不显示滚动条
  149. end: function(){ //此处用于演示
  150. table.reload('tablerReload');
  151. }
  152. });
  153. },
  154. reloadb:function () {
  155. var form = pfgs_serialize($('form'));
  156. var city = '';
  157. var name = '';
  158. if(form.province != ''){
  159. city = form.province;
  160. }
  161. if(form.name != ''){
  162. name = form.name;
  163. }
  164. // if(form.city != ''){
  165. // city = form.city;
  166. // }
  167. renderTable({id:city,name:name});
  168. }
  169. };
  170. $('.demoTable .layui-btn').on('click', function(){
  171. var type = $(this).data('type');
  172. active[type] ? active[type].call(this) : '';
  173. });
  174. form.on('submit(edittel)', function(data){
  175. // $.post('/zt/editform',{'data':data.field},function (data) {
  176. // $.post('/zt/editform',{'data':data.field},function (data) {
  177. // if(data.code == 200)
  178. // {
  179. // layer.msg(data.msg);
  180. // parent.layui.table.reload('menulist');
  181. // } else if(data.code == 300 ) {
  182. // layer.msg(data.msg);
  183. // layer.msg(ReturnInfo(data.data),{icon:5});
  184. // }
  185. // })
  186. // return false;
  187. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  188. var formData = new FormData($('form')[0]);
  189. console.log(formData);
  190. $.ajax({
  191. cache : false,
  192. type : "post",
  193. url : "/zt/editform",
  194. data : formData, // 你的formid
  195. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  196. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  197. error : function(request) {
  198. layer.close(index);
  199. layer.msg("请联系管理员");
  200. },
  201. success : function(data) {
  202. if(data.data != null){
  203. layer.msg(ReturnInfo(data.data),{icon:5});
  204. return ;
  205. }
  206. layer.msg(data.msg);
  207. parent.layer.close(oindex); //再执行关闭
  208. }
  209. });
  210. return false;
  211. });
  212. form.on('submit(tijiao)', function(data){
  213. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  214. var formData = new FormData($('form')[0]);
  215. console.log(formData);
  216. $.ajax({
  217. cache : false,
  218. type : "post",
  219. url : "/zt/addform",
  220. data : formData, // 你的formid
  221. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  222. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  223. error : function(request) {
  224. layer.close(index);
  225. layer.msg("请联系管理员");
  226. },
  227. success : function(data) {
  228. if(data.data != null){
  229. layer.msg(ReturnInfo(data.data),{icon:5});
  230. return ;
  231. }
  232. layer.msg(data.msg);
  233. parent.layer.close(oindex); //再执行关闭
  234. }
  235. });
  236. return false;
  237. });
  238. form.on('submit(unload_tel)', function(data){
  239. var index = top.layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  240. var formData = new FormData($('#cityForm')[0]);
  241. $.ajax({
  242. cache : true,
  243. type : "post",
  244. url : "/othertel/addcityascription",
  245. data : formData, // 你的formid
  246. async : false,
  247. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  248. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  249. error : function(request) {
  250. top.layer.close(index); //关闭数据提交信息
  251. layer.alert("网络超时");
  252. },
  253. success : function(data) {
  254. top.layer.close(index); //关闭数据提交信息
  255. if (data.code == 200) {
  256. layer.msg(data.msg);
  257. parent.layui.table.reload('menulist');
  258. // TableClose();
  259. } else if(data.code == 300){
  260. layer.msg(data.msg);
  261. if(data.data.length > 0){
  262. layer.msg(ReturnInfo(data.data),{icon:5});
  263. }
  264. }
  265. }
  266. });
  267. return false;
  268. });
  269. //上传图片
  270. upload.render({
  271. elem: '#test1'
  272. ,url: '/house/createimg'
  273. ,data:{token:csrfToken}
  274. ,field:'img'
  275. ,size:1000 //限制上传图片的大小,单位为KB
  276. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  277. ,auto:false
  278. ,bindAction:'#addcity'
  279. ,choose: function(obj){
  280. obj.preview(function(index, file, result){
  281. $('#demo1').attr('src', result); //图片链接(base64)
  282. });
  283. }
  284. });
  285. //上传图片
  286. upload.render({
  287. elem: '#test2'
  288. ,url: '/house/createimg'
  289. ,data:{token:csrfToken}
  290. ,field:'img1'
  291. ,size:1000 //限制上传图片的大小,单位为KB
  292. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  293. ,auto:false
  294. ,bindAction:'#addcity'
  295. ,choose: function(obj){
  296. obj.preview(function(index, file, result){
  297. $('#demo2').attr('src', result); //图片链接(base64)
  298. });
  299. }
  300. });
  301. });