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

336 lines
7.8 KiB

3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
  1. <template>
  2. <view>
  3. <view class="se-bgc-white se-pb-20 se-pt-30 se-px-40">
  4. <uv-search @search="onSearch()" placeholder="搜索租房信息" :showAction="false" v-model="keyword"></uv-search>
  5. </view>
  6. <view class="se-pb-10 se-px-40 se-bgc-white">
  7. <uv-drop-down ref="dropDown" sign="dropDown_1" text-active-color="#20CD7D"
  8. :extra-icon="{name:'arrow-down-fill',color:'#666',size:'26rpx'}"
  9. :extra-active-icon="{name:'arrow-up-fill',color:'#20CD7D',size:'26rpx'}" :defaultValue="defaultValue"
  10. :custom-style="{padding: '0rpx 0rpx',borderBottom:'1rpx solid transparent'}" @click="selectMenu">
  11. <uv-drop-down-item name="region" type="2" :label="dropItem('region').label" :value="dropItem('region').value">
  12. </uv-drop-down-item>
  13. <uv-drop-down-item name="rent" type="2" :label="dropItem('rent').label" :value="dropItem('rent').value">
  14. </uv-drop-down-item>
  15. <uv-drop-down-item name="type" type="2" :label="dropItem('type').label" :value="dropItem('type').value">
  16. </uv-drop-down-item>
  17. <uv-drop-down-item name="duration" type="2" :label="dropItem('duration').label" :value="dropItem('duration').value">
  18. </uv-drop-down-item>
  19. <!-- <uv-drop-down-item name="vip_type" type="1" label='VIP文档' :value="dropItem('vip_type').value">
  20. </uv-drop-down-item> -->
  21. </uv-drop-down>
  22. <uv-drop-down-popup sign="dropDown_1" :click-overlay-on-close="true" :currentDropItem="currentDropItem"
  23. @clickItem="clickItem" @popupChange="change"></uv-drop-down-popup>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import { houseArea,houseIconClass,housePrice,houseYear } from "@/common/api.js"
  29. export default {
  30. onPageScroll() {
  31. // 滚动后及时更新位置
  32. this.$refs.dropDown.init();
  33. },
  34. computed: {
  35. dropItem(name) {
  36. return (name) => {
  37. const result = {};
  38. const find = this.result.find(item => item.name === name);
  39. if (find) {
  40. result.label = find.label;
  41. result.value = find.value;
  42. } else {
  43. result.label = this[name].label;
  44. result.value = this[name].value;
  45. }
  46. return result;
  47. }
  48. },
  49. // 获取当前下拉筛选项
  50. currentDropItem() {
  51. return this[this.activeName];
  52. }
  53. },
  54. data() {
  55. return {
  56. keyword: "",
  57. // 表示value等于这些值,就属于默认值
  58. defaultValue: ['all', 'all', 'all','all'],
  59. // 筛选结果
  60. result: [],
  61. region:{
  62. label: '区域',
  63. value: 'all',
  64. activeIndex: 0,
  65. color: '#333',
  66. activeColor: '#20CD7D',
  67. child: [
  68. // {
  69. // label: '全部区域',
  70. // value: 'all'
  71. // }, {
  72. // label: '湖南',
  73. // value: 'hunan'
  74. // }, {
  75. // label: '广州',
  76. // value: 'guangzhou'
  77. // },
  78. ]
  79. },
  80. rent:{
  81. label: '租金',
  82. value: 'all',
  83. activeIndex: 0,
  84. color: '#333',
  85. activeColor: '#20CD7D',
  86. child: [
  87. // {
  88. // label: '全部',
  89. // value: 'all'
  90. // },
  91. // {
  92. // label: '0-2k',
  93. // value: '2000'
  94. // }, {
  95. // label: '2k-4k',
  96. // value: '4000'
  97. // }, {
  98. // label: '4k-6k',
  99. // value: '6000'
  100. // }, {
  101. // label: '6k+',
  102. // value: '6000+'
  103. // },
  104. ]
  105. },
  106. type: {
  107. label: '类型',
  108. value: 'all',
  109. activeIndex: 0,
  110. color: '#333',
  111. activeColor: '#20CD7D',
  112. child: [
  113. // {
  114. // label: '全部',
  115. // value: 'all'
  116. // }, {
  117. // label: '闲置散居农房',
  118. // value: 'nongfang'
  119. // }, {
  120. // label: '鱼塘',
  121. // value: 'yutang'
  122. // }, {
  123. // label: '耕地',
  124. // value: 'gengdi'
  125. // },
  126. ]
  127. },
  128. duration:{
  129. label: '年限',
  130. value: 'all',
  131. activeIndex: 0,
  132. color: '#333',
  133. activeColor: '#20CD7D',
  134. child: [
  135. // {
  136. // label: '全部',
  137. // value: 'all'
  138. // },
  139. // {
  140. // label: '5年内',
  141. // value: '0-5'
  142. // }, {
  143. // label: '5-10年',
  144. // value: '5-10'
  145. // }, {
  146. // label: '10-20年',
  147. // value: '10-20'
  148. // },
  149. ]
  150. },
  151. activeName: 'region',
  152. vip_type: {
  153. label: 'VIP文档',
  154. value: 0,
  155. activeIndex: 0
  156. }
  157. }
  158. },
  159. mounted() {
  160. let that = this
  161. // setTimeout(()=>{
  162. that.onhouseArea()
  163. that.onhouseIconClass()
  164. that.onhousePrice()
  165. that.onhouseYear()
  166. // },2000)
  167. console.info('组件')
  168. // houseArea,houseIconClass,housePrice,houseYear
  169. },
  170. methods: {
  171. onhouseArea(){
  172. let that = this
  173. houseArea({}).then(response=>{
  174. let arr = [
  175. {
  176. label: '全部',
  177. value: 'all'
  178. }
  179. ]
  180. response.result.forEach(items=>{
  181. let obj = {}
  182. obj.label=items.title;
  183. obj.value=items.id
  184. arr.push(obj)
  185. })
  186. that.region.child=arr
  187. console.info('houseArea',response.result)
  188. }).catch(error=>{
  189. })
  190. },
  191. onhouseIconClass(){
  192. let that = this
  193. houseIconClass({}).then(response=>{
  194. console.info(response.result)
  195. let arr = [
  196. {
  197. label: '全部',
  198. value: 'all'
  199. }
  200. ]
  201. response.result.forEach(items=>{
  202. let obj = {}
  203. obj.label=items.title;
  204. obj.value=items.id
  205. arr.push(obj)
  206. })
  207. that.type.child=arr
  208. }).catch(error=>{
  209. })
  210. },
  211. onhousePrice(){
  212. let that = this
  213. housePrice({}).then(response=>{
  214. let arr = [
  215. {
  216. label: '全部',
  217. value: 'all'
  218. }
  219. ]
  220. response.result.forEach(items=>{
  221. let obj = {}
  222. obj.label=items.title;
  223. obj.value=items.price
  224. arr.push(obj)
  225. })
  226. that.rent.child=arr
  227. }).catch(error=>{
  228. })
  229. },
  230. onhouseYear(){
  231. let that = this
  232. houseYear({}).then(response=>{
  233. console.info(response.result)
  234. let arr = [
  235. {
  236. label: '全部',
  237. value: 'all'
  238. }
  239. ]
  240. response.result.forEach(items=>{
  241. let obj = {}
  242. obj.label=items.title;
  243. obj.value=items.timeGo
  244. arr.push(obj)
  245. })
  246. that.duration.child=arr
  247. }).catch(error=>{
  248. })
  249. },
  250. onSearch(){
  251. this.$emit("onSearch",this.keyword)
  252. },
  253. change(e) {
  254. console.log('弹窗打开状态:', e);
  255. },
  256. /**
  257. * 点击每个筛选项回调
  258. * @param {Object} e { name, active, type } = e
  259. */
  260. selectMenu(e) {
  261. const {
  262. name,
  263. active,
  264. type
  265. } = e;
  266. this.activeName = name;
  267. // type 等于1 的需要特殊处理:type不等于1可以忽略
  268. if (type == 1) {
  269. this.clickItem({
  270. name: 'vip_type',
  271. label: 'VIP文档',
  272. value: e.active ? 1 : 0
  273. });
  274. } else {
  275. const find = this.result.find(item => item.name == this.activeName);
  276. if (find) {
  277. const findIndex = this[this.activeName].child.findIndex(item => item.label == find.label && item
  278. .value == find.value);
  279. this[this.activeName].activeIndex = findIndex;
  280. } else {
  281. this[this.activeName].activeIndex = 0;
  282. }
  283. }
  284. },
  285. /**
  286. * 点击菜单回调处理
  287. * @param {Object} item 选中项 { label,value } = e
  288. */
  289. clickItem(e) {
  290. // 下面有重新赋值,所以用let
  291. let {
  292. label,
  293. value
  294. } = e;
  295. this.result.push({
  296. name: this.activeName,
  297. label,
  298. value
  299. });
  300. const findIndex = this.result.findIndex(item => item.name == this.activeName);
  301. if (this.defaultValue.indexOf(value) > -1 && this[this.activeName].label) {
  302. label = this[this.activeName].label;
  303. }
  304. // 已经存在筛选项
  305. if (findIndex > -1) {
  306. this.$set(this.result, findIndex, {
  307. name: this.activeName,
  308. label,
  309. value
  310. })
  311. } else {
  312. this.result.push({
  313. name: this.activeName,
  314. label,
  315. value
  316. });
  317. }
  318. this.result = this.result.filter(item => this.defaultValue.indexOf(item.value) == -1);
  319. // uni.showModal({
  320. // content: `筛选的值:${JSON.stringify(this.result)}`
  321. // })
  322. console.info('onParent',this.result)
  323. this.$emit("onParent",this.result)
  324. }
  325. }
  326. }
  327. </script>
  328. <style>
  329. </style>