NewsEdit.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 + '_adm0'" 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 isLtM = file.size / 1024 / 1024 < 10
  84. if (!isJPGPNG) {
  85. this.$message.error('上传图片只能是 JPG PNG GIF 格式!')
  86. }
  87. if (!isLtM) {
  88. this.$message.error('上传图片大小不能超过 10M!')
  89. }
  90. return isJPGPNG && isLt2M
  91. },
  92. getDef (str) {
  93. let params = {}
  94. params = { ...this.curObj }
  95. let imagesArr = []
  96. if (params.images) imagesArr = params.images.split(',')
  97. this.imagesArr = [...imagesArr]
  98. this.formData = [
  99. { label: '标题', key: 'title'},
  100. { label: '时间', key: 'news_at', type: 'datePicker', type2: 'date'},
  101. { label: '动态内容', key: 'trends_cont', type: 'textarea'},
  102. ]
  103. this.setDefaultValue(params)
  104. },
  105. close (str) {
  106. if (str === 'confirm') {
  107. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  108. if (valid) {
  109. const oldform = this.$refs.ruleForm.baseForm
  110. const newForm = { ...oldform }
  111. if (this.curObj.id) newForm.estate_news_id = this.curObj.id
  112. newForm.estate_id = this.parentData.searchForm.estate_id
  113. if (this.imagesArr && this.imagesArr.length > 0) newForm.images = this.imagesArr.join(',')
  114. let apiStr = 'admestatenewsadd'
  115. if (this.curObj.id) apiStr = 'admestatenewsedit'
  116. this.$api.house[apiStr](newForm).then(data => {
  117. this.$msgs(newForm.estate_id ? '编辑成功' : '新增成功')
  118. this.productData = []
  119. this.$emit('close', newForm)
  120. })
  121. }
  122. })
  123. } else {
  124. this.$emit('close')
  125. this.productData = []
  126. this.setDefaultValue()
  127. }
  128. },
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. @import '../../../../styles/libEdit.scss';
  134. .lib-edit {
  135. padding-top: 0;
  136. ::v-deep .el-date-editor.el-input {
  137. width: 100%;
  138. }
  139. ::v-deep .el-textarea__inner {
  140. height: 300px;
  141. }
  142. }
  143. .scoped-img-area {
  144. padding-left: 40px;
  145. .sia-op {
  146. display: inline-block;
  147. vertical-align: middle;
  148. margin-right: 10px;
  149. margin-bottom: 10px;
  150. border: 1px solid #f2f2f2;
  151. width: 80px;
  152. height: 80px;
  153. position: relative;
  154. &:hover {
  155. .img-big {
  156. display: block;
  157. }
  158. }
  159. .img {
  160. width: 80px;
  161. height: 80px;
  162. }
  163. .close {
  164. position: absolute;
  165. width: 20px;
  166. height: 20px;
  167. top: -10px;
  168. right: -10px;
  169. background: url(../../../../assets/icon_g_close.png) no-repeat;
  170. background-size: 20px;
  171. cursor: pointer;
  172. }
  173. .img-big {
  174. position: absolute;
  175. bottom: 0;
  176. left: 0;
  177. width: 400px;
  178. height: auto;
  179. display: none;
  180. box-shadow: 10px 10px 10px #ccc;
  181. z-index: 99;
  182. }
  183. }
  184. .sia-img {
  185. display: inline-block;
  186. vertical-align: middle;
  187. width: 80px;
  188. height: 80px;
  189. overflow: hidden;
  190. border: 1px dashed #999;
  191. margin-bottom: 10px;
  192. .el-icon-plus {
  193. color: #999;
  194. padding: 30px;
  195. }
  196. }
  197. }
  198. </style>