timelimitsgroup.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. layui.use(['laypage', 'layer', 'laydate', 'table', 'element', 'form', 'upload'], function () {
  2. var laypage = layui.laypage //分页
  3. , $ = layui.jquery
  4. , laydate = layui.laydate
  5. , layer = layui.layer //弹层
  6. , table = layui.table //表格
  7. , element = layui.element //元素操作
  8. , form = layui.form
  9. , upload = layui.upload;
  10. var tableIds = 'videolist'; //表格ID
  11. var type_id = $('input[name="typeid"]').val();
  12. //第一个实例
  13. table.render({
  14. elem: '#' + tableIds
  15. , url: '/push/timelimitsgroupform' //数据接口
  16. , where: {token: csrfToken, type: type_id}
  17. , method: 'post'
  18. , page: true //开启分页
  19. ,height:600
  20. , text: '数据加载中'
  21. , id: 'tablerReload'
  22. , limit: 15
  23. , cols: [[ //表头
  24. {type: 'numbers', title: '序号', width: 50},
  25. {field: 'name', title: '楼盘名称', align: 'center'},
  26. {field: 'province', title: '区域', align: 'center'},
  27. {
  28. field: 'click',
  29. title: '关注度',
  30. width: 100,
  31. event: 'clickData',
  32. edit: 'text',
  33. align: 'center',
  34. sort: true,
  35. templet: "#clickBox"
  36. },
  37. {
  38. field: 'group_num',
  39. title: '抢购数',
  40. width: 100,
  41. event: 'groupnumData',
  42. edit: 'text',
  43. align: 'center',
  44. sort: true,
  45. templet: "#groupnumBox"
  46. },
  47. {
  48. field: 'sort',
  49. title: '排序',
  50. width: 100,
  51. event: 'sortData',
  52. edit: 'text',
  53. align: 'center',
  54. sort: true,
  55. templet: "#sortBox"
  56. },
  57. {field: 'create_at', title: '添加时间', width: 150, align: 'center'},
  58. {
  59. field: 'is_show', title: '审核', align: 'center', width: 100, templet: function (d) {
  60. if (d.is_show == 2) {
  61. return '<input type="checkbox" value="' + d.id + '" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  62. } else {
  63. return '<input type="checkbox" checked value="' + d.id + '" name="open" title="' + d.is_show + '" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  64. }
  65. }
  66. }
  67. , {fixed: 'right', title: '操作', width: 120, align: 'center', toolbar: '#operate'}
  68. ]]
  69. });
  70. //监听指定开关
  71. form.on('switch(switchTest)', function (data) {
  72. layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
  73. $.post('/push/timelimitsgroupdelandshow', {id: data.value, type: 'show'}, function (data) {
  74. layer.msg(data.msg);
  75. table.reload('tablerReload');
  76. })
  77. }, function (aa) {
  78. table.reload('tablerReload'); //重新加载
  79. })
  80. });
  81. // 日期
  82. laydate.render({
  83. elem: '#EventDate'
  84. });
  85. laydate.render({
  86. elem: '#ModificationDate'
  87. });
  88. //列表操作
  89. table.on('tool(' + tableIds + ')', function (obj) {
  90. var layEvent = obj.event,
  91. data = obj.data;
  92. if (layEvent === 'sortData') { //修改排序
  93. /* 列表操作 edit 修改后执行 2018.7.24*/
  94. table.on('edit(' + tableIds + ')', function (obj) {
  95. var data = obj.data;
  96. $.post('/push/timelimitsgroupdelandshow', {
  97. id: data.id,
  98. type: 'sort',
  99. sort: data.sort
  100. }, function (data) {
  101. if (data.code == 200) {
  102. layer.msg(data.msg);
  103. } else if (data.code == 300) {
  104. layer.msg(data.msg);
  105. }
  106. })
  107. })
  108. // layer.prompt({
  109. // formType: 2
  110. // ,title: '排序热销楼盘:<span style="color:red">'+data.name+'</span>'
  111. // ,value: data.sort
  112. // }, function(value, index){
  113. // $.post('/pushm/saledelshow',{id:data.id,type:'sort',sort:value},function (data) {
  114. // layer.msg(data.msg);
  115. // table.reload('tablerReload');
  116. // })pfg_pushm_hothousesort
  117. // });
  118. }
  119. if (layEvent === 'clickData') { //修改排序
  120. /* 列表操作 edit 修改后执行 2018.7.24*/
  121. table.on('edit(' + tableIds + ')', function (obj) {
  122. var data = obj.data;
  123. $.post('/push/timelimitsgroupdelandshow', {
  124. id: data.id,
  125. type: 'click',
  126. click: data.click
  127. }, function (data) {
  128. if (data.code == 200) {
  129. layer.msg(data.msg);
  130. } else if (data.code == 300) {
  131. layer.msg(data.msg);
  132. }
  133. })
  134. })
  135. // layer.prompt({
  136. // formType: 2
  137. // ,title: '排序热销楼盘:<span style="color:red">'+data.name+'</span>'
  138. // ,value: data.sort
  139. // }, function(value, index){
  140. // $.post('/pushm/saledelshow',{id:data.id,type:'sort',sort:value},function (data) {
  141. // layer.msg(data.msg);
  142. // table.reload('tablerReload');
  143. // })
  144. // });
  145. }
  146. if (layEvent === 'groupnumData') { //修改排序
  147. /* 列表操作 edit 修改后执行 2018.7.24*/
  148. table.on('edit(' + tableIds + ')', function (obj) {
  149. var data = obj.data;
  150. $.post('/push/timelimitsgroupdelandshow', {
  151. id: data.id,
  152. type: 'group_num',
  153. group_num: data.group_num
  154. }, function (data) {
  155. if (data.code == 200) {
  156. layer.msg(data.msg);
  157. } else if (data.code == 300) {
  158. layer.msg(data.msg);
  159. }
  160. })
  161. })
  162. // layer.prompt({
  163. // formType: 2
  164. // ,title: '排序热销楼盘:<span style="color:red">'+data.name+'</span>'
  165. // ,value: data.sort
  166. // }, function(value, index){
  167. // $.post('/pushm/saledelshow',{id:data.id,type:'sort',sort:value},function (data) {
  168. // layer.msg(data.msg);
  169. // table.reload('tablerReload');
  170. // })
  171. // });
  172. }
  173. if (layEvent === 'del') {
  174. layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
  175. $.post('/push/timelimitsgroupdelandshow', {id: data.id, type: 'del'}, function (data) {
  176. layer.msg(data.msg);
  177. table.reload('tablerReload');
  178. })
  179. })
  180. }
  181. if (layEvent === 'edit') {
  182. var index = layer.open({
  183. type: 2,
  184. title: '修改限时团购',
  185. area: ['800px', '500px'],
  186. content: '/push/timelimitsgroupedit?id=' + data.id + '&house_name=' + data.name,
  187. end: function () {
  188. table.reload('tablerReload'); //重新加载
  189. }
  190. });
  191. }
  192. });
  193. // 新增
  194. var $ = layui.$, active = {
  195. addData: function () { //获取选中数据
  196. var index = layui.layer.open({
  197. type: 2,
  198. title: '添加楼盘',
  199. closeBtn: 1, //不显示关闭按钮
  200. area: ['600px', '345px'],
  201. content: '/push/timelimitsgroupadd?type=' + type_id
  202. , success: function (layero, index) {
  203. // indexOpen = layer.getChildFrame('body', index) ;
  204. // console.log(indexOpen);
  205. },
  206. end: function () {
  207. table.reload('tablerReload');
  208. }
  209. });
  210. },
  211. reload: function () {
  212. var form = pfgs_serialize($('form'));
  213. // var name = '';
  214. // var house_name = '';
  215. // if(form.input_house == 'name'){
  216. // name = form.input_house_text;
  217. // } else if(form.input_house == 'house_name'){
  218. // house_name = form.input_house_text;
  219. // }
  220. table.reload('tablerReload', {
  221. where: {
  222. house_name: form.input_house_text,
  223. province: form.province
  224. }
  225. })
  226. },
  227. alledit: function () { //获取选中数据
  228. var index = layui.layer.open({
  229. type: 2,
  230. title: '批量修改时间',
  231. closeBtn: 1, //不显示关闭按钮
  232. area: ['600px', '345px'],
  233. content: '/push/timealledit'
  234. , success: function (layero, index) {
  235. // indexOpen = layer.getChildFrame('body', index) ;
  236. // console.log(indexOpen);
  237. },
  238. end: function () {
  239. table.reload('tablerReload');
  240. }
  241. });
  242. },
  243. };
  244. $('.demoTable .layui-btn').on('click', function () {
  245. var type = $(this).data('type');
  246. active[type] ? active[type].call(this) : '';
  247. });
  248. // select 选中
  249. form.on('select(cityname)', function (data) {
  250. var city = $(this).html();
  251. $('.mt input').val(city);
  252. })
  253. $('.The_house').focus(function () {
  254. // $('form').append('<input type="hidden" name="aa" value="aaa">');
  255. indexOpen = parent.layui.layer.open({
  256. type: 2,
  257. title: '选择需要添加的楼盘',
  258. area: ['', '100%'],
  259. content: '/publicuse/housenamecn',
  260. success: function (layero, index) {
  261. },
  262. end: function () {
  263. }
  264. });
  265. parent.layui.layer.full(indexOpen);
  266. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  267. $(window).on("resize", function () {
  268. parent.layui.layer.full(indexOpen);
  269. })
  270. })
  271. //添加页面提交数据
  272. form.on('submit(add)', function (data) {
  273. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  274. var formData = new FormData($('form')[0]);
  275. $.ajax({
  276. cache: false,
  277. type: "post",
  278. url: "/push/timelimitsgroupaddform",
  279. data: formData, // 你的formid
  280. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  281. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  282. error: function (request) {
  283. layer.close(index);
  284. layer.msg("请联系管理员");
  285. },
  286. success: function (data) {
  287. if (data.data != null) {
  288. layer.msg(ReturnInfo(data.data), {icon: 5});
  289. return;
  290. }
  291. layer.msg(data.msg);
  292. parent.layer.close(oindex); //再执行关闭
  293. }
  294. });
  295. return false;
  296. });
  297. //修改页面提交数据
  298. form.on('submit(edit)', function (data) {
  299. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  300. var formData = new FormData($('form')[0]);
  301. $.ajax({
  302. cache: false,
  303. type: "post",
  304. url: "/push/timelimitsgroupeditform",
  305. data: formData, // 你的formid
  306. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  307. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  308. error: function (request) {
  309. layer.close(index);
  310. layer.msg("请联系管理员");
  311. },
  312. success: function (data) {
  313. if (data.data != null) {
  314. layer.msg(ReturnInfo(data.data), {icon: 5});
  315. return;
  316. }
  317. layer.msg(data.msg);
  318. parent.layer.close(oindex); //再执行关闭
  319. //layer.close(index);
  320. }
  321. });
  322. return false;
  323. });
  324. //批量修改页面提交数据
  325. form.on('submit(alledit)', function (data) {
  326. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  327. var formData = new FormData($('form')[0]);
  328. $.ajax({
  329. cache: false,
  330. type: "post",
  331. url: "/push/timealleditform",
  332. data: formData, // 你的formid
  333. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  334. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  335. error: function (request) {
  336. layer.close(index);
  337. layer.msg("请联系管理员");
  338. },
  339. success: function (data) {
  340. if (data.data != null) {
  341. layer.msg(ReturnInfo(data.data), {icon: 5});
  342. return;
  343. }
  344. layer.msg(data.msg);
  345. parent.layer.close(oindex); //再执行关闭
  346. }
  347. });
  348. return false;
  349. });
  350. })