spzt.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','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. ,upload = layui.upload;
  9. var tableIds = 'videolist'; //表格ID
  10. var type_id = $('input[name="typeid"]').val();
  11. var url = '';
  12. if(type_id == 1){
  13. url = '/zt/ztadd?type='+type_id;
  14. }
  15. if(type_id == 2){
  16. url = '/zt/newshothouseadd?type='+type_id;
  17. }
  18. if(type_id == 3){
  19. url = '/zt/ztadd?type='+type_id;
  20. }
  21. //第一个实例
  22. table.render({
  23. elem: '#'+tableIds
  24. ,url: '/zt/ztform' //数据接口
  25. ,where:{token:csrfToken,type:type_id}
  26. ,method:'post'
  27. ,page: true //开启分页
  28. ,text:'数据加载中'
  29. ,id:'tablerReload'
  30. ,limit:20
  31. ,cols: [[ //表头
  32. {type:'numbers',title:'序号',width:50},
  33. {field: 'name', title: '楼盘', align:'center'},
  34. {field: 'sort', title: '排序',width:100, event:'sortData',edit: 'text', align:'center',sort: true,templet:"#sortBox"},
  35. {field: 'create_at', title: '添加时间',width:150, align:'center'},
  36. {field: 'is_show', title: '审核',align:'center',width:100, templet:function (d) {
  37. if(d.is_show == 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. //监听指定开关
  47. form.on('switch(switchTest)', function(data){
  48. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  49. $.post('/zt/ztset',{id:data.value,type:'show'},function (data) {
  50. layer.msg(data.msg);
  51. table.reload('tablerReload');
  52. })
  53. },function (aa) {
  54. table.reload('tablerReload'); //重新加载
  55. })
  56. });
  57. //列表操作
  58. table.on('tool('+tableIds+')', function(obj){
  59. var layEvent = obj.event,
  60. data = obj.data;
  61. if(layEvent === 'sortData'){ //修改排序
  62. table.on('edit('+tableIds+')', function(obj){
  63. var data = obj.data;
  64. // console.log(data)
  65. $.post('/zt/ztset',{id:data.id,type:'sort',sort:data.sort},function (data) {
  66. if(data.code == 200)
  67. {
  68. layer.msg(data.msg);
  69. } else if(data.code == 300 ) {
  70. layer.msg(data.msg);
  71. }
  72. })
  73. })
  74. }
  75. if(layEvent === 'del') {
  76. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  77. $.post('/zt/ztset',{id:data.id,type:'del'},function (data) {
  78. layer.msg(data.msg);
  79. table.reload('tablerReload');
  80. })
  81. })
  82. }
  83. if(layEvent === 'edit'){
  84. var index = layer.open({
  85. type: 2,
  86. title: '修改数据',
  87. area:['700px','700px'],
  88. content: '/zt/ztedit?id='+data.id+'&house_name='+data.name,
  89. end:function () {
  90. table.reload('tablerReload'); //重新加载
  91. }
  92. });
  93. }
  94. });
  95. // 新增
  96. var $ = layui.$, active = {
  97. addData: function(){ //获取选中数据
  98. layer.open({
  99. content: '选择楼盘位置'
  100. ,btn: ['列表', '其他']
  101. ,btnAlign: 'c'
  102. ,yes: function(item, layero){
  103. //按钮【按钮一】的回调
  104. var index = layui.layer.open({
  105. type: 2,
  106. title: '新增数据',
  107. closeBtn: 1, //不显示关闭按钮
  108. area: ['700px','700px'],
  109. content: url
  110. ,success:function (layero, index) {
  111. },
  112. end:function () {
  113. layer.close(item);
  114. table.reload('tablerReload');
  115. }
  116. });
  117. }
  118. ,btn2: function(item, layero){
  119. //按钮【按钮二】的回调
  120. var type = 4;
  121. var URL = '/zt/manilaztadd?type='+type;
  122. var index = layui.layer.open({
  123. type: 2,
  124. title: '新增数据',
  125. closeBtn: 1, //不显示关闭按钮
  126. area: ['700px','700px'],
  127. content: URL
  128. ,success:function (layero, index) {
  129. },
  130. end:function () {
  131. layer.close(item);
  132. table.reload('tablerReload');
  133. }
  134. });
  135. //return false 开启该代码可禁止点击该按钮关闭
  136. }
  137. ,cancel: function(){
  138. //右上角关闭回调
  139. //return false 开启该代码可禁止点击该按钮关闭
  140. }
  141. });
  142. // var index = layui.layer.open({
  143. // type: 2,
  144. // title: '新增数据',
  145. // closeBtn: 1, //不显示关闭按钮
  146. // area: ['700px','700px'],
  147. // content: url
  148. // ,success:function (layero, index) {
  149. //
  150. // },
  151. // end:function () {
  152. // table.reload('tablerReload');
  153. // }
  154. // });
  155. },
  156. reload:function(){
  157. var form = pfgs_serialize($('form'));
  158. table.reload('tablerReload',{
  159. where:{
  160. name: form.input_house_text,
  161. }
  162. })
  163. }
  164. };
  165. $('.demoTable .layui-btn').on('click', function(){
  166. var type = $(this).data('type');
  167. active[type] ? active[type].call(this) : '';
  168. });
  169. $('.The_house').focus(function(){
  170. indexOpen = parent.layui.layer.open({
  171. type: 2,
  172. title: '选择需要添加的楼盘',
  173. area: ['','100%'],
  174. content: '/publicuse/housename',
  175. success:function (layero, index) {
  176. },
  177. end:function(){
  178. }
  179. });
  180. parent.layui.layer.full(indexOpen);
  181. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  182. $(window).on("resize",function(){
  183. parent.layui.layer.full(indexOpen);
  184. })
  185. })
  186. //添加页面提交数据
  187. form.on('submit(add)', function(data){
  188. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  189. var formData = new FormData($('form')[0]);
  190. $.ajax({
  191. cache : false,
  192. type : "post",
  193. url : "/zt/ztaddform",
  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(edit_house)', function(data){
  213. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  214. // var oindex = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  215. var formData = new FormData($('form')[0]);
  216. $.ajax({
  217. type : "post",
  218. url : "/zt/zteditform",
  219. data : formData,
  220. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  221. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  222. error : function(request) {
  223. layer.close(index);
  224. layer.msg("请联系管理员");
  225. },
  226. success : function(data) {
  227. if(data.data != null){
  228. layer.msg(ReturnInfo(data.data),{icon:5});
  229. return ;
  230. }
  231. layer.msg(data.msg);
  232. parent.layer.close(oindex); //再执行关闭
  233. }
  234. });
  235. return false;
  236. });
  237. form.on('select(position)',function (data) {
  238. // console.log(data.value);
  239. var type= data.value;
  240. table.reload('tablerReload',{
  241. url: '/zt/ztform'
  242. ,where:{token:csrfToken,type:type}
  243. ,method:'post'
  244. });
  245. });
  246. })