2023-12-17 16:05:38 +08:00
|
|
|
<template>
|
|
|
|
<div class="table-page">
|
2023-12-27 16:49:37 +08:00
|
|
|
<div class="search-part" v-show="isSearch">
|
2023-12-17 16:05:38 +08:00
|
|
|
<div class="search-cell">
|
|
|
|
<span class="label">用户名</span>
|
|
|
|
<el-input v-model="queryParams.userName" placeholder="请输入用户名"></el-input>
|
|
|
|
</div>
|
2023-12-18 14:29:28 +08:00
|
|
|
<el-button type="primary" icon="Search" @click="queryData(queryParams)">查询</el-button>
|
2023-12-28 14:48:45 +08:00
|
|
|
<el-button icon="Refresh" @click="queryData()">重置</el-button>
|
2023-12-17 16:05:38 +08:00
|
|
|
</div>
|
2023-12-27 14:06:02 +08:00
|
|
|
<div class="button-part" style="justify-content: space-between;">
|
|
|
|
<div>
|
|
|
|
<el-button type="primary" icon="FirstAidKit" @click="addData">新增</el-button>
|
|
|
|
<el-button icon="FirstAidKit" @click="importData">导入</el-button>
|
|
|
|
<el-button icon="Delete" @click="removeData()">删除</el-button>
|
|
|
|
</div>
|
2023-12-28 14:48:45 +08:00
|
|
|
<TableAbility @searchBtn="isSearch = !isSearch" @refreshBtn="queryData()"
|
2023-12-27 16:49:37 +08:00
|
|
|
@downloadBtn="exportData('医生数据', tableData)"></TableAbility>
|
2023-12-17 16:05:38 +08:00
|
|
|
</div>
|
|
|
|
<div class="table-part">
|
2023-12-27 16:49:37 +08:00
|
|
|
<el-table ref="tableRef" v-loading="loading" :data="tableData" height="100%" border show-overflow-tooltip
|
|
|
|
:row-class-name="({ row }: any) => !row.enable && 'disable'" @row-click="tableRowClick">
|
2023-12-17 16:05:38 +08:00
|
|
|
<el-table-column type="selection" width="55" />
|
|
|
|
<el-table-column type="index" label="#" width="55" align="center" />
|
|
|
|
<el-table-column property="name" label="姓名" width="120" align="center" />
|
|
|
|
<el-table-column label="手机号" width="220" align="center">
|
2023-12-18 14:29:28 +08:00
|
|
|
<template #default="scope">{{ scope.row.phone.slice(0, 3) + '****' + scope.row.phone.slice(7)
|
|
|
|
}}</template>
|
2023-12-17 16:05:38 +08:00
|
|
|
</el-table-column>
|
|
|
|
<el-table-column property="role" label="角色" width="220" align="center" />
|
|
|
|
<el-table-column label="启用" width="120" align="center">
|
2023-12-18 14:29:28 +08:00
|
|
|
<template #default="scope">
|
2023-12-18 17:16:47 +08:00
|
|
|
<span @click.stop><el-switch v-model="scope.row.enable" @change="enableChange(scope.row)" /></span>
|
2023-12-18 14:29:28 +08:00
|
|
|
</template>
|
2023-12-17 16:05:38 +08:00
|
|
|
</el-table-column>
|
|
|
|
<el-table-column label="操作" align="center">
|
|
|
|
<template #default="scope">
|
2023-12-18 17:16:47 +08:00
|
|
|
<span @click.stop>
|
2023-12-27 16:49:37 +08:00
|
|
|
<el-button link icon="RefreshLeft" @click="resetPassword(scope.row)"
|
|
|
|
:disabled="!scope.row.enable">密码</el-button>
|
|
|
|
<el-button link icon="EditPen" @click="editData(scope.row)"
|
|
|
|
:disabled="!scope.row.enable">修改</el-button>
|
|
|
|
<el-button link icon="Delete" @click="removeData(scope.row)"
|
|
|
|
:disabled="!scope.row.enable">删除</el-button>
|
2023-12-18 17:16:47 +08:00
|
|
|
</span>
|
2023-12-17 16:05:38 +08:00
|
|
|
</template>
|
|
|
|
</el-table-column>
|
|
|
|
</el-table>
|
|
|
|
</div>
|
|
|
|
<div class="pagination-part">
|
|
|
|
<CommonPagination :total="100" @paginationChange="paginationChange" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-27 16:49:37 +08:00
|
|
|
<el-dialog v-model="isFormDialog" :title="formDialogTitle" width="750px">
|
2023-12-28 14:27:47 +08:00
|
|
|
<DoctorForm ref="doctorFormRef" :type="formDialogTitle === '添加' ? 'add' : 'edit'" @close="isFormDialog = false" @save="doctorFormSave" />
|
2023-12-27 16:49:37 +08:00
|
|
|
</el-dialog>
|
2023-12-18 17:16:47 +08:00
|
|
|
<ImportDialog ref="importDialogRef" title="用户导入" templateUrl="#" importUrl="#" />
|
2023-12-17 16:05:38 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang='ts' setup>
|
|
|
|
import { onMounted, reactive, ref, toRefs, watch } from 'vue'
|
2023-12-18 14:29:28 +08:00
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
|
import { tableRemoveRow, exportData } from '@/utils/table-util'
|
2023-12-17 16:05:38 +08:00
|
|
|
import CommonPagination from '@/components/common-pagination.vue'
|
2023-12-18 14:29:28 +08:00
|
|
|
import DoctorForm from './form/doctor-form.vue'
|
|
|
|
import ImportDialog from '@/components/import-dialog.vue'
|
2023-12-17 16:05:38 +08:00
|
|
|
|
2023-12-18 14:29:28 +08:00
|
|
|
const tableRef = ref()
|
|
|
|
const doctorFormRef = ref()
|
2023-12-18 17:16:47 +08:00
|
|
|
const importDialogRef = ref()
|
2023-12-27 16:49:37 +08:00
|
|
|
const isSearch = ref(true)
|
|
|
|
const loading = ref(true)
|
2023-12-18 14:29:28 +08:00
|
|
|
const isFormDialog = ref(false)
|
|
|
|
const formDialogTitle = ref('')
|
2023-12-17 16:05:38 +08:00
|
|
|
const queryParams = ref({
|
|
|
|
userName: ''
|
2023-12-18 14:29:28 +08:00
|
|
|
} as any)
|
2023-12-17 16:05:38 +08:00
|
|
|
const tableData = ref([] as any)
|
|
|
|
|
2023-12-28 14:48:45 +08:00
|
|
|
queryData()
|
2023-12-17 16:05:38 +08:00
|
|
|
|
2023-12-28 14:48:45 +08:00
|
|
|
function queryData(e?: any) {
|
2023-12-27 16:49:37 +08:00
|
|
|
loading.value = true
|
2023-12-28 14:48:45 +08:00
|
|
|
if(e?.userName) {
|
|
|
|
tableData.value = tableData.value.filter((item: any) => item.name.indexOf(e.userName) !== -1)
|
2023-12-27 16:49:37 +08:00
|
|
|
loading.value = false
|
2023-12-28 14:48:45 +08:00
|
|
|
return
|
|
|
|
}else{
|
|
|
|
queryParams.value = {}
|
|
|
|
tableData.value = []
|
|
|
|
setTimeout(() => {
|
|
|
|
while (tableData.value.length < 10) {
|
|
|
|
tableData.value.push({
|
|
|
|
id: tableData.value.length + 1,
|
|
|
|
userName: 'cscs',
|
|
|
|
name: '测试' + tableData.value.length,
|
|
|
|
phone: '12312345678',
|
|
|
|
role: '高级管理员',
|
|
|
|
enable: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
loading.value = false
|
|
|
|
}, 200);
|
|
|
|
}
|
2023-12-18 14:29:28 +08:00
|
|
|
}
|
|
|
|
const addData = () => {
|
|
|
|
isFormDialog.value = true
|
|
|
|
formDialogTitle.value = '添加'
|
|
|
|
setTimeout(() => {
|
|
|
|
doctorFormRef.value.resetData()
|
|
|
|
}, 0)
|
|
|
|
}
|
|
|
|
const importData = () => {
|
|
|
|
setTimeout(() => {
|
2023-12-18 17:16:47 +08:00
|
|
|
importDialogRef.value.open()
|
2023-12-18 14:29:28 +08:00
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
const removeData = (e?: any) => {
|
|
|
|
const selectRow = e || tableRef.value.getSelectionRows()
|
|
|
|
tableRemoveRow({ data: selectRow }, (res: boolean) => {
|
|
|
|
if (res) {
|
2023-12-28 14:27:47 +08:00
|
|
|
const index = tableData.value.findIndex((item: any) => item === selectRow)
|
|
|
|
tableData.value.splice(index, 1)
|
|
|
|
console.log('调用删除', selectRow, index)
|
2023-12-18 14:29:28 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
const enableChange = (e: any) => {
|
2023-12-26 17:11:15 +08:00
|
|
|
ElMessage.success(e.enable ? '启用成功' : '禁用成功')
|
2023-12-18 14:29:28 +08:00
|
|
|
}
|
|
|
|
const resetPassword = (e: any) => {
|
2023-12-28 10:18:10 +08:00
|
|
|
ElMessageBox.confirm('是否确定要重置密码?', '系统提醒', { type: 'warning', draggable: true }).then(() => {
|
2023-12-18 14:29:28 +08:00
|
|
|
ElMessage.success('重置成功!')
|
|
|
|
}).catch(() => { })
|
|
|
|
}
|
|
|
|
const editData = (e: any) => {
|
|
|
|
isFormDialog.value = true
|
|
|
|
formDialogTitle.value = '修改'
|
|
|
|
setTimeout(() => {
|
|
|
|
doctorFormRef.value.resetData()
|
2023-12-24 16:15:33 +08:00
|
|
|
doctorFormRef.value.formData = JSON.parse(JSON.stringify(e))
|
2023-12-18 14:29:28 +08:00
|
|
|
}, 0)
|
|
|
|
}
|
|
|
|
const tableRowClick = (row: any) => {
|
|
|
|
tableRef.value.toggleRowSelection(row)
|
|
|
|
}
|
2023-12-28 14:27:47 +08:00
|
|
|
const doctorFormSave = (data: any, type: string) => {
|
|
|
|
if(type === 'add') {
|
|
|
|
tableData.value.unshift(Object.assign({}, data))
|
|
|
|
}else {
|
|
|
|
tableData.value.forEach((item: any) => {
|
|
|
|
if(item.id === data.id) {
|
|
|
|
Object.assign(item, data)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
console.log(data, type)
|
|
|
|
}
|
2023-12-17 16:05:38 +08:00
|
|
|
const paginationChange = (page: number, size: number) => {
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2023-12-27 16:49:37 +08:00
|
|
|
<style lang='scss' scoped></style>
|