housealbum.js 11 KB

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