flat:AI+
This commit is contained in:
226
components/expected-station/expected-station.vue
Normal file
226
components/expected-station/expected-station.vue
Normal file
@@ -0,0 +1,226 @@
|
||||
<template>
|
||||
<view class="expected-station">
|
||||
<view class="sex-search" v-if="search">
|
||||
<uni-icons class="iconsearch" type="search" size="20"></uni-icons>
|
||||
<input class="uni-input searchinput" confirm-type="search" />
|
||||
</view>
|
||||
<view class="sex-content">
|
||||
<scroll-view :show-scrollbar="false" :scroll-y="true" class="sex-content-left">
|
||||
<view
|
||||
v-for="item in copyTree"
|
||||
:key="item.id"
|
||||
class="left-list-btn"
|
||||
:class="{ 'left-list-btned': item.id === leftValue.id }"
|
||||
@click="changeStationLog(item)"
|
||||
>
|
||||
{{ item.label }}
|
||||
<view class="positionNum" v-show="item.checkednumber">
|
||||
{{ item.checkednumber }}
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<scroll-view :show-scrollbar="false" :scroll-y="true" class="sex-content-right">
|
||||
<view v-for="item in rightValue" :key="item.id">
|
||||
<view class="secondary-title">{{ item.label }}</view>
|
||||
<view class="grid-sex">
|
||||
<view
|
||||
v-for="item in item.children"
|
||||
:key="item.id"
|
||||
:class="{ 'sex-right-btned': item.checked }"
|
||||
class="sex-right-btn"
|
||||
@click="addItem(item)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</view>
|
||||
<!-- <view class="sex-right-btn sex-right-btned" @click="addItem()">客户经理</view>
|
||||
<view class="sex-right-btn" @click="addItem()">客户经理</view> -->
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'expected-station',
|
||||
data() {
|
||||
return {
|
||||
leftValue: {},
|
||||
rightValue: [],
|
||||
stationCateLog: 0,
|
||||
copyTree: [],
|
||||
};
|
||||
},
|
||||
props: {
|
||||
station: {
|
||||
type: Array,
|
||||
default: [],
|
||||
},
|
||||
search: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
max: {
|
||||
type: Number,
|
||||
default: 5,
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.copyTree = this.station;
|
||||
if (this.copyTree.length) {
|
||||
this.leftValue = this.copyTree[0];
|
||||
this.rightValue = this.copyTree[0].children;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
station(newVal) {
|
||||
this.copyTree = this.station;
|
||||
if (this.copyTree.length) {
|
||||
this.leftValue = this.copyTree[0];
|
||||
this.rightValue = this.copyTree[0].children;
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
changeStationLog(item) {
|
||||
this.leftValue = item;
|
||||
this.rightValue = item.children;
|
||||
},
|
||||
addItem(item) {
|
||||
let titiles = [];
|
||||
let count = 0;
|
||||
|
||||
// 先统计已选中的职位数量
|
||||
for (const firstLayer of this.copyTree) {
|
||||
for (const secondLayer of firstLayer.children) {
|
||||
for (const thirdLayer of secondLayer.children) {
|
||||
if (thirdLayer.checked) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const firstLayer of this.copyTree) {
|
||||
firstLayer.checkednumber = 0; // 初始化当前层级的 checked 计数
|
||||
for (const secondLayer of firstLayer.children) {
|
||||
for (const thirdLayer of secondLayer.children) {
|
||||
// **如果是当前点击的职位**
|
||||
if (thirdLayer.id === item.id) {
|
||||
if (!thirdLayer.checked && count >= 5) {
|
||||
// 如果已经选了 5 个,并且点击的是未选中的职位,则禁止选择
|
||||
uni.showToast({
|
||||
title: `最多选择5个职位`,
|
||||
icon: 'none',
|
||||
});
|
||||
continue; // 跳过后续逻辑,继续循环
|
||||
}
|
||||
// 切换选中状态
|
||||
thirdLayer.checked = !thirdLayer.checked;
|
||||
}
|
||||
// 统计被选中的第三层节点
|
||||
if (thirdLayer.checked) {
|
||||
titiles.push(`${thirdLayer.id}`);
|
||||
firstLayer.checkednumber++; // 累加计数器
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
titiles = titiles.join(',');
|
||||
this.$emit('onChange', titiles);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="stylus" scoped>
|
||||
.secondary-title{
|
||||
font-weight: bold;
|
||||
padding: 40rpx 0 10rpx 30rpx;
|
||||
}
|
||||
.expected-station{
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.sex-search
|
||||
width: calc(100% - 28rpx - 28rpx);
|
||||
padding: 10rpx 28rpx;
|
||||
display: grid;
|
||||
// grid-template-columns: 50rpx auto;
|
||||
position: relative;
|
||||
.iconsearch
|
||||
position: absolute;
|
||||
left: 40rpx;
|
||||
top: 20rpx;
|
||||
.searchinput
|
||||
border-radius: 10rpx;
|
||||
background: #FFFFFF;
|
||||
padding: 10rpx 0 10rpx 58rpx;
|
||||
.sex-content
|
||||
background: #FFFFFF;
|
||||
border-radius: 20rpx;
|
||||
width: 100%;
|
||||
margin-top: 20rpx;
|
||||
display: flex;
|
||||
border-bottom: 2px solid #D9D9D9;
|
||||
overflow: hidden;
|
||||
height: 100%
|
||||
.sex-content-left
|
||||
width: 250rpx;
|
||||
.left-list-btn
|
||||
padding: 0 40rpx 0 24rpx;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
height: 100rpx;
|
||||
text-align: center;
|
||||
color: #606060;
|
||||
font-size: 28rpx;
|
||||
position: relative
|
||||
.positionNum
|
||||
position: absolute
|
||||
right: 0
|
||||
top: 50%;
|
||||
transform: translate(0, -50%)
|
||||
color: #FFFFFF
|
||||
background: #4778EC
|
||||
border-radius: 50%
|
||||
width: 36rpx;
|
||||
height: 36rpx;
|
||||
.left-list-btned
|
||||
color: #4778EC;
|
||||
position: relative;
|
||||
.left-list-btned::after
|
||||
position: absolute;
|
||||
left: 20rpx;
|
||||
content: '';
|
||||
width: 7rpx;
|
||||
height: 38rpx;
|
||||
background: #4778EC;
|
||||
border-radius: 0rpx 0rpx 0rpx 0rpx;
|
||||
|
||||
.sex-content-right
|
||||
border-left: 2px solid #D9D9D9;
|
||||
flex: 1;
|
||||
.grid-sex
|
||||
display: grid;
|
||||
grid-template-columns: 50% 50%;
|
||||
place-items: center;
|
||||
padding: 0 0 40rpx 0;
|
||||
.sex-right-btn
|
||||
width: 211rpx;
|
||||
height: 84rpx;
|
||||
font-size: 32rpx;
|
||||
line-height: 41rpx;
|
||||
text-align: center;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: #D9D9D9;
|
||||
border-radius: 20rpx;
|
||||
margin-top:30rpx;
|
||||
color: #606060;
|
||||
.sex-right-btned
|
||||
color: #FFFFFF;
|
||||
background: #4778EC;
|
||||
</style>
|
Reference in New Issue
Block a user