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.

268 lines
6.5 KiB

<template>
8 months ago
<div>
<el-button type="primary" icon="Plus" @click="add" class="btn">
新增
</el-button>
<el-button type="danger" icon="Delete" @click="del" class="btn">
8 months ago
删除
</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
@click="openDialog(row)"
v-model="row.realname"
placeholder="请选择"
:prefix-icon="ClusterOutlined"
/>
</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-cascader
:modelValue="row.captain"
@update:modelValue="(arr: any[]) => (row.captain = arr[0])"
:options="options"
/>
</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.work_no" />
</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" />
</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" />
</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" />
</template>
</el-table-column>
</el-table>
</div>
8 months ago
<stu-dialog v-model="visible" @selected="handleSelected" />
</div>
</template>
<script lang="ts" setup>
import { reactive, ref, onMounted, watch } 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 options = [
8 months ago
{
value: '1',
label: '是',
},
{
value: '0',
label: '否',
},
]
// 数据
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,
work_no: userModel.userInfo.workNo,
phone: userModel.userInfo.phone,
email: userModel.userInfo.email,
captain: '1',
teamSeq: 1,
})
}, 500)
})
// watch(()=>userModel.userInfo,()=>{
// if(tableData.length === 1) return
// tableData.push({
// userId: userModel.userInfo.id,
// realname: userModel.userInfo.realname,
// captain: '1',
// teamSeq: 1,
// })
// })
const add = () => {
8 months ago
const length = tableData.push({
realname: '', // 用户
captain: '0', // 是否队长
teamSeq: tableData.length + 1, // 队员序号
8 months ago
userId: '', // id
work_no: '',
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
}
8 months ago
const visible = ref(false)
// 像数据源中添加数据
const handleSelected = (row: any = {}) => {
8 months ago
if (tableData.some((o) => o.userId === row.id)) {
ElMessage({
message: '用户不能多选!',
type: 'error',
})
return
}
console.log(row, 'aqq')
target.value.work_no = 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>