OldEdit.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <div>
  3. <el-drawer
  4. v-loading="loading"
  5. :show-close="false"
  6. :title="curObj.id ? '编辑房源' : '新增房源'"
  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. <base-form ref="ruleForm" class="lib-edit" :data="formData" :is-inline="false" label-width="110px" :insertSlotArr="[8,9]">
  15. <div slot="OI8">
  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. </div>
  20. <el-upload
  21. class="sia-img"
  22. :action="`${domainUrl}/adm/upload/picture`"
  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"/>
  30. </el-upload>
  31. </div>
  32. </div>
  33. <div slot="OI9" class="scoped-other-form">
  34. <el-form-item label="点位坐标" class="scoped-item-two item">
  35. 纬度N<el-input v-model="cObj.latitude" disabled />
  36. 经度E<el-input v-model="cObj.longitude" disabled />
  37. <el-button type="primary" class="map-btn" size="small" @click="openMap">点击从地图获取</el-button>
  38. </el-form-item>
  39. </div>
  40. </base-form>
  41. <div class="xl-form">
  42. <div class="xl-form-footer fixed" style="width:960px;padding-top: 20px;border-top: 1px solid #dcdcdc;right:0;">
  43. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  44. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  45. </div>
  46. </div>
  47. </el-drawer>
  48. <handle-map :is-show="isShowMap" @close="closeMap" />
  49. </div>
  50. </template>
  51. <script>
  52. import { arrToObj } from '@/utils'
  53. import handleMap from '@/components/Common/Map'
  54. export default {
  55. components: { handleMap },
  56. mixins,
  57. props: {
  58. isShow: Boolean,
  59. curObj: Object
  60. },
  61. inject: ['parentData'],
  62. data() {
  63. const token = window.sessionStorage.getItem('fp_token')
  64. let domainUrl = process.env.VUE_APP_BASE_API
  65. return {
  66. domainUrl,
  67. token,
  68. loading: false,
  69. formData: [],
  70. cObj: {},
  71. isShowMap: false,
  72. imagesArr: [],
  73. }
  74. },
  75. watch: {
  76. isShow: function(val) {
  77. if (val) {
  78. if (this.curObj.id) {
  79. this.loading = true
  80. this.$api.house.admoldhousedetail({id: this.curObj.id}).then(res => {
  81. let curData = res || {}
  82. if (curData.pri_image) curData.pri_image = `${curData.domain}${curData.pri_image}?url=${curData.pri_image}`
  83. this.cObj = curData || {}
  84. this.getDef()
  85. this.loading = false
  86. })
  87. } else {
  88. this.cObj = this.curObj
  89. this.getDef()
  90. }
  91. }
  92. },
  93. },
  94. methods: {
  95. roomAreaUploadSuccess(res, file) {
  96. const data = res.data || {}
  97. this.imagesArr.push(`${data.domain}${data.url}?url=${data.url}&id=${data.file_id}`)
  98. },
  99. roomAreaUploadBefore(file) {
  100. const isJPGPNG = file.type === 'image/jpeg' || file.type === 'image/png'
  101. const isLt2M = file.size / 1024 / 1024 < 2
  102. if (!isJPGPNG) {
  103. this.$message.error('上传图片只能是 JPG PNG 格式!')
  104. }
  105. if (!isLt2M) {
  106. this.$message.error('上传图片大小不能超过 400k!')
  107. }
  108. return isJPGPNG && isLt2M
  109. },
  110. getDef (str) {
  111. let params = {}
  112. params = { ...this.cObj }
  113. let disabled = false
  114. if (params.id) disabled = true
  115. this.formData = [
  116. { label: '房源标题', key: 'title'},
  117. { label: '所属区域', key: 'area_type', type: 'select', class: 'c-3', options: this.$dictData.area_type },
  118. { label: '产品类型', key: 'product_type', class: 'c-3', type: 'select', options: this.$dictData.product_type},
  119. { label: '房源户型', key: 'house_type', class: 'c-3', type: 'select', options: this.$dictData.house_type},
  120. { label: '面积', key: 'area', class: 'c-3', type: 'inputFont', appendFont: '㎡'},
  121. { label: '总价', key: 'price', class: 'c-3'},
  122. { label: '所属楼盘', key: 'estate_id', class: 'c-3', type: 'selectRemote',
  123. remoteParams: { skey: 'estate_name', api: `house.admestatelist`, opKey: 'estate_name', opVal: 'id' },
  124. },
  125. { label: '房源主图', key: 'pri_image', class: 'c-3', type: 'upload' },
  126. { label: '房源简介', key: 'remarked', class: 'c-3s', type: 'textarea' },
  127. { label: '房源地址', key: 'address' },
  128. ]
  129. this.setDefaultValue(params)
  130. },
  131. getImgUrl (str) {
  132. let backStr = ''
  133. if (str && str.indexOf('?') > -1) {
  134. const imgArr = str.split('?')
  135. const queryArr = imgArr[1].split('&')
  136. queryArr.forEach(q =>{
  137. const curQArr = q.split('=')
  138. if (curQArr[0] === 'url') {
  139. backStr = curQArr[1]
  140. }
  141. })
  142. }
  143. return backStr
  144. },
  145. close (str) {
  146. if (str === 'confirm') {
  147. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  148. if (valid) {
  149. const oldform = this.$refs.ruleForm.baseForm
  150. const newForm = { ...oldform }
  151. if (this.curObj.id) newForm.id = this.curObj.id
  152. newForm.longitude = this.cObj.longitude
  153. newForm.latitude = this.cObj.latitude
  154. if (!newForm.longitude) return this.$msgw('请选择经度!')
  155. else if (!newForm.latitude) return this.$msgw('请选择纬度!')
  156. // if (newForm.pri_image && newForm.pri_image.indexOf('?') > -1) {
  157. // const imgArr = newForm.pri_image.split('?')
  158. // const queryArr = imgArr[1].split('&')
  159. // queryArr.forEach(q =>{
  160. // const curQArr = q.split('=')
  161. // if (curQArr[0] === 'url') {
  162. // newForm.pri_image = curQArr[1]
  163. // }
  164. // })
  165. // }
  166. newForm.pri_image = this.getImgUrl(newForm.pri_image)
  167. const imgUrlArr = this.imagesArr.map(urlStr => {
  168. return this.getImgUrl(urlStr)
  169. })
  170. newForm.images = imgUrlArr.join(',')
  171. let apiStr = 'admoldhouseadd'
  172. if (this.curObj.id) apiStr = 'admoldhouseedit'
  173. this.$api.house[apiStr](newForm).then(data => {
  174. this.$msgs(newForm.id ? '编辑成功' : '新增成功')
  175. this.productData = []
  176. this.$emit('close', newForm)
  177. })
  178. }
  179. })
  180. } else {
  181. this.$emit('close')
  182. this.productData = []
  183. this.setDefaultValue()
  184. }
  185. },
  186. openMap() { // 定位
  187. this.isShowMap = true
  188. const pointObj = {
  189. latitude: this.cObj.latitude || '',
  190. longitude: this.cObj.longitude || '',
  191. address: this.cObj.address || ''
  192. }
  193. this.$root.$emit('handleMap', pointObj)
  194. },
  195. closeMap(obj) {
  196. if (obj) {
  197. const oldform = this.$refs.ruleForm.baseForm
  198. const newForm = { ...oldform, ...obj }
  199. this.cObj = newForm
  200. this.setDefaultValue(newForm)
  201. }
  202. this.isShowMap = false
  203. }
  204. }
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  208. @import '../../../../styles/libEdit.scss';
  209. .lib-edit {
  210. width: 900px;
  211. padding-top: 0;
  212. padding-left: 0;
  213. padding-bottom: 40px;
  214. ::v-deep .el-form-item {
  215. margin-bottom: 10px;
  216. }
  217. ::v-deep .el-date-editor.el-input {
  218. width: 100%;
  219. }
  220. }
  221. .scoped-other-form {
  222. .scoped-item-two {
  223. .el-input {
  224. display: inline-block;
  225. width: 140px;
  226. margin: 0 10px;
  227. }
  228. }
  229. }
  230. .map-btn{
  231. height: 36px;
  232. }
  233. ::v-deep .el-drawer__header {
  234. margin-bottom: 10px;
  235. }
  236. .scoped-img-area {
  237. text-align: center;
  238. .sia-op {
  239. display: inline-block;
  240. vertical-align: middle;
  241. margin-right: 10px;
  242. margin-bottom: 10px;
  243. border: 1px solid #f2f2f2;
  244. width: 80px;
  245. height: 80px;
  246. overflow: hidden;
  247. .img {
  248. width: 80px;
  249. height: 80px;
  250. }
  251. }
  252. .sia-img {
  253. display: inline-block;
  254. vertical-align: middle;
  255. width: 80px;
  256. height: 80px;
  257. overflow: hidden;
  258. border: 1px dashed #999;
  259. margin-bottom: 10px;
  260. .el-icon-plus {
  261. color: #999;
  262. padding: 30px;
  263. }
  264. }
  265. }
  266. </style>