hi-ucs/front/src/views/home/apply.vue

649 lines
20 KiB
Vue
Raw Normal View History

2022-06-14 09:32:49 +08:00
<template>
<div>
<home-header></home-header>
<div id="apply-container">
<!-- <aside>
<aside-menu></aside-menu>
</aside> -->
<article>
2022-06-23 19:19:48 +08:00
<div class="from-card" v-if="applySuccess">
<AbilityToApplyFor :dataList="dataList"></AbilityToApplyFor>
</div>
2022-06-14 09:32:49 +08:00
<div class="form-container">
<div v-if="applySuccess">
<a-form
ref="formRef"
:model="formName"
name="basic"
:label-col="{ style: { width: '106px' } }"
:wrapper-col="{ style: { width: '230px' } }"
labelAlign="left"
autocomplete="off"
>
<div class="base-info">
<a-form-item
2022-06-23 19:19:48 +08:00
label="申请人信息"
2022-06-14 09:32:49 +08:00
name="user"
:rules="[{ required: true, message: '请输入申请人' }]"
>
<a-input
placeholder="请输入申请人"
v-model:value="formName.user"
disabled
/>
</a-form-item>
<a-form-item
style="margin: 0 22px"
2022-06-23 19:19:48 +08:00
label="电话"
2022-06-14 09:32:49 +08:00
name="phone"
:rules="[
{
required: true,
pattern: /^1[3456789]\d{9}$/,
message: '请输入正确的电话号码',
},
]"
>
<a-input
placeholder="请输入申请人电话"
v-model:value="formName.phone"
/>
</a-form-item>
<a-form-item
2022-06-23 19:19:48 +08:00
label="单位"
2022-06-14 09:32:49 +08:00
name="unit"
2022-06-23 19:19:48 +08:00
:rules="[{ required: true, message: '请输入单位' }]"
2022-06-14 09:32:49 +08:00
>
<a-input
2022-06-23 19:19:48 +08:00
placeholder="请输入单位"
2022-06-14 09:32:49 +08:00
v-model:value="formName.unit"
/>
</a-form-item>
</div>
<a-form-item
style="margin-bottom: 10px"
label="申请应用"
name="system"
:rules="[{ required: true, message: '请输入申请应用' }]"
>
<a-tooltip placement="top">
<template #title>
<span>{{ formName.formNameSystem }}</span>
</template>
<a-input
style="width: 350px; background-color: #f5f5f5"
v-model:value="formName.formNameSystem"
:disabled="disabled"
/>
<span style="width: 350px; background-color: #f5f5f5"></span>
</a-tooltip>
</a-form-item>
<a-form-item
style="margin-bottom: 10px"
label="应用场景"
name="scene"
:rules="[{ required: true, message: '请输入应用场景' }]"
>
<a-textarea
style="
width: 500px;
height: 150px;
font-size: 16px;
line-height: 24px;
color: #333;
border: 1px solid #e0e0e0;
resize: none;
border-radius: 6px;
padding: 10px;
"
v-model:value="formName.scene"
/>
</a-form-item>
<a-form-item
style="margin-bottom: 10px"
label="申请依据"
name="basis"
:rules="[{ required: true, message: '请输入申请依据' }]"
>
<a-textarea
style="
width: 500px;
height: 150px;
font-size: 16px;
line-height: 24px;
color: #333;
border: 1px solid #e0e0e0;
border-radius: 6px;
padding: 10px;
resize: none;
"
v-model:value="formName.basis"
/>
</a-form-item>
<a-form-item
style="color: #666; font-size: 16px"
label="申请单附件"
name="applyDoc"
>
<a-upload
v-model:file-list="fileList"
name="file"
2022-06-23 19:19:48 +08:00
:action="`${baseURL}/upload`"
2022-06-14 09:32:49 +08:00
:headers="headers"
@change="handleChange"
:before-upload="beforeUpload"
>
<a-button
style="
width: 100px;
height: 30px;
margin-right: 10px;
background: #edf4fc;
color: #0087ff;
font-size: 14px;
border-radius: 6px;
border: 1px solid #bbd3ef;
padding: 0;
text-align: center;
"
>
<upload-outlined></upload-outlined>
文件上传
</a-button>
<span style="font-size: 14px; color: #999">
支持docdocxjpgpngjpegpdfxlxsppt类型文件
</span>
</a-upload>
</a-form-item>
<a-form-item :wrapper-col="{ offset: 8, span: 16 }">
<a-button
style="
width: 80px;
height: 38px;
margin-right: 20px;
background: #e1edfa;
color: #0087ff;
font-size: 14px;
border-radius: 6px;
border: none;
padding: 0;
text-align: center;
"
type="primary"
html-type="cancle"
@click="resetFields()"
>
退出申请
</a-button>
<a-button
style="
width: 80px;
height: 38px;
background: #0087ff;
color: #fff;
font-size: 14px;
border-radius: 6px;
border: none;
padding: 0;
text-align: center;
"
type="primary"
html-type="submit"
@click="processStartHandle()"
>
提交申请
</a-button>
</a-form-item>
</a-form>
</div>
<div class="success" v-else>
<div>
<img src="../../assets/home/success.png" alt="" />
</div>
<p>
您已成功申请{{
formName.formNameSystem || ''
}},请耐心等待审批结果结果会第一时间通知您
</p>
</div>
</div>
</article>
</div>
</div>
</template>
<script>
2022-06-23 19:19:48 +08:00
import AbilityToApplyFor from './AbilityToApplyFor.vue'
2022-06-14 09:32:49 +08:00
import HomeHeader from '@/views/home/components/header'
2022-06-23 19:19:48 +08:00
import { reactive, ref, watch, onBeforeUnmount } from 'vue'
2022-06-14 09:32:49 +08:00
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
import qs from 'qs'
// import { UploadOutlined } from '@ant-design/icons-vue'
import { Upload } from 'ant-design-vue'
import {
lastestPage,
tabilityapplication,
startOfBusinessKey,
updateInstanceId,
submitApply,
getUser,
getUserInfo,
relaunch,
2022-06-23 19:19:48 +08:00
selectOne,
2022-06-14 09:32:49 +08:00
} from '@/api/home'
import mybus from '@/myplugins/mybus'
import { sgcDel, getApplyForm } from '@/api/personalCenter'
2022-06-16 16:58:49 +08:00
// import { baseURL } from '@/config'
2022-06-14 09:32:49 +08:00
// import AsideMenu from './components/asideMenu.vue'
export default {
name: '',
props: {},
components: {
HomeHeader,
2022-06-23 19:19:48 +08:00
AbilityToApplyFor,
2022-06-14 09:32:49 +08:00
// AsideMenu,
// UploadOutlined,
},
setup() {
const router = useRouter()
const disabled = ref(false)
2022-06-23 19:19:48 +08:00
const baseURL = window.SITE_CONFIG.apiURL
let record = ref('1')
2022-06-14 09:32:49 +08:00
const formName = reactive({
user: '',
userId: '',
phone: '',
unit: '',
area: '',
system: [],
scene: '',
basis: '',
formNameSystem: '',
enclosure: '', //附件
})
2022-06-23 19:19:48 +08:00
const dataList = ref([])
2022-06-14 09:32:49 +08:00
getUser().then((res) => {
formName.user = res.data.data.realName
formName.userId = res.data.data.id
getUserInfo(formName.userId).then((res) => {
if (res.data.data.mobile) {
formName.phone = res.data.data.mobile
}
formName.unit = res.data.data.deptName
})
})
console.log(
'router传参==================>',
router.currentRoute.value.query.name
)
2022-06-23 19:19:48 +08:00
let arr =
2022-06-14 09:32:49 +08:00
router.currentRoute.value.query.name instanceof Array
? router.currentRoute.value.query.name
: [router.currentRoute.value.query.name]
console.log(router.currentRoute.value.query.ids)
const ids = router.currentRoute.value.query.ids
2022-06-23 19:19:48 +08:00
let dataResourceId = router.currentRoute.value.query.resourceId
dataResourceId.map((item) => {
selectOne(item).then((res) => {
dataList.value.push(res.data.data)
console.log('dataResourceId', dataList.value)
})
})
2022-06-14 09:32:49 +08:00
const businessKey = ref(router.currentRoute.value.query.id)
const taskId = ref(router.currentRoute.value.query.taskId)
if (businessKey.value) {
getApplyForm(businessKey.value).then((res) => {
formName.id = res.data.data.id
formName.phone = res.data.data.phone
formName.scene = res.data.data.scene
formName.basis = res.data.data.basis
formName.enclosure = res.data.data.enclosure
console.log('回填数据================>', res, formName.phone)
})
}
2022-06-23 19:19:48 +08:00
console.log(formName.system)
2022-06-14 09:32:49 +08:00
const formRef = ref()
const applySuccess = ref(true)
// const rootObj = null
const dataForm = {
processDefinitionKey: 'abilityprocess',
}
const callbacks = {
startProcessSuccessCallback: null,
startProcessErrorCallback: null,
formSaveSuccessCallback: null,
formSaveErrorCallback: null,
}
const instanceIdUrl = '/processForm/tabilityapplication/updateInstanceId'
const formUrl = '/processForm/tabilityapplication'
//退出返回上一页
const resetFields = () => {
window.history.go(-1)
}
const processStartHandle = () => {
if (businessKey.value) {
const obj = ref({})
for (const key in formName) {
if (key !== 'formNameSystem') {
obj.value[key] = formName[key]
}
}
obj.value.system = formName.system[0].resourceName
tabilityapplication(obj.value).then((upres) => {
if (upres.data.code == 0) {
relaunch({ data: obj.value, taskId: taskId.value }).then(
(res) => {
console.log('驳回================>', res)
if (res.data.code == 0) {
message.success('重新发起流程成功!')
window.setTimeout(() => {
window.history.go(-1)
}, 1000)
} else {
message.error('重新发起流程失败!')
}
}
)
} else {
message.error('数据更新失败!')
}
})
} else {
formRef.value.validate().then(() => {
if (!formUrl) {
return message.error('请设置保存表单的URL')
}
if (!formName) {
return message.error('请设置表单名称')
}
if (arr && arr.length !== 0) {
console.log('提交')
const obj = ref({})
for (const key in formName) {
if (key !== 'formNameSystem') {
obj.value[key] = formName[key]
}
}
submitApply(obj.value).then((res) => {
applySuccess.value = false
message.success('操作成功!')
console.log('能力申请================>', res)
if (ids) {
sgcDel({ ids: ids }).then((res) => {
if (res.data.msg === 'success') {
mybus.emit('getSgcNum')
}
})
}
})
} else {
lastestPage({
key: dataForm.processDefinitionKey,
})
.then(({ data: res }) => {
if (res.code !== 0) {
return message.error(res.msg)
}
if (!res.data.list || res.data.list.length <= 0) {
return message.error('没有查询到流程,请先设计流程')
}
// proxy.$http['post'](formUrl, rootObj[formName])
tabilityapplication(formName)
.then(({ data: res }) => {
if (res.code !== 0) {
message.error(res.msg)
if (callbacks.formSaveErrorCallback) {
callbacks.formSaveErrorCallback(res)
}
}
if (callbacks.formSaveSuccessCallback) {
callbacks.formSaveSuccessCallback(res)
}
if (!res.data.businessKey) {
return message.error('业务KEY为空无法启动流程')
// startProcess(dataForm.processDefinitionKey, null, rootObj[formName])
} else {
startProcess(
dataForm.processDefinitionKey,
res.data.businessKey
// rootObj[formName]
)
}
})
.catch(() => {})
})
.catch(() => {})
// })
}
})
}
}
// 启动流程
const startProcess = (processDefinitionKey, businessKey, formData) => {
var data = {
processDefinitionKey: processDefinitionKey,
businessKey: businessKey,
variables: formData,
}
// proxy.$http['post']('/act/running/startOfBusinessKey', data)
startOfBusinessKey(data)
.then(({ data: res }) => {
applySuccess.value = false
if (res.code !== 0) {
if (callbacks.startProcessErrorCallback) {
callbacks.startProcessErrorCallback(res.data)
}
}
message({
message: '操作成功',
type: 'success',
duration: 500,
onClose: () => {
if (callbacks.startProcessSuccessCallback) {
callbacks.startProcessSuccessCallback(res.data)
}
},
})
if (instanceIdUrl) {
var params = qs.stringify({
processInstanceId: res.data.processInstanceId,
processDefinitionKey: processDefinitionKey,
businessKey: businessKey,
})
// proxy.$http['post'](instanceIdUrl + '?' + params)
updateInstanceId(params).then(
// ({ data: res }) => {}
() => {}
)
}
})
.catch(() => {})
}
const options = ref([
{
value: '政法委',
label: '政法委',
},
{
value: '公安局',
label: '公安局',
},
{
value: '卫健委',
label: '卫健委',
},
{
value: '城市管理局',
label: '城市管理局',
},
{
value: '生态环境局',
label: '生态环境局',
},
{
value: '交通运输局',
label: '交通运输局',
},
])
const handleChange = (info) => {
if (info.file.status !== 'uploading') {
console.log(info.file, info.fileList)
}
if (info.file.status === 'done') {
message.success(`${info.file.name} 上传成功`)
formName.enclosure = info.file.response.data
} else if (info.file.status === 'error') {
message.error(`${info.file.name} 上传失败`)
}
}
const beforeUpload = (file) => {
const isPNG =
file.type === 'image/png' ||
'image/doc' ||
'image/docx' ||
'image/jpg' ||
'image/png' ||
'image/jpeg' ||
'image/pdf' ||
'image/xlxs' ||
'image/ppt'
if (!isPNG) {
message.error(`上传失败`)
}
return isPNG || Upload.LIST_IGNORE
}
const fileList = ref([])
2022-06-23 19:19:48 +08:00
//删除改变arr
mybus.on('reomveOldData', (item) => {
debugger
arr = []
formName.system = []
record.value = record.value + '1'
arr = item.Name
dataResourceId = item.depID
if (arr && arr.length !== 0) {
disabled.value = true
let str = ''
arr.forEach((val, index) => {
str += val
if (index < arr.length - 1) {
str += '、'
}
})
formName.formNameSystem = str
}
arr.forEach((val, index) => {
formName.system.push({
resourceName: val,
resourceId: dataResourceId[index],
})
})
})
onBeforeUnmount(() => {
mybus.off('reomveOldData')
})
2022-06-14 09:32:49 +08:00
return {
formRef,
formName,
instanceIdUrl,
formUrl,
processStartHandle,
resetFields,
startProcess,
options,
fileList,
headers: {
authorization: 'authorization-text',
},
handleChange,
applySuccess,
disabled,
2022-06-23 19:19:48 +08:00
baseURL,
2022-06-14 09:32:49 +08:00
beforeUpload,
2022-06-23 19:19:48 +08:00
dataList,
2022-06-14 09:32:49 +08:00
}
},
}
</script>
<style scoped lang="less">
#apply-container {
2022-06-23 19:19:48 +08:00
// background-color: #f5f8fc;
2022-06-14 09:32:49 +08:00
height: 100%;
width: 100%;
margin: 130px auto 0;
display: flex;
justify-content: space-between;
aside {
width: 282px;
height: 96%;
overflow-y: auto;
background-color: #fff;
margin: 1% 0 3%;
}
article {
width: 1090px;
height: 99%;
overflow-y: auto;
background-color: #fff;
margin: 1% auto;
}
.form-container {
padding: 20px 20px 30px 20px;
.title {
font-size: 20px;
color: #000;
font-weight: bold;
margin-bottom: 20px;
}
}
.base-info {
display: flex;
}
:deep(.ant-form-item-label) {
label {
color: #666;
font-size: 16px;
&::after {
content: '';
}
}
}
:deep(.ant-form-item-required) {
&::before {
font-size: 8px;
margin-right: 10px;
}
}
:deep(.ant-input) {
border: 1px solid #e0e0e0;
border-radius: 6px;
}
.success {
div {
width: 100px;
margin: 80px auto 40px;
}
text-align: center;
font-size: 20px;
font-weight: bold;
color: #000;
}
}
</style>