housetypebinding.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. //楼盘列表
  13. var indexTtable = table.render({
  14. elem: '#housetypelist',
  15. url : '/house/housetypeform',
  16. where:{hid:inputId},
  17. method:'post',
  18. id:'tablerReload',
  19. cols : [[
  20. {type:'numbers'},
  21. {field: 'huxing_name', title: '户型',align:"center",sort: true},
  22. // {field: 'state', title: '审核',width:80, align:'center',templet:'#examineTpl'},
  23. {field: 'num', title: '数量', align:'center',width:100},
  24. {title: '操作', templet:'#housesalbumListBar',fixed:"right",align:"center",width:200}
  25. ]]
  26. });
  27. indexTtable.reload('tablerReload'); //重新加载
  28. table.on('tool(housetypelist)',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/housetypeedit?id="+inputId+'&name='+inputName+'&type='+data.type_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/typetatesave',{id:data.id,state:data.state,type_id:data.type_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('/house/typedel',{id:data.id,type_id:data.type_id,hid:inputId},function (data) {
  71. if(data.code == 200)
  72. {
  73. layer.msg(data.msg);
  74. table.reload('tablerReload');
  75. } else if(data.code == 300 ) {
  76. layer.msg(data.msg);
  77. }
  78. })
  79. })
  80. }
  81. })
  82. /*
  83. * 添加相册
  84. * */
  85. function addAlbum(edit){
  86. var index = parent.layui.layer.open({
  87. title : '<span style="color:red" >['+inputName+']</span> 楼盘添加户型',
  88. type : 2,
  89. maxmin: true,
  90. area: ['', '100%'],
  91. content : "/house/housetypeadd?id="+inputId+'&name='+inputName,
  92. end:function () {
  93. layui.table.reload('tablerReload');
  94. }
  95. })
  96. parent.layui.layer.full(index);
  97. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  98. $(window).on("resize",function(){
  99. parent.layui.layer.full(index);
  100. })
  101. }
  102. //添加相册
  103. $("#add-album").click(function(){
  104. addAlbum()
  105. });
  106. //多图片上传
  107. upload.render({
  108. elem: '#upload_edit'
  109. ,url: '/upload/'
  110. ,multiple: true
  111. ,auto: false
  112. ,number: 30
  113. ,choose:function(obj){
  114. //将每次选择的文件追加到文件队列
  115. files = obj.pushFile();
  116. //预读本地文件示例,不支持ie8
  117. obj.preview(function(index, file, result){
  118. filesContainer[index] = file; //将每次选择的文件追加到文件队列
  119. var _html ='<div class="layui-upload-img layer-photos-demo" id="layer-photos-demo">'
  120. +'<div class="info_box">'
  121. +'<input type="text" name="aa" placeholder="如A户型" autocomplete="off" class="layui-input">'
  122. +'<input type="text" name="bb" placeholder="厅卫厨" autocomplete="off" class="layui-input">'
  123. +'<input type="text" name="cc" placeholder="建筑面积" autocomplete="off" class="layui-input">'
  124. +'</div>'
  125. +'<div class="picture_box">'
  126. +'<div class="delete-list" id="delimg" ><i class="layui-icon fa-trash-o" >&#xe640;</i></div>'
  127. +'<img delIdentification="'+index+'" layer-pid="'+index+'" layer-src="'+ result +'" src="'+ result +'" alt="'+ file.name +'" id="hhhh">'
  128. +'</div>'
  129. +'</div>';
  130. $('#demo2').append(_html);
  131. layer.photos({
  132. photos: '#demo2'
  133. ,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
  134. });
  135. });
  136. }
  137. });
  138. form.on('submit(tijiao)',function (data) {
  139. var formData = new FormData($('#album_form')[0]);
  140. formData.delete('file'); //删除添加图片组件自带的FILE文件
  141. var index = layer.msg('数据提交中,请稍候。。。',{icon: 16,time:false,shade:0.8}); //数据提交提示
  142. var a = $('#demo2');
  143. $.each(a.find('input[name=aa]'),function () {
  144. formData.append('title[]',$(this).val());
  145. // console.log($(this).val());
  146. })
  147. $.each(a.find('input[name=bb]'),function () {
  148. formData.append('indoor_info[]',$(this).val());
  149. // console.log($(this).val());
  150. })
  151. $.each(a.find('input[name=cc]'),function () {
  152. formData.append('area[]',$(this).val());
  153. })
  154. $.each(filesContainer,function (k,v) {
  155. if(v != null){
  156. formData.append('img[]',v);
  157. }
  158. })
  159. $.ajax({
  160. cache : true,
  161. type : "post",
  162. url : "/house/housetypeaddform",
  163. data : formData, // 你的formid
  164. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  165. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  166. error : function(request) {
  167. layer.close(index); //关闭数据提交信息
  168. layer.alert("网络超时");
  169. },
  170. success : function(data) {
  171. layer.close(index); //关闭数据提交信息
  172. if (data.code == 200) {
  173. layer.msg(data.msg);
  174. indexTtable.reload('tablerReload');
  175. // table.reload('tablerReload');
  176. TableClose();
  177. // layui.table.reload('housealbumlistReload');
  178. } else if(data.code == 300){
  179. layer.msg(data.msg);
  180. layer.msg(ReturnInfo(data.data),{icon:5});
  181. }
  182. }
  183. });
  184. return false;
  185. })
  186. form.on('submit(editAlbum)',function (data) {
  187. var index = layer.msg('数据提交中,请稍候。。。',{icon: 16,time:false,shade:0.8}); //数据提交提示
  188. var formData = new FormData($('#album_form')[0]);
  189. formData.delete('file'); //删除添加图片组件自带的FILE文件
  190. var a = $('#demo2');
  191. $.each(a.find('input[name=aa]'),function () {
  192. formData.append('title[]',$(this).val());
  193. })
  194. $.each(a.find('input[name=bb]'),function () {
  195. formData.append('indoor_info[]',$(this).val());
  196. })
  197. $.each(a.find('input[name=cc]'),function () {
  198. formData.append('area[]',$(this).val());
  199. })
  200. $.each(a.find('img'),function () {
  201. formData.append('editid[]',$(this).attr('imgname'));
  202. })
  203. //需要添加的图片
  204. $.each(filesContainer,function (k,v) {
  205. if(v != null){
  206. formData.append('img[]',v);
  207. }
  208. })
  209. //需要删除的图片
  210. if(delFiles.length > 0){
  211. $.each(delFiles,function (k,v) {
  212. formData.append('delimg[]',v);
  213. })
  214. }
  215. $.ajax({
  216. cache : true,
  217. type : "post",
  218. url : "/house/housetypeeditform",
  219. data : formData, // 你的formid
  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.alert("网络超时");
  225. },
  226. success : function(data) {
  227. filesContainer = {};
  228. layer.close(index); //关闭数据提交信息
  229. if (data.code == 200) {
  230. layer.msg(data.msg);
  231. } else if(data.code == 300){
  232. layer.msg(data.msg);
  233. layer.msg(ReturnInfo(data.data),{icon:5});
  234. }
  235. }
  236. });
  237. return false;
  238. })
  239. layer.photos({
  240. photos: '#demo2'
  241. ,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
  242. });
  243. //设置图片的高度
  244. $(window).resize(function(){
  245. $("#Images li img").height($("#Images li img").width());
  246. });
  247. });
  248. //删除图片
  249. $('#demo2').on("click","#delimg",function () {
  250. var name = $(this).next().attr("imgname");
  251. var delIdentification = $(this).next().attr("delIdentification");
  252. if(typeof(delIdentification) != 'undefined'){
  253. delete filesContainer[delIdentification];
  254. delete files[delIdentification] ;
  255. // imgnumber -= 1;
  256. }
  257. if(typeof(name) != 'undefined'){
  258. delFiles.push(name);
  259. }
  260. // $(this).parent().remove();
  261. $(this).parents('#layer-photos-demo').remove();
  262. })