photoalbum.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','upload'], function(){
  2. var laypage = layui.laypage //分页
  3. ,layer = layui.layer //弹层
  4. ,table = layui.table //表格
  5. ,element = layui.element //元素操作
  6. ,form = layui.form
  7. ,upload = layui.upload;
  8. var tableIds = 'photoalbumlist';
  9. //第一个实例
  10. table.render({
  11. elem: '#'+tableIds
  12. ,url: '/dictionary/photoalbumform' //数据接口
  13. ,where:{token:csrfToken}
  14. ,method:'post'
  15. ,page: true //开启分页
  16. ,height:600
  17. ,text:'数据加载中'
  18. ,id:'tablerReload'
  19. ,cols: [[ //表头
  20. // {type: "checkbox", width:50}
  21. {type:'numbers'}
  22. ,{field: 'name', title: '相册分类名称', align:'center'}
  23. ,{field: 'sort', title: '排序',width:80, edit: 'text',align:'center',sort: true,templet:"#sortBox"}
  24. ,{field: 'check_img', title: '选中', width:150,align:'center',templet:function(d){
  25. return '<img class="layui_magnify" src="'+d.check_img+'">';
  26. }}
  27. ,{field: 'uncheck_img', title: '未选中', width:150,align:'center',templet:function(d){
  28. return '<img class="layui_magnify" src="'+d.uncheck_img+'">';
  29. }}
  30. ,{field: 'is_show', title: '是否下架',width:100, align:'center', templet:"#Toexamine",templet:function(d){
  31. if(d.is_show == 2){
  32. return '<input type="checkbox" value="'+d.id+'" name="'+d.is_show+'" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  33. } else {
  34. return '<input type="checkbox" checked value="'+d.id+'" name="'+d.is_show+'" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  35. }
  36. }}
  37. ,{field: 'create_at', title: '添加时间', width:200,align:'center'}
  38. ,{field: 'update_at', title: '更新时间', width:200,align:'center'}
  39. ,{fixed: 'right',title:'操作', width: 180, align:'center', toolbar: '#operate'}
  40. ]]
  41. });
  42. table.reload('tablerReload'); //重新加载
  43. //列表操作
  44. table.on('tool('+tableIds+')', function(obj){
  45. var layEvent = obj.event,
  46. data = obj.data;
  47. if(layEvent === 'edit'){
  48. layer.open({
  49. type: 2,
  50. title: '修改户型',
  51. closeBtn: 1, //不显示关闭按钮
  52. shade: [0],
  53. area: ['600px', '500px'],
  54. anim: 2,
  55. content: ['/dictionary/photoalbumedit?id='+data.id, 'yes'], //iframe的url,no代表不显示滚动条
  56. });
  57. } else if(layEvent === 'del') {
  58. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  59. $.post('/dictionary/photoalbumdel',{'id':data.id,type:'del'},function (data) {
  60. if(data.code == 200)
  61. {
  62. layer.msg(data.msg);
  63. table.reload('tablerReload');
  64. } else if(data.code == 300 ) {
  65. layer.msg(data.msg);
  66. }
  67. })
  68. })
  69. }
  70. });
  71. /* 列表操作 edit 修改后执行 */
  72. table.on('edit('+tableIds+')', function(obj){
  73. var data = obj.data;
  74. if(obj.field=="sort"){
  75. $.post('/dictionary/photoalbumdel',{id:data.id,sort:data.sort,type:'sort'},function (data) {
  76. if(data.code == 200)
  77. {
  78. layer.msg(data.msg);
  79. } else if(data.code == 300 ) {
  80. layer.msg(data.msg);
  81. }
  82. })
  83. }
  84. })
  85. //显示或隐藏
  86. form.on('switch(switchTest)', function(data){
  87. var state = '';
  88. if(data.elem.name == 1){
  89. state = 2;
  90. }else if(data.elem.name == 2){
  91. state = 1;
  92. }
  93. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  94. $.post('/dictionary/photoalbumdel',{id:data.value,type:'is_show',is_show:state},function (data) {
  95. if(data.data != null){
  96. layer.msg(data.msg);
  97. return false;
  98. }
  99. layer.msg(data.msg);
  100. table.reload('tablerReload');
  101. })
  102. },function (aa) {
  103. table.reload('tablerReload');
  104. })
  105. });
  106. var $ = layui.$, active = {
  107. addData: function(){ //获取选中数据
  108. layer.open({
  109. type: 2,
  110. title: '添加相册分类',
  111. closeBtn: 1, //不显示关闭按钮
  112. shade: [0],
  113. area: ['600px', '500px'],
  114. anim: 2,
  115. content: ['/dictionary/photoalbumadd', 'yes'], //iframe的url,no代表不显示滚动条
  116. });
  117. // var checkStatus = table.checkStatus('idTest')
  118. // ,data = checkStatus.data;
  119. // layer.alert(JSON.stringify(data));
  120. }
  121. };
  122. $('.demoTable .layui-btn').on('click', function(){
  123. var type = $(this).data('type');
  124. active[type] ? active[type].call(this) : '';
  125. });
  126. // //修改
  127. // form.on('submit(editphotoalbum)', function(data){
  128. // $.post('/dictionary/photoalbumeditform',{'data':data.field,'token':csrfToken},function (data) {
  129. // if(data.code == 200)
  130. // {
  131. // layer.msg(data.msg);
  132. // parent.layui.table.reload('tablerReload');
  133. // TableClose();
  134. // // parent.layui.table.reload(tableIds);
  135. // } else if(data.code == 300 ) {
  136. // layer.msg(data.msg);
  137. // }
  138. // })
  139. // return false;
  140. // });
  141. // //添加
  142. // form.on('submit(addphotoalbum)', function(data){
  143. // $.post('/dictionary/photoalbumaddform',{'data':data.field,'token':csrfToken},function (data) {
  144. // if(data.code == 200)
  145. // {
  146. // layer.msg(data.msg);
  147. // // parent.layui.table.reload(tableIds);
  148. // parent.layui.table.reload('tablerReload');
  149. // TableClose();
  150. // } else if(data.code == 300 ) {
  151. // layer.msg(data.msg);
  152. // }
  153. // })
  154. // return false;
  155. // });
  156. //添加图片上传
  157. upload.render({
  158. elem: '#test1'
  159. ,url: '/house/createimg'
  160. ,data:{token:csrfToken}
  161. ,field:'check_img'
  162. ,size:1000 //限制上传图片的大小,单位为KB
  163. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  164. ,auto:false
  165. ,bindAction:'#addcity'
  166. ,choose: function(obj){
  167. obj.preview(function(index, file, result){
  168. $('#demo1').attr('src', result); //图片链接(base64)
  169. });
  170. }
  171. });
  172. //添加图片上传
  173. upload.render({
  174. elem: '#test2'
  175. ,url: '/house/createimg'
  176. ,data:{token:csrfToken}
  177. ,field:'uncheck_img'
  178. ,size:1000 //限制上传图片的大小,单位为KB
  179. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  180. ,auto:false
  181. ,bindAction:'#addcity'
  182. ,choose: function(obj){
  183. obj.preview(function(index, file, result){
  184. $('#demo2').attr('src', result); //图片链接(base64)
  185. });
  186. }
  187. });
  188. // 点击放大图片
  189. $('.layui_magnify').on('click', function(){
  190. var _src = $(this).attr('src');
  191. layui.layer.open({
  192. type: 1,
  193. title: false, //是否显示标题
  194. area: ['60%', '80%'],
  195. shade: 0.6, //透明度
  196. closeBtn: 1, //按钮 1有,0无
  197. shadeClose: true,
  198. content: '<img style="width:100%;height:100%" src="'+_src+'">',
  199. });
  200. });
  201. //添加
  202. form.on('submit(addphotoalbum)', function(data){
  203. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  204. var formData = new FormData($('#add_photo')[0]);
  205. //layer.msg(data.msg);
  206. $.ajax({
  207. cache : true,
  208. type : "post",
  209. url : '/dictionary/photoalbumaddform',
  210. data : formData, // 你的formid
  211. // async : false, //async 默认为true异步,修改为false为同步
  212. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  213. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  214. // error : function(request) {
  215. // layer.close(index); //关闭数据提交信息
  216. // layer.alert("网络超时");
  217. // },
  218. success : function(data) {
  219. if (data.code == 200) {
  220. layer.msg(data.msg);
  221. parent.layui.table.reload('tablerReload');
  222. TableClose();
  223. } else if(data.code == 300){
  224. layer.msg(data.msg);
  225. layer.msg(ReturnInfo(data.data),{icon:5});
  226. }
  227. }
  228. });
  229. return false;
  230. });
  231. //修改
  232. form.on('submit(editphotoalbum)', function(data){
  233. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  234. var formData = new FormData($('#photo_form')[0]);
  235. $.ajax({
  236. cache : true,
  237. type : "post",
  238. url : '/dictionary/photoalbumeditform',
  239. data : formData, // 你的formid
  240. // async : false, //async 默认为true异步,修改为false为同步
  241. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  242. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  243. error : function(request) {
  244. layer.close(index); //关闭数据提交信息
  245. layer.alert("网络超时");
  246. },
  247. success : function(data) {
  248. if (data.code == 200) {
  249. layer.msg(data.msg);
  250. parent.layui.table.reload('tablerReload');
  251. TableClose();
  252. } else if(data.code == 300){
  253. layer.msg(data.msg);
  254. layer.msg(ReturnInfo(data.data));
  255. }
  256. }
  257. });
  258. return false;
  259. });
  260. });