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

226 lines
5.6 KiB

6 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. export default {
  29. onPageScroll() {
  30. // 滚动后及时更新位置
  31. this.$refs.dropDown.init();
  32. },
  33. computed: {
  34. dropItem(name) {
  35. return (name) => {
  36. const result = {};
  37. const find = this.result.find(item => item.name === name);
  38. if (find) {
  39. result.label = find.label;
  40. result.value = find.value;
  41. } else {
  42. result.label = this[name].label;
  43. result.value = this[name].value;
  44. }
  45. return result;
  46. }
  47. },
  48. // 获取当前下拉筛选项
  49. currentDropItem() {
  50. return this[this.activeName];
  51. }
  52. },
  53. data() {
  54. return {
  55. keyword: "",
  56. // 表示value等于这些值,就属于默认值
  57. defaultValue: ['all', 'all', 'all','all'],
  58. // 筛选结果
  59. result: [],
  60. region:{
  61. label: '区域',
  62. value: 'all',
  63. activeIndex: 0,
  64. color: '#333',
  65. activeColor: '#20CD7D',
  66. child: [{
  67. label: '全部区域',
  68. value: 'all'
  69. }, {
  70. label: '湖南',
  71. value: 'hunan'
  72. }, {
  73. label: '广州',
  74. value: 'guangzhou'
  75. }]
  76. },
  77. rent:{
  78. label: '租金',
  79. value: 'all',
  80. activeIndex: 0,
  81. color: '#333',
  82. activeColor: '#20CD7D',
  83. child: [{
  84. label: '全部',
  85. value: 'all'
  86. }, {
  87. label: '0-2k',
  88. value: '2000'
  89. }, {
  90. label: '2k-4k',
  91. value: '4000'
  92. }, {
  93. label: '4k-6k',
  94. value: '6000'
  95. }, {
  96. label: '6k+',
  97. value: '6000+'
  98. }]
  99. },
  100. type: {
  101. label: '类型',
  102. value: 'all',
  103. activeIndex: 0,
  104. color: '#333',
  105. activeColor: '#20CD7D',
  106. child: [{
  107. label: '全部',
  108. value: 'all'
  109. }, {
  110. label: '闲置散居农房',
  111. value: 'nongfang'
  112. }, {
  113. label: '鱼塘',
  114. value: 'yutang'
  115. }, {
  116. label: '耕地',
  117. value: 'gengdi'
  118. }]
  119. },
  120. duration:{
  121. label: '年限',
  122. value: 'all',
  123. activeIndex: 0,
  124. color: '#333',
  125. activeColor: '#20CD7D',
  126. child: [{
  127. label: '全部',
  128. value: 'all'
  129. }, {
  130. label: '5年内',
  131. value: '0-5'
  132. }, {
  133. label: '5-10年',
  134. value: '5-10'
  135. }, {
  136. label: '10-20年',
  137. value: '10-20'
  138. }]
  139. },
  140. activeName: 'region',
  141. vip_type: {
  142. label: 'VIP文档',
  143. value: 0,
  144. activeIndex: 0
  145. }
  146. }
  147. },
  148. methods: {
  149. onSearch(){
  150. this.$emit("onSearch",this.keyword)
  151. },
  152. change(e) {
  153. console.log('弹窗打开状态:', e);
  154. },
  155. /**
  156. * 点击每个筛选项回调
  157. * @param {Object} e { name, active, type } = e
  158. */
  159. selectMenu(e) {
  160. const {
  161. name,
  162. active,
  163. type
  164. } = e;
  165. this.activeName = name;
  166. // type 等于1 的需要特殊处理:type不等于1可以忽略
  167. if (type == 1) {
  168. this.clickItem({
  169. name: 'vip_type',
  170. label: 'VIP文档',
  171. value: e.active ? 1 : 0
  172. });
  173. } else {
  174. const find = this.result.find(item => item.name == this.activeName);
  175. if (find) {
  176. const findIndex = this[this.activeName].child.findIndex(item => item.label == find.label && item
  177. .value == find.value);
  178. this[this.activeName].activeIndex = findIndex;
  179. } else {
  180. this[this.activeName].activeIndex = 0;
  181. }
  182. }
  183. },
  184. /**
  185. * 点击菜单回调处理
  186. * @param {Object} item 选中项 { label,value } = e
  187. */
  188. clickItem(e) {
  189. // 下面有重新赋值,所以用let
  190. let {
  191. label,
  192. value
  193. } = e;
  194. const findIndex = this.result.findIndex(item => item.name == this.activeName);
  195. if (this.defaultValue.indexOf(value) > -1 && this[this.activeName].label) {
  196. label = this[this.activeName].label;
  197. }
  198. // 已经存在筛选项
  199. if (findIndex > -1) {
  200. this.$set(this.result, findIndex, {
  201. name: this.activeName,
  202. label,
  203. value
  204. })
  205. } else {
  206. this.result.push({
  207. name: this.activeName,
  208. label,
  209. value
  210. });
  211. }
  212. this.result = this.result.filter(item => this.defaultValue.indexOf(item.value) == -1);
  213. // uni.showModal({
  214. // content: `筛选的值:${JSON.stringify(this.result)}`
  215. // })
  216. console.info(this.result)
  217. this.$emit("onParent",this.result)
  218. }
  219. }
  220. }
  221. </script>
  222. <style>
  223. </style>