images.js 5.5 KB

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