grouppurchase.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. ,height : 600
  24. ,id:'tablerReload'
  25. ,cols: [[ //表头
  26. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  27. {type:'numbers'},
  28. {field: 'title', title: '标题', align:'center'},
  29. {field: 'house_name', title: '楼盘名称', align:'center'},
  30. {field: 'city_name', title: '所属区域', align:'center'},
  31. {field: 'sign_num', title: '报名人数', align:'center'},
  32. {field: 'clicks', title: '浏览次数', align:'center'},
  33. {field: 'sort', title: '排序', edit: 'text', align:'center'}
  34. ,{field: 'create_at', title: '添加时间',width:130, align:'center'}
  35. ,{field: 'update_at', title: '更新时间',width:130, align:'center'}
  36. ,{field: 'is_view', title: '是否显示',width:100, templet:function (d) {
  37. if(d.is_view == 2){
  38. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  39. } else {
  40. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  41. }
  42. }}
  43. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  44. ]]
  45. });
  46. table.reload('tablerReload'); //重新加载
  47. // 日期
  48. laydate.render({
  49. elem: '#s_date'
  50. });
  51. laydate.render({
  52. elem: '#ModificationDate'
  53. });
  54. // 日期
  55. laydate.render({
  56. elem: '#e_date'
  57. });
  58. laydate.render({
  59. elem: '#ModificationDate'
  60. });
  61. //监听指定开关
  62. form.on('switch(switchTest)', function(data){
  63. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  64. $.post('/grouppurchase/is_view',{id:data.value},function (data) {
  65. if(data.data != null){
  66. layer.msg(ReturnInfo(data.data),{icon:5});
  67. return ;
  68. }
  69. layer.msg(data.msg);
  70. table.reload('tablerReload');
  71. })
  72. },function (aa) {
  73. table.reload('tablerReload'); //重新加载
  74. })
  75. });
  76. /* 列表操作 edit 修改后执行 2018.7.24*/
  77. table.on('edit('+tableIds+')', function(obj){
  78. var data = obj.data;
  79. // console.log(data)
  80. $.post('/news/',{id:data.id,sort:data.sort},function (data) { //排序提交地址没有
  81. if(data.code == 200)
  82. {
  83. layer.msg(data.msg);
  84. } else if(data.code == 300 ) {
  85. layer.msg(data.msg);
  86. }
  87. })
  88. })
  89. //列表操作
  90. table.on('tool('+tableIds+')', function(obj){
  91. var layEvent = obj.event,
  92. data = obj.data;
  93. if(layEvent === 'edit'){
  94. // console.log(data.house_name)
  95. var index = layer.open({
  96. title: '修改团购',
  97. type : 2,
  98. area:['','100%'],
  99. content: '/grouppurchase/edit?id='+data.id+'&house_name='+data.house_name,
  100. end:function () {
  101. table.reload('tablerReload'); //重新加载
  102. }
  103. });
  104. layui.layer.full(index);
  105. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  106. $(window).on("resize",function(){
  107. layui.layer.full(index);
  108. })
  109. } else if(layEvent === 'del') {
  110. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  111. $.post('/grouppurchase/del',{'id':data.id},function (data) {
  112. if(data.data != null){
  113. layer.msg(ReturnInfo(data.data),{icon:5});
  114. return ;
  115. }
  116. layer.msg(data.msg);
  117. table.reload('tablerReload');
  118. })
  119. })
  120. }
  121. });
  122. $('.layui_magnify').click(function(){
  123. var _src = $(this).attr('src');
  124. layui.layer.open({
  125. type: 1,
  126. title: false, //是否显示标题
  127. area: ['60%', '80%'],
  128. shade: 0.6, //透明度
  129. closeBtn: 1, //按钮 1有,0无
  130. shadeClose: true,
  131. content: '<img style="width:100%;height:100%" src="'+_src+'">',
  132. });
  133. })
  134. // 添加图片上传PC
  135. upload.render({
  136. elem: '#img_pc'
  137. ,url: '/house/createimg'
  138. ,data:{token:csrfToken}
  139. ,field:'img_pc'
  140. ,auto:false
  141. ,bindAction:'#addcity'
  142. ,choose: function(obj){
  143. obj.preview(function(index, file, result){
  144. $('#breviary_img').attr('src', result); //图片链接(base64)
  145. });
  146. }
  147. });
  148. //添加图片上传mobile
  149. upload.render({
  150. elem: '#img_mobile'
  151. ,url: '/house/createimg'
  152. ,data:{token:csrfToken}
  153. ,field:'img_mobile'
  154. ,auto:false
  155. ,bindAction:'#addcity'
  156. ,choose: function(obj){
  157. obj.preview(function(index, file, result){
  158. $('#img_mobile_src').attr('src', result); //图片链接(base64)
  159. });
  160. }
  161. });
  162. //添加and修改图片 多图
  163. upload.render({
  164. elem: '#upload_edit'
  165. ,url: '/news/newseditform'
  166. ,multiple: true
  167. ,number:10
  168. ,auto:false
  169. ,size:2000 //限制上传图片的大小,单位为KB
  170. // ,exts: 'png|jpg' //只允许上传压缩文件
  171. ,bindAction:'#addcity'
  172. ,choose: function(obj){
  173. //将每次选择的文件追加到文件队列
  174. files = obj.pushFile();
  175. //预读本地文件,如果是多文件,则会遍历。(不支持ie8/9)
  176. obj.preview(function(index, file, result){
  177. filesContainer[index] = file;
  178. $('#demo2').append('<div class="layui-upload-img"><div class="delete-list" id="delimg"><i class="layui-icon fa-trash-o" >&#xe640;</i></div><img delIdentification="'+index+'" src="'+ result +'" alt="'+ file.name +'"></div>');
  179. layer.photos({
  180. photos: '#demo2'
  181. ,closeBtn: 1
  182. ,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
  183. });
  184. });
  185. }
  186. });
  187. var $ = layui.$, active = {
  188. addData: function(){ //获取选中数据
  189. var index = layui.layer.open({
  190. type: 2,
  191. title: '添加团购',
  192. area: ['','100%'],
  193. content: '/grouppurchase/add' //iframe的url,no代表不显示滚动条
  194. ,success:function (layero, index) {
  195. // indexOpen = layer.getChildFrame('body', index) ;
  196. // console.log(indexOpen);
  197. }
  198. });
  199. layui.layer.full(index);
  200. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  201. $(window).on("resize",function(){
  202. layui.layer.full(index);
  203. })
  204. },
  205. reload:function(){
  206. var form = pfgs_serialize($('form'));
  207. var name = '';
  208. var house_name = '';
  209. if(form.input_house == 'name'){
  210. name = form.input_house_text;
  211. } else if(form.input_house == 'house_name'){
  212. house_name = form.input_house_text;
  213. }
  214. table.reload('tablerReload',{
  215. where:{
  216. title:name,
  217. house_name:house_name,
  218. city:form.input_city,
  219. type_name:form.type_name
  220. }
  221. })
  222. }
  223. };
  224. $('.demoTable .layui-btn').on('click', function(){
  225. var type = $(this).data('type');
  226. active[type] ? active[type].call(this) : '';
  227. });
  228. //修改
  229. form.on('submit(edit_group_submit)', function(data){
  230. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  231. var formData = new FormData($( "#signupForm" )[0]);
  232. $.each(filesContainer,function (k,v) {
  233. if(v != null){
  234. formData.append('img[]',v);
  235. }
  236. })
  237. //需要删除的图片
  238. if(delFiles.length > 0){
  239. $.each(delFiles,function (k,v) {
  240. formData.append('delimg[]',v);
  241. })
  242. }
  243. $.ajax({
  244. cache : false,
  245. type : "post",
  246. url : "/grouppurchase/editform",
  247. data : formData,
  248. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  249. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  250. error : function(request) {
  251. layer.close(index);
  252. layer.msg("请联系管理员");
  253. },
  254. success : function(data) {
  255. if(data.data != null){
  256. layer.msg(ReturnInfo(data.data),{icon:5});
  257. return ;
  258. }
  259. layer.msg(data.msg);
  260. }
  261. });
  262. return false;
  263. });
  264. //添加
  265. form.on('submit(group_submit)', function(data){
  266. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  267. var formData = new FormData($( "#signupForm" )[0]);
  268. $.each(filesContainer,function (k,v) {
  269. if(v != null){
  270. formData.append('img[]',v);
  271. }
  272. })
  273. $.ajax({
  274. cache : false,
  275. type : "post",
  276. url : "/grouppurchase/addform",
  277. data : formData, // 你的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.msg("请联系管理员");
  283. },
  284. success : function(data) {
  285. if(data.data != null){
  286. layer.msg(ReturnInfo(data.data),{icon:5});
  287. return ;
  288. }
  289. layer.msg(data.msg);
  290. // if (data.code == 200) {
  291. // layer.msg(data.msg);
  292. // } else if(data.code == 300){
  293. // layer.msg(data.msg);
  294. // }
  295. }
  296. });
  297. return false;
  298. });
  299. $('.The_house').focus(function(){
  300. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  301. indexOpen = layui.layer.open({
  302. type: 2,
  303. title: '选择需要添加的楼盘',
  304. area: ['','100%'],
  305. content: '/grouppurchase/allhouse',
  306. success:function (layero, index) {
  307. // console.log(index);
  308. // indexOpen = parent.layer.getChildFrame('body', index);
  309. },
  310. end:function(){
  311. // $('form').append('<span>aaaa</span>');
  312. // console.log($.globalEval("demoS"));
  313. }
  314. });
  315. layui.layer.full(indexOpen);
  316. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  317. $(window).on("resize",function(){
  318. layui.layer.full(indexOpen);
  319. })
  320. })
  321. var indexO = table.render({
  322. elem: '#houselist'
  323. ,url: '/grouppurchase/allhouseform' //数据接口
  324. ,where:{token:csrfToken}
  325. ,method:'post'
  326. ,page: true //开启分页
  327. ,text:'数据加载中'
  328. ,id:'houseReload'
  329. ,cols: [[ //表头
  330. {title:'选择',event:'check',width:60,align:'center',templet:"#checkBox",templet:function(d){
  331. return '<div class="layui-inline"><input type="radio" name="sex" ></div>'
  332. }},
  333. {type:'numbers',title:'序号'},
  334. {field: 'name', title: '楼盘名称', align:'center'},
  335. ]]
  336. });
  337. //删除图片
  338. $('#demo2').on("click","#delimg",function () {
  339. var name = $(this).next().attr("imgname");
  340. var delIdentification = $(this).next().attr("delIdentification");
  341. if(typeof(delIdentification) != 'undefined'){
  342. delete filesContainer[delIdentification];
  343. delete files[delIdentification] ;
  344. }
  345. if(typeof(name) != 'undefined'){
  346. delFiles.push(name);
  347. }
  348. $(this).parent().remove();
  349. })
  350. //选择所属楼盘添加
  351. var _data;
  352. table.on('tool(houselist)', function(obj){
  353. var layEvent = obj.event,
  354. data = obj.data;
  355. if(layEvent === 'check'){
  356. _data = data;
  357. }
  358. });
  359. // 提交按钮
  360. $('.xuanzhouse').click(function () {
  361. var a = parent.layer.getChildFrame('body', indexOpen);
  362. var _length = a.find('input#hiddenBox[type="hidden"]');
  363. if(_length.length > 0){
  364. _length.remove();
  365. }
  366. if(typeof _data == 'object'){
  367. //console.log(_data.name)
  368. $('#house_name', window.parent.document).val(_data.name)
  369. $('#hiddenBox', window.parent.document).val(_data.id)
  370. //a.find('#house_name').val(_data.name)
  371. //a.find('form').append('<input type="hidden" id="hiddenBox" name="hid" value="'+_data.id+'" />');
  372. // $('#house_name', window.parent.document).find('form').append('<input type="hidden" id="hiddenBox" name="hid" value="'+_data.id+'" />');
  373. TableClose();
  374. }
  375. // layer.msg('请选择楼盘');
  376. })
  377. //判断是否需要编辑,需要才加载
  378. var verdict = $('#editor').html();
  379. if(typeof verdict == "string"){
  380. var ue = UE.getEditor('editor'); //编辑器
  381. }
  382. });