IndexEdit.vue 13 KB

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