decorationcont.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 tableIds ='housealbumlist';
  15. var indexTtable = table.render({
  16. elem: '#'+tableIds,
  17. url : '/routinedecoration/contform',
  18. where:{nid:inputId},
  19. method:'post',
  20. id:'tablerReload',
  21. cols : [[
  22. {type:'numbers'},
  23. {field: 'name', title: '栏目', align:"center",sort: true},
  24. {field: 'sort', title: '排序',width:100,edit: 'text', align:'center',sort: true,templet:"#sortBox"},
  25. {field: 'is_show', title: '审核',width:75, event:'housesNews', align:'center',templet:function (d) {
  26. if(d.is_show === '1'){
  27. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  28. } else {
  29. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  30. }
  31. }},
  32. {field: 'create_at', title: '添加时间', align:"center",width:200},
  33. {title: '操作', width:200, templet:'#housesalbumListBar',fixed:"right",align:"center"}
  34. ]]
  35. });
  36. indexTtable.reload('tablerReload'); //重新加载
  37. /* 列表操作 edit 修改后执行 2018.7.24*/
  38. table.on('edit('+tableIds+')', function(obj){
  39. var data = obj.data;
  40. console.log(data)
  41. $.post('/routinedecoration/conteditsort',{id:data.id,sort:data.sort},function (data) {
  42. if(data.code == 200)
  43. {
  44. layer.msg(data.msg);
  45. } else if(data.code == 300 ) {
  46. layer.msg(data.msg);
  47. }
  48. })
  49. })
  50. // if(obj.event === 'sortData'){ //修改排序
  51. // layer.prompt({
  52. // formType: 2
  53. // ,title: '排序栏目:'+data.name
  54. // ,value: data.sort
  55. // }, function(value, index){
  56. // $.post('/routinedecoration/conteditsort',{id:data.id,sort:value},function (data) {
  57. // if(data.code == 200)
  58. // {
  59. // layer.msg(data.msg);
  60. // layer.close(index);
  61. // obj.update({
  62. // sort: value
  63. // });
  64. // // TableClose();
  65. // } else if(data.code == 300 ) {
  66. // layer.msg(data.msg);
  67. // }
  68. // })
  69. // });
  70. // } else
  71. /*操作列表 */
  72. table.on('tool('+tableIds+')',function (obj) {
  73. var data = obj.data;
  74. if(obj.event === 'edit'){
  75. var index = parent.layui.layer.open({
  76. title : '<span style="color:red" >['+inputName+']</span> 栏目内容编辑',
  77. type: 2,
  78. closeBtn: 1, //不显示关闭按钮
  79. shade: [0],
  80. area: ['', '100%'],
  81. anim: 2,
  82. content : "/routinedecoration/contedit?id="+data.id+'&name='+inputName+'&nid='+inputId,
  83. end:function(){
  84. layui.table.reload('tablerReload');
  85. }
  86. })
  87. parent.layui.layer.full(index);
  88. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  89. $(window).on("resize",function(){
  90. parent.layui.layer.full(index);
  91. })
  92. } else if(obj.event === 'del'){
  93. layer.confirm('确定要删除吗?',{btn: ['确定', '取消']},function () {
  94. $.post('/house/albumdel',{id:data.id,album_id:data.album_id,hid:inputId},function (data) {
  95. // var data = eval('('+data+')');
  96. // console.log(data);
  97. if(data.code == 200)
  98. {
  99. layer.msg(data.msg);
  100. table.reload('tablerReload');
  101. } else if(data.code == 300 ) {
  102. layer.msg(data.msg);
  103. }
  104. })
  105. })
  106. }
  107. })
  108. //监听指定开关
  109. form.on('switch(switchTest)', function(data){
  110. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  111. $.post('/routinedecoration/conteditsort',{id:data.value,is_show:1},function (data) {
  112. layer.msg(data.msg);
  113. table.reload('tablerReload');
  114. })
  115. },function (aa) {
  116. table.reload('tablerReload');
  117. })
  118. });
  119. /*
  120. * 添加
  121. * */
  122. function addAlbum(edit){
  123. var index = parent.layui.layer.open({
  124. title : '<span style="color:red" >['+inputName+']</span> 栏目内容',
  125. type : 2,
  126. maxmin: true,
  127. area: ['', '100%'],
  128. content : "/routinedecoration/contadd?id="+inputId+'&name='+inputName,
  129. end:function () {
  130. layui.table.reload('tablerReload');
  131. }
  132. })
  133. parent.layui.layer.full(index);
  134. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  135. $(window).on("resize",function(){
  136. parent.layui.layer.full(index);
  137. })
  138. }
  139. //添加相册
  140. $("#add-album").click(function(){
  141. addAlbum()
  142. });
  143. //多图片上传
  144. upload.render({
  145. elem: '#upload_edit'
  146. ,url: '/upload/'
  147. ,multiple: true
  148. ,auto: false
  149. ,number: 30
  150. ,choose:function(obj){
  151. //将每次选择的文件追加到文件队列
  152. files = obj.pushFile();
  153. //预读本地文件示例,不支持ie8
  154. obj.preview(function(index, file, result){
  155. var selectText = $('#ddlregtype').find("option:selected").text();
  156. filesContainer[index] = file; //将每次选择的文件追加到文件队列
  157. $('#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>');
  158. layer.photos({
  159. photos: '#demo2',
  160. closeBtn: 1
  161. ,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
  162. });
  163. });
  164. }
  165. });
  166. //判断是否需要编辑,需要才加载
  167. var verdict = $('#editor_content').html();
  168. if(typeof verdict == "string"){
  169. var ue = UE.getEditor('editor_content'); //编辑器
  170. }
  171. form.on('submit(tijiao)',function (data) {
  172. layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  173. var formData = new FormData($('#album_form')[0]);
  174. $.ajax({
  175. cache : true,
  176. type : "post",
  177. url : "/routinedecoration/contaddform",
  178. data : formData, // 你的formid
  179. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  180. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  181. error : function(request) {
  182. layer.msg("请联系管理员");
  183. },
  184. success : function(data) {
  185. if(data.data != null){
  186. layer.msg(ReturnInfo(data.data),{icon:5});
  187. return ;
  188. }
  189. layer.msg(data.msg);
  190. indexTtable.reload('tablerReload');
  191. TableClose();
  192. }
  193. });
  194. return false;
  195. })
  196. form.on('submit(edit)',function (data) {
  197. layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  198. var formData = new FormData($('#album_form')[0]);
  199. $.ajax({
  200. cache : true,
  201. type : "post",
  202. url : "/routinedecoration/conteditform",
  203. data : formData, // 你的formid
  204. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  205. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  206. error : function(request) {
  207. layer.msg("请联系管理员");
  208. },
  209. success : function(data) {
  210. if(data.data != null){
  211. layer.msg(ReturnInfo(data.data),{icon:5});
  212. return ;
  213. }
  214. layer.msg(data.msg);
  215. indexTtable.reload('tablerReload');
  216. TableClose();
  217. }
  218. });
  219. return false;
  220. })
  221. layer.photos({
  222. photos: '#demo2',
  223. closeBtn: 1
  224. ,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
  225. });
  226. //设置图片的高度
  227. $(window).resize(function(){
  228. $("#Images li img").height($("#Images li img").width());
  229. });
  230. // form.on('select(sele_album)', function(data){
  231. // var _text = data.elem[data.elem.selectedIndex].text;
  232. // $('#demo2').find('input').val(_houseNmae+'-'+_text);
  233. // })
  234. });