lookhouse.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. var delFiles = []; //用于删除图片
  2. var filesContainer= {}; //存储最终要上传的图片
  3. var files ; //存储选择图片的数量
  4. layui.use(['form','layer','laydate','table','laytpl','layedit','upload'],function(){
  5. var form = layui.form,
  6. // layer = parent.layer === undefined ? layui.layer : top.layer,
  7. layer = layui.layer,
  8. $ = layui.jquery,
  9. laydate = layui.laydate,
  10. laytpl = layui.laytpl,
  11. table = layui.table,
  12. layedit = layui.layedit
  13. ,upload = layui.upload;
  14. var tableIds = 'newsList';
  15. //楼盘列表
  16. var tableIns = table.render({
  17. elem: '#'+tableIds,
  18. url : '/news/newsform',
  19. cellMinWidth : 95,
  20. method:'post',
  21. page : true,
  22. height : "full-125",
  23. limit : 20,
  24. id:'tablerReload',
  25. cols : [[
  26. {type:'numbers',title:'序号'},
  27. {type: "checkbox", width:50},
  28. {field: 'id', title: 'ID', width:80, align:"center",sort: true},
  29. {field: 'subject', title: '标题',align:'center',templet:function(d){
  30. return '<a href="" target="_blank">'+d.subject+'</a>'
  31. }},
  32. {field: 'area_houses', title: '关联楼盘',width:120, align:'center',templet:function (d) {
  33. return '<a href="javascript:;" lay-event="relevance" >['+d.area_houses+']</a>'
  34. }},
  35. {field: 'startTime', title: '开始时间',width:120, align:'center',sort: true},
  36. {field: 'endTime', title: '结束时间',width:120, event:'sortData', align:'center',sort: true},
  37. {field: 'state', title: '审核',width:75, event:'housesNews', align:'center',templet:function (d) {
  38. if(d.state === 'N'){
  39. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  40. } else {
  41. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  42. }
  43. }},
  44. {title: '操作', width:100, templet:'#housesListBar',fixed:"right",align:"center"}
  45. ]]
  46. });
  47. table.reload('tablerReload'); //重新加载
  48. //日期时间选择器
  49. laydate.render({
  50. elem: '#test5'
  51. ,type: 'datetime'
  52. });
  53. //日期范围
  54. laydate.render({
  55. elem: '#test6'
  56. ,range: true
  57. });
  58. //判断是否需要编辑,需要才加载
  59. var verdict = $('#editor_content').html();
  60. if(typeof verdict == "string"){
  61. var ue = UE.getEditor('editor_content'); //编辑器
  62. }
  63. //表格头部操作菜单
  64. var $ = layui.$, active = {
  65. addData: function(){ //获取选中数据
  66. var index = layui.layer.open({
  67. title : "添加看房团",
  68. type : 2,
  69. area:['80%','100%'],
  70. maxmin: true,
  71. content : "/lookhouse/add",
  72. })
  73. layui.layer.full(index);
  74. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  75. $(window).on("resize",function(){
  76. layui.layer.full(index);
  77. })
  78. },
  79. reload:function () {
  80. var form = pfgs_serialize($('form'));
  81. var name = '';
  82. var id = '';
  83. if(form.input_house == 'name'){
  84. name = form.input_house_text;
  85. } else if(form.input_house == 'id'){
  86. id = form.input_house_text;
  87. }
  88. table.reload('tablerReload',{
  89. where:{
  90. sort:form.input_sort,
  91. id:id,
  92. name:name,
  93. news:form.input_news,
  94. city:form.input_city
  95. }
  96. })
  97. }
  98. };
  99. //监听指定开关
  100. form.on('switch(switchTest)', function(data){
  101. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  102. $.post('/house/housesortedit',{id:data.value,examineid:1},function (data) {
  103. if(data.code == 200)
  104. {
  105. layer.msg(data.msg);
  106. table.reload('tablerReload');
  107. } else if(data.code == 300 ) {
  108. layer.msg(data.msg);
  109. }
  110. })
  111. },function (aa) {
  112. table.reload('tablerReload'); //重新加载
  113. })
  114. });
  115. $('.demoTable .layui-btn').on('click', function(){
  116. var type = $(this).data('type');
  117. active[type] ? active[type].call(this) : '';
  118. });
  119. //表格右边操作栏目
  120. table.on('tool('+tableIds+')', function(obj){
  121. var data = obj.data;
  122. if(obj.event === 'edit'){ //编辑操作
  123. var index = layui.layer.open({
  124. title : "编辑看房团",
  125. type : 2,
  126. area:['','100%'],
  127. maxmin: true,
  128. content : "/lookhouse/edit"
  129. })
  130. layui.layer.full(index);
  131. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  132. $(window).on("resize",function(){
  133. layui.layer.full(index);
  134. })
  135. }else if(obj.event === 'relevance'){
  136. alert(5165)
  137. }
  138. });
  139. //监听指定开关
  140. form.on('switch(switchTest)', function(data){
  141. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  142. $.post('/news/newsviewcontrol',{id:data.value},function (data) {
  143. if(data.code == 200)
  144. {
  145. layer.msg(data.msg);
  146. table.reload('tablerReload');
  147. } else if(data.code == 300 ) {
  148. layer.msg(data.msg);
  149. }
  150. })
  151. },function (aa) {
  152. table.reload('tablerReload');
  153. })
  154. });
  155. //添加and修改图片
  156. upload.render({
  157. elem: '#upload_edit',
  158. url: '/news/newseditform'
  159. ,data:{token:csrfToken}
  160. ,multiple: true
  161. ,number:3
  162. ,auto:false
  163. ,size:1000 //限制上传图片的大小,单位为KB
  164. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  165. ,bindAction:'#addcity'
  166. ,choose: function(obj){
  167. //将每次选择的文件追加到文件队列
  168. files = obj.pushFile();
  169. //预读本地文件,如果是多文件,则会遍历。(不支持ie8/9)
  170. obj.preview(function(index, file, result){
  171. var selectText = $('#ddlregtype').find("option:selected").text();
  172. filesContainer[index] = file; //将每次选择的文件追加到文件队列
  173. $('#demo2').append('<div class="layui-upload-img layer-photos-demo" id="layer-photos-demo"><div class="delete-list" id="delimg"><i class="layui-icon fa-trash-o" >&#xe640;</i></div><img delIdentification="'+index+'" layer-pid="'+index+'" layer-src="'+ result +'" src="'+ result +'" alt="'+ file.name +'" id="hhhh"></div>');
  174. layer.photos({
  175. photos: '#demo2',
  176. closeBtn: 1
  177. ,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
  178. });
  179. })
  180. }
  181. });
  182. //添加看房团提交数据
  183. form.on('submit(tijiao)',function (data) {
  184. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  185. var formData = new FormData($( "#signupForm" )[0]);
  186. formData.delete('file'); //删除添加图片组件自带的FILE文件
  187. $.each(filesContainer,function (k,v) {
  188. if(v != null){
  189. if(typeof (formData.get(k)) != 'undefined'){
  190. formData.append('imginput[]',formData.get(k))
  191. }
  192. formData.append('img[]',v);
  193. }
  194. })
  195. $.ajax({
  196. cache : true,
  197. type : "post",
  198. url : "/news/addform",
  199. data : formData, // 你的formid
  200. // async : false, //async 默认为true异步,修改为false为同步,
  201. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  202. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  203. error : function(request) {
  204. layer.close(index);
  205. layer.alert("网络超时");
  206. },
  207. success : function(data) {
  208. if (data.code == 200) {
  209. layer.msg(data.msg);
  210. parent.layui.table.reload('tablerReload');
  211. TableClose();
  212. } else if(data.code == 300){
  213. layer.msg(data.msg)
  214. layer.msg(ReturnInfo(data.data),{icon:5});
  215. }
  216. }
  217. });
  218. return false;
  219. })
  220. //修改页面提交数据
  221. form.on('submit(edit)',function (data) {
  222. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  223. var formData = new FormData($( "#signupForm" )[0]);
  224. formData.delete('file'); //删除添加图片组件自带的FILE文件
  225. $.each(filesContainer,function (k,v) {
  226. if(v != null){
  227. if(typeof (formData.get(k)) != 'undefined'){
  228. formData.append('imginput[]',formData.get(k))
  229. }
  230. formData.append('img[]',v);
  231. }
  232. })
  233. //需要删除的图片
  234. if(delFiles.length > 0){
  235. $.each(delFiles,function (k,v) {
  236. formData.append('delimg[]',v);
  237. })
  238. }
  239. $.ajax({
  240. cache : true,
  241. type : "post",
  242. url : "/news/newseditform",
  243. data : formData, // 你的formid
  244. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  245. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  246. error : function(request) {
  247. layer.close(index); //关闭数据提交信息
  248. layer.alert("网络超时");
  249. },
  250. success : function(data) {
  251. if (data.code == 200) {
  252. layer.msg(data.msg);
  253. parent.layui.table.reload('tablerReload');
  254. TableClose();
  255. } else if(data.code == 300){
  256. layer.msg(data.msg)
  257. layer.msg(ReturnInfo(data.data),{icon:5});
  258. }
  259. }
  260. });
  261. return false;
  262. })
  263. //批量删除
  264. form.on('submit(del_alls_news)',function (data) {
  265. var checkStatus = table.checkStatus('tablerReload');
  266. if(typeof checkStatus.data[0] == 'object'){
  267. layer.confirm('您确定要删除吗?',{btn:['确认','取消']},function(){
  268. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  269. var formdat = new FormData();
  270. $.each(checkStatus.data,function (key,val) {
  271. formdat.append('id[]',val.id);
  272. })
  273. $.ajax({
  274. cache : true,
  275. type : "post",
  276. url : "/news/newsdel",
  277. data : formdat, // 你的formid
  278. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  279. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  280. error : function(request) {
  281. layer.close(index); //关闭数据提交信息
  282. layer.alert("网络超时");
  283. },
  284. success : function(data) {
  285. if (data.code == 200) {
  286. layer.msg(data.msg);
  287. table.reload('tablerReload')
  288. } else {
  289. layer.msg(data.msg);
  290. }
  291. }
  292. });
  293. })
  294. return false;
  295. }
  296. layer.msg('请选择需要删除的资讯',{icon:5});
  297. return false;
  298. })
  299. });
  300. //删除图片
  301. $('#demo2').on("click","#delimg",function () {
  302. var name = $(this).next().attr("imgname");
  303. var delIdentification = $(this).next().attr("delIdentification");
  304. if(typeof(delIdentification) != 'undefined'){
  305. filesContainer[delIdentification] = false;
  306. delete files.delIdentification;
  307. console.log(files);
  308. // imgnumber -= 1;
  309. }
  310. if(typeof(name) != 'undefined'){
  311. delFiles.push(name);
  312. }
  313. $(this).parent().remove();
  314. })