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.

278 lines
7.3 KiB

<template>
8 months ago
<div>
<el-button type="primary" icon="Plus" @click="add" class="btn" :disabled="isDisable">
8 months ago
新增
</el-button>
<el-button
type="danger"
icon="Delete"
@click="del"
class="btn"
:disabled="isDisable"
8 months ago
>
删除
</el-button>
<div class="table-box">
<el-table
ref="multipleTableRef"
border
:data="tableData"
@select="(selection: any[]) => (isSele = !!selection.length)"
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-cascader
:disabled="isDisable"
8 months ago
:modelValue="row.teacherType"
@update:modelValue="(arr: any[]) => (row.teacherType = 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 }">
2 months ago
<el-input v-model="row.teacherName" placeholder="请输入指导老师姓名" :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-input v-model="row.teacherXl" placeholder="请输入学历" :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-input v-model="row.teacherZc" placeholder="请输入职称" :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-input v-model="row.teacherZy" placeholder="请输入专业" :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-input v-model="row.teacherYjfx" placeholder="请输入研究方向" :disabled="isDisable"/>
8 months ago
</template>
</el-table-column>
2 months ago
<el-table-column >
8 months ago
<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.teacherPhone" @blur="validatePhoneInput(row)" placeholder="请输入手机号" :disabled="isDisable"/>
8 months ago
</template>
</el-table-column>
</el-table>
</div>
8 months ago
<tea-dialog v-model="visible" @selected="handleSelected" />
</div>
</template>
<script lang="ts" setup>
import { reactive, ref ,onMounted} from 'vue'
8 months ago
import teaDialog from './teaDialog.vue'
import { ClusterOutlined } from '@ant-design/icons-vue'
import { ElMessage } from 'element-plus'
import {getTeacherList} from '@/api/oldRace'
import { useRoute } from 'vue-router'
const route = useRoute()
const isDisable = ref(false)
isDisable.value = route.query.info as any
const options = [
8 months ago
{
value: '1',
label: '指导老师',
},
{
value: '2',
label: '领队老师',
},
]
2 months ago
// 手机号格式校验函数
const validatePhone = (teacherPhone: string) => {
const pattern = /^1[3-9]\d{9}$/;
return pattern.test(teacherPhone);
};
// 数据
const tableData = reactive<any[]>([])
onMounted(async() => {
if (route.query.edit) {
const res:any = await getTeacherList({ id: route.query.id})
res.result.forEach((item: any) => {
tableData.push({
teacherName: item.teacherName,
teacherPhone: item.teacherPhone,
teacherType: item.teacherType.toString(),
teacherXl: item.teacherXl,
teacherYjfx: item.teacherYjfx,
teacherZc: item.teacherZc,
teacherZy: item.teacherZy,
teacherid: item.teacherid,
})
})
}
})
const add = () => {
8 months ago
const length = tableData.push({
teacherName: '',
teacherPhone: '',
teacherType: '1',
8 months ago
teacherXl: '',
teacherYjfx: '',
teacherZc: '',
teacherZy: '',
teacherid: '',
})
openDialog(tableData[length - 1])
}
// 当下打开dialog的数据源,在打开dialog时赋值
8 months ago
const target = ref<any>()
const openDialog = (row: any) => {
8 months ago
visible.value = true
target.value = row
}
8 months ago
const visible = ref(false)
// 像数据源中添加数据
const handleSelected = (row: any = {}) => {
2 months ago
console.log(row,'row');
// 如果是空对象,删除 tableData 中最后新增的对象
if (Object.keys(row).length === 0) {
2 months ago
console.log(Object)
if (tableData.length > 0) {
tableData.pop(); // 删除最后一个元素
}
}
8 months ago
if (tableData.some((o) => o.teacherid === row.user_id)) {
ElMessage({
message: '已有该用户,不能重复选择用户!',
8 months ago
type: 'error',
})
2 months ago
tableData.pop(); // 删除最后一个元素
8 months ago
}
2 months ago
console.log(row,'row')
8 months ago
target.value.teacherName = row.realname
target.value.teacherXl = row.exp_title
target.value.teacherZc = row.exp_zc
target.value.teacherZy = row.teamajor
target.value.teacherYjfx = row.exp_yjfx
target.value.teacherPhone = row.phone
target.value.teacherid = row.user_id
2 months ago
}
// 提交
8 months ago
const submit = () => tableData
defineExpose({ submit })
// 删除逻辑
8 months ago
const multipleTableRef = ref<any>(null)
const isSele = ref(false)
const del = () => {
8 months ago
const rows = multipleTableRef.value.getSelectionRows()
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>