admin-vue3/src/views/crm/contract/components/ContractBAuthorizedPersonFo...

167 lines
5.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
v-loading="formLoading"
label-width="0px"
:inline-message="true"
>
<el-table :data="formData" class="-mt-10px">
<el-table-column label="序号" type="index" width="100" />
<el-table-column label="用户" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.userId`" :rules="formRules.userId" class="mb-0px!">
<el-input v-model="row.userId" placeholder="请输入用户" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="姓名" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.name`" :rules="formRules.name" class="mb-0px!">
<el-input v-model="row.name" placeholder="请输入姓名" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="类别" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.authType`" :rules="formRules.authType" class="mb-0px!">
<el-select v-model="row.authType" placeholder="请选择类别">
<el-option
v-for="dict in getIntDictOptions('auth_type')"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
</template>
</el-table-column>
<el-table-column label="岗位" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.postId`" :rules="formRules.postId" class="mb-0px!">
<el-input v-model="row.postId" placeholder="请输入岗位" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="职级" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.userRank`" :rules="formRules.userRank" class="mb-0px!">
<el-input v-model="row.userRank" placeholder="请输入职级" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="权限说明" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.authDesc`" :rules="formRules.authDesc" class="mb-0px!">
<el-input v-model="row.authDesc" placeholder="请输入权限说明" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="手机号" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.phoneNumber`" :rules="formRules.phoneNumber" class="mb-0px!">
<el-input v-model="row.phoneNumber" placeholder="请输入手机号" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="微信号" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.wechat`" :rules="formRules.wechat" class="mb-0px!">
<el-input v-model="row.wechat" placeholder="请输入微信号" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="电子邮箱" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.email`" :rules="formRules.email" class="mb-0px!">
<el-input v-model="row.email" placeholder="请输入电子邮箱" />
</el-form-item>
</template>
</el-table-column>
<el-table-column align="center" fixed="right" label="操作" width="60" v-if="!type">
<template #default="{ $index }">
<el-button @click="handleDelete($index)" link>—</el-button>
</template>
</el-table-column>
</el-table>
</el-form>
<el-row justify="center" class="mt-3" v-if="!type">
<el-button @click="handleAdd" round>+ 添加</el-button>
</el-row>
</template>
<script setup lang="ts">
import * as ContractApi from '@/api/crm/contract'
import { getIntDictOptions, getStrDictOptions, DICT_TYPE, getBoolDictOptions } from '@/utils/dict'
const props = defineProps<{
contractId: undefined, // ID
type: undefined
}>()
const formLoading = ref(false) // 表单的加载中
const formData = ref([])
const formRules = reactive({
contractId: [{ required: true, message: '合同ID不能为空', trigger: 'blur' }],
userId: [{ required: true, message: '用户ID不能为空', trigger: 'blur' }],
name: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
phoneNumber: [{ required: true, message: '手机号不能为空', trigger: 'blur' }]
})
const formRef = ref() // 表单 Ref
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
() => props.contractId,
async (val) => {
// 1. 重置表单
formData.value = []
// 2. val 非空,则加载数据
if (!val) {
return;
}
try {
formLoading.value = true
formData.value = await ContractApi.getContractBAuthorizedPersonListByContractId(val)
} finally {
formLoading.value = false
}
},
{ immediate: true }
)
/** 新增按钮操作 */
const handleAdd = () => {
const row = {
id: undefined,
contractId: undefined,
userId: undefined,
name: undefined,
authType: undefined,
postId: undefined,
userRank: undefined,
authDesc: undefined,
phoneNumber: undefined,
wechat: undefined,
email: undefined,
deletedFlag: undefined
}
row.contractId = props.contractId
formData.value.push(row)
}
/** 删除按钮操作 */
const handleDelete = (index) => {
formData.value.splice(index, 1)
}
/** 表单校验 */
const validate = () => {
return formRef.value.validate()
}
/** 表单值 */
const getData = () => {
return formData.value
}
defineExpose({ validate, getData })
</script>