瑶都万能墙
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

592 lines
13 KiB

1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. <template>
  2. <view class="page">
  3. <navbar :title="isEdit ? '编辑租房' : '发布租房'" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="form">
  5. <view class="help-issue">
  6. <text>租房标题</text>
  7. <text style="color: #BD3624;">*</text>
  8. </view>
  9. <view class="form-sheet-cell">
  10. <input type="text" class="title-input" v-model="form.title"/>
  11. </view>
  12. <uv-cell
  13. title="租房地点"
  14. rightIconStyle="fontSize: 30rpx;"
  15. :value="form.address || '请选择租房地点'"
  16. @click="selectAddr"
  17. isLink
  18. ></uv-cell>
  19. <uv-cell
  20. title="朝向"
  21. rightIconStyle="fontSize: 30rpx;"
  22. :value="form.face || '请选择朝向'"
  23. @click="openPicker('face')"
  24. isLink
  25. ></uv-cell>
  26. <uv-cell
  27. title="装修"
  28. rightIconStyle="fontSize: 30rpx;"
  29. :value="form.decoration || '请选择装修'"
  30. @click="openPicker('decoration')"
  31. isLink
  32. ></uv-cell>
  33. <!-- <uv-cell
  34. title="楼层"
  35. rightIconStyle="fontSize: 30rpx;"
  36. value="请选择楼层"
  37. isLink
  38. ></uv-cell> -->
  39. <!-- <view class="form-sheet-cell">
  40. <view class="label">
  41. 租房地点
  42. </view>
  43. <view class="price">
  44. <input placeholder="请输入租房地点" v-model="form.address" />
  45. </view>
  46. </view> -->
  47. <view class="form-sheet-cell">
  48. <view class="label">
  49. 楼层
  50. </view>
  51. <view class="price">
  52. <input placeholder="请输入楼层(1楼)" v-model="form.floor" />
  53. </view>
  54. </view>
  55. <view class="form-sheet-cell">
  56. <view class="label">
  57. 户型
  58. </view>
  59. <view class="price">
  60. <input placeholder="请输入户型(三室一厅)" v-model="form.home" />
  61. </view>
  62. </view>
  63. <view class="form-sheet-cell">
  64. <view class="label">
  65. 付款方式
  66. </view>
  67. <view class="price">
  68. <input placeholder="请输入付款方式(押一付三)" v-model="form.payment" />
  69. </view>
  70. </view>
  71. <view class="form-sheet-cell">
  72. <view class="label">
  73. 租金/
  74. </view>
  75. <view class="price">
  76. <input placeholder="请输入租金" type="text" v-model="form.money" />
  77. </view>
  78. </view>
  79. <view class="form-sheet-cell">
  80. <view class="label">
  81. 面积
  82. </view>
  83. <view class="price">
  84. <input placeholder="请输入面积(平方米)" type="number" v-model="form.crm" />
  85. </view>
  86. </view>
  87. <view class="form-sheet-cell">
  88. <view class="label">
  89. 看房
  90. </view>
  91. <uv-radio-group v-model="form.showings">
  92. <view class="price">
  93. <uv-radio
  94. :customStyle="{margin: '8px'}"
  95. iconSize="30rpx"
  96. size="40rpx"
  97. labelSize="26rpx"
  98. :label="t.name"
  99. v-for="(t, i) in showingsRadio"
  100. :key="i"
  101. :name="t.name">
  102. </uv-radio>
  103. </view>
  104. </uv-radio-group>
  105. </view>
  106. <view class="form-sheet-cell">
  107. <view class="label">
  108. 电梯
  109. </view>
  110. <uv-radio-group v-model="form.lift">
  111. <view class="price">
  112. <uv-radio
  113. :customStyle="{margin: '8px'}"
  114. iconSize="30rpx"
  115. size="40rpx"
  116. labelSize="26rpx"
  117. :label="t.name"
  118. :name="t.name"
  119. v-for="(t, i) in liftRadio"
  120. :key="i">
  121. </uv-radio>
  122. </view>
  123. </uv-radio-group>
  124. </view>
  125. <view class="form-sheet-cell">
  126. <view class="label">
  127. 交付
  128. </view>
  129. <uv-radio-group v-model="form.deliver">
  130. <view class="price">
  131. <uv-radio
  132. :customStyle="{margin: '8px'}"
  133. iconSize="30rpx"
  134. size="40rpx"
  135. labelSize="26rpx"
  136. :label="t.name"
  137. :name="t.name"
  138. v-for="(t, i) in deliverRadio"
  139. :key="i">
  140. </uv-radio>
  141. </view>
  142. </uv-radio-group>
  143. </view>
  144. <view class="form-sheet-cell">
  145. <view class="label">
  146. 联系电话
  147. </view>
  148. <input placeholder="请输入联系电话" v-model="form.phone" />
  149. </view>
  150. <view class="form-sheet-cell">
  151. <view class="label">
  152. 备注
  153. </view>
  154. <input placeholder="请输入备注" v-model="form.titleSub" />
  155. </view>
  156. <view class="images box">
  157. <view class="">
  158. 精选照片
  159. </view>
  160. <uv-upload
  161. :fileList="fileList"
  162. :maxCount="imageMax"
  163. multiple
  164. width="150rpx"
  165. height="150rpx"
  166. @delete="deleteImage"
  167. @afterRead="afterRead"
  168. :previewFullImage="true"></uv-upload>
  169. </view>
  170. <view class="category">
  171. <view class="title">
  172. 选择地区
  173. </view>
  174. <view class="tagList">
  175. <view
  176. :class="{act : t.id == form.addId}"
  177. @click="form.addId = t.id"
  178. v-for="(t, i) in cityList"
  179. :key="i">
  180. {{ t.name }}
  181. </view>
  182. </view>
  183. </view>
  184. <!-- <view class="">
  185. <uv-textarea
  186. v-model="form.content"
  187. count
  188. :maxlength="300"
  189. autoHeight
  190. placeholder="请输入详细介绍"></uv-textarea>
  191. </view> -->
  192. <uv-picker
  193. ref="picker"
  194. :columns="columns"
  195. @confirm="pickerConfirm"></uv-picker>
  196. <view class="uni-color-btn"
  197. @click="submit">
  198. {{ isEdit ? '保存修改' : '发布' }}
  199. </view>
  200. <!-- 编辑模式下显示删除按钮 -->
  201. <view v-if="isEdit" class="delete-btn"
  202. @click="deleteRenting">
  203. 删除租房
  204. </view>
  205. </view>
  206. </view>
  207. </template>
  208. <script>
  209. import { Position } from '@/utils/position.js'
  210. import { mapState } from 'vuex'
  211. import { subscribeBeforePublish } from '@/utils/subscribeMessage.js'
  212. export default {
  213. data() {
  214. return {
  215. rentingId: '', // 租房ID,用于编辑模式
  216. isEdit: false, // 是否为编辑模式
  217. form : {
  218. addId : '',//地区id
  219. address : '',//地址
  220. crm : '',//面积
  221. showings : '随时可看',//看房
  222. face : '',
  223. lift : '有',
  224. deliver : '整租',
  225. floor : '',
  226. decoration : '',
  227. title: '', // 租房标题
  228. home: '', // 户型
  229. payment: '', // 付款方式
  230. money: '', // 租金
  231. phone: '', // 联系电话
  232. titleSub: '', // 备注
  233. latitude: '', // 纬度
  234. longitude: '', // 经度
  235. },
  236. showingsRadio : [//看房
  237. {
  238. name : '随时可看',
  239. },
  240. {
  241. name : '电话预约',
  242. },
  243. ],
  244. liftRadio : [
  245. {
  246. name : '有',
  247. },
  248. {
  249. name : '无',
  250. },
  251. ],
  252. deliverRadio : [
  253. {
  254. name : '整租',
  255. },
  256. {
  257. name : '合租',
  258. },
  259. ],
  260. fileList : [],
  261. imageMax : 9,
  262. picker : {
  263. face : [
  264. '朝东',
  265. '朝南',
  266. '朝西',
  267. '朝北',
  268. ],
  269. decoration : [
  270. '精装',
  271. '毛胚',
  272. ],
  273. },
  274. pickerKey : '',
  275. }
  276. },
  277. onLoad(options) {
  278. // 检查是否是编辑模式
  279. if (options.id) {
  280. this.rentingId = options.id
  281. this.isEdit = true
  282. this.getRentingDetail()
  283. } else {
  284. // 新增模式,设置默认地区
  285. if (this.cityList && this.cityList.length > 0) {
  286. this.form.addId = this.cityList[0].id
  287. }
  288. }
  289. },
  290. computed : {
  291. columns(){
  292. return [this.picker[this.pickerKey]]
  293. },
  294. ...mapState(['cityList', 'category']),
  295. },
  296. watch: {
  297. // 监听cityList变化,用于处理异步加载的城市数据
  298. cityList: {
  299. handler(newVal) {
  300. if (newVal && newVal.length > 0 && !this.isEdit && !this.form.addId) {
  301. this.form.addId = newVal[0].id
  302. }
  303. },
  304. immediate: true
  305. }
  306. },
  307. methods: {
  308. // 获取租房详情数据
  309. getRentingDetail() {
  310. this.$api('getRentDetail', { id: this.rentingId }, res => {
  311. if (res.code == 200) {
  312. const data = res.result
  313. // 回显基本信息
  314. this.form = {
  315. ...this.form,
  316. title: data.title || '',
  317. address: data.address || '',
  318. face: data.face || '',
  319. decoration: data.decoration || '',
  320. floor: data.floor || '',
  321. home: data.home || '',
  322. payment: data.payment || '',
  323. money: data.money || '',
  324. crm: data.crm || '',
  325. showings: data.showings || '随时可看',
  326. lift: data.lift || '有',
  327. deliver: data.deliver || '整租',
  328. phone: data.phone || '',
  329. titleSub: data.titleSub || '',
  330. addId: data.addId || (this.cityList.length > 0 ? this.cityList[0].id : ''),
  331. latitude: data.latitude || '',
  332. longitude: data.longitude || '',
  333. }
  334. // 回显图片
  335. if (data.image) {
  336. const images = data.image.split(',').filter(img => img.trim())
  337. this.fileList = images.map(url => ({ url: url.trim() }))
  338. }
  339. } else {
  340. uni.showToast({
  341. title: res.msg || '获取租房信息失败',
  342. icon: 'none'
  343. })
  344. }
  345. })
  346. },
  347. openPicker(key){
  348. this.pickerKey = key
  349. this.$refs.picker.open()
  350. },
  351. pickerConfirm(e){
  352. this.form[this.pickerKey] = e.value[0]
  353. },
  354. deleteImage(e){
  355. this.fileList.splice(e.index, 1)
  356. },
  357. afterRead(e){
  358. let self = this
  359. e.file.forEach(file => {
  360. self.$Oss.ossUpload(file.url).then(url => {
  361. self.fileList.push({
  362. url
  363. })
  364. })
  365. })
  366. },
  367. //地图上选择地址
  368. selectAddr() {
  369. Position.selectAddress(this.form.latitude || 0, this.form.longitude || 0, res => {
  370. //经纬度信息
  371. this.form.latitude = res.latitude
  372. this.form.longitude = res.longitude
  373. if (res.name) {
  374. return this.form.address = res.name
  375. }
  376. this.form.address = ''
  377. })
  378. },
  379. // 提交
  380. async submit(){
  381. if (this.$utils.verificationAll(this.form, {
  382. title: '请输入标题',
  383. address : '请选择租房地点',
  384. face : '请选择朝向',
  385. decoration : '请选择装修',
  386. floor : '请输入楼层',
  387. home : '请输入户型',
  388. payment : '请输入付款方式',
  389. money : '请输入租金',
  390. crm : '请输入面积',
  391. showings : '请选择看房',
  392. lift : '请选择电梯',
  393. deliver : '请选择交付方式',
  394. phone: '请输入联系电话',
  395. })) {
  396. return
  397. }
  398. if(this.fileList.length == 0){
  399. return uni.showToast({
  400. title: '请上传精选照片',
  401. icon : 'none'
  402. })
  403. }
  404. // 只有在新发布时才订阅消息通知,编辑时不需要
  405. if (!this.isEdit) {
  406. const subscribed = await subscribeBeforePublish()
  407. if (!subscribed) {
  408. return // 用户拒绝订阅,停止发布
  409. }
  410. }
  411. // 处理图片数据
  412. this.form.image = this.fileList.map(n => n.url).join(',')
  413. // 根据是否是编辑模式调用不同的API
  414. const apiName = this.isEdit ? 'editMyRent' : 'publishRent'
  415. const params = this.isEdit ? { ...this.form, id: this.rentingId } : this.form
  416. this.$api(apiName, params, res => {
  417. if(res.code == 200){
  418. uni.showToast({
  419. title: this.isEdit ? '修改成功!' : '发布成功!',
  420. icon: 'none'
  421. })
  422. setTimeout(() => {
  423. uni.navigateBack()
  424. }, 1000)
  425. } else {
  426. uni.showToast({
  427. title: res.msg || (this.isEdit ? '修改失败' : '发布失败'),
  428. icon: 'none'
  429. })
  430. }
  431. })
  432. },
  433. // 删除租房
  434. deleteRenting() {
  435. uni.showModal({
  436. title: '确认删除',
  437. content: '确定要删除这个租房信息吗?删除后无法恢复。',
  438. confirmColor: '#ff4757',
  439. success: (res) => {
  440. if (res.confirm) {
  441. this.$api('deleteMyRent', { id: this.rentingId }, res => {
  442. if (res.code == 200) {
  443. uni.showToast({
  444. title: '删除成功!',
  445. icon: 'none'
  446. })
  447. setTimeout(() => {
  448. uni.navigateBack()
  449. }, 1000)
  450. } else {
  451. uni.showToast({
  452. title: res.msg || '删除失败',
  453. icon: 'none'
  454. })
  455. }
  456. })
  457. }
  458. }
  459. })
  460. },
  461. }
  462. }
  463. </script>
  464. <style scoped lang="scss">
  465. .page{
  466. background-color: #fff;
  467. min-height: 100vh;
  468. box-sizing: border-box;
  469. color: #333333;
  470. font-size: 28rpx;
  471. /deep/ text{
  472. font-size: 28rpx !important;
  473. }
  474. .form{
  475. padding: 30rpx;
  476. .help-issue {
  477. margin: 20rpx;
  478. }
  479. .title-input{
  480. border: 1px solid $uni-color;
  481. width: 100%;
  482. border-radius: 10rpx;
  483. padding: 10rpx 20rpx;
  484. box-sizing: border-box;
  485. height: 65rpx;
  486. }
  487. .form-sheet-cell{
  488. display: flex;
  489. background-color: #fff;
  490. padding: 20rpx 30rpx;
  491. align-items: center;
  492. .label{
  493. width: 160rpx;
  494. }
  495. .price{
  496. display: flex;
  497. // text-align: center;
  498. input{
  499. width: 450rpx;
  500. // border: 1px solid $uni-color;
  501. margin: 0 10rpx;
  502. }
  503. }
  504. .right-icon{
  505. margin-left: auto;
  506. }
  507. }
  508. .images{
  509. padding: 30rpx;
  510. view{
  511. padding-bottom: 20rpx;
  512. }
  513. }
  514. }
  515. .delete-btn {
  516. background: #ff4757;
  517. color: white;
  518. text-align: center;
  519. padding: 20rpx;
  520. margin: 30rpx;
  521. border-radius: 40rpx;
  522. font-size: 28rpx;
  523. font-weight: bold;
  524. &:active {
  525. background: #ff3742;
  526. }
  527. }
  528. .category{
  529. padding: 20rpx;
  530. .title{
  531. // font-weight: 900;
  532. // font-size: 30rpx;
  533. }
  534. .tagList{
  535. display: flex;
  536. flex-wrap: wrap;
  537. padding: 10rpx 0;
  538. view{
  539. background: rgba($uni-color, 0.1);
  540. padding: 10rpx 20rpx;
  541. margin: 10rpx;
  542. border-radius: 10rpx;
  543. font-size: 26rpx;
  544. }
  545. .act{
  546. color: #fff;
  547. background: $uni-color;
  548. }
  549. }
  550. }
  551. }
  552. </style>