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.
280 lines
7.4 KiB
280 lines
7.4 KiB
<template> |
|
<div> |
|
<el-button type="primary" icon="Plus" @click="add" class="btn" :disabled="isDisable"> |
|
新增 |
|
</el-button> |
|
<el-button type="danger" icon="Delete" @click="del" class="btn" :disabled="isDisable"> |
|
删除 |
|
</el-button> |
|
<div class="table-box"> |
|
<el-table ref="multipleTableRef" @select="(selection: any[]) => (isSele = !!selection.length)" border |
|
:data="tableData" class="table" height="276px"> |
|
<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 }"> |
|
<el-input v-model="row.realname" :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-select v-model="row.captain" @update:modelValue="(arr: any[]) => {row.captain = arr[0];console.log(arr); |
|
}" |
|
@change="()=>checkUniqueness(row)" |
|
:options="options"> |
|
<el-option |
|
v-for="item in options" |
|
:key="item.value" |
|
:label="item.label" |
|
:value="item.value" |
|
/> |
|
</el-select> |
|
</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> |
|
<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" /> |
|
</template> |
|
</el-table-column> |
|
</el-table> |
|
</div> |
|
<stu-dialog v-model="visible" @selected="handleSelected" /> |
|
</div> |
|
</template> |
|
|
|
<script lang="ts" setup> |
|
import { reactive, ref, onMounted, nextTick } from 'vue' |
|
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 = [ |
|
{ |
|
value: '1', |
|
label: '是', |
|
}, |
|
{ |
|
value: '0', |
|
label: '否', |
|
}, |
|
] |
|
// 检查队长的唯一性 |
|
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 = () => { |
|
const length = tableData.push({ |
|
realname: '', // 用户 |
|
captain: '0', // 是否队长 |
|
teamSeq: tableData.length + 1, // 队员序号 |
|
userId: '', // id |
|
workNo: '', |
|
phone: '', |
|
email: '', |
|
}) |
|
openDialog(tableData[length - 1]) |
|
} |
|
|
|
// 当下打开dialog的数据源,在打开dialog时赋值 |
|
const target = ref<any>() |
|
const openDialog = (row: any) => { |
|
// console.log(row,'row'); |
|
visible.value = true |
|
target.value = row |
|
} |
|
|
|
// 像数据源中添加数据 |
|
const handleSelected = (row: any = {}) => { |
|
// 如果是空对象,删除 tableData 中最后新增的对象 |
|
if (Object.keys(row).length === 0) { |
|
if (tableData.length > 0) { |
|
tableData.pop(); // 删除最后一个元素 |
|
} |
|
} |
|
if (tableData.some((o) => o.userId === row.id)) { |
|
ElMessage({ |
|
message: '已有该用户,不能重复选择用户!', |
|
type: 'error', |
|
}) |
|
tableData.pop(); // 删除最后一个元素 |
|
} |
|
console.log(row, 'aqq') |
|
target.value.workNo = row.work_no |
|
target.value.phone = row.phone |
|
target.value.email = row.email |
|
target.value.realname = row.realname |
|
target.value.userId = row.id |
|
} |
|
|
|
// 提交 |
|
defineExpose({ submit: () => tableData }) |
|
|
|
// 删除逻辑 |
|
const multipleTableRef = ref<any>(null) |
|
const isSele = ref(false) |
|
const del = () => { |
|
const rows = multipleTableRef.value.getSelectionRows() |
|
console.log(rows, '111') |
|
if (rows.length === 0) { |
|
return ElMessage({ |
|
message: '请选择要删除的成员', |
|
type: 'error', |
|
}) |
|
} |
|
rows.forEach((row: any) => { |
|
const index = tableData.indexOf(row) |
|
if (index === -1) return |
|
tableData.splice(index, 1) |
|
}) |
|
} |
|
</script> |
|
|
|
<style lang="scss" scoped> |
|
.btn { |
|
margin-bottom: 20px; |
|
} |
|
|
|
.table-box { |
|
.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; |
|
} |
|
|
|
li.number.is-active { |
|
background-color: #42d9ac; |
|
color: rgba(255, 255, 255, 0.9); |
|
font-family: |
|
Microsoft YaHei UI, |
|
Microsoft YaHei UI; |
|
} |
|
|
|
span.el-pagination__jump { |
|
background-color: #f3f3f3; |
|
padding: 2px 8px; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
</style>
|
|
|