NewsEdit.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-loading="loading"
  5. :show-close="false"
  6. :close-on-click-modal="false"
  7. :visible.sync="isShow"
  8. :title="curObj.id ? '编辑楼盘动态' : '新增楼盘动态'"
  9. :fullscreen="false"
  10. width="700px"
  11. custom-class="xl-dialog"
  12. center
  13. >
  14. <base-form ref="ruleForm" class="lib-edit" :data="formData" :is-inline="false" label-width="110px">
  15. <div slot="otherItem">
  16. <div class="scoped-img-area">
  17. <div class="sia-op" v-for="(imgsrc,index) in imagesArr" :key="index">
  18. <img class="img" :src="imgsrc" alt="img">
  19. <span class="close" @click="imgDel(index)"></span>
  20. </div>
  21. <el-upload
  22. class="sia-img"
  23. :action="`${domainUrl}/adm/upload/cloud`"
  24. :data="{logic_type: 'estate', token}"
  25. name="upload"
  26. :show-file-list="false"
  27. :on-success="roomAreaUploadSuccess"
  28. :before-upload="roomAreaUploadBefore"
  29. >
  30. <i class="el-icon-plus icon"/>
  31. </el-upload>
  32. </div>
  33. </div>
  34. </base-form>
  35. <div class="xl-form">
  36. <div class="xl-form-footer">
  37. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  38. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  39. </div>
  40. </div>
  41. </el-dialog>
  42. </div>
  43. </template>
  44. <script>
  45. import { arrToObj } from '@/utils'
  46. export default {
  47. components: { },
  48. mixins,
  49. props: {
  50. isShow: Boolean,
  51. curObj: Object
  52. },
  53. inject: ['parentData'],
  54. data() {
  55. const token = window.sessionStorage.getItem('fp_token')
  56. let domainUrl = process.env.VUE_APP_BASE_API
  57. return {
  58. domainUrl,
  59. token,
  60. loading: false,
  61. formData: [],
  62. cObj: {},
  63. imagesArr: [],
  64. }
  65. },
  66. watch: {
  67. isShow: function(val) {
  68. if (val) {
  69. this.getDef()
  70. }
  71. },
  72. },
  73. methods: {
  74. imgDel (index) {
  75. this.imagesArr.splice(index, 1)
  76. },
  77. roomAreaUploadSuccess(res, file) {
  78. const data = res.data || {}
  79. this.imagesArr.push(`${data.url}`)
  80. },
  81. roomAreaUploadBefore(file) {
  82. const isJPGPNG = file.type === 'image/jpeg' || file.type === 'image/png'
  83. const isLt2M = file.size / 1024 / 1024 < 2
  84. if (!isJPGPNG) {
  85. this.$message.error('上传图片只能是 JPG PNG 格式!')
  86. }
  87. if (!isLt2M) {
  88. this.$message.error('上传图片大小不能超过 2M!')
  89. }
  90. return isJPGPNG && isLt2M
  91. },
  92. getDef (str) {
  93. let params = {}
  94. params = { ...this.curObj }
  95. let disabled = false
  96. if (params.id) disabled = true
  97. this.formData = [
  98. { label: '动态内容', key: 'trends_cont', type: 'textarea'},
  99. ]
  100. this.setDefaultValue(params)
  101. },
  102. close (str) {
  103. if (str === 'confirm') {
  104. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  105. if (valid) {
  106. const oldform = this.$refs.ruleForm.baseForm
  107. const newForm = { ...oldform }
  108. if (this.curObj.id) newForm.estate_news_id = this.curObj.id
  109. newForm.estate_id = this.parentData.searchForm.estate_id
  110. if (this.imagesArr && this.imagesArr.length > 0) newForm.images = this.imagesArr.join(',')
  111. let apiStr = 'admestatenewsadd'
  112. if (this.curObj.id) apiStr = 'admestatenewsedit'
  113. this.$api.house[apiStr](newForm).then(data => {
  114. this.$msgs(newForm.id ? '编辑成功' : '新增成功')
  115. this.productData = []
  116. this.$emit('close', newForm)
  117. })
  118. }
  119. })
  120. } else {
  121. this.$emit('close')
  122. this.productData = []
  123. this.setDefaultValue()
  124. }
  125. },
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. @import '../../../../styles/libEdit.scss';
  131. .lib-edit {
  132. padding-top: 0;
  133. ::v-deep .el-date-editor.el-input {
  134. width: 100%;
  135. }
  136. ::v-deep .el-textarea__inner {
  137. height: 300px;
  138. }
  139. }
  140. .scoped-img-area {
  141. padding-left: 40px;
  142. .sia-op {
  143. display: inline-block;
  144. vertical-align: middle;
  145. margin-right: 10px;
  146. margin-bottom: 10px;
  147. border: 1px solid #f2f2f2;
  148. width: 80px;
  149. height: 80px;
  150. position: relative;
  151. &:hover {
  152. .img-big {
  153. display: block;
  154. }
  155. }
  156. .img {
  157. width: 80px;
  158. height: 80px;
  159. }
  160. .close {
  161. position: absolute;
  162. width: 20px;
  163. height: 20px;
  164. top: -10px;
  165. right: -10px;
  166. background: url(../../../../assets/icon_g_close.png) no-repeat;
  167. background-size: 20px;
  168. cursor: pointer;
  169. }
  170. .img-big {
  171. position: absolute;
  172. bottom: 0;
  173. left: 0;
  174. width: 400px;
  175. height: auto;
  176. display: none;
  177. box-shadow: 10px 10px 10px #ccc;
  178. z-index: 99;
  179. }
  180. }
  181. .sia-img {
  182. display: inline-block;
  183. vertical-align: middle;
  184. width: 80px;
  185. height: 80px;
  186. overflow: hidden;
  187. border: 1px dashed #999;
  188. margin-bottom: 10px;
  189. .el-icon-plus {
  190. color: #999;
  191. padding: 30px;
  192. }
  193. }
  194. }
  195. </style>