images.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. layui.use(['layer','upload'], function() {
  2. var upload = layui.upload;
  3. var layer = layui.layer;
  4. //点击选择图片
  5. $('img').on('click',function (e) {
  6. var parentNode = $(this).parent();
  7. parentNode.toggleClass('on');
  8. // if(Array.from(parentNode.classList).indexOf('on') !== -1) {
  9. // parentNode.removeClass('on');
  10. // choices.splice(value.indexOf(this.id),1);
  11. // }else{
  12. // parentNode.addClass('on');
  13. // choices.push(this.id);
  14. // }
  15. });
  16. //图片上传
  17. upload.render({
  18. elem: '#upload'
  19. ,url: uploadurl
  20. ,multiple: true
  21. ,size: 2097152 //限制文件大小,单位 KB
  22. ,done: function(res){
  23. layer.msg(res.msg,{time:1000});
  24. // var e = $($(".imagesbox").children("div").get(0));
  25. // $(e).before('<div class="image-item"><div class="image-delete" data-url=""></div><img class="pic" src="'+res.src+'"></img> </div>');
  26. // onloadimg();
  27. setTimeout(function () {
  28. window.location.reload();
  29. }, 1000);
  30. }
  31. });
  32. //关闭窗口
  33. $("#close").on('click',function (e) {
  34. if(parent.$f){
  35. parent.$f.closeModal();
  36. }else{
  37. var index = parent.layer.getFrameIndex(window.name);
  38. parent.layer.close(index);
  39. }
  40. });
  41. //确定选择
  42. $("#ConfirmChoices").on('click',function (e) {
  43. if(parent.$f){
  44. var value = parent.$f.getValue(parentinputname);//父级input 值
  45. var list = value||[];
  46. // console.log(list);
  47. var images = Array.from(self.document.getElementsByTagName('img'));
  48. images.forEach(function (image) {
  49. if(Array.from(image.parentNode.classList).indexOf('on') !== -1 && value.indexOf(image.src) == -1){
  50. list.push(image.src);
  51. }
  52. });
  53. parent.$f.changeField(parentinputname,list);
  54. parent.$f.closeModal();
  55. }else{
  56. //普通弹出选择图片
  57. var images = Array.from(self.document.getElementsByTagName('img'));
  58. images.forEach(function (image) {
  59. if(Array.from(image.parentNode.classList).indexOf('on') !== -1 ){
  60. parent.changeIMG(parentinputname,image.src);
  61. }
  62. });
  63. var index = parent.layer.getFrameIndex(window.name);
  64. parent.layer.close(index);
  65. }
  66. });
  67. //删除选择图片
  68. $('#deleteimg').on('click',function (e) {
  69. var images = Array.from(self.document.getElementsByTagName('img'));
  70. var list = [];
  71. images.forEach(function (image) {
  72. if(Array.from(image.parentNode.classList).indexOf('on') !== -1){
  73. list.push(image.id);
  74. }
  75. });
  76. if(list==''){
  77. layer.msg('还没选择要删除的图片呢?');
  78. }else{
  79. layer.confirm('确定删除吗?', {
  80. btn: ['确定','取消'] //按钮
  81. }, function(){
  82. $.post(deleteurl,{imageid:list},function(result){
  83. // console.log(result);
  84. layer.msg(result.msg);
  85. setTimeout(function () {
  86. window.location.reload();
  87. }, 1000);
  88. },'json');
  89. });
  90. }
  91. });
  92. //移动选择图片
  93. $('#moveimg').on('click',function (e) {
  94. var images = Array.from(self.document.getElementsByTagName('img'));
  95. var list = [];
  96. images.forEach(function (image) {
  97. if(Array.from(image.parentNode.classList).indexOf('on') !== -1){
  98. list.push(image.id);
  99. }
  100. });
  101. if(list==''){
  102. layer.msg('还没选择要移动的图片呢?');
  103. }else{
  104. var url = moveurl+'?imgaes='+list.join();
  105. layer.open({
  106. type: 2,
  107. title: '编辑分类',
  108. shade: [0],
  109. area: ['340px', '365px'],
  110. anim: 2,
  111. content: [url, 'no'],
  112. end: function () {
  113. window.location.reload();
  114. }
  115. });
  116. }
  117. });
  118. //添加图片分类
  119. $('#addcate').on('click',function (e) {
  120. layer.open({
  121. type: 2,
  122. title: '编辑分类',
  123. shade: [0],
  124. area: ['340px', '265px'],
  125. anim: 2,
  126. content: [addcate, 'no'],
  127. end: function () {
  128. window.location.reload();
  129. }
  130. });
  131. });
  132. //编辑图片分类
  133. $('#editcate').on('click',function (e) {
  134. if(pid == 0){
  135. layer.msg('禁止编辑');
  136. }else{
  137. layer.open({
  138. type: 2,
  139. title: '编辑分类',
  140. shade: [0],
  141. area: ['340px', '265px'],
  142. anim: 2,
  143. content: [editcate, 'no'],
  144. end: function () {
  145. window.location.reload();
  146. }
  147. });
  148. }
  149. });
  150. //删除图片分类
  151. $('#deletecate').on('click',function (e) {
  152. layer.confirm('确定删除吗?', {
  153. btn: ['确定','取消'] //按钮
  154. }, function(){
  155. $.post(deletecate,{id:pid},function(result){
  156. layer.msg(result.msg);
  157. if(result.code == 200){
  158. setTimeout(function () {
  159. window.location.reload();
  160. }, 1000);
  161. }
  162. },'json');
  163. });
  164. });
  165. });
  166. //非组件修改样式
  167. if(!parent.$f){
  168. $('.main-top').hide();
  169. $('.main').css('margin','0px');
  170. $('.foot-tool').css('bottom','20px');
  171. }