IndexEdit.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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="[17,18]">
  15. <div slot="OI17" class="scoped-product">
  16. <div class="sp-item" v-for="(product, one) in productData" :key="one">
  17. <div class="sp-title">{{product.product_type_name}}</div>
  18. <div class="sp-content">
  19. <el-form-item label="产品最低均价">
  20. <el-input v-model="product.price_min" placeholder="请输入产品类型最低均价"></el-input>
  21. </el-form-item>
  22. <el-form-item label="产品最高均价">
  23. <el-input v-model="product.price_max" placeholder="请输入产品类型最大高价"></el-input>
  24. </el-form-item>
  25. <el-form-item label="户型">
  26. <el-select v-model="product.house_type_list_val" placeholder="请选择" :multiple="true" @change="houseTypeChange(one)">
  27. <el-option
  28. v-for="item in $dictData.house_type"
  29. :key="item.val"
  30. :label="item.key"
  31. :value="item.val">
  32. </el-option>
  33. </el-select>
  34. </el-form-item>
  35. <div class="room-box">
  36. <div class="room-item" v-for="(room, two) in product.house_type_list" :key="two">
  37. <div class="ri-title">{{room.house_type_name}}
  38. <el-button type="small" icon="el-icon-plus" class="xl-form-btn xs t3" @click="roomAreaAdd(one, two)">添加</el-button>
  39. </div>
  40. <div class="ri-content">
  41. <div class="ri-op" v-for="(area, three) in room.area_list" :key="three">
  42. <el-upload
  43. class="ri-img"
  44. :action="`${domainUrl}/adm/upload/picture`"
  45. :data="{logic_type: 'estate', token}"
  46. name="upload"
  47. :show-file-list="false"
  48. :on-success="roomAreaUploadSuccess"
  49. :on-error="roomAreaUploadError"
  50. :before-upload="roomAreaUploadBefore"
  51. >
  52. <img v-if="area.img_url" :src="area.img_url" class="img" @click="roomAreaUploadImg(one, two, three)">
  53. <i v-else class="el-icon-plus icon" @click="roomAreaUploadImg(one, two, three)"/>
  54. </el-upload>
  55. <div class="ri-deal">
  56. <input class="ri-input" v-model="area.area" type="text" placeholder="输面积">
  57. <span class="ri-del" @click="roomAreaDel(one, two, three)">删除</span>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <div slot="OI18" class="scoped-other-form">
  67. <el-form-item label="点位坐标" class="scoped-item-two item">
  68. 纬度N<el-input v-model="cObj.latitude" disabled />
  69. 经度E<el-input v-model="cObj.longitude" disabled />
  70. <el-button type="primary" class="map-btn" size="small" @click="openMap">点击从地图获取</el-button>
  71. </el-form-item>
  72. </div>
  73. </base-form>
  74. <div class="xl-form">
  75. <div class="xl-form-footer fixed" style="width:960px;padding-top: 20px;border-top: 1px solid #dcdcdc;right:0;">
  76. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  77. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  78. </div>
  79. </div>
  80. </el-drawer>
  81. <handle-map :is-show="isShowMap" @close="closeMap" />
  82. </div>
  83. </template>
  84. <script>
  85. import { arrToObj } from '@/utils'
  86. import handleMap from '@/components/Common/Map'
  87. export default {
  88. components: { handleMap },
  89. mixins,
  90. props: {
  91. isShow: Boolean,
  92. curObj: Object
  93. },
  94. inject: ['parentData'],
  95. data() {
  96. const token = window.sessionStorage.getItem('fp_token')
  97. let domainUrl = process.env.VUE_APP_BASE_API
  98. return {
  99. domainUrl,
  100. token,
  101. loading: false,
  102. formData: [],
  103. cObj: {},
  104. isShowMap: false,
  105. productData: [],
  106. tempImgIndex: [0, 0, 0],
  107. }
  108. },
  109. watch: {
  110. isShow: function(val) {
  111. if (val) {
  112. if (this.curObj.id) {
  113. this.loading = true
  114. this.$api.house.admestatedetail({id: this.curObj.id}).then(res => {
  115. let curData = res || {}
  116. if (curData.house_type) curData.house_type = curData.house_type.split(',')
  117. if (curData.product_type) curData.product_type = curData.product_type.split(',')
  118. if (curData.hospital_type) curData.hospital_type = curData.hospital_type.split(',')
  119. if (curData.high_street) curData.high_street = curData.high_street.split(',')
  120. if (curData.park_type) curData.park_type = curData.park_type.split(',')
  121. if (curData.metro_line) curData.metro_line = curData.metro_line.split(',')
  122. if (curData.metro_type) curData.metro_type = curData.metro_type.split(',')
  123. curData.pri_image = `${curData.domain}${curData.pri_image}?url=${curData.pri_image}`
  124. this.cObj = curData || {}
  125. let productData = curData.area_data || []
  126. productData.map(one =>{
  127. one.product_type_name = arrToObj(this.$dictData.product_type)[one.product_type_val]
  128. let houseTypeList = one.house_type_list || []
  129. one.house_type_list_val = []
  130. houseTypeList.map(two => {
  131. two.house_type_name = arrToObj(this.$dictData.house_type)[two.house_type_val]
  132. one.house_type_list_val.push(String(two.house_type_val))
  133. const areaList = two.area_list || []
  134. areaList.map(three =>{
  135. three.img_url = `${curData.domain}${three.img_url}?url=${three.img_url}`
  136. })
  137. })
  138. })
  139. this.productData = [...productData]
  140. this.getDef()
  141. this.loading = false
  142. })
  143. } else {
  144. this.cObj = this.curObj
  145. this.getDef()
  146. }
  147. }
  148. },
  149. },
  150. methods: {
  151. houseTypeChange (one) {
  152. let productData = [...this.productData]
  153. let tempList = []
  154. let houseTypeList = productData[one].house_type_list || []
  155. const curVal = productData[one].house_type_list_val ||[]
  156. curVal.forEach(v =>{
  157. let cObj = {
  158. house_type_name: arrToObj(this.$dictData.house_type)[v],
  159. house_type_val: v,
  160. area_list: [{img_url: '', area: ''}]
  161. }
  162. houseTypeList.forEach((h, hIndex) =>{
  163. if (v === String(h.house_type_val)) {
  164. cObj.area_list = houseTypeList[hIndex].area_list || []
  165. }
  166. })
  167. tempList.push(cObj)
  168. })
  169. productData[one].house_type_list = tempList
  170. this.productData = [...productData]
  171. },
  172. roomAreaDel (one, two, three) {
  173. let productData = [...this.productData]
  174. productData[one].house_type_list[two].area_list.splice(three, 1)
  175. this.productData = [...productData]
  176. },
  177. roomAreaAdd (one, two) {
  178. let productData = [...this.productData]
  179. productData[one].house_type_list[two].area_list.push({img_url: '', area: ''})
  180. this.productData = [...productData]
  181. },
  182. roomAreaUploadImg (one, two, three) {
  183. this.tempImgIndex = [one, two, three]
  184. },
  185. roomAreaUploadSuccess(res, file) {
  186. const data = res.data || {}
  187. let productData = [...this.productData]
  188. productData[this.tempImgIndex[0]].house_type_list[this.tempImgIndex[1]].area_list[this.tempImgIndex[2]].img_url = `${data.domain}${data.url}?url=${data.url}&id=${data.file_id}`
  189. this.productData = [...productData]
  190. },
  191. roomAreaUploadError(file) {
  192. // this.changeHandle(file)
  193. },
  194. roomAreaUploadBefore(file) {
  195. const isJPGPNG = file.type === 'image/jpeg' || file.type === 'image/png'
  196. const isLt2M = file.size / 1024 / 1024 < 2
  197. if (!isJPGPNG) {
  198. this.$message.error('上传图片只能是 JPG PNG 格式!')
  199. }
  200. if (!isLt2M) {
  201. this.$message.error('上传图片大小不能超过 400k!')
  202. }
  203. return isJPGPNG && isLt2M
  204. },
  205. metroLineChange (val) {
  206. this.getDef('change', 'metro_line')
  207. },
  208. productTypeChange (val, op, item) {
  209. const valArr = [...val]
  210. const productData = [...this.productData]
  211. let newArr = []
  212. valArr.forEach(v => {
  213. let vObj = {
  214. product_type_name: arrToObj(this.$dictData.product_type)[v],
  215. product_type_val: v,
  216. }
  217. productData.forEach(old =>{
  218. if (v === String(old.product_type_val)) {
  219. vObj = {...old}
  220. }
  221. })
  222. newArr.push(vObj)
  223. })
  224. this.productData = [...newArr]
  225. },
  226. getDef (str, strKey, strParams) {
  227. let params = {}
  228. if (str === 'change') {
  229. params = {...this.cObj, ...this.$refs.ruleForm.baseForm}
  230. } else {
  231. params = { ...this.cObj }
  232. }
  233. let metroLine = params.metro_line || []
  234. let metroTypeArr = []
  235. if (str === 'change' && strKey === 'metro_line') params.metro_type = ''
  236. const metroTypeAll = this.$dictData.metro_type || []
  237. metroTypeAll.map(item => {
  238. metroLine.map(mline => {
  239. if (item.option1.indexOf(mline) > -1) {
  240. metroTypeArr.push(item)
  241. }
  242. })
  243. })
  244. let disabled = false
  245. if (params.id) disabled = true
  246. const remoteOptionsSchoolList = []
  247. if (params.school_list) {
  248. params.school_id_list = params.school_list.map(item => {
  249. remoteOptionsSchoolList.push({ keyRO: item.school_name, valRO: item.id })
  250. return item.id
  251. })
  252. } else {
  253. params.school_id_list = []
  254. }
  255. this.formData = [
  256. { label: '楼盘名称', key: 'estate_name' },
  257. { label: '所属区域', key: 'area_type', type: 'select', class: 'c-3', options: this.$dictData.area_type },
  258. { label: '地铁线路', key: 'metro_line', type: 'select', class: 'c-3', options: this.$dictData.metro_line, changeHandle: this.metroLineChange, multiple: true },
  259. { label: '地铁站名', key: 'metro_type', type: 'select', class: 'c-3', options: metroTypeArr, multiple: true},
  260. { label: '周边医院', key: 'hospital_type', type: 'select', class: 'c-3', options: this.$dictData.hospital_type, multiple: true },
  261. { label: '周边商圈', key: 'high_street', type: 'select', class: 'c-3', options: this.$dictData.high_street, multiple: true },
  262. { label: '周边公园', key: 'park_type', type: 'select', class: 'c-3', options: this.$dictData.park_type, multiple: true },
  263. { label: '建设时间', key: 'build_time', class: 'c-3', type: 'datePicker', type2: 'month', valueFormat: 'yyyy-MM'},
  264. { label: '竣工时间', key: 'complete_time', class: 'c-3', type: 'datePicker', type2: 'month', valueFormat: 'yyyy-MM'},
  265. { label: '容积率', key: 'plot_ratio', class: 'c-3', type: 'inputFont', appendFont: '%'},
  266. { label: '占地面积', key: 'acreage', class: 'c-3', type: 'inputFont', appendFont: '㎡'},
  267. { label: '建筑面积', key: 'built_up_area', class: 'c-3', type: 'inputFont', appendFont: '㎡'},
  268. { label: '总户数', key: 'household', class: 'c-3', type: 'inputFont', appendFont: '户'},
  269. { label: '物业公司', key: 'property_type', class: 'c-3'},
  270. { label: '物业费', key: 'property_fee', class: 'c-3'},
  271. { label: '车位数量', key: 'parking', class: 'c-3'},
  272. { label: '产品类型', key: 'product_type', type: 'select', options: this.$dictData.product_type, multiple: true, changeHandle: this.productTypeChange},
  273. // { label: '房型', key: 'house_type', type: 'select', options: this.$dictData.house_type, multiple: true},
  274. // { label: '面积', label2: '多个面积英文逗号,分开(如:100,120)', key: 'house_area', type: 'inputFont', appendFont: '㎡'},
  275. // { label: '均价范围1', key: 'price_min', class: 'c-3', type: 'inputFont', appendFont: '元(最小)'},
  276. // { label: '均价范围2', key: 'price_max', class: 'c-3', type: 'inputFont', appendFont: '元(最大)'},
  277. { label: '就读学校', key: 'school_id_list', type: 'selectRemote', multiple: true,
  278. remoteParams: { skey: 'school_name', api: `house.admschoollist`, opKey: 'school_name', opVal: 'id' },
  279. remoteOptions: remoteOptionsSchoolList
  280. },
  281. { label: '楼盘地址', key: 'address' },
  282. { label: '不利因素', key: 'minus_points' },
  283. { label: '楼盘图', key: 'pri_image', class: 'c-3', type: 'upload' },
  284. { label: '简评', key: 'remarked', class: 'c-3s', type: 'textarea' },
  285. ]
  286. this.setDefaultValue(params)
  287. },
  288. close (str) {
  289. if (str === 'confirm') {
  290. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  291. if (valid) {
  292. const oldform = this.$refs.ruleForm.baseForm
  293. const newForm = { ...oldform }
  294. if (this.curObj.id) newForm.id = this.curObj.id
  295. if (newForm.school_id_list && newForm.school_id_list.length > 0) {
  296. newForm.school_id_list = newForm.school_id_list.join(',')
  297. } else {
  298. newForm.school_id_list = ''
  299. }
  300. newForm.longitude = this.cObj.longitude
  301. newForm.latitude = this.cObj.latitude
  302. if (!newForm.longitude) return this.$msgw('请选择经度!')
  303. else if (!newForm.latitude) return this.$msgw('请选择纬度!')
  304. if (newForm.pri_image && newForm.pri_image.indexOf('?') > -1) {
  305. const imgArr = newForm.pri_image.split('?')
  306. const queryArr = imgArr[1].split('&')
  307. queryArr.forEach(q =>{
  308. const curQArr = q.split('=')
  309. if (curQArr[0] === 'url') {
  310. newForm.pri_image = curQArr[1]
  311. }
  312. })
  313. }
  314. if (newForm.house_type) newForm.house_type = newForm.house_type.join(',')
  315. if (newForm.product_type) newForm.product_type = newForm.product_type.join(',')
  316. if (newForm.hospital_type) newForm.hospital_type = newForm.hospital_type.join(',')
  317. if (newForm.high_street) newForm.high_street = newForm.high_street.join(',')
  318. if (newForm.park_type) newForm.park_type = newForm.park_type.join(',')
  319. if (newForm.metro_line) newForm.metro_line = newForm.metro_line.join(',')
  320. if (newForm.metro_type) newForm.metro_type = newForm.metro_type.join(',')
  321. let productData = this.productData || []
  322. productData.map(one => {
  323. const houseTypeList = one.house_type_list || []
  324. houseTypeList.map(two => {
  325. const areaList = two.area_list || []
  326. areaList.map(three =>{
  327. if (three.img_url && three.img_url.indexOf('?') > -1) {
  328. const imgArr = three.img_url.split('?')
  329. const queryArr = imgArr[1].split('&')
  330. queryArr.forEach(q =>{
  331. const curQArr = q.split('=')
  332. if (curQArr[0] === 'url') {
  333. three.img_url = curQArr[1]
  334. }
  335. })
  336. }
  337. })
  338. })
  339. })
  340. if (productData.length === 0) {
  341. newForm.area_data = ''
  342. } else {
  343. newForm.area_data = JSON.stringify([...productData])
  344. }
  345. let apiStr = 'admestateadd'
  346. if (this.curObj.id) apiStr = 'admestateedit'
  347. this.$api.house[apiStr](newForm).then(data => {
  348. this.$msgs(newForm.id ? '编辑成功' : '新增成功')
  349. this.productData = []
  350. this.$emit('close', newForm)
  351. })
  352. }
  353. })
  354. } else {
  355. this.$emit('close')
  356. this.productData = []
  357. this.setDefaultValue()
  358. }
  359. },
  360. openMap() { // 定位
  361. this.isShowMap = true
  362. const pointObj = {
  363. latitude: this.cObj.latitude || '',
  364. longitude: this.cObj.longitude || '',
  365. address: this.cObj.address || ''
  366. }
  367. this.$root.$emit('handleMap', pointObj)
  368. },
  369. closeMap(obj) {
  370. if (obj) {
  371. const oldform = this.$refs.ruleForm.baseForm
  372. const newForm = { ...oldform, ...obj }
  373. this.cObj = newForm
  374. this.setDefaultValue(newForm)
  375. }
  376. this.isShowMap = false
  377. }
  378. }
  379. }
  380. </script>
  381. <style lang="scss" scoped>
  382. @import '../../../../styles/libEdit.scss';
  383. .lib-edit {
  384. width: 900px;
  385. padding-top: 0;
  386. padding-left: 0;
  387. padding-bottom: 40px;
  388. ::v-deep .el-form-item {
  389. margin-bottom: 10px;
  390. }
  391. ::v-deep .el-date-editor.el-input {
  392. width: 100%;
  393. }
  394. }
  395. .scoped-other-form {
  396. .scoped-item-two {
  397. .el-input {
  398. display: inline-block;
  399. width: 140px;
  400. margin: 0 10px;
  401. }
  402. }
  403. }
  404. .map-btn{
  405. height: 36px;
  406. }
  407. ::v-deep .el-drawer__header {
  408. margin-bottom: 10px;
  409. }
  410. .scoped-product {
  411. width: 100%;
  412. .sp-item {
  413. border: 1px solid #dcdcdc;
  414. margin-bottom: 10px;
  415. margin-left: 55px;
  416. margin-right: 30px;
  417. border-radius: 10px;
  418. }
  419. .sp-title {
  420. background: #dcdcdc;
  421. font-weight: bold;
  422. padding: 10px;
  423. border-top-left-radius: 10px;
  424. border-top-right-radius: 10px;
  425. font-size: 14px;
  426. color: #666;
  427. }
  428. .sp-content {
  429. padding: 10px 10px 0;
  430. }
  431. }
  432. .room-box {
  433. margin: 0 20px 10px 80px;
  434. .room-item {
  435. background: #f7f7f7;
  436. border-radius: 10px;
  437. padding: 10px;
  438. margin-bottom: 10px;
  439. }
  440. .ri-title {
  441. color: #666;
  442. margin-bottom: 10px;
  443. }
  444. .ri-op {
  445. text-align: center;
  446. display: inline-block;
  447. vertical-align: middle;
  448. margin-right: 20px;
  449. }
  450. .ri-img {
  451. display: inline-block;
  452. vertical-align: middle;
  453. width: 80px;
  454. height: 80px;
  455. overflow: hidden;
  456. border: 1px dashed #999;
  457. img {
  458. width: 80px;
  459. height: 80px;
  460. }
  461. .el-icon-plus {
  462. color: #999;
  463. padding: 30px;
  464. }
  465. }
  466. .ri-deal {
  467. display: inline-block;
  468. vertical-align: middle;
  469. width: 50px;
  470. }
  471. .ri-input {
  472. width: 50px;
  473. border: 1px solid #dcdcdc;
  474. height: 30px;
  475. text-align: center;
  476. border-radius: 0;
  477. outline: none;
  478. color: #666;
  479. font-size: 12px;
  480. margin-top: -5px;
  481. }
  482. .ri-del {
  483. font-size: 12px;
  484. background: #e6a23c;
  485. color: #fff;
  486. width: 100%;
  487. height: 26px;
  488. line-height: 26px;
  489. margin-top: 10px;
  490. cursor: pointer;
  491. display: inline-block;
  492. }
  493. }
  494. </style>