PhotoEdit.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div>
  3. <el-drawer
  4. v-loading="loading"
  5. :show-close="false"
  6. :title="'编辑相册'"
  7. :wrapper-closable="false"
  8. :close-on-press-escape="false"
  9. :visible.sync="isShow"
  10. size="960px"
  11. custom-class="xl-drawer"
  12. direction="rtl"
  13. >
  14. <div class="scoped-img-area" v-for="(item, iIndex) in imagesArr" :key="iIndex">
  15. <div class="sia-title">{{item.key}}</div>
  16. <div class="sia-op" v-for="(imgsrc,index) in item.urls" :key="index">
  17. <img class="img" :src="imgsrc + '_adm0'" alt="img" @click="openbigImg(imgsrc + '_adm0')">
  18. <span class="close" @click="imgDel(iIndex, index)"></span>
  19. </div>
  20. <el-upload
  21. class="sia-img"
  22. :action="`${domainUrl}/adm/upload/cloud`"
  23. :data="{logic_type: 'estate', token}"
  24. name="upload"
  25. :show-file-list="false"
  26. :on-success="roomAreaUploadSuccess"
  27. :before-upload="roomAreaUploadBefore"
  28. >
  29. <i class="el-icon-plus icon" @click="addImgHandle(iIndex)" />
  30. </el-upload>
  31. </div>
  32. <div class="xl-form">
  33. <div class="xl-form-footer fixed" style="width:960px;padding-top: 20px;border-top: 1px solid #dcdcdc;right:0;">
  34. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  35. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  36. </div>
  37. </div>
  38. </el-drawer>
  39. <popup-big-img :is-show="bigImgShow" :src="`${bigImgSrc}`" @close="closebigImg" />
  40. </div>
  41. </template>
  42. <script>
  43. import bigImgPopup from '_m/bigImgPopup.js'
  44. export default {
  45. components: { },
  46. mixins: [...mixins, bigImgPopup],
  47. props: {
  48. isShow: Boolean,
  49. curObj: Object
  50. },
  51. inject: ['parentData'],
  52. data() {
  53. let domainUrl = process.env.VUE_APP_BASE_API
  54. const token = window.sessionStorage.getItem('fp_token')
  55. return {
  56. domainUrl,
  57. token,
  58. loading: false,
  59. formData: [],
  60. cObj: {},
  61. isShowMap: false,
  62. imagesArr: [],
  63. curIndex: 0,
  64. }
  65. },
  66. watch: {
  67. isShow: function(val) {
  68. if (val) {
  69. let imagesArr = JSON.parse(JSON.stringify(this.$dictData.estate_photo))
  70. if (this.curObj.id) {
  71. this.loading = true
  72. this.$api.house.admestatephotolist({estate_id: this.curObj.id}).then(res => {
  73. let curArr = res.data ? JSON.parse(res.data) : []
  74. curArr.forEach(item => {
  75. imagesArr.map(one => {
  76. if (item.val === one.val) {
  77. one.urls = item.urls
  78. }
  79. })
  80. })
  81. this.imagesArr = [...imagesArr]
  82. this.loading = false
  83. }).catch(err => {
  84. this.loading = false
  85. })
  86. }
  87. }
  88. },
  89. },
  90. methods: {
  91. addImgHandle (index) {
  92. this.curIndex = index
  93. },
  94. imgDel (iIndex, index) {
  95. this.imagesArr[iIndex].urls.splice(index, 1)
  96. this.imagesArr = [...this.imagesArr]
  97. },
  98. roomAreaUploadSuccess(res, file) {
  99. const data = res.data || {}
  100. let urls = this.imagesArr[this.curIndex].urls || []
  101. urls.push(`${data.url}`)
  102. this.imagesArr[this.curIndex].urls = urls
  103. this.imagesArr = [...this.imagesArr]
  104. },
  105. roomAreaUploadBefore(file) {
  106. const isJPGPNG = file.type === 'image/jpeg' || file.type === 'image/png'
  107. const isLt2M = file.size / 1024 / 1024 < 2
  108. if (!isJPGPNG) {
  109. this.$message.error('上传图片只能是 JPG PNG 格式!')
  110. }
  111. if (!isLt2M) {
  112. this.$message.error('上传图片大小不能超过 2M!')
  113. }
  114. return isJPGPNG && isLt2M
  115. },
  116. close (str) {
  117. if (str === 'confirm') {
  118. const newForm = { }
  119. if (this.curObj.id) newForm.estate_id = this.curObj.id
  120. let cArr = []
  121. this.imagesArr.forEach(obj => {
  122. const imgArr = obj.urls || []
  123. if (imgArr.length > 0) {
  124. cArr.push({
  125. key: obj.key,
  126. val: obj.val,
  127. urls: imgArr
  128. })
  129. }
  130. })
  131. newForm.images = JSON.stringify(cArr)
  132. let apiStr = 'admestatephotoedit'
  133. if (this.curObj.id) apiStr = 'admestatephotoedit'
  134. this.$api.house[apiStr](newForm).then(data => {
  135. this.$msgs(newForm.id ? '编辑成功' : '新增成功')
  136. this.$emit('close', newForm)
  137. this.curIndex = 0
  138. })
  139. } else {
  140. this.$emit('close')
  141. this.curIndex = 0
  142. }
  143. },
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .scoped-img-area {
  149. padding-left: 20px;
  150. margin-bottom: 20px;
  151. .sia-title {
  152. font-size: 16px;
  153. padding-bottom: 10px;
  154. color: #666;
  155. font-weight: bold;
  156. }
  157. .sia-op {
  158. display: inline-block;
  159. vertical-align: middle;
  160. margin-right: 10px;
  161. margin-bottom: 10px;
  162. border: 1px solid #f2f2f2;
  163. width: 80px;
  164. height: 80px;
  165. position: relative;
  166. &:hover {
  167. .img-big {
  168. display: block;
  169. }
  170. }
  171. .img {
  172. width: 80px;
  173. height: 80px;
  174. }
  175. .close {
  176. position: absolute;
  177. width: 20px;
  178. height: 20px;
  179. top: -10px;
  180. right: -10px;
  181. background: url(../../../../assets/icon_g_close.png) no-repeat;
  182. background-size: 20px;
  183. cursor: pointer;
  184. }
  185. .img-big {
  186. position: absolute;
  187. bottom: 0;
  188. left: 0;
  189. width: 400px;
  190. height: auto;
  191. display: none;
  192. box-shadow: 10px 10px 10px #ccc;
  193. z-index: 99;
  194. }
  195. }
  196. .sia-img {
  197. display: inline-block;
  198. vertical-align: middle;
  199. width: 80px;
  200. height: 80px;
  201. overflow: hidden;
  202. border: 1px dashed #999;
  203. margin-bottom: 10px;
  204. .el-icon-plus {
  205. color: #999;
  206. padding: 30px;
  207. }
  208. }
  209. }
  210. </style>