photoalbum.js 11 KB

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