diff --git a/src/router/modules/measure.ts b/src/router/modules/measure.ts index 2fc1181..759009e 100644 --- a/src/router/modules/measure.ts +++ b/src/router/modules/measure.ts @@ -202,6 +202,18 @@ }, }, { + path: ':type/:id?', + name: 'PlanAdd', + component: () => import('@/views/measure/train/planAdd.vue'), + meta: { + title: '培训计划', + icon: 'ep:key', + sidebar: false, + breadcrumb: true, + activeMenu: '/measure/train/plan', + }, + }, + { path: 'trainPlanApprove', name: 'TrainPlanApprove', component: () => import('@/views/measure/train/trainPlanApprove.vue'), @@ -221,6 +233,18 @@ auth: '/measure/train/trainLog', }, }, + { + path: 'trainLog/:type/:id?', + name: 'planlogAdd', + component: () => import('@/views/measure/train/trainLogAdd.vue'), + meta: { + title: '培训记录', + icon: 'ep:key', + sidebar: false, + breadcrumb: true, + activeMenu: '/measure/train/trainLog', + }, + }, ], }, { diff --git a/src/router/modules/measure.ts b/src/router/modules/measure.ts index 2fc1181..759009e 100644 --- a/src/router/modules/measure.ts +++ b/src/router/modules/measure.ts @@ -202,6 +202,18 @@ }, }, { + path: ':type/:id?', + name: 'PlanAdd', + component: () => import('@/views/measure/train/planAdd.vue'), + meta: { + title: '培训计划', + icon: 'ep:key', + sidebar: false, + breadcrumb: true, + activeMenu: '/measure/train/plan', + }, + }, + { path: 'trainPlanApprove', name: 'TrainPlanApprove', component: () => import('@/views/measure/train/trainPlanApprove.vue'), @@ -221,6 +233,18 @@ auth: '/measure/train/trainLog', }, }, + { + path: 'trainLog/:type/:id?', + name: 'planlogAdd', + component: () => import('@/views/measure/train/trainLogAdd.vue'), + meta: { + title: '培训记录', + icon: 'ep:key', + sidebar: false, + breadcrumb: true, + activeMenu: '/measure/train/trainLog', + }, + }, ], }, { diff --git a/src/views/measure/price/list_interface.ts b/src/views/measure/price/list_interface.ts index f4c394f..9e1df00 100644 --- a/src/views/measure/price/list_interface.ts +++ b/src/views/measure/price/list_interface.ts @@ -43,10 +43,10 @@ // 价格表单对象类型 export interface priceForm { checkType: string // 校验类型-字典value - createTime: string // 创建时间 + createTime: null | string // 创建时间 directorDiscountPermission: string // 负责人折扣权限-字典value historicalPriceList?: historyPriceItem[] // 历史价格列表 - id: string // 主键id + id: null | string // 主键id isDel: number // 删除标记 model: string // 型号 operatorDiscountPermission: string // 业务员折扣权限-字典value @@ -59,5 +59,5 @@ priceStandard: string // 依据标准-计量规程文件名 priceType: string // 价格类别-字典value remark: string // 备注 - updateTime: string // 更新时间 + updateTime: null | string // 更新时间 } diff --git a/src/router/modules/measure.ts b/src/router/modules/measure.ts index 2fc1181..759009e 100644 --- a/src/router/modules/measure.ts +++ b/src/router/modules/measure.ts @@ -202,6 +202,18 @@ }, }, { + path: ':type/:id?', + name: 'PlanAdd', + component: () => import('@/views/measure/train/planAdd.vue'), + meta: { + title: '培训计划', + icon: 'ep:key', + sidebar: false, + breadcrumb: true, + activeMenu: '/measure/train/plan', + }, + }, + { path: 'trainPlanApprove', name: 'TrainPlanApprove', component: () => import('@/views/measure/train/trainPlanApprove.vue'), @@ -221,6 +233,18 @@ auth: '/measure/train/trainLog', }, }, + { + path: 'trainLog/:type/:id?', + name: 'planlogAdd', + component: () => import('@/views/measure/train/trainLogAdd.vue'), + meta: { + title: '培训记录', + icon: 'ep:key', + sidebar: false, + breadcrumb: true, + activeMenu: '/measure/train/trainLog', + }, + }, ], }, { diff --git a/src/views/measure/price/list_interface.ts b/src/views/measure/price/list_interface.ts index f4c394f..9e1df00 100644 --- a/src/views/measure/price/list_interface.ts +++ b/src/views/measure/price/list_interface.ts @@ -43,10 +43,10 @@ // 价格表单对象类型 export interface priceForm { checkType: string // 校验类型-字典value - createTime: string // 创建时间 + createTime: null | string // 创建时间 directorDiscountPermission: string // 负责人折扣权限-字典value historicalPriceList?: historyPriceItem[] // 历史价格列表 - id: string // 主键id + id: null | string // 主键id isDel: number // 删除标记 model: string // 型号 operatorDiscountPermission: string // 业务员折扣权限-字典value @@ -59,5 +59,5 @@ priceStandard: string // 依据标准-计量规程文件名 priceType: string // 价格类别-字典value remark: string // 备注 - updateTime: string // 更新时间 + updateTime: null | string // 更新时间 } diff --git a/src/views/measure/price/priceAdd.vue b/src/views/measure/price/priceAdd.vue index 1195962..a776302 100644 --- a/src/views/measure/price/priceAdd.vue +++ b/src/views/measure/price/priceAdd.vue @@ -26,10 +26,10 @@ } const defaultForm: priceForm = { checkType: '', - createTime: '', + createTime: null, directorDiscountPermission: '', historicalPriceList: [], - id: '', + id: null, isDel: 0, model: '', operatorDiscountPermission: '', @@ -42,7 +42,7 @@ priceStandard: '', priceType: '', remark: '', - updateTime: '', + updateTime: null, } const formInline: Ref = ref({ ...defaultForm }) const ruleFormRef = ref() diff --git a/src/router/modules/measure.ts b/src/router/modules/measure.ts index 2fc1181..759009e 100644 --- a/src/router/modules/measure.ts +++ b/src/router/modules/measure.ts @@ -202,6 +202,18 @@ }, }, { + path: ':type/:id?', + name: 'PlanAdd', + component: () => import('@/views/measure/train/planAdd.vue'), + meta: { + title: '培训计划', + icon: 'ep:key', + sidebar: false, + breadcrumb: true, + activeMenu: '/measure/train/plan', + }, + }, + { path: 'trainPlanApprove', name: 'TrainPlanApprove', component: () => import('@/views/measure/train/trainPlanApprove.vue'), @@ -221,6 +233,18 @@ auth: '/measure/train/trainLog', }, }, + { + path: 'trainLog/:type/:id?', + name: 'planlogAdd', + component: () => import('@/views/measure/train/trainLogAdd.vue'), + meta: { + title: '培训记录', + icon: 'ep:key', + sidebar: false, + breadcrumb: true, + activeMenu: '/measure/train/trainLog', + }, + }, ], }, { diff --git a/src/views/measure/price/list_interface.ts b/src/views/measure/price/list_interface.ts index f4c394f..9e1df00 100644 --- a/src/views/measure/price/list_interface.ts +++ b/src/views/measure/price/list_interface.ts @@ -43,10 +43,10 @@ // 价格表单对象类型 export interface priceForm { checkType: string // 校验类型-字典value - createTime: string // 创建时间 + createTime: null | string // 创建时间 directorDiscountPermission: string // 负责人折扣权限-字典value historicalPriceList?: historyPriceItem[] // 历史价格列表 - id: string // 主键id + id: null | string // 主键id isDel: number // 删除标记 model: string // 型号 operatorDiscountPermission: string // 业务员折扣权限-字典value @@ -59,5 +59,5 @@ priceStandard: string // 依据标准-计量规程文件名 priceType: string // 价格类别-字典value remark: string // 备注 - updateTime: string // 更新时间 + updateTime: null | string // 更新时间 } diff --git a/src/views/measure/price/priceAdd.vue b/src/views/measure/price/priceAdd.vue index 1195962..a776302 100644 --- a/src/views/measure/price/priceAdd.vue +++ b/src/views/measure/price/priceAdd.vue @@ -26,10 +26,10 @@ } const defaultForm: priceForm = { checkType: '', - createTime: '', + createTime: null, directorDiscountPermission: '', historicalPriceList: [], - id: '', + id: null, isDel: 0, model: '', operatorDiscountPermission: '', @@ -42,7 +42,7 @@ priceStandard: '', priceType: '', remark: '', - updateTime: '', + updateTime: null, } const formInline: Ref = ref({ ...defaultForm }) const ruleFormRef = ref() diff --git a/src/views/measure/train/plan.vue b/src/views/measure/train/plan.vue index 5c99aa8..1467017 100644 --- a/src/views/measure/train/plan.vue +++ b/src/views/measure/train/plan.vue @@ -3,10 +3,8 @@ import { getCurrentInstance, reactive, ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import type { IOptions, IlistQuery, IlistType } from './plan_interface' -import PlanAdd from './planAdd.vue' import { exportExcel } from '@/utils/exportXlsx' import { getDeptTree, getListDelete, getPlanList } from '@/api/system/plan' -import QrDialog from '@/components/QrDialog/index.vue' const listQuery: Ref = ref({ trainTime: '', createTime: '', @@ -27,6 +25,8 @@ // 主管部门下拉框 const options = ref([]) const loadingTable = ref(false) +// 初始化路由 +const $router = useRouter() const fetchData = (isNowPage: boolean) => { loadingTable.value = true if (!isNowPage) { @@ -163,11 +163,9 @@ id: string planName: string } -const handleEdit = (index: string, row: rowReturn, type: string) => { - console.log(row) - infoId.value = row.id - buttonType.value = type - show.value = false +// 点击编辑/详情 +const handleEdit = (row: rowReturn, pageType: 'edit' | 'detail') => { + $router.push(`/train/${pageType}/${row.id}`) } // 点击删除 const handleDelete = (index: string, row: rowReturn) => { @@ -197,9 +195,7 @@ checkoutList.value = e } const add = () => { - infoId.value = '' - buttonType.value = '新建' - show.value = false + $router.push('/train/add') } const exportAll = () => { exportExcelBtn() @@ -226,10 +222,6 @@ } fetchData(true) } -const qrDialog = ref() -function showQrDialog(row) { - qrDialog.value.initDialog(row.id, row.planName) -} // 打印 const printObj = ref({ id: 'print', // 需要打印元素的id @@ -311,7 +303,7 @@ size="small" type="primary" link - @click="handleEdit(row.$index, row, '编辑')" + @click="handleEdit(row, 'edit')" > 编辑 @@ -319,7 +311,7 @@ size="small" link type="primary" - @click="handleEdit(row.$index, row, '详情')" + @click="handleEdit(row, 'detail')" > 详情 @@ -336,7 +328,6 @@ size="small" link type="primary" - @click="showQrDialog(row)" > 二维码 @@ -346,18 +337,5 @@ - - - - diff --git a/src/router/modules/measure.ts b/src/router/modules/measure.ts index 2fc1181..759009e 100644 --- a/src/router/modules/measure.ts +++ b/src/router/modules/measure.ts @@ -202,6 +202,18 @@ }, }, { + path: ':type/:id?', + name: 'PlanAdd', + component: () => import('@/views/measure/train/planAdd.vue'), + meta: { + title: '培训计划', + icon: 'ep:key', + sidebar: false, + breadcrumb: true, + activeMenu: '/measure/train/plan', + }, + }, + { path: 'trainPlanApprove', name: 'TrainPlanApprove', component: () => import('@/views/measure/train/trainPlanApprove.vue'), @@ -221,6 +233,18 @@ auth: '/measure/train/trainLog', }, }, + { + path: 'trainLog/:type/:id?', + name: 'planlogAdd', + component: () => import('@/views/measure/train/trainLogAdd.vue'), + meta: { + title: '培训记录', + icon: 'ep:key', + sidebar: false, + breadcrumb: true, + activeMenu: '/measure/train/trainLog', + }, + }, ], }, { diff --git a/src/views/measure/price/list_interface.ts b/src/views/measure/price/list_interface.ts index f4c394f..9e1df00 100644 --- a/src/views/measure/price/list_interface.ts +++ b/src/views/measure/price/list_interface.ts @@ -43,10 +43,10 @@ // 价格表单对象类型 export interface priceForm { checkType: string // 校验类型-字典value - createTime: string // 创建时间 + createTime: null | string // 创建时间 directorDiscountPermission: string // 负责人折扣权限-字典value historicalPriceList?: historyPriceItem[] // 历史价格列表 - id: string // 主键id + id: null | string // 主键id isDel: number // 删除标记 model: string // 型号 operatorDiscountPermission: string // 业务员折扣权限-字典value @@ -59,5 +59,5 @@ priceStandard: string // 依据标准-计量规程文件名 priceType: string // 价格类别-字典value remark: string // 备注 - updateTime: string // 更新时间 + updateTime: null | string // 更新时间 } diff --git a/src/views/measure/price/priceAdd.vue b/src/views/measure/price/priceAdd.vue index 1195962..a776302 100644 --- a/src/views/measure/price/priceAdd.vue +++ b/src/views/measure/price/priceAdd.vue @@ -26,10 +26,10 @@ } const defaultForm: priceForm = { checkType: '', - createTime: '', + createTime: null, directorDiscountPermission: '', historicalPriceList: [], - id: '', + id: null, isDel: 0, model: '', operatorDiscountPermission: '', @@ -42,7 +42,7 @@ priceStandard: '', priceType: '', remark: '', - updateTime: '', + updateTime: null, } const formInline: Ref = ref({ ...defaultForm }) const ruleFormRef = ref() diff --git a/src/views/measure/train/plan.vue b/src/views/measure/train/plan.vue index 5c99aa8..1467017 100644 --- a/src/views/measure/train/plan.vue +++ b/src/views/measure/train/plan.vue @@ -3,10 +3,8 @@ import { getCurrentInstance, reactive, ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import type { IOptions, IlistQuery, IlistType } from './plan_interface' -import PlanAdd from './planAdd.vue' import { exportExcel } from '@/utils/exportXlsx' import { getDeptTree, getListDelete, getPlanList } from '@/api/system/plan' -import QrDialog from '@/components/QrDialog/index.vue' const listQuery: Ref = ref({ trainTime: '', createTime: '', @@ -27,6 +25,8 @@ // 主管部门下拉框 const options = ref([]) const loadingTable = ref(false) +// 初始化路由 +const $router = useRouter() const fetchData = (isNowPage: boolean) => { loadingTable.value = true if (!isNowPage) { @@ -163,11 +163,9 @@ id: string planName: string } -const handleEdit = (index: string, row: rowReturn, type: string) => { - console.log(row) - infoId.value = row.id - buttonType.value = type - show.value = false +// 点击编辑/详情 +const handleEdit = (row: rowReturn, pageType: 'edit' | 'detail') => { + $router.push(`/train/${pageType}/${row.id}`) } // 点击删除 const handleDelete = (index: string, row: rowReturn) => { @@ -197,9 +195,7 @@ checkoutList.value = e } const add = () => { - infoId.value = '' - buttonType.value = '新建' - show.value = false + $router.push('/train/add') } const exportAll = () => { exportExcelBtn() @@ -226,10 +222,6 @@ } fetchData(true) } -const qrDialog = ref() -function showQrDialog(row) { - qrDialog.value.initDialog(row.id, row.planName) -} // 打印 const printObj = ref({ id: 'print', // 需要打印元素的id @@ -311,7 +303,7 @@ size="small" type="primary" link - @click="handleEdit(row.$index, row, '编辑')" + @click="handleEdit(row, 'edit')" > 编辑 @@ -319,7 +311,7 @@ size="small" link type="primary" - @click="handleEdit(row.$index, row, '详情')" + @click="handleEdit(row, 'detail')" > 详情 @@ -336,7 +328,6 @@ size="small" link type="primary" - @click="showQrDialog(row)" > 二维码 @@ -346,18 +337,5 @@ - - - - diff --git a/src/views/measure/train/planAdd.vue b/src/views/measure/train/planAdd.vue index 76ed102..e1457c8 100644 --- a/src/views/measure/train/planAdd.vue +++ b/src/views/measure/train/planAdd.vue @@ -10,17 +10,23 @@ getListDetail, getListUpdate, } from '@/api/system/plan' -const props = defineProps({ - infoId: { - type: String, - default: '', - }, - buttonType: { - type: String, - default: '', - }, -}) -const emit = defineEmits(['close']) +const loading = ref(false) // 表单加载状态 +const infoId = ref('') // id +const pageType = ref('add') // 页面类型: add,edit, detail +const buttonLoading = ref(false) // 按钮加载状态 +const textMap: { [key: string]: string } = { + edit: '编辑', + add: '新建', + detail: '详情', +}// 字典 +// 从路由中获取页面类型参数 +const $route = useRoute() +if ($route.params && $route.params.type) { + pageType.value = $route.params.type as string + if ($route.params.id) { + infoId.value = $route.params.id as string + } +} const formInline = ref({ createTime: null, deptId: null, @@ -72,9 +78,18 @@ director: [{ required: true, message: '负责人不能为空', trigger: 'blur' }], trainContent: [{ required: true, message: '培训内容不能为空', trigger: 'blur' }], }) // 表单验证规则 +// 新增校验规则 +const addRules = ref({ + name: [{ required: true, message: '学员名称不能为空', trigger: 'blur' }], + company: [{ required: true, message: '单位名称不能为空', trigger: 'blur' }], + technologyJob: [{ required: true, message: '技术职称不能为空', trigger: 'blur' }], + signTime: [{ required: true, message: '签到时间不能为空', trigger: 'blur' }], +}) // 表单验证规则 +// 初始化router +const $router = useRouter() // 关闭新增页面的回调 const close = () => { - emit('close') + $router.back() } const userListRef = ref() // 选择人员 @@ -115,13 +130,13 @@ console.log(object) formInline.value.director = object.name } -if (props.infoId && props.infoId !== '') { - getListDetail({ id: props.infoId }).then((res) => { +if (infoId.value && infoId.value !== '') { + getListDetail({ id: infoId.value }).then((res) => { formInline.value = res.data }) } const getAddList = async (formEl: FormInstance | undefined, buttonType: string) => { - if (buttonType === '提交' && props.buttonType !== '编辑') { + if (buttonType === '提交' && pageType.value !== 'edit') { if (!formEl) { return } await formEl.validate((valid, fields) => { if (valid) { @@ -143,12 +158,12 @@ } }) } - else if (buttonType === '提交' && props.buttonType === '编辑') { + else if (buttonType === '提交' && pageType.value === 'edit') { formInline.value.trainStaffList.map((item) => { delete item.updateTime delete item.createTime }) - formInline.value.id = props.infoId + formInline.value.id = infoId.value getListUpdate(formInline.value).then((res) => { if (res.code === 200) { close() @@ -171,16 +186,16 @@ - - diff --git a/src/views/measure/train/planAdd.vue b/src/views/measure/train/planAdd.vue index 76ed102..e1457c8 100644 --- a/src/views/measure/train/planAdd.vue +++ b/src/views/measure/train/planAdd.vue @@ -10,17 +10,23 @@ getListDetail, getListUpdate, } from '@/api/system/plan' -const props = defineProps({ - infoId: { - type: String, - default: '', - }, - buttonType: { - type: String, - default: '', - }, -}) -const emit = defineEmits(['close']) +const loading = ref(false) // 表单加载状态 +const infoId = ref('') // id +const pageType = ref('add') // 页面类型: add,edit, detail +const buttonLoading = ref(false) // 按钮加载状态 +const textMap: { [key: string]: string } = { + edit: '编辑', + add: '新建', + detail: '详情', +}// 字典 +// 从路由中获取页面类型参数 +const $route = useRoute() +if ($route.params && $route.params.type) { + pageType.value = $route.params.type as string + if ($route.params.id) { + infoId.value = $route.params.id as string + } +} const formInline = ref({ createTime: null, deptId: null, @@ -72,9 +78,18 @@ director: [{ required: true, message: '负责人不能为空', trigger: 'blur' }], trainContent: [{ required: true, message: '培训内容不能为空', trigger: 'blur' }], }) // 表单验证规则 +// 新增校验规则 +const addRules = ref({ + name: [{ required: true, message: '学员名称不能为空', trigger: 'blur' }], + company: [{ required: true, message: '单位名称不能为空', trigger: 'blur' }], + technologyJob: [{ required: true, message: '技术职称不能为空', trigger: 'blur' }], + signTime: [{ required: true, message: '签到时间不能为空', trigger: 'blur' }], +}) // 表单验证规则 +// 初始化router +const $router = useRouter() // 关闭新增页面的回调 const close = () => { - emit('close') + $router.back() } const userListRef = ref() // 选择人员 @@ -115,13 +130,13 @@ console.log(object) formInline.value.director = object.name } -if (props.infoId && props.infoId !== '') { - getListDetail({ id: props.infoId }).then((res) => { +if (infoId.value && infoId.value !== '') { + getListDetail({ id: infoId.value }).then((res) => { formInline.value = res.data }) } const getAddList = async (formEl: FormInstance | undefined, buttonType: string) => { - if (buttonType === '提交' && props.buttonType !== '编辑') { + if (buttonType === '提交' && pageType.value !== 'edit') { if (!formEl) { return } await formEl.validate((valid, fields) => { if (valid) { @@ -143,12 +158,12 @@ } }) } - else if (buttonType === '提交' && props.buttonType === '编辑') { + else if (buttonType === '提交' && pageType.value === 'edit') { formInline.value.trainStaffList.map((item) => { delete item.updateTime delete item.createTime }) - formInline.value.id = props.infoId + formInline.value.id = infoId.value getListUpdate(formInline.value).then((res) => { if (res.code === 200) { close() @@ -171,16 +186,16 @@ - diff --git a/src/router/modules/measure.ts b/src/router/modules/measure.ts index 2fc1181..759009e 100644 --- a/src/router/modules/measure.ts +++ b/src/router/modules/measure.ts @@ -202,6 +202,18 @@ }, }, { + path: ':type/:id?', + name: 'PlanAdd', + component: () => import('@/views/measure/train/planAdd.vue'), + meta: { + title: '培训计划', + icon: 'ep:key', + sidebar: false, + breadcrumb: true, + activeMenu: '/measure/train/plan', + }, + }, + { path: 'trainPlanApprove', name: 'TrainPlanApprove', component: () => import('@/views/measure/train/trainPlanApprove.vue'), @@ -221,6 +233,18 @@ auth: '/measure/train/trainLog', }, }, + { + path: 'trainLog/:type/:id?', + name: 'planlogAdd', + component: () => import('@/views/measure/train/trainLogAdd.vue'), + meta: { + title: '培训记录', + icon: 'ep:key', + sidebar: false, + breadcrumb: true, + activeMenu: '/measure/train/trainLog', + }, + }, ], }, { diff --git a/src/views/measure/price/list_interface.ts b/src/views/measure/price/list_interface.ts index f4c394f..9e1df00 100644 --- a/src/views/measure/price/list_interface.ts +++ b/src/views/measure/price/list_interface.ts @@ -43,10 +43,10 @@ // 价格表单对象类型 export interface priceForm { checkType: string // 校验类型-字典value - createTime: string // 创建时间 + createTime: null | string // 创建时间 directorDiscountPermission: string // 负责人折扣权限-字典value historicalPriceList?: historyPriceItem[] // 历史价格列表 - id: string // 主键id + id: null | string // 主键id isDel: number // 删除标记 model: string // 型号 operatorDiscountPermission: string // 业务员折扣权限-字典value @@ -59,5 +59,5 @@ priceStandard: string // 依据标准-计量规程文件名 priceType: string // 价格类别-字典value remark: string // 备注 - updateTime: string // 更新时间 + updateTime: null | string // 更新时间 } diff --git a/src/views/measure/price/priceAdd.vue b/src/views/measure/price/priceAdd.vue index 1195962..a776302 100644 --- a/src/views/measure/price/priceAdd.vue +++ b/src/views/measure/price/priceAdd.vue @@ -26,10 +26,10 @@ } const defaultForm: priceForm = { checkType: '', - createTime: '', + createTime: null, directorDiscountPermission: '', historicalPriceList: [], - id: '', + id: null, isDel: 0, model: '', operatorDiscountPermission: '', @@ -42,7 +42,7 @@ priceStandard: '', priceType: '', remark: '', - updateTime: '', + updateTime: null, } const formInline: Ref = ref({ ...defaultForm }) const ruleFormRef = ref() diff --git a/src/views/measure/train/plan.vue b/src/views/measure/train/plan.vue index 5c99aa8..1467017 100644 --- a/src/views/measure/train/plan.vue +++ b/src/views/measure/train/plan.vue @@ -3,10 +3,8 @@ import { getCurrentInstance, reactive, ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import type { IOptions, IlistQuery, IlistType } from './plan_interface' -import PlanAdd from './planAdd.vue' import { exportExcel } from '@/utils/exportXlsx' import { getDeptTree, getListDelete, getPlanList } from '@/api/system/plan' -import QrDialog from '@/components/QrDialog/index.vue' const listQuery: Ref = ref({ trainTime: '', createTime: '', @@ -27,6 +25,8 @@ // 主管部门下拉框 const options = ref([]) const loadingTable = ref(false) +// 初始化路由 +const $router = useRouter() const fetchData = (isNowPage: boolean) => { loadingTable.value = true if (!isNowPage) { @@ -163,11 +163,9 @@ id: string planName: string } -const handleEdit = (index: string, row: rowReturn, type: string) => { - console.log(row) - infoId.value = row.id - buttonType.value = type - show.value = false +// 点击编辑/详情 +const handleEdit = (row: rowReturn, pageType: 'edit' | 'detail') => { + $router.push(`/train/${pageType}/${row.id}`) } // 点击删除 const handleDelete = (index: string, row: rowReturn) => { @@ -197,9 +195,7 @@ checkoutList.value = e } const add = () => { - infoId.value = '' - buttonType.value = '新建' - show.value = false + $router.push('/train/add') } const exportAll = () => { exportExcelBtn() @@ -226,10 +222,6 @@ } fetchData(true) } -const qrDialog = ref() -function showQrDialog(row) { - qrDialog.value.initDialog(row.id, row.planName) -} // 打印 const printObj = ref({ id: 'print', // 需要打印元素的id @@ -311,7 +303,7 @@ size="small" type="primary" link - @click="handleEdit(row.$index, row, '编辑')" + @click="handleEdit(row, 'edit')" > 编辑 @@ -319,7 +311,7 @@ size="small" link type="primary" - @click="handleEdit(row.$index, row, '详情')" + @click="handleEdit(row, 'detail')" > 详情 @@ -336,7 +328,6 @@ size="small" link type="primary" - @click="showQrDialog(row)" > 二维码 @@ -346,18 +337,5 @@ - - - - diff --git a/src/views/measure/train/planAdd.vue b/src/views/measure/train/planAdd.vue index 76ed102..e1457c8 100644 --- a/src/views/measure/train/planAdd.vue +++ b/src/views/measure/train/planAdd.vue @@ -10,17 +10,23 @@ getListDetail, getListUpdate, } from '@/api/system/plan' -const props = defineProps({ - infoId: { - type: String, - default: '', - }, - buttonType: { - type: String, - default: '', - }, -}) -const emit = defineEmits(['close']) +const loading = ref(false) // 表单加载状态 +const infoId = ref('') // id +const pageType = ref('add') // 页面类型: add,edit, detail +const buttonLoading = ref(false) // 按钮加载状态 +const textMap: { [key: string]: string } = { + edit: '编辑', + add: '新建', + detail: '详情', +}// 字典 +// 从路由中获取页面类型参数 +const $route = useRoute() +if ($route.params && $route.params.type) { + pageType.value = $route.params.type as string + if ($route.params.id) { + infoId.value = $route.params.id as string + } +} const formInline = ref({ createTime: null, deptId: null, @@ -72,9 +78,18 @@ director: [{ required: true, message: '负责人不能为空', trigger: 'blur' }], trainContent: [{ required: true, message: '培训内容不能为空', trigger: 'blur' }], }) // 表单验证规则 +// 新增校验规则 +const addRules = ref({ + name: [{ required: true, message: '学员名称不能为空', trigger: 'blur' }], + company: [{ required: true, message: '单位名称不能为空', trigger: 'blur' }], + technologyJob: [{ required: true, message: '技术职称不能为空', trigger: 'blur' }], + signTime: [{ required: true, message: '签到时间不能为空', trigger: 'blur' }], +}) // 表单验证规则 +// 初始化router +const $router = useRouter() // 关闭新增页面的回调 const close = () => { - emit('close') + $router.back() } const userListRef = ref() // 选择人员 @@ -115,13 +130,13 @@ console.log(object) formInline.value.director = object.name } -if (props.infoId && props.infoId !== '') { - getListDetail({ id: props.infoId }).then((res) => { +if (infoId.value && infoId.value !== '') { + getListDetail({ id: infoId.value }).then((res) => { formInline.value = res.data }) } const getAddList = async (formEl: FormInstance | undefined, buttonType: string) => { - if (buttonType === '提交' && props.buttonType !== '编辑') { + if (buttonType === '提交' && pageType.value !== 'edit') { if (!formEl) { return } await formEl.validate((valid, fields) => { if (valid) { @@ -143,12 +158,12 @@ } }) } - else if (buttonType === '提交' && props.buttonType === '编辑') { + else if (buttonType === '提交' && pageType.value === 'edit') { formInline.value.trainStaffList.map((item) => { delete item.updateTime delete item.createTime }) - formInline.value.id = props.infoId + formInline.value.id = infoId.value getListUpdate(formInline.value).then((res) => { if (res.code === 200) { close() @@ -171,16 +186,16 @@ - diff --git a/src/views/measure/train/trainLogAdd.vue b/src/views/measure/train/trainLogAdd.vue index 32422e1..64ddd58 100644 --- a/src/views/measure/train/trainLogAdd.vue +++ b/src/views/measure/train/trainLogAdd.vue @@ -1,4 +1,4 @@ -