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.

281 lines
7.4 KiB

<template>
8 months ago
<div>
2 months ago
<el-button type="primary" icon="Plus" @click="add" class="btn" :disabled="isDisable">
8 months ago
新增
</el-button>
2 months ago
<el-button type="danger" icon="Delete" @click="del" class="btn" :disabled="isDisable">
8 months ago
删除
</el-button>
<div class="table-box">
2 months ago
<el-table ref="multipleTableRef" @select="(selection: any[]) => (isSele = !!selection.length)" border
:data="tableData" class="table" height="276px">
8 months ago
<el-table-column type="selection" width="55" />
<el-table-column label="#" width="55">
<template #default="{ $index }">
{{ $index + 1 }}
</template>
</el-table-column>
<el-table-column>
<template #header>
<el-icon>
<Edit />
</el-icon>
<span style="margin-left: 10px">用户</span>
</template>
<template #default="{ row }">
2 months ago
<el-input v-model="row.realname" :disabled="isDisable" />
8 months ago
</template>
</el-table-column>
<el-table-column>
<template #header>
<el-icon>
<Edit />
</el-icon>
<span style="margin-left: 10px">是否队长</span>
</template>
<template #default="{ row }">
<el-select v-model="row.captain" @update:modelValue="(arr: any[]) => {row.captain = arr[0];console.log(arr);
2 months ago
}"
@change="()=>checkUniqueness(row)"
:options="options">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
8 months ago
</template>
</el-table-column>
<el-table-column>
<template #header>
<el-icon>
<Edit />
</el-icon>
<span style="margin-left: 10px">学号</span>
</template>
<template #default="{ row }">
<el-input v-model="row.workNo" :disabled="isDisable" />
</template>
</el-table-column>
<el-table-column>
<template #header>
<el-icon>
<Edit />
</el-icon>
<span style="margin-left: 10px">手机号</span>
</template>
<template #default="{ row }">
<el-input v-model="row.phone" :disabled="isDisable" />
</template>
</el-table-column>
<el-table-column>
<template #header>
<el-icon>
<Edit />
</el-icon>
<span style="margin-left: 10px">邮箱</span>
</template>
<template #default="{ row }">
<el-input v-model="row.email" :disabled="isDisable" />
</template>
</el-table-column>
8 months ago
<el-table-column>
<template #header>
<el-icon>
<Edit />
</el-icon>
<span style="margin-left: 10px">队员序号</span>
</template>
<template #default="{ row }">
<el-input v-model="row.teamSeq" :disabled="isDisable" />
8 months ago
</template>
</el-table-column>
</el-table>
</div>
8 months ago
<stu-dialog v-model="visible" @selected="handleSelected" />
</div>
</template>
<script lang="ts" setup>
2 months ago
import { reactive, ref, onMounted, nextTick } from 'vue'
8 months ago
import stuDialog from './stuDialog.vue'
import { ClusterOutlined } from '@ant-design/icons-vue'
import { ElMessage } from 'element-plus'
import userStore from '@/store/module/user'
import { getTeamList } from '@/api/oldRace'
import { useRoute } from 'vue-router'
const route = useRoute()
const userModel = userStore()
const visible = ref(false)
// 是否禁用控件
const isDisable = ref(false)
isDisable.value = route.query.info as any
const options = [
8 months ago
{
value: '1',
label: '是',
},
{
value: '0',
label: '否',
},
]
2 months ago
// 检查队长的唯一性
const checkUniqueness = (row:any) => {
// console.log(row);
//查询tableData中队长的人数
const count = tableData.filter(item => item.captain === '1').length
// console.log(count,'count');
//检查是否已经存在该值
if(count === 2){
//如果存在,弹出消息提示
ElMessage({
message: '已有队长人选!',
type: 'error',
})
row.captain = '0';
}else if(count === 0){
ElMessage({
message: '请选择队长人选!',
type: 'error',
})
}
}
// 数据
const tableData = reactive<any[]>([])
onMounted(() => {
if (route.query.edit) {
const getTeamListEvent = async () => {
const res: any = await getTeamList({ id: route.query.id })
console.log(res, 'res~~~')
res.result.forEach((item: any) => {
tableData.push(item)
})
}
getTeamListEvent()
return
}
if (tableData.length === 1) return
setTimeout(() => {
tableData.push({
userId: userModel.userInfo.id,
realname: userModel.userInfo.realname,
workNo: userModel.userInfo.workNo,
phone: userModel.userInfo.phone,
email: userModel.userInfo.email,
captain: '1',
teamSeq: 1,
})
}, 500)
})
const add = () => {
8 months ago
const length = tableData.push({
realname: '', // 用户
captain: '0', // 是否队长
teamSeq: tableData.length + 1, // 队员序号
8 months ago
userId: '', // id
workNo: '',
phone: '',
email: '',
8 months ago
})
openDialog(tableData[length - 1])
}
// 当下打开dialog的数据源,在打开dialog时赋值
8 months ago
const target = ref<any>()
const openDialog = (row: any) => {
// console.log(row,'row');
8 months ago
visible.value = true
target.value = row
}
// 像数据源中添加数据
const handleSelected = (row: any = {}) => {
// 如果是空对象,删除 tableData 中最后新增的对象
if (Object.keys(row).length === 0) {
if (tableData.length > 0) {
tableData.pop(); // 删除最后一个元素
}
}
8 months ago
if (tableData.some((o) => o.userId === row.id)) {
ElMessage({
message: '已有该用户,不能重复选择用户!',
8 months ago
type: 'error',
})
2 months ago
tableData.pop(); // 删除最后一个元素
8 months ago
}
console.log(row, 'aqq')
target.value.workNo = row.work_no
target.value.phone = row.phone
target.value.email = row.email
8 months ago
target.value.realname = row.realname
target.value.userId = row.id
}
// 提交
defineExpose({ submit: () => tableData })
// 删除逻辑
8 months ago
const multipleTableRef = ref<any>(null)
const isSele = ref(false)
const del = () => {
8 months ago
const rows = multipleTableRef.value.getSelectionRows()
console.log(rows, '111')
6 months ago
if (rows.length === 0) {
return ElMessage({
message: '请选择要删除的成员',
type: 'error',
})
6 months ago
}
8 months ago
rows.forEach((row: any) => {
const index = tableData.indexOf(row)
if (index === -1) return
tableData.splice(index, 1)
})
}
</script>
<style lang="scss" scoped>
.btn {
8 months ago
margin-bottom: 20px;
}
.table-box {
8 months ago
.table {
width: 100%;
}
.pagin-box {
width: 100%;
height: 64px;
display: flex;
align-items: center;
.pagination {
padding: 0 24px;
:deep() {
.el-pagination__total {
margin-right: auto;
}
8 months ago
li.number.is-active {
background-color: #42d9ac;
color: rgba(255, 255, 255, 0.9);
font-family:
Microsoft YaHei UI,
Microsoft YaHei UI;
}
8 months ago
span.el-pagination__jump {
background-color: #f3f3f3;
padding: 2px 8px;
}
}
}
8 months ago
}
}
8 months ago
</style>