mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-14 21:36:45 +08:00
连选
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="item">
|
||||
<view class="item" style='margin-bottom: 180rpx;'>
|
||||
<view class="title">
|
||||
职级
|
||||
</view>
|
||||
@@ -35,7 +35,7 @@
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="bandShow" class="body">
|
||||
<view @click="isBand(item,index)" :class="bandIndexs.includes(index)?'item2':''" v-for="(item,index) in bandLists" :key="index" class="item">
|
||||
<view @click="isBand(item,index)" :class=" {'item2': bandIndexs.includes(index),'disabled-item': isDisabled(index)}" v-for="(item,index) in bandLists" :key="index" class="item">
|
||||
{{item.bandCode}}
|
||||
</view>
|
||||
</view>
|
||||
@@ -137,17 +137,69 @@
|
||||
downList(){
|
||||
this.bandShow = !this.bandShow
|
||||
},
|
||||
isDisabled(index) {
|
||||
if (this.bandIndexs.length >= 1) {
|
||||
const firstClickIndex = Math.min(...this.bandIndexs);
|
||||
const allowedRangeEnd = firstClickIndex + 2;
|
||||
return index < firstClickIndex || index > allowedRangeEnd;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
isBand(item,index){
|
||||
const indexToRemove = this.bandIndexs.indexOf(index);
|
||||
if (this.bandIndexs.length >= 1) {
|
||||
const firstClickIndex = Math.min(...this.bandIndexs);
|
||||
const allowedRangeEnd = firstClickIndex + 2;
|
||||
if (index < firstClickIndex || index > allowedRangeEnd) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this.bandIndexs.length === 3 && this.bandIndexs.includes(index) && this.bandIndexs.indexOf(index) === 1) {
|
||||
// 删除最后一个元素
|
||||
this.bandIndexs.pop();
|
||||
this.bandItem = this.bandIndexs.map(index => this.bandLists[index])
|
||||
this.bandItem = this.bandItem.sort((a, b) => parseInt(a.bandId, 10) - parseInt(b.bandId, 10));
|
||||
this.bandFirst = this.bandItem[0].bandCode
|
||||
if(this.bandItem && this.bandItem.length > 1){
|
||||
this.bandEnd = this.bandItem[this.bandItem.length - 1].bandCode
|
||||
}
|
||||
return;
|
||||
}
|
||||
let currentIndex = index;
|
||||
let firstClickIndex = this.bandIndexs[0];
|
||||
|
||||
if (this.bandIndexs.length === 0) {
|
||||
this.bandIndexs.push(currentIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保currentIndex和firstClickIndex按顺序排列
|
||||
if (currentIndex < firstClickIndex) {
|
||||
[currentIndex, firstClickIndex] = [firstClickIndex, currentIndex];
|
||||
}
|
||||
|
||||
// 检查是否有连续的未选择项,并自动填充
|
||||
for (let i = firstClickIndex + 1; i < currentIndex; i++) {
|
||||
if (!this.bandIndexs.includes(i)) {
|
||||
this.bandIndexs.splice(this.bandIndexs.indexOf(i - 1) + 1, 0, i);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加或移除当前点击的index
|
||||
const indexToRemove = this.bandIndexs.indexOf(currentIndex);
|
||||
if (indexToRemove !== -1) {
|
||||
this.bandIndexs.splice(indexToRemove, 1);
|
||||
this.bandIndexs.splice(indexToRemove, 1);
|
||||
} else {
|
||||
this.bandIndexs.push(index);
|
||||
this.bandIndexs.push(currentIndex);
|
||||
}
|
||||
if(this.bandIndexs.length == 0){
|
||||
this.bandFirst = ''
|
||||
this.bandItem = []
|
||||
return
|
||||
}
|
||||
console.log(this.bandIndexs,'this.bandIndexs')
|
||||
if(this.bandIndexs.length == 1){
|
||||
this.bandEnd = ''
|
||||
}
|
||||
|
||||
this.bandItem = this.bandIndexs.map(index => this.bandLists[index])
|
||||
this.bandItem = this.bandItem.sort((a, b) => parseInt(a.bandId, 10) - parseInt(b.bandId, 10));
|
||||
this.bandFirst = this.bandItem[0].bandCode
|
||||
@@ -162,9 +214,11 @@
|
||||
<style>
|
||||
.searchs{
|
||||
background: #fff;
|
||||
height: 100vh;
|
||||
padding: 56rpx 56rpx 180rpx 38rpx;
|
||||
min-height: 100vh;
|
||||
overflow: auto;
|
||||
padding: 56rpx 56rpx 0 38rpx;
|
||||
.item{
|
||||
|
||||
.downlist{
|
||||
margin: 0 auto;
|
||||
.body{
|
||||
@@ -190,6 +244,9 @@
|
||||
font-size: 28rpx;
|
||||
color: #387DF7;
|
||||
}
|
||||
.disabled-item {
|
||||
background-color: #ccc;
|
||||
}
|
||||
}
|
||||
.title{
|
||||
display: flex;
|
||||
@@ -289,12 +346,16 @@
|
||||
|
||||
}
|
||||
.footers{
|
||||
width: 100%;
|
||||
height: 120rpx;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
transform: translate(-50%, 0%);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
/* align-items: center; */
|
||||
background: #fff;
|
||||
.btn{
|
||||
width: 284rpx;
|
||||
height: 96rpx;
|
||||
|
||||
Reference in New Issue
Block a user