代码优化
This commit is contained in:
parent
478b20ef44
commit
6e54c974a4
|
|
@ -120,7 +120,7 @@ const handleCloseInner = () => {
|
|||
|
||||
.com-dialog__outer .el-dialog__headerbtn,
|
||||
.com-dialog__inner .el-dialog__headerbtn {
|
||||
top: 14px;
|
||||
top: 4px;
|
||||
right: 16px;
|
||||
|
||||
.el-dialog__close {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
</template>
|
||||
|
||||
<script setup name="Position">
|
||||
import { ref } from 'vue'
|
||||
import { ref, nextTick } from 'vue'
|
||||
import {
|
||||
listBusinessTypeAPI,
|
||||
addBusinessTypeAPI,
|
||||
|
|
@ -68,12 +68,16 @@ const { proxy } = getCurrentInstance()
|
|||
const addAndEditFormRef = ref(null)
|
||||
const comTableRef = ref(null)
|
||||
const editId = ref(null)
|
||||
const addAndEditForm = ref({
|
||||
|
||||
// 定义初始表单数据函数
|
||||
const getInitFormData = () => ({
|
||||
planMajorName: '',
|
||||
remark: '',
|
||||
category: 1,
|
||||
})
|
||||
|
||||
const addAndEditForm = ref(getInitFormData())
|
||||
|
||||
const addAndEditRules = ref({
|
||||
planMajorName: [{ required: true, message: '请输入业务类型名称', trigger: 'blur' }],
|
||||
})
|
||||
|
|
@ -85,14 +89,14 @@ const actionColumns = [
|
|||
link: true,
|
||||
handler: (row) => {
|
||||
const { planMajorId, planMajorName, remark } = row
|
||||
addAndEditForm.value = {
|
||||
planMajorId,
|
||||
planMajorName,
|
||||
remark,
|
||||
}
|
||||
editId.value = row.planMajorId
|
||||
editId.value = planMajorId
|
||||
dialogConfig.outerTitle = '编辑业务类型'
|
||||
dialogConfig.outerVisible = true
|
||||
// 使用 nextTick 确保在弹框渲染、表单组件挂载后再赋值
|
||||
nextTick(() => {
|
||||
addAndEditForm.value.planMajorName = planMajorName
|
||||
addAndEditForm.value.remark = remark
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -116,20 +120,26 @@ const actionColumns = [
|
|||
// 新增
|
||||
const onHandleAdd = () => {
|
||||
editId.value = null
|
||||
dialogConfig.outerTitle = '新增业务类型'
|
||||
dialogConfig.outerVisible = true
|
||||
// 重置表单数据
|
||||
addAndEditForm.value = getInitFormData()
|
||||
// 清除之前的校验信息
|
||||
nextTick(() => {
|
||||
addAndEditFormRef.value?.clearValidate()
|
||||
})
|
||||
}
|
||||
|
||||
// 取消
|
||||
const onHandleCancel = () => {
|
||||
addAndEditFormRef?.value?.resetFields() // 重置表单
|
||||
dialogConfig.outerVisible = false
|
||||
}
|
||||
|
||||
// 保存
|
||||
const onHandleSave = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
addAndEditFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
await addAndEditFormRef.value.validate()
|
||||
const API = editId.value ? updateBusinessTypeAPI : addBusinessTypeAPI
|
||||
const params = JSON.parse(JSON.stringify(addAndEditForm.value))
|
||||
editId.value ? (params.planMajorId = editId.value) : null
|
||||
|
|
@ -141,16 +151,16 @@ const onHandleSave = async () => {
|
|||
dialogConfig.outerVisible = false
|
||||
comTableRef.value?.refresh() // 刷新表格
|
||||
}
|
||||
resolve(result)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
reject()
|
||||
console.error('表单校验失败或请求错误:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onCloseDialogOuter = (visible) => {
|
||||
dialogConfig.outerVisible = visible
|
||||
if (!visible) {
|
||||
addAndEditFormRef.value?.resetFields()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
</template>
|
||||
|
||||
<script setup name="inspectionStation">
|
||||
import { ref } from 'vue'
|
||||
import { ref, nextTick } from 'vue'
|
||||
import {
|
||||
listInspectionStationAPI,
|
||||
addInspectionStationAPI,
|
||||
|
|
@ -77,12 +77,16 @@ const { proxy } = getCurrentInstance()
|
|||
const addAndEditFormRef = ref(null)
|
||||
const comTableRef = ref(null)
|
||||
const editId = ref(null)
|
||||
const addAndEditForm = ref({
|
||||
|
||||
// 定义初始表单数据函数
|
||||
const getInitFormData = () => ({
|
||||
inspectionStationName: '',
|
||||
remark: '',
|
||||
category: 0,
|
||||
})
|
||||
|
||||
const addAndEditForm = ref(getInitFormData())
|
||||
|
||||
const addAndEditRules = ref({
|
||||
inspectionStationName: [{ required: true, message: '请输入运检站名称', trigger: 'blur' }],
|
||||
})
|
||||
|
|
@ -94,14 +98,15 @@ const actionColumns = [
|
|||
link: true,
|
||||
handler: (row) => {
|
||||
const { inspectionStationId, inspectionStationName, remark } = row
|
||||
addAndEditForm.value = {
|
||||
inspectionStationId,
|
||||
inspectionStationName,
|
||||
remark,
|
||||
}
|
||||
editId.value = row.inspectionStationId
|
||||
editId.value = inspectionStationId
|
||||
dialogConfig.outerTitle = '编辑运检站'
|
||||
dialogConfig.outerVisible = true
|
||||
// 使用 nextTick 确保在弹框渲染、表单组件挂载后再赋值
|
||||
// 这样 el-form 记录的 "initial value" 才是空值,resetFields 才能生效
|
||||
nextTick(() => {
|
||||
addAndEditForm.value.inspectionStationName = inspectionStationName
|
||||
addAndEditForm.value.remark = remark
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -125,7 +130,14 @@ const actionColumns = [
|
|||
// 新增
|
||||
const onHandleAdd = () => {
|
||||
editId.value = null
|
||||
dialogConfig.outerTitle = '新增运检站'
|
||||
dialogConfig.outerVisible = true
|
||||
// 重置表单数据
|
||||
addAndEditForm.value = getInitFormData()
|
||||
// 清除之前的校验信息
|
||||
nextTick(() => {
|
||||
addAndEditFormRef.value?.clearValidate()
|
||||
})
|
||||
}
|
||||
|
||||
// 取消
|
||||
|
|
@ -136,10 +148,8 @@ const onHandleCancel = () => {
|
|||
|
||||
// 保存
|
||||
const onHandleSave = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
addAndEditFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
await addAndEditFormRef.value.validate()
|
||||
const API = editId.value ? updateInspectionStationAPI : addInspectionStationAPI
|
||||
const params = JSON.parse(JSON.stringify(addAndEditForm.value))
|
||||
editId.value ? (params.inspectionStationId = editId.value) : null
|
||||
|
|
@ -151,16 +161,17 @@ const onHandleSave = async () => {
|
|||
dialogConfig.outerVisible = false
|
||||
comTableRef.value?.refresh() // 刷新表格
|
||||
}
|
||||
resolve(result)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
reject()
|
||||
console.error('表单校验失败或请求错误:', error)
|
||||
// 必须抛出错误或返回 Promise.reject(),ComButton 才能捕获并结束 loading 状态
|
||||
return Promise.reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onCloseDialogOuter = (visible) => {
|
||||
dialogConfig.outerVisible = visible
|
||||
if (!visible) {
|
||||
addAndEditFormRef.value?.resetFields()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
</template>
|
||||
|
||||
<script setup name="PersonNature">
|
||||
import { ref } from 'vue'
|
||||
import { ref, nextTick } from 'vue'
|
||||
import {
|
||||
listPersonCategoryAPI,
|
||||
addPersonCategoryAPI,
|
||||
|
|
@ -77,12 +77,16 @@ const { proxy } = getCurrentInstance()
|
|||
const addAndEditFormRef = ref(null)
|
||||
const comTableRef = ref(null)
|
||||
const editId = ref(null)
|
||||
const addAndEditForm = ref({
|
||||
|
||||
// 定义初始表单数据函数
|
||||
const getInitFormData = () => ({
|
||||
personnelClassificationName: '',
|
||||
remark: '',
|
||||
category: 1,
|
||||
})
|
||||
|
||||
const addAndEditForm = ref(getInitFormData())
|
||||
|
||||
const addAndEditRules = ref({
|
||||
personnelClassificationName: [
|
||||
{ required: true, message: '请输入人员分类名称', trigger: 'blur' },
|
||||
|
|
@ -96,14 +100,14 @@ const actionColumns = [
|
|||
link: true,
|
||||
handler: (row) => {
|
||||
const { personnelClassificationId, personnelClassificationName, remark } = row
|
||||
addAndEditForm.value = {
|
||||
personnelClassificationId,
|
||||
personnelClassificationName,
|
||||
remark,
|
||||
}
|
||||
editId.value = row.personnelClassificationId
|
||||
editId.value = personnelClassificationId
|
||||
dialogConfig.outerTitle = '编辑人员分类'
|
||||
dialogConfig.outerVisible = true
|
||||
// 使用 nextTick 确保在弹框渲染、表单组件挂载后再赋值
|
||||
nextTick(() => {
|
||||
addAndEditForm.value.personnelClassificationName = personnelClassificationName
|
||||
addAndEditForm.value.remark = remark
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -127,7 +131,14 @@ const actionColumns = [
|
|||
// 新增
|
||||
const onHandleAdd = () => {
|
||||
editId.value = null
|
||||
dialogConfig.outerTitle = '新建人员分类'
|
||||
dialogConfig.outerVisible = true
|
||||
// 重置表单数据
|
||||
addAndEditForm.value = getInitFormData()
|
||||
// 清除之前的校验信息
|
||||
nextTick(() => {
|
||||
addAndEditFormRef.value?.clearValidate()
|
||||
})
|
||||
}
|
||||
|
||||
// 取消
|
||||
|
|
@ -138,10 +149,8 @@ const onHandleCancel = () => {
|
|||
|
||||
// 保存
|
||||
const onHandleSave = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
addAndEditFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
await addAndEditFormRef.value.validate()
|
||||
const API = editId.value ? updatePersonCategoryAPI : addPersonCategoryAPI
|
||||
const params = JSON.parse(JSON.stringify(addAndEditForm.value))
|
||||
editId.value ? (params.personnelClassificationId = editId.value) : null
|
||||
|
|
@ -153,16 +162,16 @@ const onHandleSave = async () => {
|
|||
dialogConfig.outerVisible = false
|
||||
comTableRef.value?.refresh() // 刷新表格
|
||||
}
|
||||
resolve(result)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
reject()
|
||||
console.error('表单校验失败或请求错误:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onCloseDialogOuter = (visible) => {
|
||||
dialogConfig.outerVisible = visible
|
||||
if (!visible) {
|
||||
addAndEditFormRef.value?.resetFields()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
</template>
|
||||
|
||||
<script setup name="PersonNature">
|
||||
import { ref } from 'vue'
|
||||
import { ref, nextTick } from 'vue'
|
||||
import {
|
||||
listPersonNatureAPI,
|
||||
addPersonNatureAPI,
|
||||
|
|
@ -77,12 +77,16 @@ const { proxy } = getCurrentInstance()
|
|||
const addAndEditFormRef = ref(null)
|
||||
const comTableRef = ref(null)
|
||||
const editId = ref(null)
|
||||
const addAndEditForm = ref({
|
||||
|
||||
// 定义初始表单数据函数
|
||||
const getInitFormData = () => ({
|
||||
personnelClassificationName: '',
|
||||
remark: '',
|
||||
category: 1,
|
||||
})
|
||||
|
||||
const addAndEditForm = ref(getInitFormData())
|
||||
|
||||
const addAndEditRules = ref({
|
||||
personnelClassificationName: [
|
||||
{ required: true, message: '请输入人员性质名称', trigger: 'blur' },
|
||||
|
|
@ -96,14 +100,14 @@ const actionColumns = [
|
|||
link: true,
|
||||
handler: (row) => {
|
||||
const { personnelClassificationId, personnelClassificationName, remark } = row
|
||||
addAndEditForm.value = {
|
||||
personnelClassificationId,
|
||||
personnelClassificationName,
|
||||
remark,
|
||||
}
|
||||
editId.value = row.personnelClassificationId
|
||||
editId.value = personnelClassificationId
|
||||
dialogConfig.outerTitle = '编辑人员性质'
|
||||
dialogConfig.outerVisible = true
|
||||
// 使用 nextTick 确保在弹框渲染、表单组件挂载后再赋值
|
||||
nextTick(() => {
|
||||
addAndEditForm.value.personnelClassificationName = personnelClassificationName
|
||||
addAndEditForm.value.remark = remark
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -127,7 +131,14 @@ const actionColumns = [
|
|||
// 新增
|
||||
const onHandleAdd = () => {
|
||||
editId.value = null
|
||||
dialogConfig.outerTitle = '新建人员性质'
|
||||
dialogConfig.outerVisible = true
|
||||
// 重置表单数据
|
||||
addAndEditForm.value = getInitFormData()
|
||||
// 清除之前的校验信息
|
||||
nextTick(() => {
|
||||
addAndEditFormRef.value?.clearValidate()
|
||||
})
|
||||
}
|
||||
|
||||
// 取消
|
||||
|
|
@ -138,10 +149,8 @@ const onHandleCancel = () => {
|
|||
|
||||
// 保存
|
||||
const onHandleSave = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
addAndEditFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
await addAndEditFormRef.value.validate()
|
||||
const API = editId.value ? updatePersonNatureAPI : addPersonNatureAPI
|
||||
const params = JSON.parse(JSON.stringify(addAndEditForm.value))
|
||||
editId.value ? (params.personnelClassificationId = editId.value) : null
|
||||
|
|
@ -153,16 +162,16 @@ const onHandleSave = async () => {
|
|||
dialogConfig.outerVisible = false
|
||||
comTableRef.value?.refresh() // 刷新表格
|
||||
}
|
||||
resolve(result)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
reject()
|
||||
console.error('表单校验失败或请求错误:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onCloseDialogOuter = (visible) => {
|
||||
dialogConfig.outerVisible = visible
|
||||
if (!visible) {
|
||||
addAndEditFormRef.value?.resetFields()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
</template>
|
||||
|
||||
<script setup name="Position">
|
||||
import { ref } from 'vue'
|
||||
import { ref, nextTick } from 'vue'
|
||||
import {
|
||||
listPlanCategoryAPI,
|
||||
addPlanCategoryAPI,
|
||||
|
|
@ -77,12 +77,16 @@ const { proxy } = getCurrentInstance()
|
|||
const addAndEditFormRef = ref(null)
|
||||
const comTableRef = ref(null)
|
||||
const editId = ref(null)
|
||||
const addAndEditForm = ref({
|
||||
|
||||
// 定义初始表单数据函数
|
||||
const getInitFormData = () => ({
|
||||
planMajorName: '',
|
||||
remark: '',
|
||||
category: 2,
|
||||
})
|
||||
|
||||
const addAndEditForm = ref(getInitFormData())
|
||||
|
||||
const addAndEditRules = ref({
|
||||
planMajorName: [{ required: true, message: '请输入计划类别名称', trigger: 'blur' }],
|
||||
})
|
||||
|
|
@ -94,14 +98,14 @@ const actionColumns = [
|
|||
link: true,
|
||||
handler: (row) => {
|
||||
const { planMajorId, planMajorName, remark } = row
|
||||
addAndEditForm.value = {
|
||||
planMajorId,
|
||||
planMajorName,
|
||||
remark,
|
||||
}
|
||||
editId.value = row.planMajorId
|
||||
editId.value = planMajorId
|
||||
dialogConfig.outerTitle = '编辑计划类别'
|
||||
dialogConfig.outerVisible = true
|
||||
// 使用 nextTick 确保在弹框渲染、表单组件挂载后再赋值
|
||||
nextTick(() => {
|
||||
addAndEditForm.value.planMajorName = planMajorName
|
||||
addAndEditForm.value.remark = remark
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -125,7 +129,14 @@ const actionColumns = [
|
|||
// 新增
|
||||
const onHandleAdd = () => {
|
||||
editId.value = null
|
||||
dialogConfig.outerTitle = '新建计划类别'
|
||||
dialogConfig.outerVisible = true
|
||||
// 重置表单数据
|
||||
addAndEditForm.value = getInitFormData()
|
||||
// 清除之前的校验信息
|
||||
nextTick(() => {
|
||||
addAndEditFormRef.value?.clearValidate()
|
||||
})
|
||||
}
|
||||
|
||||
// 取消
|
||||
|
|
@ -136,10 +147,8 @@ const onHandleCancel = () => {
|
|||
|
||||
// 保存
|
||||
const onHandleSave = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
addAndEditFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
await addAndEditFormRef.value.validate()
|
||||
const API = editId.value ? updatePlanCategoryAPI : addPlanCategoryAPI
|
||||
const params = JSON.parse(JSON.stringify(addAndEditForm.value))
|
||||
editId.value ? (params.planMajorId = editId.value) : null
|
||||
|
|
@ -151,16 +160,16 @@ const onHandleSave = async () => {
|
|||
dialogConfig.outerVisible = false
|
||||
comTableRef.value?.refresh() // 刷新表格
|
||||
}
|
||||
resolve(result)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
reject()
|
||||
console.error('表单校验失败或请求错误:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onCloseDialogOuter = (visible) => {
|
||||
dialogConfig.outerVisible = visible
|
||||
if (!visible) {
|
||||
addAndEditFormRef.value?.resetFields()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
</template>
|
||||
|
||||
<script setup name="Position">
|
||||
import { ref } from 'vue'
|
||||
import { ref, nextTick } from 'vue'
|
||||
import {
|
||||
listPlanProfessionalAPI,
|
||||
addPlanProfessionalAPI,
|
||||
|
|
@ -77,12 +77,16 @@ const { proxy } = getCurrentInstance()
|
|||
const addAndEditFormRef = ref(null)
|
||||
const comTableRef = ref(null)
|
||||
const editId = ref(null)
|
||||
const addAndEditForm = ref({
|
||||
|
||||
// 定义初始表单数据函数
|
||||
const getInitFormData = () => ({
|
||||
planMajorName: '',
|
||||
remark: '',
|
||||
category: 0,
|
||||
})
|
||||
|
||||
const addAndEditForm = ref(getInitFormData())
|
||||
|
||||
const addAndEditRules = ref({
|
||||
planMajorName: [{ required: true, message: '请输入计划专业名称', trigger: 'blur' }],
|
||||
})
|
||||
|
|
@ -94,14 +98,14 @@ const actionColumns = [
|
|||
link: true,
|
||||
handler: (row) => {
|
||||
const { planMajorId, planMajorName, remark } = row
|
||||
addAndEditForm.value = {
|
||||
planMajorId,
|
||||
planMajorName,
|
||||
remark,
|
||||
}
|
||||
editId.value = row.planMajorId
|
||||
editId.value = planMajorId
|
||||
dialogConfig.outerTitle = '编辑计划专业'
|
||||
dialogConfig.outerVisible = true
|
||||
// 使用 nextTick 确保在弹框渲染、表单组件挂载后再赋值
|
||||
nextTick(() => {
|
||||
addAndEditForm.value.planMajorName = planMajorName
|
||||
addAndEditForm.value.remark = remark
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -125,7 +129,14 @@ const actionColumns = [
|
|||
// 新增
|
||||
const onHandleAdd = () => {
|
||||
editId.value = null
|
||||
dialogConfig.outerTitle = '新建计划专业'
|
||||
dialogConfig.outerVisible = true
|
||||
// 重置表单数据
|
||||
addAndEditForm.value = getInitFormData()
|
||||
// 清除之前的校验信息
|
||||
nextTick(() => {
|
||||
addAndEditFormRef.value?.clearValidate()
|
||||
})
|
||||
}
|
||||
|
||||
// 取消
|
||||
|
|
@ -136,10 +147,8 @@ const onHandleCancel = () => {
|
|||
|
||||
// 保存
|
||||
const onHandleSave = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
addAndEditFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
await addAndEditFormRef.value.validate()
|
||||
const API = editId.value ? updatePlanProfessionalAPI : addPlanProfessionalAPI
|
||||
const params = JSON.parse(JSON.stringify(addAndEditForm.value))
|
||||
editId.value ? (params.planMajorId = editId.value) : null
|
||||
|
|
@ -151,16 +160,16 @@ const onHandleSave = async () => {
|
|||
dialogConfig.outerVisible = false
|
||||
comTableRef.value?.refresh() // 刷新表格
|
||||
}
|
||||
resolve(result)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
reject()
|
||||
console.error('表单校验失败或请求错误:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onCloseDialogOuter = (visible) => {
|
||||
dialogConfig.outerVisible = visible
|
||||
if (!visible) {
|
||||
addAndEditFormRef.value?.resetFields()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
</template>
|
||||
|
||||
<script setup name="Position">
|
||||
import { ref } from 'vue'
|
||||
import { ref, nextTick } from 'vue'
|
||||
import {
|
||||
listPositionAPI,
|
||||
addPositionAPI,
|
||||
|
|
@ -77,12 +77,16 @@ const { proxy } = getCurrentInstance()
|
|||
const addAndEditFormRef = ref(null)
|
||||
const comTableRef = ref(null)
|
||||
const editId = ref(null)
|
||||
const addAndEditForm = ref({
|
||||
|
||||
// 定义初始表单数据函数
|
||||
const getInitFormData = () => ({
|
||||
personnelClassificationName: '',
|
||||
remark: '',
|
||||
category: 2,
|
||||
})
|
||||
|
||||
const addAndEditForm = ref(getInitFormData())
|
||||
|
||||
const addAndEditRules = ref({
|
||||
personnelClassificationName: [{ required: true, message: '请输入岗位名称', trigger: 'blur' }],
|
||||
})
|
||||
|
|
@ -94,14 +98,14 @@ const actionColumns = [
|
|||
link: true,
|
||||
handler: (row) => {
|
||||
const { personnelClassificationId, personnelClassificationName, remark } = row
|
||||
addAndEditForm.value = {
|
||||
personnelClassificationId,
|
||||
personnelClassificationName,
|
||||
remark,
|
||||
}
|
||||
editId.value = row.personnelClassificationId
|
||||
editId.value = personnelClassificationId
|
||||
dialogConfig.outerTitle = '编辑岗位'
|
||||
dialogConfig.outerVisible = true
|
||||
// 使用 nextTick 确保在弹框渲染、表单组件挂载后再赋值
|
||||
nextTick(() => {
|
||||
addAndEditForm.value.personnelClassificationName = personnelClassificationName
|
||||
addAndEditForm.value.remark = remark
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -125,7 +129,14 @@ const actionColumns = [
|
|||
// 新增
|
||||
const onHandleAdd = () => {
|
||||
editId.value = null
|
||||
dialogConfig.outerTitle = '新建岗位'
|
||||
dialogConfig.outerVisible = true
|
||||
// 重置表单数据
|
||||
addAndEditForm.value = getInitFormData()
|
||||
// 清除之前的校验信息
|
||||
nextTick(() => {
|
||||
addAndEditFormRef.value?.clearValidate()
|
||||
})
|
||||
}
|
||||
|
||||
// 取消
|
||||
|
|
@ -136,10 +147,8 @@ const onHandleCancel = () => {
|
|||
|
||||
// 保存
|
||||
const onHandleSave = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
addAndEditFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
await addAndEditFormRef.value.validate()
|
||||
const API = editId.value ? updatePositionAPI : addPositionAPI
|
||||
const params = JSON.parse(JSON.stringify(addAndEditForm.value))
|
||||
editId.value ? (params.personnelClassificationId = editId.value) : null
|
||||
|
|
@ -151,16 +160,16 @@ const onHandleSave = async () => {
|
|||
dialogConfig.outerVisible = false
|
||||
comTableRef.value?.refresh() // 刷新表格
|
||||
}
|
||||
resolve(result)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
reject()
|
||||
console.error('表单校验失败或请求错误:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onCloseDialogOuter = (visible) => {
|
||||
dialogConfig.outerVisible = visible
|
||||
if (!visible) {
|
||||
addAndEditFormRef.value?.resetFields()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
</template>
|
||||
|
||||
<script setup name="projectDept">
|
||||
import { ref } from 'vue'
|
||||
import { ref, nextTick } from 'vue'
|
||||
import {
|
||||
listProjectDeptAPI,
|
||||
addProjectDeptAPI,
|
||||
|
|
@ -77,12 +77,16 @@ const { proxy } = getCurrentInstance()
|
|||
const addAndEditFormRef = ref(null)
|
||||
const comTableRef = ref(null)
|
||||
const editId = ref(null)
|
||||
const addAndEditForm = ref({
|
||||
|
||||
// 定义初始表单数据函数
|
||||
const getInitFormData = () => ({
|
||||
inspectionStationName: '',
|
||||
remark: '',
|
||||
category: 1,
|
||||
})
|
||||
|
||||
const addAndEditForm = ref(getInitFormData())
|
||||
|
||||
const addAndEditRules = ref({
|
||||
inspectionStationName: [{ required: true, message: '请输入项目部名称', trigger: 'blur' }],
|
||||
})
|
||||
|
|
@ -94,14 +98,14 @@ const actionColumns = [
|
|||
link: true,
|
||||
handler: (row) => {
|
||||
const { inspectionStationId, inspectionStationName, remark } = row
|
||||
addAndEditForm.value = {
|
||||
inspectionStationId,
|
||||
inspectionStationName,
|
||||
remark,
|
||||
}
|
||||
editId.value = row.inspectionStationId
|
||||
editId.value = inspectionStationId
|
||||
dialogConfig.outerTitle = '编辑项目部'
|
||||
dialogConfig.outerVisible = true
|
||||
// 使用 nextTick 确保在弹框渲染、表单组件挂载后再赋值
|
||||
nextTick(() => {
|
||||
addAndEditForm.value.inspectionStationName = inspectionStationName
|
||||
addAndEditForm.value.remark = remark
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -125,7 +129,14 @@ const actionColumns = [
|
|||
// 新增
|
||||
const onHandleAdd = () => {
|
||||
editId.value = null
|
||||
dialogConfig.outerTitle = '新建项目部'
|
||||
dialogConfig.outerVisible = true
|
||||
// 重置表单数据
|
||||
addAndEditForm.value = getInitFormData()
|
||||
// 清除之前的校验信息
|
||||
nextTick(() => {
|
||||
addAndEditFormRef.value?.clearValidate()
|
||||
})
|
||||
}
|
||||
|
||||
// 取消
|
||||
|
|
@ -136,10 +147,8 @@ const onHandleCancel = () => {
|
|||
|
||||
// 保存
|
||||
const onHandleSave = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
addAndEditFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
await addAndEditFormRef.value.validate()
|
||||
const API = editId.value ? updateProjectDeptAPI : addProjectDeptAPI
|
||||
const params = JSON.parse(JSON.stringify(addAndEditForm.value))
|
||||
editId.value ? (params.inspectionStationId = editId.value) : null
|
||||
|
|
@ -151,16 +160,16 @@ const onHandleSave = async () => {
|
|||
dialogConfig.outerVisible = false
|
||||
comTableRef.value?.refresh() // 刷新表格
|
||||
}
|
||||
resolve(result)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
reject()
|
||||
console.error('表单校验失败或请求错误:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onCloseDialogOuter = (visible) => {
|
||||
dialogConfig.outerVisible = visible
|
||||
if (!visible) {
|
||||
addAndEditFormRef.value?.resetFields()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@
|
|||
</template>
|
||||
|
||||
<script setup name="Position">
|
||||
import { ref } from 'vue'
|
||||
import { ref, nextTick } from 'vue'
|
||||
import {
|
||||
listWorkloadCategoryAPI,
|
||||
addWorkloadCategoryAPI,
|
||||
|
|
@ -95,12 +95,16 @@ const { proxy } = getCurrentInstance()
|
|||
const addAndEditFormRef = ref(null)
|
||||
const comTableRef = ref(null)
|
||||
const editId = ref(null)
|
||||
const addAndEditForm = ref({
|
||||
|
||||
// 定义初始表单数据函数
|
||||
const getInitFormData = () => ({
|
||||
workloadCategoryName: '',
|
||||
unitPrice: 0.1,
|
||||
remark: '',
|
||||
})
|
||||
|
||||
const addAndEditForm = ref(getInitFormData())
|
||||
|
||||
const addAndEditRules = ref({
|
||||
workloadCategoryName: [{ required: true, message: '请输入工作量类别名称', trigger: 'blur' }],
|
||||
unitPrice: [{ required: true, message: '请输入单价', trigger: 'blur' }],
|
||||
|
|
@ -113,15 +117,15 @@ const actionColumns = [
|
|||
link: true,
|
||||
handler: (row) => {
|
||||
const { workloadCategoryId, workloadCategoryName, remark, unitPrice } = row
|
||||
addAndEditForm.value = {
|
||||
workloadCategoryId,
|
||||
workloadCategoryName,
|
||||
unitPrice: fenToYuan(unitPrice), // 分转元回显
|
||||
remark,
|
||||
}
|
||||
editId.value = row.workloadCategoryId
|
||||
editId.value = workloadCategoryId
|
||||
dialogConfig.outerTitle = '编辑工作量类别'
|
||||
dialogConfig.outerVisible = true
|
||||
// 使用 nextTick 确保在弹框渲染、表单组件挂载后再赋值
|
||||
nextTick(() => {
|
||||
addAndEditForm.value.workloadCategoryName = workloadCategoryName
|
||||
addAndEditForm.value.unitPrice = fenToYuan(unitPrice) // 分转元回显
|
||||
addAndEditForm.value.remark = remark
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -145,7 +149,14 @@ const actionColumns = [
|
|||
// 新增
|
||||
const onHandleAdd = () => {
|
||||
editId.value = null
|
||||
dialogConfig.outerTitle = '新建工作量类别'
|
||||
dialogConfig.outerVisible = true
|
||||
// 重置表单数据
|
||||
addAndEditForm.value = getInitFormData()
|
||||
// 清除之前的校验信息
|
||||
nextTick(() => {
|
||||
addAndEditFormRef.value?.clearValidate()
|
||||
})
|
||||
}
|
||||
|
||||
// 取消
|
||||
|
|
@ -156,10 +167,8 @@ const onHandleCancel = () => {
|
|||
|
||||
// 保存
|
||||
const onHandleSave = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
addAndEditFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
await addAndEditFormRef.value.validate()
|
||||
const API = editId.value ? updateWorkloadCategoryAPI : addWorkloadCategoryAPI
|
||||
const params = JSON.parse(JSON.stringify(addAndEditForm.value))
|
||||
params.unitPrice = yuanToFen(params.unitPrice) // 元转分提交
|
||||
|
|
@ -172,16 +181,16 @@ const onHandleSave = async () => {
|
|||
dialogConfig.outerVisible = false
|
||||
comTableRef.value?.refresh() // 刷新表格
|
||||
}
|
||||
resolve(result)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
reject()
|
||||
console.error('表单校验失败或请求错误:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onCloseDialogOuter = (visible) => {
|
||||
dialogConfig.outerVisible = visible
|
||||
if (!visible) {
|
||||
addAndEditFormRef.value?.resetFields()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue