Files
city-store-transfer/components/DropDown/DropDown.vue

126 lines
2.5 KiB
Vue

<template>
<view class="container">
<view class="tabs-bg" />
<view class="tabs">
<view class="title-view" v-for="(item, index) in title" :key="item" @click="changeActiveIndex(index)"
:class="{isActive: activeIndex === index}">
<text>{{item}}</text>
<view class="arrow" v-if="activeIndex !== index">
<u-image src="/static/dropdown/dp_icon_lxia.png" width="14rpx" height="11rpx" />
</view>
<view class="arrow" v-if="activeIndex === index">
<u-image src="/static/dropdown/dp_icon_hlxia.png" width="14rpx" height="11rpx" />
</view>
</view>
</view>
<view class="item-border">
<DropDownItem v-if="activeIndex !== -1" :list="tablist" @cancelDrop="cancelDrop" :type="'region'" />
</view>
</view>
</template>
<script>
/**
* @property {Array} postlist 传递一个二维数组
*/
import DropDownItem from "./DropDownItem.vue"
export default {
name: "DropDown",
components: {
DropDownItem
},
props: {
postlist: {
type: Array,
default () {
return [
['全部', '餐饮美食', '百货超市', '美容美发'],
['区域1', '区域2', '区域3', '区域4'],
['100m2', '200m2', '300m2'],
['附近的', '最新发布的', '其他']
]
}
}
},
data() {
return {
title: ['行业', '区域', '面积', '筛选'],
activeIndex: -1,
};
},
computed: {
tablist: function() {
return this.postlist[this.activeIndex]
}
},
created() {
this.postlist[1]=JSON.parse(uni.getStorageSync('regionList'))
},
methods: {
changeActiveIndex(index) {
if (this.activeIndex === index) {
this.activeIndex = -1;
} else
this.activeIndex = index
},
cancelDrop() {
console.log("取消遮罩");
this.activeIndex = -1;
}
}
}
</script>
<style lang="scss" scoped>
.isActive {
color: #CC3333;
}
.container {
margin-top: 10px;
position: relative;
.tabs-bg {
position: absolute;
background-color: $uni-bg-color-grey;
height: 120rpx;
width: 100%;
transform: translateY(-20rpx);
z-index: 2;
}
.tabs {
background-color: #fff;
height: 100rpx;
display: flex;
justify-content: space-around;
position: relative;
z-index: 3;
}
.title-view {
display: flex;
>text {
font-size: 14px;
display: flex;
flex-direction: column;
justify-content: center;
}
}
.arrow {
margin-left: 8rpx;
display: flex;
flex-direction: column;
justify-content: center;
}
}
.item-border {
position: absolute;
width: 100%;
height: 100%;
}
</style>