From f9f8afcb0a32929502c4f606828ebee61b06836b Mon Sep 17 00:00:00 2001 From: YDKD <1606354057@qq.com> Date: Tue, 12 Apr 2022 15:48:20 +0800 Subject: [PATCH] feat(salary): complete salary functional --- index.html | 2 +- src/api/getApi.ts | 7 ++ src/api/postApi.ts | 10 +- src/styles/index.less | 1 + src/views/salary/components/salary-panel.vue | 104 +++++++++++++++++++ src/views/salary/hooks/index.ts | 28 +++++ src/views/salary/hooks/useForm.ts | 71 +++++++++++++ src/views/salary/index.vue | 26 +++++ src/views/salary/types/index.ts | 16 +++ types/components.d.ts | 3 +- 10 files changed, 265 insertions(+), 3 deletions(-) create mode 100644 src/views/salary/components/salary-panel.vue create mode 100644 src/views/salary/hooks/index.ts create mode 100644 src/views/salary/hooks/useForm.ts create mode 100644 src/views/salary/index.vue create mode 100644 src/views/salary/types/index.ts diff --git a/index.html b/index.html index 386262b..c3afc6f 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ - + diff --git a/src/api/getApi.ts b/src/api/getApi.ts index 04849ec..79f372e 100644 --- a/src/api/getApi.ts +++ b/src/api/getApi.ts @@ -59,6 +59,13 @@ export function getPerson(params: any) { params }) } +export function getWorkerSalary(params: any) { + return defaultRequest.request({ + url: '/sys/person/salary', + method: 'GET', + params + }) +} export function getSerialNum() { return defaultRequest.request({ diff --git a/src/api/postApi.ts b/src/api/postApi.ts index 3dd27e4..dff8131 100644 --- a/src/api/postApi.ts +++ b/src/api/postApi.ts @@ -3,7 +3,7 @@ * @Autor: YDKD * @Date: 2022-03-19 18:42:32 * @LastEditors: YDKD - * @LastEditTime: 2022-04-04 20:44:17 + * @LastEditTime: 2022-04-12 15:21:44 */ import { defaultRequest } from '@/service' import { ReutrnDataType } from './type' @@ -55,3 +55,11 @@ export function addPersonInfo(data: any) { data }) } + +export function updateWorkerSalary(data: any) { + return defaultRequest.request({ + url: '/sys/person/salary', + method: 'POST', + data + }) +} diff --git a/src/styles/index.less b/src/styles/index.less index bcded54..3657e2e 100644 --- a/src/styles/index.less +++ b/src/styles/index.less @@ -1,2 +1,3 @@ @import './var.css'; @import './transition.css'; +@import './element-plus.css'; diff --git a/src/views/salary/components/salary-panel.vue b/src/views/salary/components/salary-panel.vue new file mode 100644 index 0000000..14d87af --- /dev/null +++ b/src/views/salary/components/salary-panel.vue @@ -0,0 +1,104 @@ + + + + diff --git a/src/views/salary/hooks/index.ts b/src/views/salary/hooks/index.ts new file mode 100644 index 0000000..85ecc63 --- /dev/null +++ b/src/views/salary/hooks/index.ts @@ -0,0 +1,28 @@ +/* + * @Version: 1.0 + * @Autor: YDKD + * @Date: 2022-04-12 10:26:56 + * @LastEditors: YDKD + * @LastEditTime: 2022-04-12 15:29:53 + */ +import { + searchName, + getInitData, + queried, + salaryForm, + salaryFormRef, + submit, + real_pay, + step +} from './useForm' + +export { + searchName, + getInitData, + queried, + salaryForm, + salaryFormRef, + submit, + real_pay, + step +} diff --git a/src/views/salary/hooks/useForm.ts b/src/views/salary/hooks/useForm.ts new file mode 100644 index 0000000..40c1994 --- /dev/null +++ b/src/views/salary/hooks/useForm.ts @@ -0,0 +1,71 @@ +/* + * @Version: 1.0 + * @Autor: YDKD + * @Date: 2022-04-12 10:27:55 + * @LastEditors: YDKD + * @LastEditTime: 2022-04-12 15:42:33 + */ +import { getWorkerSalary } from '@/api/getApi' +import { updateWorkerSalary } from '@/api/postApi' +import { useMessage } from '@/hooks' +import { FormInstance } from 'element-plus' +import { computed, ref } from 'vue' + +import type { SalaryForm } from '../types' + +const searchName = ref('小王') + +const queried = ref(false) + +const salaryFormRef = ref() + +const step = 20 + +const salaryForm = ref({ + id: '', + serialNumber: '', + base_pay: 0, + allowance: 0, + performance_pay: 0, + tax: 0, + workerName: '' +}) + +const real_pay = computed(() => { + const { base_pay, allowance, performance_pay, tax } = salaryForm.value + return base_pay + performance_pay + allowance - tax +}) + +const getInitData = async () => { + if (searchName.value == '') return + const params = { + username: searchName.value + } + const { data, code } = await getWorkerSalary(params) + if (code == 200) { + const result: Array | undefined = await data.result + if (result && result.length > 0) { + salaryForm.value = result[0] + queried.value = true + } else { + useMessage({ msg: '未查询到该职工信息', type: 'error' }) + queried.value = false + } + } +} + +const submit = async () => { + const { code, msg } = await updateWorkerSalary(salaryForm.value) + useMessage({ msg: msg, type: code == 200 ? 'success' : 'error' }) +} + +export { + searchName, + getInitData, + queried, + salaryForm, + salaryFormRef, + submit, + real_pay, + step +} diff --git a/src/views/salary/index.vue b/src/views/salary/index.vue new file mode 100644 index 0000000..9606e3c --- /dev/null +++ b/src/views/salary/index.vue @@ -0,0 +1,26 @@ + + + + + + diff --git a/src/views/salary/types/index.ts b/src/views/salary/types/index.ts new file mode 100644 index 0000000..784d8a9 --- /dev/null +++ b/src/views/salary/types/index.ts @@ -0,0 +1,16 @@ +/* + * @Version: 1.0 + * @Autor: YDKD + * @Date: 2022-04-12 11:08:28 + * @LastEditors: YDKD + * @LastEditTime: 2022-04-12 15:28:58 + */ +export type SalaryForm = { + id: number | string + allowance: number + base_pay: number + performance_pay: number + serialNumber: number | string + tax: number + workerName: string +} diff --git a/types/components.d.ts b/types/components.d.ts index 2b007c8..b0682af 100644 --- a/types/components.d.ts +++ b/types/components.d.ts @@ -10,7 +10,6 @@ declare module 'vue' { ElAvatar: typeof import('element-plus/es')['ElAvatar'] ElButton: typeof import('element-plus/es')['ElButton'] ElCard: typeof import('element-plus/es')['ElCard'] - ElCheckbox: typeof import('element-plus/es')['ElCheckbox'] ElCol: typeof import('element-plus/es')['ElCol'] ElContainer: typeof import('element-plus/es')['ElContainer'] ElDropdown: typeof import('element-plus/es')['ElDropdown'] @@ -21,7 +20,9 @@ declare module 'vue' { ElHeader: typeof import('element-plus/es')['ElHeader'] ElIcon: typeof import('element-plus/es')['ElIcon'] ElInput: typeof import('element-plus/es')['ElInput'] + ElInputNumber: typeof import('element-plus/es')['ElInputNumber'] ElMain: typeof import('element-plus/es')['ElMain'] + ElNumberInput: typeof import('element-plus/es')['ElNumberInput'] ElPagination: typeof import('element-plus/es')['ElPagination'] ElRow: typeof import('element-plus/es')['ElRow'] ElSkeleton: typeof import('element-plus/es')['ElSkeleton']