look.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. var delFiles = []; //用于删除图片
  2. var indexOpen;
  3. var filesContainer = {};
  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 = 'videolist'; //表格ID
  15. //第一个实例
  16. table.render({
  17. elem: '#'+tableIds
  18. ,url: '/grouppurchase/indexform' //数据接口
  19. ,where:{token:csrfToken}
  20. ,method:'post'
  21. ,page: true //开启分页
  22. ,text:'数据加载中'
  23. ,id:'tablerReload'
  24. ,cols: [[ //表头
  25. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  26. {type:'numbers'},
  27. {field: 'title', title: '标题', align:'center'},
  28. {field: 'house_name', title: '楼盘名称', align:'center'},
  29. {field: 'city_name', title: '所属区域', align:'center'},
  30. {field: 'sign_num', title: '报名人数', align:'center'},
  31. {field: 'clicks', title: '浏览次数', align:'center'},
  32. {field: 'sort', title: '排序', align:'center'}
  33. ,{field: 'create_at', title: '添加时间',width:130, align:'center'}
  34. ,{field: 'update_at', title: '更新时间',width:130, align:'center'}
  35. ,{field: 'is_view', title: '是否显示',width:100, templet:function (d) {
  36. if(d.is_view == 2){
  37. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  38. } else {
  39. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  40. }
  41. }}
  42. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  43. ]]
  44. });
  45. // table.reload('tablerReload'); //重新加载
  46. // 日期
  47. laydate.render({
  48. elem: '#e_date',
  49. type:'datetime'
  50. });
  51. //监听指定开关
  52. form.on('switch(switchTest)', function(data){
  53. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  54. $.post('/grouppurchase/is_view',{id:data.value},function (data) {
  55. if(data.data != null){
  56. layer.msg(ReturnInfo(data.data),{icon:5});
  57. return ;
  58. }
  59. layer.msg(data.msg);
  60. table.reload('tablerReload');
  61. })
  62. },function (aa) {
  63. table.reload('tablerReload'); //重新加载
  64. })
  65. });
  66. //列表操作
  67. table.on('tool('+tableIds+')', function(obj){
  68. var layEvent = obj.event,
  69. data = obj.data;
  70. if(layEvent === 'edit'){
  71. console.log(data.house_name)
  72. var index = layer.open({
  73. title: '修改团购',
  74. type : 2,
  75. area:['','100%'],
  76. content: '/grouppurchase/edit?id='+data.id+'&house_name='+data.house_name,
  77. end:function () {
  78. table.reload('tablerReload'); //重新加载
  79. }
  80. });
  81. layui.layer.full(index);
  82. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  83. $(window).on("resize",function(){
  84. layui.layer.full(index);
  85. })
  86. } else if(layEvent === 'del') {
  87. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  88. $.post('/grouppurchase/del',{'id':data.id},function (data) {
  89. if(data.data != null){
  90. layer.msg(ReturnInfo(data.data),{icon:5});
  91. return ;
  92. }
  93. layer.msg(data.msg);
  94. table.reload('tablerReload');
  95. })
  96. })
  97. }
  98. });
  99. $('.layui_magnify').click(function(){
  100. var _src = $(this).attr('src');
  101. layui.layer.open({
  102. type: 1,
  103. title: false, //是否显示标题
  104. area: ['60%', '80%'],
  105. shade: 0.6, //透明度
  106. closeBtn: 1, //按钮 1有,0无
  107. shadeClose: true,
  108. content: '<img style="width:100%;height:100%" src="'+_src+'">',
  109. });
  110. })
  111. // 添加图片上传PC
  112. upload.render({
  113. elem: '#img_pc'
  114. ,url: '/house/createimg'
  115. ,data:{token:csrfToken}
  116. ,field:'img'
  117. ,auto:false
  118. ,bindAction:'#addcity'
  119. ,choose: function(obj){
  120. obj.preview(function(index, file, result){
  121. $('#breviary_img').attr('src', result); //图片链接(base64)
  122. });
  123. }
  124. });
  125. var $ = layui.$, active = {
  126. addData: function(){ //获取选中数据
  127. var index = layui.layer.open({
  128. type: 2,
  129. title: '添加看房团',
  130. area: ['','100%'],
  131. content: '/grouppurchase/lookhouseadd' //iframe的url,no代表不显示滚动条
  132. ,success:function (layero, index) {
  133. // indexOpen = layer.getChildFrame('body', index) ;
  134. // console.log(indexOpen);
  135. }
  136. });
  137. layui.layer.full(index);
  138. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  139. $(window).on("resize",function(){
  140. layui.layer.full(index);
  141. })
  142. },
  143. reload:function(){
  144. var form = pfgs_serialize($('form'));
  145. var name = '';
  146. var house_name = '';
  147. if(form.input_house == 'name'){
  148. name = form.input_house_text;
  149. } else if(form.input_house == 'house_name'){
  150. house_name = form.input_house_text;
  151. }
  152. table.reload('tablerReload',{
  153. where:{
  154. title:name,
  155. house_name:house_name,
  156. city:form.input_city,
  157. type_name:form.type_name
  158. }
  159. })
  160. }
  161. };
  162. $('.demoTable .layui-btn').on('click', function(){
  163. var type = $(this).data('type');
  164. active[type] ? active[type].call(this) : '';
  165. });
  166. //修改
  167. form.on('submit(edit_group_submit)', function(data){
  168. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  169. var formData = new FormData($( "#signupForm" )[0]);
  170. $.each(filesContainer,function (k,v) {
  171. if(v != null){
  172. formData.append('img[]',v);
  173. }
  174. })
  175. //需要删除的图片
  176. if(delFiles.length > 0){
  177. $.each(delFiles,function (k,v) {
  178. formData.append('delimg[]',v);
  179. })
  180. }
  181. $.ajax({
  182. cache : false,
  183. type : "post",
  184. url : "/grouppurchase/editform",
  185. data : formData,
  186. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  187. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  188. error : function(request) {
  189. layer.close(index);
  190. layer.msg("请联系管理员");
  191. },
  192. success : function(data) {
  193. if(data.data != null){
  194. layer.msg(ReturnInfo(data.data),{icon:5});
  195. return ;
  196. }
  197. layer.msg(data.msg);
  198. }
  199. });
  200. return false;
  201. });
  202. //添加
  203. form.on('submit(look_submit)', function(data){
  204. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  205. var formData = new FormData($( "#signupForm" )[0]);
  206. var trArry = $('.layui-input-block table.layui-table tbody tr');
  207. var dataObj = [];
  208. $.each(trArry,function(key,val){
  209. var _id = $(this).find('input[name="houseid"]').val();
  210. dataObj.push(_id);
  211. })
  212. formData.append('hid',dataObj);
  213. $.ajax({
  214. cache : false,
  215. type : "post",
  216. url : "/grouppurchase/lookhouseaddform",
  217. data : formData, // 你的formid
  218. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  219. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  220. error : function(request) {
  221. layer.msg("请联系管理员");
  222. },
  223. success : function(data) {
  224. if(data.data != null){
  225. layer.msg(ReturnInfo(data.data),{icon:5});
  226. return false;
  227. }
  228. layer.msg(data.msg);
  229. // if (data.code == 200) {
  230. // layer.msg(data.msg);
  231. // } else if(data.code == 300){
  232. // layer.msg(data.msg);
  233. // }
  234. }
  235. });
  236. return false;
  237. });
  238. $('.The_house').focus(function(){
  239. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  240. var indexOpen = layui.layer.open({
  241. type: 2,
  242. title: '选择需要添加的楼盘',
  243. area: ['','100%'],
  244. content: '/grouppurchase/allhouse',
  245. success:function (layero, index) {
  246. // console.log(index);
  247. // indexOpen = parent.layer.getChildFrame('body', index);
  248. },
  249. end:function(){
  250. // $('form').append('<span>aaaa</span>');
  251. // console.log($.globalEval("demoS"));
  252. }
  253. });
  254. layui.layer.full(indexOpen);
  255. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  256. $(window).on("resize",function(){
  257. layui.layer.full(indexOpen);
  258. })
  259. })
  260. var indexO = table.render({
  261. elem: '#houselist'
  262. ,url: '/grouppurchase/allhouseform' //数据接口
  263. ,where:{token:csrfToken}
  264. ,method:'post'
  265. ,page: true //开启分页
  266. ,text:'数据加载中'
  267. ,id:'houseReload'
  268. ,cols: [[ //表头
  269. {title:'选择',event:'check',width:60,align:'center',templet:"#checkBox",templet:function(d){
  270. return '<div class="layui-inline"><input type="radio" name="sex" ></div>'
  271. }},
  272. {type:'numbers',title:'序号'},
  273. {field: 'name', title: '楼盘名称', align:'center'},
  274. ]]
  275. });
  276. //删除图片
  277. $('#demo2').on("click","#delimg",function () {
  278. var name = $(this).next().attr("imgname");
  279. var delIdentification = $(this).next().attr("delIdentification");
  280. if(typeof(delIdentification) != 'undefined'){
  281. delete filesContainer[delIdentification];
  282. delete files[delIdentification] ;
  283. }
  284. if(typeof(name) != 'undefined'){
  285. delFiles.push(name);
  286. }
  287. $(this).parent().remove();
  288. })
  289. //选择所属楼盘添加
  290. var _data;
  291. table.on('tool(houselist)', function(obj){
  292. var layEvent = obj.event,
  293. data = obj.data;
  294. if(layEvent === 'check'){
  295. _data = data;
  296. }
  297. });
  298. // 提交按钮
  299. $('.xuanzhouse').click(function () {
  300. var a = parent.layer.getChildFrame('body', indexOpen);
  301. var _length = a.find('input#hiddenBox[type="hidden"]');
  302. if(_length.length > 0){
  303. _length.remove();
  304. }
  305. if(typeof _data == 'object'){
  306. //console.log(_data.name)
  307. $('#house_name', window.parent.document).val(_data.name)
  308. $('#hiddenBox', window.parent.document).val(_data.id)
  309. //a.find('#house_name').val(_data.name)
  310. //a.find('form').append('<input type="hidden" id="hiddenBox" name="hid" value="'+_data.id+'" />');
  311. // $('#house_name', window.parent.document).find('form').append('<input type="hidden" id="hiddenBox" name="hid" value="'+_data.id+'" />');
  312. TableClose();
  313. }
  314. // layer.msg('请选择楼盘');
  315. })
  316. var ue = UE.getEditor('editor'); //编辑器
  317. //展示数据删除按钮
  318. $('table.layui-table tbody').on('click','.del',function(){
  319. $(this).parents('tr').remove();
  320. })
  321. });