IndexEdit.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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="[2,4]">
  15. <div class="scoped-form-diy" slot="OI2">
  16. <div class="sfd-item">
  17. <div class="l">地址</div>
  18. <div class="r">
  19. <input type="text" v-model="diyFormObj.addr1" class="i"/>
  20. <div class="dot">栋座</div>
  21. <input type="text" v-model="diyFormObj.addr2" class="i" />
  22. <div class="dot">单元</div>
  23. <input type="text" v-model="diyFormObj.addr3" class="i" />
  24. <div class="dot">室号</div>
  25. </div>
  26. </div>
  27. <div class="sfd-item">
  28. <div class="l">户型</div>
  29. <div class="r">
  30. <input type="text" v-model="diyFormObj.hType1" class="i"/>
  31. <div class="dot">室</div>
  32. <input type="text" v-model="diyFormObj.hType2" class="i" />
  33. <div class="dot">厅</div>
  34. <input type="text" v-model="diyFormObj.hType3" class="i" />
  35. <div class="dot">卫</div>
  36. </div>
  37. </div>
  38. <div class="sfd-item">
  39. <div class="l">楼层</div>
  40. <div class="r">
  41. <input type="text" v-model="cObj.floor" class="i"/>
  42. <div class="dot t2">/</div>
  43. <input type="text" v-model="cObj.storeys" class="i" />
  44. <div class="dot">层</div>
  45. </div>
  46. </div>
  47. <div class="sfd-item">
  48. <div class="l">梯户比</div>
  49. <div class="r">
  50. <input type="text" v-model="diyFormObj.sRate1" class="i"/>
  51. <div class="dot">梯</div>
  52. <input type="text" v-model="diyFormObj.sRate2" class="i" />
  53. <div class="dot">户</div>
  54. </div>
  55. </div>
  56. <div class="sfd-item">
  57. <div class="l">上传视频</div>
  58. <div class="r">
  59. <video
  60. v-if="cObj.video"
  61. controls
  62. muted
  63. loop
  64. width="300"
  65. >
  66. <source
  67. :src="cObj.video"
  68. type="video/mp4"
  69. />
  70. </video>
  71. <div class="tip">上传新的视频:请等待<span class="b">上传成功</span>后再点击顶部的确定保存</div>
  72. <el-upload
  73. class="upload-demo"
  74. ref="upload"
  75. action="https://jsonplaceholder.typicode.com/posts/"
  76. :on-preview="handlePreview"
  77. :on-remove="handleRemove"
  78. :multiple="false"
  79. :limit="1"
  80. :file-list="fileList"
  81. @change="fileChange"
  82. :http-request="submitUpload"
  83. :auto-upload="true">
  84. <el-button slot="trigger" size="small" type="primary">选取新视频</el-button>
  85. <el-button v-if="fileNextResObj.total && fileNextResObj.total.percent === 100" size="small" type="success" style="margin-left: 10px;">{{ fileNextResObj.total ? fileNextResObj.total.percent === 100 ? '上传成功' :`上传中${parseInt(fileNextResObj.total.percent)}%` : '上传到服务器'}}</el-button>
  86. <el-progress v-else-if="fileNextResObj.total" class="tip3" :text-inside="true" :stroke-width="20" :percentage="parseInt(fileNextResObj.total.percent)"></el-progress>
  87. <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->
  88. <!-- v-else-if="fileNextResObj.total" fileNextResObj.total.percent-->
  89. </el-upload>
  90. </div>
  91. </div>
  92. </div>
  93. <div slot="OI4">
  94. <div class="scoped-img-area">
  95. <div class="sia-op" v-for="(imgsrc,index) in imagesArr" :key="index">
  96. <img class="img" :src="imgsrc + '_adm0'" alt="img">
  97. <span class="close" @click="imgDel(index)"></span>
  98. </div>
  99. <el-upload
  100. class="sia-img"
  101. :action="`${domainUrl}/adm/upload/cloud`"
  102. :data="{logic_type: 'estate', token}"
  103. name="upload"
  104. :show-file-list="false"
  105. :on-success="roomAreaUploadSuccess"
  106. :before-upload="roomAreaUploadBefore"
  107. >
  108. <i class="el-icon-plus icon"/>
  109. </el-upload>
  110. </div>
  111. </div>
  112. <div slot="footer">
  113. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  114. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  115. </div>
  116. <div slot="otherItem" style="padding-left: 100px">
  117. <div v-for="(op, index) in historyPriceList" :key="index">{{ op.des }}</div>
  118. </div>
  119. </base-form>
  120. </el-dialog>
  121. <handle-map :is-show="isShowMap" @close="closeMap" />
  122. </div>
  123. </template>
  124. <script>
  125. import { arrToObj } from '@/utils'
  126. import handleMap from '@/components/Common/Map'
  127. import * as qiniu from 'qiniu-js'
  128. export default {
  129. components: { handleMap },
  130. mixins,
  131. props: {
  132. isShow: Boolean,
  133. curObj: Object
  134. },
  135. inject: ['parentData'],
  136. data() {
  137. const token = window.sessionStorage.getItem('fp_token')
  138. let domainUrl = process.env.VUE_APP_BASE_API
  139. return {
  140. domainUrl,
  141. token,
  142. loading: false,
  143. formData: [],
  144. cObj: {},
  145. isShowMap: false,
  146. imagesArr: [],
  147. roomAreaList: [],
  148. estate_id: '',
  149. diyFormObj: {},
  150. fileList: [],
  151. fileConfig: {},
  152. fileNextResObj: {},
  153. fileCompleteResObj: {},
  154. historyPriceList: [],
  155. }
  156. },
  157. created () {
  158. this.$api.base.admuploadtoken().then(res => {
  159. this.fileConfig = res || {}
  160. })
  161. },
  162. watch: {
  163. isShow: function(val) {
  164. if (val) {
  165. if (this.curObj.id) {
  166. this.loading = true
  167. this.$api.house.admeshousedetail({id: this.curObj.id}).then(res => {
  168. let cObj = res || {}
  169. this.historyPriceList = cObj.history_price ? JSON.parse(cObj.history_price) : []
  170. this.imagesArr = cObj.images ? cObj.images.split(',') : []
  171. this.cObj = {...cObj}
  172. this.getDef()
  173. let diyFormObj = {...this.diyFormObj}
  174. const addr = cObj.house_no ? cObj.house_no.split('-') : []
  175. const hType = cObj.house_type ? cObj.house_type.split('-') : []
  176. const sRate = cObj.stairs_rate ? cObj.stairs_rate.split('-') : []
  177. diyFormObj = {
  178. addr1: addr[0],
  179. addr2: addr[1],
  180. addr3: addr[2],
  181. hType1: hType[0],
  182. hType2: hType[1],
  183. hType3: hType[2],
  184. sRate1: sRate[0],
  185. sRate2: sRate[1],
  186. }
  187. this.diyFormObj = {...diyFormObj}
  188. this.loading = false
  189. })
  190. } else {
  191. this.cObj = this.curObj
  192. this.imagesArr = []
  193. this.getDef()
  194. }
  195. }
  196. },
  197. },
  198. methods: {
  199. submitUpload() {
  200. if (this.fileNextResObj.total) {
  201. this.$msgConfrm('正在上传中,如需重新上传,请保存当前页面重新上传')
  202. return
  203. }
  204. const upload = this.$refs.upload || {}
  205. const curFile = upload.uploadFiles[0] || {}
  206. let config = {
  207. useCdnDomain: true,
  208. region: qiniu.region.z2,
  209. debugLogLevel: 'INFO'
  210. }
  211. let putExtra = {
  212. fname: "",
  213. params: {},
  214. mimeType: null
  215. }
  216. let next = (response) =>{
  217. console.log(response)
  218. this.fileNextResObj = response
  219. }
  220. let complete = (response) =>{
  221. let cObj = this.cObj
  222. cObj.video = `${this.fileConfig.domain}/${response.key}`
  223. this.cObj = {...cObj}
  224. }
  225. let subscription;
  226. // 调用sdk上传接口获得相应的observable,控制上传和暂停
  227. let observable = qiniu.upload(curFile.raw, curFile.name, this.fileConfig.token, putExtra, config);
  228. observable.subscribe(next, null, complete)
  229. // this.$refs.upload.submit();
  230. },
  231. handleRemove(file, fileList) {
  232. this.fileNextResObj = {}
  233. let cObj = this.cObj
  234. cObj.video = ''
  235. this.cObj = {...cObj}
  236. console.log(file, fileList);
  237. },
  238. handlePreview(file) {
  239. console.log(file);
  240. },
  241. fileChange (e) {
  242. console.log(e)
  243. },
  244. imgDel (index) {
  245. this.imagesArr.splice(index, 1)
  246. },
  247. roomAreaUploadSuccess(res, file) {
  248. const data = res.data || {}
  249. this.imagesArr.push(`${data.url}`)
  250. },
  251. roomAreaUploadBefore(file) {
  252. const isJPGPNG = file.type === 'image/jpeg' || file.type === 'image/png'
  253. const isLtM = file.size / 1024 / 1024 < 10
  254. if (!isJPGPNG) {
  255. this.$message.error('上传图片只能是 JPG PNG GIF 格式!')
  256. }
  257. if (!isLtM) {
  258. this.$message.error('上传图片大小不能超过 10M!')
  259. }
  260. return isJPGPNG && isLtM
  261. },
  262. getDef (str) {
  263. let params = {}
  264. params = { ...this.cObj }
  265. if (str === 'edit') {
  266. params = {...this.$refs.ruleForm.baseForm, ...params}
  267. }
  268. if (!params.custom_tag) params.custom_tag = '洪楼房源'
  269. if (params.estate_id) {
  270. this.estate_id = params.estate_id
  271. this.formData = [
  272. { label: '所属楼盘', key: 'estate_id', rules: 1, type: 'selectRemote', changeHandle: this.estateChange,
  273. remoteParams: { skey: 'estate_name', api: `house.admestatelist?estate_tag=二手`, opKey: 'estate_name', opVal: 'id' },
  274. remoteOptions: [
  275. { keyRO: params.estate_name, valRO: params.estate_id }
  276. ]
  277. },
  278. // { label: `面积产品户型`, label2: `快捷选择工具`, class: 'c-3', key: `HT`, type: 'select', options: this.roomAreaList, changeHandle: this.htChange,},
  279. { label: '房源标题', key: 'title', rules: 1},
  280. { label: '户型图', key: 'house_img', class: 'c-3', type: 'uploads' },
  281. { label: '房源封面', key: 'pri_image', rules: 1, class: 'c-3', type: 'cuImg',
  282. options: {
  283. w: 375,
  284. h: 250,
  285. SY: 1,
  286. }
  287. },
  288. { label: '面积', key: 'area', class: 'c-3', type: 'inputFont', appendFont: '㎡', rules: [
  289. { validator: (rule, value, callback) => {
  290. if (Number(value) < 0 || isNaN(Number(value))) {
  291. callback(new Error('请输入数字'))
  292. } else {
  293. callback()
  294. }
  295. }, trigger: 'blur' },
  296. ]},
  297. { label: '总价', key: 'price', class: 'c-3', type: 'inputFont', appendFont: '万元', rules: [
  298. { validator: (rule, value, callback) => {
  299. if (Number(value) < 0 || isNaN(Number(value))) {
  300. callback(new Error('请输入数字'))
  301. } else {
  302. callback()
  303. }
  304. }, trigger: 'blur' },
  305. ]},
  306. { label: '实际总价', key: 'floor_price', class: 'c-3', type: 'inputFont', appendFont: '万元', rules: [
  307. { validator: (rule, value, callback) => {
  308. if (Number(value) < 0 || isNaN(Number(value))) {
  309. callback(new Error('请输入数字'))
  310. } else {
  311. callback()
  312. }
  313. }, trigger: 'blur' },
  314. ]},
  315. { label: '业主称呼', class: 'c-3', key: 'owner' },
  316. { label: '业主电话', class: 'c-3', key: 'owner_phone' },
  317. { label: '装修状态', key: 'is_dec', class: 'c-3', type: 'select', options: this.$dictData.room_dec },
  318. { label: '满几年', key: 'full_year', class: 'c-3', type: 'select', options: this.$dictData.house_room_year },
  319. { label: '有电梯', key: 'is_elevator', class: 'c-3', type: 'select', options: this.$dictData.sys_yesno },
  320. { label: '交房时间', key: 'delivery_at', type: 'datePicker', class: 'c-3', type2: 'month', valueFormat: 'yyyy-MM'},
  321. { label: '显示隐藏', key: 'hide_status', class: 'c-3', type: 'select', options: this.$dictData.hide_status },
  322. { label: '户型方位', key: 'position', class: 'c-3', type: 'select', options: this.$dictData.room_position },
  323. { label: '自定义标签', class: 'c-3', key: 'custom_tag', rules: 1 },
  324. { label: '置业经理', key: 'sale_id', rules: 1, class: 'c-3', type: 'selectRemote',
  325. remoteParams: { skey: 'sale_name', api: `user.admsaleuserlist?page_size=999`, opKey: 'sale_name', opVal: 'id' },
  326. remoteOptions: [
  327. { keyRO: params.sale_name, valRO: params.sale_id }
  328. ]
  329. },
  330. { label: '销售状态', key: 'is_sold', class: 'c-3', type: 'select', options: this.$dictData.sys_yesno },
  331. { label: '(对外展示)房源简介', key: 'introduce', type: 'textarea' },
  332. { label: '备注', key: 'remarked', type: 'textarea' },
  333. ]
  334. } else {
  335. this.formData = [
  336. { label: '所属楼盘', key: 'estate_id', rules: 1, type: 'selectRemote', changeHandle: this.estateChange,
  337. remoteParams: { skey: 'estate_name', api: `house.admestatelist?estate_tag=二手`, opKey: 'estate_name', opVal: 'id' },
  338. },
  339. ]
  340. }
  341. params.pri_image = this.IMadd(params.pri_image)
  342. this.setDefaultValue(params)
  343. },
  344. estateChange (estate_id, op, cur) {
  345. if (estate_id) {
  346. this.estate_id = estate_id
  347. this.$api.house.admestatehousearealist({estate_id}).then(res => {
  348. const list = res.list || []
  349. const htObj = arrToObj(this.$dictData.house_type)
  350. const ptObj = arrToObj(this.$dictData.product_type)
  351. list.map(item => {
  352. item.key = `${item.area}㎡-${ptObj[item.product_type]}-${htObj[item.house_type]}`
  353. item.key2 = `${htObj[item.house_type]}`
  354. item.val = item.id
  355. })
  356. this.roomAreaList = [...list]
  357. this.cObj.estate_id = estate_id
  358. this.cObj.area_type = cur.area_type
  359. this.cObj.address = cur.address
  360. this.cObj.latitude = cur.latitude
  361. this.cObj.longitude = cur.longitude
  362. this.cObj.estate_name = cur.estate_name
  363. this.cObj.title = `${cur.estate_name}-${arrToObj(this.$dictData.area_type)[cur.area_type]}`
  364. this.cObj.product_type = ''
  365. this.cObj.house_type = ''
  366. this.cObj.area = ''
  367. this.cObj.house_img = ''
  368. this.cObj.HT = ''
  369. this.getDef('edit')
  370. })
  371. } else {
  372. this.estate_id = ''
  373. }
  374. },
  375. htChange (val) {
  376. this.roomAreaList.forEach(ra => {
  377. if (val === ra.id) {
  378. this.cObj.product_type = ra.product_type
  379. this.cObj.house_type = ra.house_type
  380. this.cObj.area = ra.area
  381. this.cObj.house_img = ra.pri_image
  382. this.cObj.HT = val
  383. this.cObj.title = `${ra.key}(${arrToObj(this.$dictData.area_type)[this.cObj.area_type]})`
  384. this.getDef('edit')
  385. }
  386. return
  387. })
  388. },
  389. close (str) {
  390. if (str === 'confirm') {
  391. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  392. if (valid) {
  393. const oldform = this.$refs.ruleForm.baseForm
  394. const newForm = { ...oldform }
  395. if (this.curObj.id) newForm.id = this.curObj.id
  396. if (this.diyFormObj.addr1 && this.diyFormObj.addr2 && this.diyFormObj.addr3) {
  397. newForm.house_no = `${this.diyFormObj.addr1}-${this.diyFormObj.addr2}-${this.diyFormObj.addr3}`
  398. } else {
  399. this.$msg('请输入楼栋单号房间号')
  400. return
  401. }
  402. if (this.diyFormObj.hType1 && this.diyFormObj.hType2 && this.diyFormObj.hType3) {
  403. newForm.house_type = `${this.diyFormObj.hType1}-${this.diyFormObj.hType2}-${this.diyFormObj.hType3}`
  404. } else {
  405. this.$msg('请输入户型')
  406. return
  407. }
  408. if (this.diyFormObj.sRate1 && this.diyFormObj.sRate2) {
  409. newForm.stairs_rate = `${this.diyFormObj.sRate1}-${this.diyFormObj.sRate2}`
  410. } else {
  411. this.$msg('请输入梯户比')
  412. return
  413. }
  414. if (this.cObj.floor && this.cObj.storeys) {
  415. newForm.floor = this.cObj.floor
  416. newForm.storeys = this.cObj.storeys
  417. } else {
  418. this.$msg('请输入楼层')
  419. return
  420. }
  421. if (this.cObj.video) newForm.video = this.cObj.video
  422. // newForm.longitude = this.cObj.longitude
  423. // newForm.latitude = this.cObj.latitude
  424. // if (!newForm.longitude) return this.$msgw('请选择经度!')
  425. // else if (!newForm.latitude) return this.$msgw('请选择纬度!')
  426. const imgUrlArr = this.imagesArr.map(urlStr => {
  427. return urlStr
  428. })
  429. newForm.images = imgUrlArr.join(',')
  430. newForm.pri_image = this.IMdel(newForm.pri_image)
  431. newForm.custom_tag = newForm.custom_tag.replace(/,|、|\/|\\/g, ',')
  432. let apiStr = 'admeshouseadd'
  433. if (this.curObj.id) apiStr = 'admeshouseedit'
  434. this.$api.house[apiStr](newForm).then(data => {
  435. this.$msgs(newForm.id ? '编辑成功' : '新增成功')
  436. this.productData = []
  437. this.$emit('close', newForm)
  438. })
  439. }
  440. })
  441. } else {
  442. this.$emit('close')
  443. this.productData = []
  444. this.setDefaultValue()
  445. }
  446. },
  447. openMap() { // 定位
  448. this.isShowMap = true
  449. const pointObj = {
  450. latitude: this.cObj.latitude || '',
  451. longitude: this.cObj.longitude || '',
  452. address: this.cObj.address || ''
  453. }
  454. this.$root.$emit('handleMap', pointObj)
  455. },
  456. closeMap(obj) {
  457. if (obj) {
  458. const oldform = this.$refs.ruleForm.baseForm
  459. const newForm = { ...oldform, ...obj }
  460. this.cObj = newForm
  461. this.setDefaultValue(newForm)
  462. }
  463. this.isShowMap = false
  464. }
  465. }
  466. }
  467. </script>
  468. <style lang="scss" scoped>
  469. @import '../../../../styles/libEdit.scss';
  470. .lib-edit {
  471. width: 900px;
  472. padding-top: 0;
  473. padding-left: 0;
  474. padding-bottom: 40px;
  475. &.scoped-le2 {
  476. width: 300px;
  477. }
  478. ::v-deep .el-form-item {
  479. margin-bottom: 10px;
  480. }
  481. ::v-deep .el-date-editor.el-input {
  482. width: 100%;
  483. }
  484. }
  485. .scoped-other-form {
  486. .scoped-item-two {
  487. .el-input {
  488. display: inline-block;
  489. width: 140px;
  490. margin: 0 10px;
  491. }
  492. }
  493. }
  494. .map-btn{
  495. height: 36px;
  496. }
  497. ::v-deep .el-drawer__header {
  498. margin-bottom: 10px;
  499. }
  500. .scoped-img-area {
  501. text-align: left;
  502. padding: 0 40px;
  503. .sia-op {
  504. display: inline-block;
  505. vertical-align: middle;
  506. margin-right: 10px;
  507. margin-bottom: 10px;
  508. border: 1px solid #f2f2f2;
  509. width: 80px;
  510. height: 80px;
  511. position: relative;
  512. &:hover {
  513. .img-big {
  514. display: block;
  515. }
  516. }
  517. .img {
  518. width: 80px;
  519. height: 80px;
  520. }
  521. .close {
  522. position: absolute;
  523. width: 20px;
  524. height: 20px;
  525. top: -10px;
  526. right: -10px;
  527. background: url(../../../../assets/icon_g_close.png) no-repeat;
  528. background-size: 20px;
  529. cursor: pointer;
  530. }
  531. .img-big {
  532. position: absolute;
  533. bottom: 0;
  534. left: 0;
  535. width: 400px;
  536. height: auto;
  537. display: none;
  538. box-shadow: 10px 10px 10px #ccc;
  539. z-index: 99;
  540. }
  541. }
  542. .sia-img {
  543. display: inline-block;
  544. vertical-align: middle;
  545. width: 80px;
  546. height: 80px;
  547. overflow: hidden;
  548. border: 1px dashed #999;
  549. margin-bottom: 10px;
  550. .el-icon-plus {
  551. color: #999;
  552. padding: 30px;
  553. }
  554. }
  555. }
  556. .scoped-form-diy {
  557. width: 100%;
  558. .sfd-item {
  559. padding-bottom: 16px;
  560. display: flex;
  561. .l {
  562. width: 110px;
  563. text-align: right;
  564. padding-right: 12px;
  565. font-size: 14px;
  566. color: #606266;
  567. font-weight: bold;
  568. }
  569. .r {
  570. flex: 1;
  571. }
  572. .tip {
  573. color: #f00;
  574. .b {
  575. font-weight: bold;
  576. display: inline-block;
  577. font-size: 20px;
  578. }
  579. }
  580. .tip2 {
  581. display: inline-block;
  582. width: 300px;
  583. color: #606266;
  584. }
  585. .tip3 {
  586. display: inline-block;
  587. margin-left: 10px;
  588. width: 300px;
  589. }
  590. .i {
  591. border: 0;
  592. border-bottom: 1px solid #dcdcdc;
  593. width: 50px;
  594. text-align: center;
  595. outline: none;
  596. }
  597. .dot {
  598. display: inline-block;
  599. width: 50px;
  600. &.t2 {
  601. text-align: center;
  602. }
  603. }
  604. }
  605. }
  606. </style>