123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <template>
- <view>
- <uni-popup ref="popup" type="bottom" @change="handleChange">
- <view class="wrap">
- <view class="title">请选择社区</view>
- <image class="close" src="@/static/images/icons/close.png" @click="close"></image>
- <scroll-view class="select-scroll" scroll-x show-scrollbar>
- <view class="select-tab" :class="{active:idx === curTab}" v-for="(tab,idx) in tabList" :key="tab.id"
- @click="tabClick(tab,idx)">
- {{tab.label}}
- </view>
- </scroll-view>
- <view class="cont-wrap">
- <scroll-view class="content" :class="{active:listIdx === curTab}" scroll-y v-for="(list,listIdx) in levels"
- :key="list">
- <view class="list-item" v-for="(item,index) in contList[listIdx]" :key="item.id"
- @click="itemClick(item,index)">
- <view class="item-text">{{item.label}}</view>
- <view class="check" :class="{checked:listIdx === lastTab && curItem === index}"></view>
- </view>
- </scroll-view>
- </view>
- </view>
- </uni-popup>
- </view>
- </template>
- <script>
- import { getUnitTree } from '@/api/business'
- export default {
- name: "LazyPicker",
- props: {
- open: {
- type: Boolean,
- required: true,
- default: false,
- }
- },
- data() {
- return {
- parentId: null,
- levels: 5,
- curTab: 0,
- lastTab: null,
- tabList: [
- { id: 0, label: '请选择' },
- ],
- curItem: null,
- contList: [],
- };
- },
- created() {
- getUnitTree().then(res => {
- if (res.code !== 200) return
- this.contList.push(res.data)
- this.levels = Number(res.level)
- })
- },
- watch: {
- open(value) {
- value ? this.$refs.popup.open() : this.$refs.popup.close()
- },
- },
- methods: {
- handleChange(e) {
- this.$emit('change', e.show)
- },
- close() {
- this.$refs.popup.close()
- },
- tabClick(tab, index) {
- this.curTab = index
- },
- itemClick(item, index) {
- this.curItem = index
- this.tabList[this.curTab] = item
- this.$emit('selected', item)
- this.parentId = item.id
- getUnitTree(this.parentId).then(({ code, data }) => {
- if (code !== 200) return
- this.lastTab = this.curTab
- if (data.length > 0) {
- // this.curItem = null //重置
- let nextTab = this.curTab + 1
- if (this.tabList[nextTab]) {
- this.tabList[nextTab] = { id: index, label: '请选择' }
- this.tabList.splice(nextTab + 1)
- this.curTab += 1
- this.contList[this.curTab] = data
- } else {
- this.tabList.push({ id: index, label: '请选择' })
- this.curTab += 1
- this.contList[this.curTab] = data
- }
- } else {
- this.tabList.splice(this.curTab + 1)
- }
- })
- }
- },
- }
- </script>
- <style lang="scss">
- .wrap {
- font-size: 14px;
- width: 100%;
- background-color: #FFFFFF;
- border-top-left-radius: 10px;
- border-top-right-radius: 10px;
- position: relative;
- .close {
- height: 20px;
- width: 20px;
- position: absolute;
- top: 12px;
- right: 8px;
- }
- .title {
- font-size: 16px;
- height: 44px;
- line-height: 44px;
- text-align: center;
- }
- .select-scroll {
- white-space: nowrap;
- border-bottom: 1px solid #f8f8f8;
- padding: 0 5px;
- }
- .select-tab {
- display: inline-block;
- margin-left: 10px;
- margin-right: 10px;
- padding: 12px 0;
- text-align: center;
- white-space: nowrap;
- position: relative;
- &::after {
- content: '';
- height: 2px;
- width: 100%;
- position: absolute;
- left: 0%;
- bottom: 0;
- }
- }
- .active::after {
- background-color: #2979ff;
- }
- .content {
- height: 460px;
- display: none;
- &.active {
- display: block;
- }
- .list-item {
- padding: 12px 15px;
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- }
- .check {
- margin-right: 5px;
- border: 2px solid #2979ff;
- border-left: 0;
- border-top: 0;
- height: 12px;
- width: 6px;
- transform-origin: center;
- transition: all 0.3s;
- transform: rotate(45deg);
- display: none;
- &.checked {
- display: block;
- }
- }
- }
- }
- </style>
|