IndexEdit.vue 20 KB

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