RentEdit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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="estate_id ? '960px' : '360px'"
  11. custom-class="xl-dialog"
  12. center
  13. >
  14. <base-form ref="ruleForm" :class="estate_id ? 'lib-edit' : 'lib-edit scoped-le2' " :data="formData" :is-inline="false" label-width="110px" :insertSlotArr="[8]">
  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 + '_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. <div slot="OI8" class="scoped-other-form">
  35. <el-form-item label="点位坐标" class="scoped-item-two item">
  36. 纬度N<el-input v-model="cObj.latitude" disabled />
  37. 经度E<el-input v-model="cObj.longitude" disabled />
  38. <el-button type="primary" class="map-btn" size="small" @click="openMap">点击从地图获取</el-button>
  39. </el-form-item>
  40. </div>
  41. <div slot="footer">
  42. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  43. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  44. </div>
  45. </base-form>
  46. </el-dialog>
  47. <handle-map :is-show="isShowMap" @close="closeMap" />
  48. </div>
  49. </template>
  50. <script>
  51. import { arrToObj } from '@/utils'
  52. import handleMap from '@/components/Common/Map'
  53. export default {
  54. components: { handleMap },
  55. mixins,
  56. props: {
  57. isShow: Boolean,
  58. curObj: Object
  59. },
  60. inject: ['parentData'],
  61. data() {
  62. const token = window.sessionStorage.getItem('fp_token')
  63. let domainUrl = process.env.VUE_APP_BASE_API
  64. return {
  65. domainUrl,
  66. token,
  67. loading: false,
  68. formData: [],
  69. cObj: {},
  70. isShowMap: false,
  71. imagesArr: [],
  72. roomAreaList: [],
  73. estate_id: '',
  74. }
  75. },
  76. watch: {
  77. isShow: function(val) {
  78. if (val) {
  79. if (this.curObj.id) {
  80. this.loading = true
  81. this.$api.house.admoldhousedetail({id: this.curObj.id}).then(res => {
  82. let curData = res || {}
  83. this.imagesArr = curData.images ? curData.images.split(',') : []
  84. this.cObj = curData || {}
  85. this.getDef()
  86. this.loading = false
  87. })
  88. } else {
  89. this.cObj = this.curObj
  90. this.imagesArr = []
  91. this.getDef()
  92. }
  93. }
  94. },
  95. },
  96. methods: {
  97. imgDel (index) {
  98. this.imagesArr.splice(index, 1)
  99. },
  100. roomAreaUploadSuccess(res, file) {
  101. const data = res.data || {}
  102. this.imagesArr.push(`${data.url}`)
  103. },
  104. roomAreaUploadBefore(file) {
  105. const isJPGPNG = file.type.toLowerCase() === 'image/jpeg' || file.type.toLowerCase() === 'image/png'
  106. const isLtM = file.size / 1024 / 1024 < 500
  107. if (!isJPGPNG) {
  108. this.$message.error('上传图片只能是 JPG PNG GIF 格式!')
  109. }
  110. if (!isLtM) {
  111. this.$message.error('上传图片大小不能超过 500M!')
  112. }
  113. return isJPGPNG && isLtM
  114. },
  115. getDef (str) {
  116. let params = {}
  117. params = { ...this.cObj }
  118. if (str === 'edit') {
  119. params = {...this.$refs.ruleForm.baseForm, ...params}
  120. }
  121. if (!params.custom_tag) params.custom_tag = '洪楼房源'
  122. if (params.estate_id) {
  123. this.estate_id = params.estate_id
  124. this.formData = [
  125. { label: '所属楼盘', key: 'estate_id', rules: 1, type: 'selectRemote', changeHandle: this.estateChange,
  126. remoteParams: { skey: 'estate_name', api: `house.admestatelist?estate_tag=二手`, opKey: 'estate_name', opVal: 'id' },
  127. remoteOptions: [
  128. { keyRO: params.estate_name, valRO: params.estate_id }
  129. ]
  130. },
  131. { label: `面积产品户型`, label2: `快捷选择工具`, key: `HT`, type: 'select', options: this.roomAreaList, changeHandle: this.htChange,},
  132. { label: '面积', key: 'area', class: 'c-3', type: 'inputFont', appendFont: '㎡', rules: [
  133. { validator: (rule, value, callback) => {
  134. if (Number(value) < 0 || isNaN(Number(value))) {
  135. callback(new Error('请输入数字'))
  136. } else {
  137. callback()
  138. }
  139. }, trigger: 'blur' },
  140. ]},
  141. { label: '产品类型', key: 'product_type', class: 'c-3', type: 'select', options: this.$dictData.product_type},
  142. { label: '房源户型', key: 'house_type', class: 'c-3', type: 'select', options: this.$dictData.house_type},
  143. { label: '房源标题', key: 'title', rules: 1},
  144. { label: '户型图', key: 'house_img', class: 'c-3', type: 'upload' },
  145. { label: '房源封面', key: 'pri_image', rules: 1, class: 'c-3', type: 'cuImg',
  146. options: {
  147. w: 375,
  148. h: 250,
  149. SY: 1,
  150. }
  151. },
  152. { label: '房源地址', key: 'address', class: 'c-3s' },
  153. { label: '区域', key: 'area_type', class: 'c-3', type: 'select', options: this.$dictData.area_type},
  154. { label: '总价', key: 'price', class: 'c-3', type: 'inputFont', appendFont: '万元', rules: [
  155. { validator: (rule, value, callback) => {
  156. if (Number(value) < 0 || isNaN(Number(value))) {
  157. callback(new Error('请输入数字'))
  158. } else {
  159. callback()
  160. }
  161. }, trigger: 'blur' },
  162. ]},
  163. { label: '层高', class: 'c-3', key: 'floor_height', rules: [
  164. { validator: (rule, value, callback) => {
  165. if (Number(value) < 0 || isNaN(Number(value))) {
  166. callback(new Error('请输入数字'))
  167. } else {
  168. callback()
  169. }
  170. }, trigger: 'blur' },
  171. ] },
  172. { label: '总层数', class: 'c-3', key: 'height', rules: [
  173. { validator: (rule, value, callback) => {
  174. if (Number(value) < 0 || isNaN(Number(value))) {
  175. callback(new Error('请输入数字'))
  176. } else {
  177. callback()
  178. }
  179. }, trigger: 'blur' },
  180. ] },
  181. { label: '详细地址', label2: '如:1栋2单元305室', class: 'c-3', key: 'detail_address' },
  182. { label: '装修状态', key: 'is_dec', class: 'c-3', type: 'select', options: this.$dictData.room_dec },
  183. { label: '业主称呼', class: 'c-3', key: 'owner' },
  184. { label: '业主电话', class: 'c-3', key: 'phone' },
  185. { label: '自定义标签', class: 'c-3', key: 'custom_tag', rules: 1 },
  186. { label: '置业经理', key: 'sale_id', rules: 1, class: 'c-3', type: 'selectRemote',
  187. remoteParams: { skey: 'sale_name', api: `user.admsaleuserlist?page_size=999`, opKey: 'sale_name', opVal: 'id' },
  188. remoteOptions: [
  189. { keyRO: params.sale_name, valRO: params.sale_id }
  190. ]
  191. },
  192. { label: '(对外展示)房源简介', key: 'introduce', type: 'textarea' },
  193. { label: '备注', key: 'remarked', type: 'textarea' },
  194. ]
  195. } else {
  196. this.formData = [
  197. { label: '所属楼盘', key: 'estate_id', rules: 1, type: 'selectRemote', changeHandle: this.estateChange,
  198. remoteParams: { skey: 'estate_name', api: `house.admestatelist?estate_tag=二手`, opKey: 'estate_name', opVal: 'id' },
  199. },
  200. ]
  201. }
  202. params.pri_image = this.IMadd(params.pri_image)
  203. this.setDefaultValue(params)
  204. },
  205. estateChange (estate_id, op, cur) {
  206. if (estate_id) {
  207. this.estate_id = estate_id
  208. this.$api.house.admestatehousearealist({estate_id}).then(res => {
  209. const list = res.list || []
  210. const htObj = arrToObj(this.$dictData.house_type)
  211. const ptObj = arrToObj(this.$dictData.product_type)
  212. list.map(item => {
  213. item.key = `${item.area}㎡-${ptObj[item.product_type]}-${htObj[item.house_type]}`
  214. item.key2 = `${htObj[item.house_type]}`
  215. item.val = item.id
  216. })
  217. this.roomAreaList = [...list]
  218. this.cObj.estate_id = estate_id
  219. this.cObj.area_type = cur.area_type
  220. this.cObj.address = cur.address
  221. this.cObj.latitude = cur.latitude
  222. this.cObj.longitude = cur.longitude
  223. this.cObj.estate_name = cur.estate_name
  224. this.cObj.title = `${cur.estate_name}-${arrToObj(this.$dictData.area_type)[cur.area_type]}`
  225. this.cObj.product_type = ''
  226. this.cObj.house_type = ''
  227. this.cObj.area = ''
  228. this.cObj.house_img = ''
  229. this.cObj.HT = ''
  230. this.getDef('edit')
  231. })
  232. } else {
  233. this.estate_id = ''
  234. }
  235. },
  236. htChange (val) {
  237. this.roomAreaList.forEach(ra => {
  238. if (val === ra.id) {
  239. this.cObj.product_type = ra.product_type
  240. this.cObj.house_type = ra.house_type
  241. this.cObj.area = ra.area
  242. this.cObj.house_img = ra.pri_image
  243. this.cObj.HT = val
  244. this.cObj.title = `${ra.key}(${arrToObj(this.$dictData.area_type)[this.cObj.area_type]})`
  245. this.getDef('edit')
  246. }
  247. return
  248. })
  249. },
  250. close (str) {
  251. if (str === 'confirm') {
  252. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  253. if (valid) {
  254. const oldform = this.$refs.ruleForm.baseForm
  255. const newForm = { ...oldform }
  256. if (this.curObj.id) newForm.id = this.curObj.id
  257. newForm.longitude = this.cObj.longitude
  258. newForm.latitude = this.cObj.latitude
  259. if (!newForm.longitude) return this.$msgw('请选择经度!')
  260. else if (!newForm.latitude) return this.$msgw('请选择纬度!')
  261. const imgUrlArr = this.imagesArr.map(urlStr => {
  262. return urlStr
  263. })
  264. newForm.images = imgUrlArr.join(',')
  265. newForm.pri_image = this.IMdel(newForm.pri_image)
  266. newForm.custom_tag = newForm.custom_tag.replace(/,|、|\/|\\/g, ',')
  267. let apiStr = 'admrenthouseadd'
  268. if (this.curObj.id) apiStr = 'admrenthouseedit'
  269. this.$api.house[apiStr](newForm).then(data => {
  270. this.$msgs(newForm.id ? '编辑成功' : '新增成功')
  271. this.productData = []
  272. this.$emit('close', newForm)
  273. })
  274. }
  275. })
  276. } else {
  277. this.$emit('close')
  278. this.productData = []
  279. this.setDefaultValue()
  280. }
  281. },
  282. openMap() { // 定位
  283. this.isShowMap = true
  284. const pointObj = {
  285. latitude: this.cObj.latitude || '',
  286. longitude: this.cObj.longitude || '',
  287. address: this.cObj.address || ''
  288. }
  289. this.$root.$emit('handleMap', pointObj)
  290. },
  291. closeMap(obj) {
  292. if (obj) {
  293. const oldform = this.$refs.ruleForm.baseForm
  294. const newForm = { ...oldform, ...obj }
  295. this.cObj = newForm
  296. this.setDefaultValue(newForm)
  297. }
  298. this.isShowMap = false
  299. }
  300. }
  301. }
  302. </script>
  303. <style lang="scss" scoped>
  304. @import '../../../../styles/libEdit.scss';
  305. .lib-edit {
  306. width: 900px;
  307. padding-top: 0;
  308. padding-left: 0;
  309. padding-bottom: 40px;
  310. &.scoped-le2 {
  311. width: 300px;
  312. }
  313. ::v-deep .el-form-item {
  314. margin-bottom: 10px;
  315. }
  316. ::v-deep .el-date-editor.el-input {
  317. width: 100%;
  318. }
  319. }
  320. .scoped-other-form {
  321. .scoped-item-two {
  322. .el-input {
  323. display: inline-block;
  324. width: 140px;
  325. margin: 0 10px;
  326. }
  327. }
  328. }
  329. .map-btn{
  330. height: 36px;
  331. }
  332. ::v-deep .el-drawer__header {
  333. margin-bottom: 10px;
  334. }
  335. .scoped-img-area {
  336. text-align: left;
  337. width: 280px;
  338. .sia-op {
  339. display: inline-block;
  340. vertical-align: middle;
  341. margin-right: 10px;
  342. margin-bottom: 10px;
  343. border: 1px solid #f2f2f2;
  344. width: 80px;
  345. height: 80px;
  346. position: relative;
  347. &:hover {
  348. .img-big {
  349. display: block;
  350. }
  351. }
  352. .img {
  353. width: 80px;
  354. height: 80px;
  355. }
  356. .close {
  357. position: absolute;
  358. width: 20px;
  359. height: 20px;
  360. top: -10px;
  361. right: -10px;
  362. background: url(../../../../assets/icon_g_close.png) no-repeat;
  363. background-size: 20px;
  364. cursor: pointer;
  365. }
  366. .img-big {
  367. position: absolute;
  368. bottom: 0;
  369. left: 0;
  370. width: 400px;
  371. height: auto;
  372. display: none;
  373. box-shadow: 10px 10px 10px #ccc;
  374. z-index: 99;
  375. }
  376. }
  377. .sia-img {
  378. display: inline-block;
  379. vertical-align: middle;
  380. width: 80px;
  381. height: 80px;
  382. overflow: hidden;
  383. border: 1px dashed #999;
  384. margin-bottom: 10px;
  385. .el-icon-plus {
  386. color: #999;
  387. padding: 30px;
  388. }
  389. }
  390. }
  391. </style>