housealbum.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. var delFiles = []; //用于删除图片
  2. var filesContainer = {}; //存储最终要上传的图片
  3. var files; //存储选择图片的数量
  4. layui.use(['form', 'layer', 'upload', 'table'], function () {
  5. var form = layui.form,
  6. layer = layui.layer,
  7. upload = layui.upload,
  8. table = layui.table,
  9. $ = layui.jquery;
  10. var inputId = $('input[name="hid"]').val();
  11. var inputName = $('input[name="name"]').val();
  12. var _houseNmae = $('#house_name').html();
  13. //楼盘列表
  14. var indexTtable = table.render({
  15. elem: '#housealbumlist',
  16. url: '/house/albumform',
  17. where: {hid: inputId},
  18. method: 'post',
  19. id: 'tablerReload',
  20. cols: [[
  21. {type: 'numbers'},
  22. {field: 'name', title: '相册名称', align: "center", sort: true},
  23. {field: 'num', title: '数量', align: "center", width: 100},
  24. {title: '操作', width: 200, templet: '#housesalbumListBar', fixed: "right", align: "center"}
  25. ]]
  26. });
  27. indexTtable.reload('tablerReload'); //重新加载
  28. table.on('tool(housealbumlist)', function (obj) {
  29. var data = obj.data;
  30. if (obj.event === 'edit') {
  31. var index = parent.layui.layer.open({
  32. title: '<span style="color:red" >[' + inputName + ']</span> 楼盘相册修改',
  33. type: 2,
  34. maxmin: true,
  35. area: ['', '100%'],
  36. content: "/house/albumedit?id=" + inputId + '&name=' + inputName + '&alnumid=' + data.album_id,
  37. end: function () {
  38. layui.table.reload('tablerReload');
  39. }
  40. })
  41. parent.layui.layer.full(index);
  42. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  43. $(window).on("resize", function () {
  44. parent.layui.layer.full(index);
  45. })
  46. } else if (obj.event === 'examine') {
  47. var examineName = '';
  48. // console.log(data.state);
  49. switch (data.state) {
  50. case 'Y':
  51. examineName = '驳回审核';
  52. break;
  53. case 'N':
  54. examineName = '审核通过';
  55. break;
  56. }
  57. layer.confirm('确定要' + examineName + '吗?', {btn: ['确定', '取消']}, function () {
  58. $.post('/house/albumstatesave', {
  59. id: data.id,
  60. state: data.state,
  61. album_id: data.album_id,
  62. hid: inputId
  63. }, function (data) {
  64. if (data.code == 200) {
  65. layer.msg(data.msg);
  66. table.reload('tablerReload');
  67. } else if (data.code == 300) {
  68. layer.msg(data.msg);
  69. }
  70. })
  71. })
  72. } else if (obj.event === 'del') {
  73. layer.confirm('确定要删除吗?', {btn: ['确定', '取消']}, function () {
  74. $.post('/house/albumdel', {id: data.id, album_id: data.album_id, hid: inputId}, function (data) {
  75. // var data = eval('('+data+')');
  76. // console.log(data);
  77. if (data.code == 200) {
  78. layer.msg(data.msg);
  79. table.reload('tablerReload');
  80. } else if (data.code == 300) {
  81. layer.msg(data.msg);
  82. }
  83. })
  84. })
  85. }
  86. })
  87. /*
  88. * 添加相册
  89. * */
  90. function addAlbum(edit) {
  91. var index = parent.layui.layer.open({
  92. title: '<span style="color:red" >[' + inputName + ']</span> 楼盘添加相册',
  93. type: 2,
  94. maxmin: true,
  95. area: ['', '100%'],
  96. content: "/house/albumadd?id=" + inputId + '&name=' + inputName,
  97. end: function () {
  98. layui.table.reload('tablerReload');
  99. }
  100. })
  101. parent.layui.layer.full(index);
  102. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  103. $(window).on("resize", function () {
  104. parent.layui.layer.full(index);
  105. })
  106. }
  107. //添加相册
  108. $("#add-album").click(function () {
  109. addAlbum()
  110. });
  111. //多图片上传
  112. upload.render({
  113. elem: '#upload_edit'
  114. , url: '/upload/'
  115. , multiple: true
  116. , auto: false
  117. , number: 30
  118. , choose: function (obj) {
  119. //将每次选择的文件追加到文件队列
  120. files = obj.pushFile();
  121. //预读本地文件示例,不支持ie8
  122. obj.preview(function (index, file, result) {
  123. var selectText = $('#ddlregtype').find("option:selected").text();
  124. filesContainer[index] = file; //将每次选择的文件追加到文件队列
  125. $('#demo2').append('<div class="layui-upload-img layer-photos-demo" id="layer-photos-demo"><div class="delete-list" id="delimg"><i class="layui-icon fa-trash-o" >&#xe640;</i></div><img delIdentification="' + index + '" layer-pid="' + index + '" layer-src="' + result + '" src="' + result + '" alt="' + file.name + '" id="hhhh"><div class="close-input"><input type="text" id="album_title" name="' + index + '" value="' + _houseNmae + '-' + selectText + '" placeholder="请输入" autocomplete="off" class="layui-input"></div></div>');
  126. layer.photos({
  127. photos: '#demo2',
  128. closeBtn: 1
  129. , anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
  130. });
  131. });
  132. }
  133. });
  134. form.on('submit(tijiao)', function (data) {
  135. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  136. var formData = new FormData($('#album_form')[0]);
  137. formData.delete('file'); //删除添加图片组件自带的FILE文件
  138. $.each(filesContainer, function (k, v) {
  139. if (v != null) {
  140. if (typeof (formData.get(k)) != 'undefined') {
  141. formData.append('imginput[]', formData.get(k))
  142. }
  143. formData.append('img[]', v);
  144. }
  145. })
  146. $.ajax({
  147. cache: true,
  148. type: "post",
  149. url: "/house/albumaddform",
  150. data: formData, // 你的formid
  151. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  152. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  153. error: function (request) {
  154. layer.close(index); //关闭数据提交信息
  155. layer.alert("网络超时");
  156. },
  157. success: function (data) {
  158. if (data.code == 200) {
  159. layer.msg(data.msg);
  160. indexTtable.reload('tablerReload');
  161. TableClose();
  162. } else if (data.code == 300) {
  163. layer.msg(data.msg);
  164. layer.msg(ReturnInfo(data.data, {icon: 5}));
  165. }
  166. }
  167. });
  168. return false;
  169. })
  170. form.on('submit(editAlbum)', function (data) {
  171. // if(!lock){ // 重复提交解决方法
  172. // return false;
  173. // }
  174. // lock = false //改变值
  175. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  176. var formData = new FormData($('#album_forms')[0]);
  177. formData.delete('file'); //删除添加图片组件自带的FILE文件
  178. var a = $('#demo2');
  179. $.each(a.find('img'), function () {
  180. formData.append('editid[]', $(this).attr('imgname'));
  181. })
  182. $.each(a.find('input'), function () {
  183. formData.append('edittitle[]', $(this).val());
  184. })
  185. //需要添加的图片
  186. $.each(filesContainer, function (k, v) {
  187. if (typeof v === 'object') {
  188. if (typeof (formData.get(k)) != 'undefined') {
  189. formData.append('imginput[]', formData.get(k))
  190. }
  191. formData.append('img[]', v);
  192. }
  193. })
  194. //需要删除的图片
  195. if (delFiles.length > 0) {
  196. $.each(delFiles, function (k, v) {
  197. formData.append('delimg[]', v);
  198. })
  199. }
  200. $.ajax({
  201. cache: false,
  202. type: "post",
  203. url: "/house/albumeditformdata",
  204. data: formData, // 你的formid
  205. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  206. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  207. error: function (request) {
  208. layer.close(index);
  209. layer.alert("网络超时");
  210. },
  211. success: function (data) {
  212. top.layer.close(index);
  213. filesContainer = {}; //成功后删除选择的图片
  214. if (data.code == 200) {
  215. layer.msg(data.msg);
  216. } else if (data.code == 300) {
  217. layer.msg(data.msg);
  218. }
  219. }
  220. });
  221. return false;
  222. })
  223. layer.photos({
  224. photos: '#demo2',
  225. closeBtn: 1
  226. , anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
  227. });
  228. //设置图片的高度
  229. $(window).resize(function () {
  230. $("#Images li img").height($("#Images li img").width());
  231. });
  232. form.on('select(sele_album)', function (data) {
  233. var _text = data.elem[data.elem.selectedIndex].text;
  234. $('#demo2').find('input').val(_houseNmae + '-' + _text);
  235. })
  236. });
  237. //删除图片
  238. $('#demo2').on("click", "#delimg", function () {
  239. var name = $(this).next().attr("imgname");
  240. var delIdentification = $(this).next().attr("delIdentification");
  241. if (typeof (delIdentification) != 'undefined') {
  242. filesContainer[delIdentification] = false;
  243. delete files.delIdentification;
  244. console.log(files);
  245. // imgnumber -= 1;
  246. }
  247. if (typeof (name) != 'undefined') {
  248. delFiles.push(name);
  249. }
  250. $(this).parent().remove();
  251. })
  252. // $('#ddlregtype').on('change',function () {
  253. // alert(111);
  254. // })
  255. // $('#ddlregtype').change(function(){
  256. // alert(111);
  257. // // $('#album_title').val('');
  258. // // $('#album_title').val(_houseNmae+'-'+$(this).text());
  259. // })