IndexEdit.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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', type: 'inputFont', appendFont: '/㎡' },
  283. { label: '户型面积区间', key: 'built_area', class: 'c-3', type: 'inputFont', appendFont: '㎡' },
  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. newForm.custom_tag = newForm.custom_tag.replace(',', ',')
  336. newForm.stairs_rate = newForm.stairs_rate.replace(',', ',')
  337. productData.map(one => {
  338. const houseTypeList = one.house_type_list || []
  339. houseTypeList.map(two => {
  340. const areaList = two.area_list || []
  341. areaList.map(three =>{
  342. if (three.img_url && three.img_url.indexOf('?') > -1) {
  343. const imgArr = three.img_url.split('?')
  344. const queryArr = imgArr[1].split('&')
  345. queryArr.forEach(q =>{
  346. const curQArr = q.split('=')
  347. if (curQArr[0] === 'url') {
  348. three.img_url = curQArr[1]
  349. }
  350. })
  351. }
  352. })
  353. })
  354. })
  355. if (productData.length === 0) {
  356. newForm.area_data = ''
  357. } else {
  358. newForm.area_data = JSON.stringify([...productData])
  359. }
  360. let apiStr = 'admestateadd'
  361. if (this.curObj.id) apiStr = 'admestateedit'
  362. this.$api.house[apiStr](newForm).then(data => {
  363. this.$msgs(newForm.id ? '编辑成功' : '新增成功')
  364. this.productData = []
  365. this.$emit('close', newForm)
  366. })
  367. }
  368. })
  369. } else {
  370. this.$emit('close')
  371. this.productData = []
  372. this.setDefaultValue()
  373. }
  374. },
  375. openMap() { // 定位
  376. this.isShowMap = true
  377. const pointObj = {
  378. latitude: this.cObj.latitude || '',
  379. longitude: this.cObj.longitude || '',
  380. address: this.cObj.address || ''
  381. }
  382. this.$root.$emit('handleMap', pointObj)
  383. },
  384. closeMap(obj) {
  385. if (obj) {
  386. const oldform = this.$refs.ruleForm.baseForm
  387. const newForm = { ...oldform, ...obj }
  388. this.cObj = newForm
  389. this.setDefaultValue(newForm)
  390. }
  391. this.isShowMap = false
  392. }
  393. }
  394. }
  395. </script>
  396. <style lang="scss" scoped>
  397. @import '../../../../styles/libEdit.scss';
  398. .lib-edit {
  399. width: 900px;
  400. padding-top: 0;
  401. padding-left: 0;
  402. padding-bottom: 40px;
  403. ::v-deep .el-form-item {
  404. margin-bottom: 10px;
  405. }
  406. ::v-deep .el-date-editor.el-input {
  407. width: 100%;
  408. }
  409. }
  410. .scoped-other-form {
  411. .scoped-item-two {
  412. .el-input {
  413. display: inline-block;
  414. width: 140px;
  415. margin: 0 10px;
  416. }
  417. }
  418. }
  419. .map-btn{
  420. height: 36px;
  421. }
  422. ::v-deep .el-drawer__header {
  423. margin-bottom: 10px;
  424. }
  425. .scoped-product {
  426. width: 100%;
  427. .sp-item {
  428. border: 1px solid #dcdcdc;
  429. margin-bottom: 10px;
  430. margin-left: 55px;
  431. margin-right: 30px;
  432. border-radius: 10px;
  433. }
  434. .sp-title {
  435. background: #dcdcdc;
  436. font-weight: bold;
  437. padding: 10px;
  438. border-top-left-radius: 10px;
  439. border-top-right-radius: 10px;
  440. font-size: 14px;
  441. color: #666;
  442. }
  443. .sp-content {
  444. padding: 10px 10px 0;
  445. }
  446. }
  447. .room-box {
  448. margin: 0 20px 10px 80px;
  449. .room-item {
  450. background: #f7f7f7;
  451. border-radius: 10px;
  452. padding: 10px;
  453. margin-bottom: 10px;
  454. }
  455. .ri-title {
  456. color: #666;
  457. margin-bottom: 10px;
  458. }
  459. .ri-op {
  460. text-align: center;
  461. display: inline-block;
  462. vertical-align: middle;
  463. margin-right: 20px;
  464. margin-bottom: 10px;
  465. }
  466. .ri-img {
  467. display: inline-block;
  468. vertical-align: middle;
  469. width: 82px;
  470. height: 82px;
  471. border: 1px dashed #999;
  472. position: relative;
  473. box-sizing: border-box;
  474. &:hover {
  475. .ri-img-big {
  476. display: block;
  477. }
  478. }
  479. img {
  480. width: 80px;
  481. height: 80px;
  482. }
  483. .ri-img-big {
  484. position: absolute;
  485. top: 0;
  486. left: 0;
  487. width: 400px;
  488. height: auto;
  489. display: none;
  490. box-shadow: 10px 10px 10px #ccc;
  491. z-index: 99;
  492. }
  493. .el-icon-plus {
  494. color: #999;
  495. padding: 30px;
  496. }
  497. }
  498. .ri-deal {
  499. display: inline-block;
  500. vertical-align: middle;
  501. width: 50px;
  502. }
  503. .ri-input {
  504. width: 50px;
  505. border: 1px solid #dcdcdc;
  506. height: 30px;
  507. text-align: center;
  508. border-radius: 0;
  509. outline: none;
  510. color: #666;
  511. font-size: 12px;
  512. margin-top: -5px;
  513. }
  514. .ri-del {
  515. font-size: 12px;
  516. background: #e6a23c;
  517. color: #fff;
  518. width: 100%;
  519. height: 26px;
  520. line-height: 26px;
  521. margin-top: 10px;
  522. cursor: pointer;
  523. display: inline-block;
  524. }
  525. }
  526. </style>