租房小程序前端代码
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.

284 lines
6.9 KiB

  1. <template>
  2. <view>
  3. <!-- 房源列表 -->
  4. <view class="se-pb-200">
  5. <view v-if="list.length > 0">
  6. <view @click="onDetail(item)" class="se-my-10 se-mx-20 se-px-20 se-py-20 se-br-20 se-bgc-white se-flex se-pos" v-for="(item, index) in list" :key="index">
  7. <view class="se-pos se-w-260 se-h-180">
  8. <image v-if="item.iconImage" class="se-a-80 se-pos-lt" :src="item.iconImage" mode=""></image>
  9. <image class="se-w-260 se-h-180 se-br-10" :src="item.images && item.images[0] ? item.images[0] : '/static/image/header.png'" mode="aspectFill"></image>
  10. </view>
  11. <view class="se-pl-10 se-w-p-100">
  12. <view class="se-c-black se-fs-28">
  13. {{ item.title }}
  14. </view>
  15. <view class="se-flex se-flex-h-sb se-flex-ai-c se-fs-24 se-mt-10 se-c-66">
  16. <text>{{ item.homeType }}</text>
  17. <text v-if="item.timeGo">{{ item.timeGo }}</text>
  18. </view>
  19. <view class="se-flex se-flex-h-sb se-flex-ai-c se-mt-10">
  20. <template v-if="item.iconTitles && item.iconTitles.length > 0">
  21. <view class="se-flex">
  22. <view class="se-display-ib se-c-white se-bgc-orange se-fs-22 se-br-8 se-px-10 se-py-5 se-mr-10" v-for="(tag, tagIndex) in item.iconTitles" :key="tagIndex">
  23. {{ tag }}
  24. </view>
  25. </view>
  26. </template>
  27. <template v-else><view></view></template>
  28. <view class="se-c-66 se-flex se-flex-ai-c">
  29. <uv-icon name="eye"></uv-icon>
  30. <text class="se-ml-5 se-fs-18">{{ item.num || 0 }}</text>
  31. </view>
  32. </view>
  33. <view class="se-flex se-flex-h-sb se-flex-ai-c se-mt-10">
  34. <text class="se-c-red se-fs-24 se-fw-6 se-toe-1">{{ item.price }}/{{ item.unit }}</text>
  35. <text class="se-c-66 se-fs-22 se-toe-1">{{ item.address }}</text>
  36. </view>
  37. </view>
  38. <!-- 操作按钮 -->
  39. <view class="action-buttons">
  40. <view class="action-btn edit-btn" @click.stop="onEdit(item)">
  41. <uv-icon name="edit-pen" size="16"></uv-icon>
  42. <text>编辑</text>
  43. </view>
  44. <view class="action-btn delete-btn" @click.stop="onDelete(item)">
  45. <uv-icon name="trash" size="16"></uv-icon>
  46. <text>删除</text>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 空状态 -->
  52. <view v-else class="empty-container">
  53. <uv-empty mode="list" text="暂无发布的房源"></uv-empty>
  54. <view class="empty-tip">快去发布您的第一套房源吧</view>
  55. <view class="publish-btn" @click="goToPublish">
  56. <uv-button type="primary" text="立即发布" customStyle="background-color: #1EC77A; border-radius: 30px;"></uv-button>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import { MyHousePageList, deleteHouse } from "@/common/api.js"
  64. export default {
  65. data() {
  66. return {
  67. list: [],
  68. pageNo: 1,
  69. pageSize: 10,
  70. loading: false
  71. }
  72. },
  73. onLoad() {
  74. // 设置页面标题
  75. uni.setNavigationBarTitle({
  76. title: '我发布的房源'
  77. })
  78. this.loadMyHouses()
  79. },
  80. onShow() {
  81. // 页面显示时刷新数据
  82. this.refreshData()
  83. },
  84. onPullDownRefresh() {
  85. this.refreshData()
  86. },
  87. onReachBottom() {
  88. this.loadMore()
  89. },
  90. methods: {
  91. // 加载我发布的房源
  92. loadMyHouses() {
  93. if (this.loading) return
  94. this.loading = true
  95. const params = {
  96. pageNo: this.pageNo,
  97. pageSize: this.pageSize
  98. }
  99. MyHousePageList(params).then(response => {
  100. uni.stopPullDownRefresh()
  101. this.loading = false
  102. if (response && response.result && response.result.records) {
  103. // 处理图片和标签数据
  104. response.result.records.forEach(item => {
  105. if (item.image) {
  106. item.images = item.image.split(',')
  107. } else {
  108. item.images = []
  109. }
  110. if (item.homeImage) {
  111. item.homeImages = item.homeImage.split(',')
  112. } else {
  113. item.homeImages = []
  114. }
  115. if (item.iconTitle) {
  116. item.iconTitles = item.iconTitle.split(',')
  117. } else {
  118. item.iconTitles = []
  119. }
  120. })
  121. if (this.pageNo === 1) {
  122. this.list = response.result.records
  123. } else {
  124. this.list = this.list.concat(response.result.records)
  125. }
  126. }
  127. }).catch(error => {
  128. uni.stopPullDownRefresh()
  129. this.loading = false
  130. console.error('获取房源列表失败:', error)
  131. uni.showToast({
  132. title: '获取数据失败',
  133. icon: 'none'
  134. })
  135. })
  136. },
  137. // 刷新数据
  138. refreshData() {
  139. this.pageNo = 1
  140. this.list = []
  141. this.loadMyHouses()
  142. },
  143. // 加载更多
  144. loadMore() {
  145. this.pageNo += 1
  146. this.loadMyHouses()
  147. },
  148. // 查看房源详情
  149. onDetail(item) {
  150. uni.navigateTo({
  151. url: `/pages_subpack/detail/index?id=${item.id}`
  152. })
  153. },
  154. // 编辑房源
  155. onEdit(item) {
  156. // 根据房源类型跳转到对应的编辑页面
  157. let editUrl = '/pages_subpack/house/index'
  158. // 根据房源分类判断跳转页面
  159. if (item.category === 'farmhouse') {
  160. editUrl = '/pages_subpack/house/farmhouse'
  161. } else if (item.category === 'commercial') {
  162. editUrl = '/pages_subpack/house/commercial'
  163. } else if (item.category === 'other') {
  164. editUrl = '/pages_subpack/house/other'
  165. }
  166. uni.navigateTo({
  167. url: `${editUrl}?id=${item.id}&mode=edit`
  168. })
  169. },
  170. // 删除房源
  171. onDelete(item) {
  172. uni.showModal({
  173. title: '确认删除',
  174. content: '确定要删除这个房源吗?删除后无法恢复。',
  175. cancelText: '取消',
  176. confirmText: '删除',
  177. confirmColor: '#ff4757',
  178. success: (res) => {
  179. if (res.confirm) {
  180. this.deleteHouse(item.id)
  181. }
  182. }
  183. })
  184. },
  185. // 执行删除
  186. deleteHouse(houseId) {
  187. uni.showLoading({
  188. title: '删除中...'
  189. })
  190. deleteHouse({ id: houseId }).then(response => {
  191. uni.hideLoading()
  192. uni.showToast({
  193. title: '删除成功',
  194. icon: 'success'
  195. })
  196. // 刷新列表
  197. this.refreshData()
  198. }).catch(error => {
  199. uni.hideLoading()
  200. console.error('删除房源失败:', error)
  201. uni.showToast({
  202. title: '删除失败',
  203. icon: 'none'
  204. })
  205. })
  206. },
  207. // 去发布房源
  208. goToPublish() {
  209. uni.navigateTo({
  210. url: '/pages_subpack/house/select'
  211. })
  212. }
  213. }
  214. }
  215. </script>
  216. <style>
  217. page {
  218. background-color: #f5f5f5;
  219. }
  220. /* 操作按钮样式 */
  221. .action-buttons {
  222. position: absolute;
  223. top: 20rpx;
  224. right: 20rpx;
  225. display: flex;
  226. gap: 10rpx;
  227. }
  228. .action-btn {
  229. display: flex;
  230. flex-direction: column;
  231. align-items: center;
  232. padding: 8rpx 12rpx;
  233. border-radius: 10rpx;
  234. background: rgba(255, 255, 255, 0.95);
  235. box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.1);
  236. font-size: 20rpx;
  237. min-width: 60rpx;
  238. }
  239. .edit-btn {
  240. color: #1EC77A;
  241. }
  242. .delete-btn {
  243. color: #ff4757;
  244. }
  245. /* 空状态样式 */
  246. .empty-container {
  247. padding: 100rpx 40rpx;
  248. text-align: center;
  249. }
  250. .empty-tip {
  251. margin: 30rpx 0;
  252. font-size: 28rpx;
  253. color: #666;
  254. }
  255. .publish-btn {
  256. margin-top: 40rpx;
  257. }
  258. </style>