images.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. $("#ConfirmChoices").on('click',function (e) {
  34. if(parent.$f){
  35. var value = parent.$f.getValue(parentinputname);//父级input 值
  36. var list = value||[];
  37. // console.log(list);
  38. var images = Array.from(self.document.getElementsByTagName('img'));
  39. images.forEach(function (image) {
  40. if(Array.from(image.parentNode.classList).indexOf('on') !== -1 && value.indexOf(image.src) == -1){
  41. list.push(image.src);
  42. // list.push(image.getAttribute("src"));
  43. }
  44. });
  45. parent.$f.changeField(parentinputname,list);
  46. parent.$f.closeModal();
  47. }else{
  48. //普通弹出选择图片
  49. var images = Array.from(self.document.getElementsByTagName('img'));
  50. images.forEach(function (image) {
  51. if(Array.from(image.parentNode.classList).indexOf('on') !== -1 ){
  52. parent.changeIMG(parentinputname,image.src);
  53. // parent.changeIMG(parentinputname,image.getAttribute("src"));
  54. }
  55. });
  56. var index = parent.layer.getFrameIndex(window.name);
  57. parent.layer.close(index);
  58. }
  59. });
  60. //删除选择图片
  61. $('#deleteimg').on('click',function (e) {
  62. var images = Array.from(self.document.getElementsByTagName('img'));
  63. var list = [];
  64. images.forEach(function (image) {
  65. if(Array.from(image.parentNode.classList).indexOf('on') !== -1){
  66. list.push(image.id);
  67. }
  68. });
  69. if(list==''){
  70. layer.msg('还没选择要删除的图片呢?');
  71. }else{
  72. layer.confirm('确定删除吗?', {
  73. btn: ['确定','取消'] //按钮
  74. }, function(){
  75. $.post(deleteurl,{imageid:list},function(result){
  76. // console.log(result);
  77. layer.msg(result.msg);
  78. setTimeout(function () {
  79. window.location.reload();
  80. }, 1000);
  81. },'json');
  82. });
  83. }
  84. });
  85. //移动选择图片
  86. $('#moveimg').on('click',function (e) {
  87. var images = Array.from(self.document.getElementsByTagName('img'));
  88. var list = [];
  89. images.forEach(function (image) {
  90. if(Array.from(image.parentNode.classList).indexOf('on') !== -1){
  91. list.push(image.id);
  92. }
  93. });
  94. if(list==''){
  95. layer.msg('还没选择要移动的图片呢?');
  96. }else{
  97. var url = moveurl+'?imgaes='+list.join();
  98. layer.open({
  99. type: 2,
  100. title: '编辑分类',
  101. shade: [0],
  102. area: ['340px', '365px'],
  103. anim: 2,
  104. content: [url, 'no'],
  105. end: function () {
  106. window.location.reload();
  107. }
  108. });
  109. }
  110. });
  111. //添加图片分类
  112. $('#addcate').on('click',function (e) {
  113. layer.open({
  114. type: 2,
  115. title: '编辑分类',
  116. shade: [0],
  117. area: ['340px', '265px'],
  118. anim: 2,
  119. content: [addcate, 'no'],
  120. end: function () {
  121. window.location.reload();
  122. }
  123. });
  124. });
  125. //编辑图片分类
  126. $('#editcate').on('click',function (e) {
  127. if(pid == 0){
  128. layer.msg('禁止编辑');
  129. }else{
  130. layer.open({
  131. type: 2,
  132. title: '编辑分类',
  133. shade: [0],
  134. area: ['340px', '265px'],
  135. anim: 2,
  136. content: [editcate, 'no'],
  137. end: function () {
  138. window.location.reload();
  139. }
  140. });
  141. }
  142. });
  143. //删除图片分类
  144. $('#deletecate').on('click',function (e) {
  145. layer.confirm('确定删除吗?', {
  146. btn: ['确定','取消'] //按钮
  147. }, function(){
  148. $.post(deletecate,{id:pid},function(result){
  149. layer.msg(result.msg);
  150. if(result.code == 200){
  151. setTimeout(function () {
  152. window.location.reload();
  153. }, 1000);
  154. }
  155. },'json');
  156. });
  157. });
  158. });
  159. //非组件修改样式
  160. if(!parent.$f){
  161. $('.main-top').hide();
  162. $('.main').css('margin','0px');
  163. $('.foot-tool').css('bottom','20px');
  164. }