deleteUploadImg2.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <div>
  3. <van-col span="6" v-for="(urls, index) in imgs" :key="index">
  4. <div class="imgview2">
  5. <van-icon
  6. name="close"
  7. size="16"
  8. v-on:click="deleteImg(index, urls.id)"
  9. v-if="writeAgain == '1'" />
  10. <img
  11. v-if="urls.type == '2'"
  12. :src="urls.fileUrl"
  13. width="100px"
  14. height="100px"
  15. @click="previewsImg(index)" />
  16. <img v-else :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)" />
  17. </div>
  18. </van-col>
  19. </div>
  20. <!-- <div style="padding: 10px 16px 0;">-->
  21. <!-- <div class="img-box" v-for="(urls, index) in imgs" :key="index">-->
  22. <!-- <van-icon name="clear" v-on:click="deleteImg(index,urls.id)"/>-->
  23. <!-- <img v-if="urls.type=='2'" :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)"/>-->
  24. <!-- <img v-else :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)"/>-->
  25. <!-- </div>-->
  26. <!-- </div>-->
  27. </template>
  28. <script>
  29. import { ImagePreview } from 'vant';
  30. import { removeSummaryPhoto, removePhoto } from '@/api/index';
  31. export default {
  32. name: 'deleteUploadImg',
  33. props: {
  34. imgs: {
  35. type: Array,
  36. default() {
  37. return [];
  38. },
  39. },
  40. // 是否允许补填
  41. writeAgain: {
  42. type: String,
  43. default: '0',
  44. },
  45. },
  46. data() {
  47. return {
  48. url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API,
  49. };
  50. },
  51. methods: {
  52. deleteImg(index, collectionItemId) {
  53. var fileName = {
  54. fileId: collectionItemId,
  55. };
  56. removeSummaryPhoto(fileName).then((res) => {
  57. if (res.code == 200) {
  58. this.$toast('删除成功!');
  59. this.imgs.splice(index, 1);
  60. } else {
  61. this.$toast('删除失败!');
  62. }
  63. });
  64. },
  65. previewsImg(index) {
  66. var arrimg = [];
  67. for (var imgi = 0; imgi < this.imgs.length; imgi++) {
  68. arrimg.push(this.imgs[imgi].fileUrl);
  69. }
  70. ImagePreview({
  71. images: arrimg,
  72. startPosition: index,
  73. onClose() {
  74. // do something
  75. },
  76. });
  77. },
  78. },
  79. };
  80. </script>
  81. <style lang="scss" scoped>
  82. .imgview2 {
  83. width: 100%;
  84. height: 80px;
  85. position: relative;
  86. display: inline-block;
  87. i {
  88. position: absolute;
  89. right: -2px;
  90. top: -3px;
  91. color: white;
  92. background: red;
  93. overflow: hidden;
  94. border-radius: 50%;
  95. }
  96. img {
  97. width: 100%;
  98. height: 100%;
  99. }
  100. }
  101. </style>