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

1025 lines
33 KiB
Vue

<template>
<div>
<home-header></home-header>
<div id="apply-container">
<article>
<div class="from-card" v-if="applySuccess && !applyAll">
<AbilityToApplyFor :dataList="list"></AbilityToApplyFor>
</div>
<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 flex-row-start">
<a-form-item
label="申请标题"
name="title"
:rules="[{ required: true, message: '请输入申请标题' }]"
>
<a-input
placeholder="请输入能力申请标题"
v-model:value="formName.title"
/>
</a-form-item>
<!-- 西海岸-摄像头-增加过期时间 -->
<a-form-item
v-if="isCamera && isXiHaiAn"
label="过期时间"
name="expireDate"
:rules="[{ required: true, message: '请选择过期时间' }]"
style="margin-left: 22px"
>
<a-select
v-model:value="formName.expireDate"
placeholder="请选择过期时间"
style="width: 200px"
:options="expireDateOptions"
></a-select>
</a-form-item>
</div>
<div class="base-info">
<a-form-item
label="申请人信息"
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"
label="电话"
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
label="单位"
name="unit"
:rules="[{ required: true, message: '请输入单位' }]"
>
<a-input
placeholder="请输入单位"
v-model:value="formName.unit"
disabled
v-if="deptFlage"
/>
<a-select
v-else
placeholder="请选择归属部门"
v-model:value="formName.unit"
@change="deptIdChangeFunction"
>
<a-select-option
v-for="(item, index) in deptNameAll"
:key="`${index}-${item}`"
:value="item.name"
>
{{ item.name }}
</a-select-option>
</a-select>
</a-form-item>
</div>
<div class="base-info" v-if="flag">
<div style="margin-bottom: 24px">
<a-form-item
style="margin-bottom: 0"
label="应用系统"
name="applicationSystem"
:rules="[{ required: true, message: '请选择应用系统' }]"
>
<a-select
v-model:value="formName.applicationSystem"
show-search
placeholder="请选择应用系统"
style="width: 230px"
:options="systemOptions"
@focus="handleFocus"
@blur="handleBlur"
@change="systemHandleChange"
@search="systemHandleSearch"
></a-select>
</a-form-item>
<span
style="font-size: 12px; color: #666; padding-left: 106px"
>
如选项没有系统请新增
</span>
</div>
<a-form-item
class="applicationScene"
label="应用领域"
name="applicationScene"
:rules="[{ required: true, message: '请选择应用领域' }]"
style="width: 6.93rem"
>
<a-select
v-model:value="formName.applicationScene"
:options="applicationSceneOpthion"
mode="tags"
:size="size"
placeholder="请选择应用领域"
:filterOption="false"
:searchValue="false"
style="width: 5.87rem"
></a-select>
</a-form-item>
</div>
<div>
<a-form-item
label="需求依据"
name="applicationBackground"
:rules="[
{ required: true, message: '请输入需求依据' },
{ min: 50, message: '需求依据最少为50个字' },
]"
>
<a-textarea
placeholder="请输入需求依据"
v-model:value="formName.applicationBackground"
:rows="4"
/>
</a-form-item>
</div>
<div class="bottom-btn">
<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>
</div>
</a-form>
</div>
<div class="success" v-else>
<div>
<img src="../../assets/home/success.png" alt="" />
</div>
<p>您已成功申请能力,请耐心等待审批结果,结果会第一时间通知您!</p>
</div>
</div>
</article>
</div>
</div>
</template>
<script>
import AbilityToApplyFor from './AbilityToApplyFor.vue'
import HomeHeader from '@/views/home/components/header'
import { reactive, ref, watch, onBeforeUnmount } from 'vue'
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
import qs from 'qs'
import { Upload } from 'ant-design-vue'
import {
lastestPage,
tabilityapplication,
startOfBusinessKey,
updateInstanceId,
submitApply,
applyAllApplication,
getUser,
getUserInfo,
relaunch,
selectOne,
} from '@/api/home'
import { getDeptAll } from '@/api/user'
import { getCategoryTreePage, endProcess } from '@/api/personalCenter'
import mybus from '@/myplugins/mybus'
import { sgcDel, getApplyForm } from '@/api/personalCenter'
import { pageWithAttrs, updateIntegrationServices } from '@/api/home'
import { DETAIL_PAGE_CONTENT_DEFAULT_TAB } from '@/global/GlobalConfig.js'
import { getIntegrationDetail, soldierApply } from '@/api/home'
import * as moment from 'moment'
export default {
name: '',
props: {},
components: {
HomeHeader,
AbilityToApplyFor,
},
setup() {
const router = useRouter()
const disabled = ref(false)
const flag = ref(false)
const list = ref(JSON.parse(localStorage.getItem('applyList')))
const deptNameAll = ref([]) //所有部门名称
const deptFlage = ref(true) //判断是否存在默认部门名称
const applyAll = router.currentRoute.value.query.applyAll
// 融合服务id
const integrationServicesId =
router.currentRoute.value.query.integrationServicesId
// 融合服务详情
const integrationServicesItemInfo = ref(null)
const num = ref(0)
// 过期时间
const expireDateOptions = [
{
value: moment().add(30, 'days').format('YYYY-MM-DD HH:mm:ss'),
label: '30天',
},
{
value: moment().add(60, 'days').format('YYYY-MM-DD HH:mm:ss'),
label: '60天',
},
{
value: moment().add(90, 'days').format('YYYY-MM-DD HH:mm:ss'),
label: '90天',
},
]
if (!applyAll) {
list.value.map((item) => {
item.arr.map((val) => {
let obj = item.children
? item.children.filter((type) => type.id == val.id)[0]
: val.type !== '应用资源'
if (obj) {
if (obj.type !== '应用资源') {
flag.value = true
}
}
})
if (item.checkedList) {
console.log(item)
num.value += Number(item.checkedList.length)
}
})
}
console.log('list', list.value)
const baseURL = window.SITE_CONFIG.apiURL
let record = ref('1')
const text = ref('')
// 西海岸-特殊处理
let wrjAndDbText = ['单兵设备', '无人机']
const isXiHaiAn = ref(whoShow.itShowXiHaiAn)
// 西海岸-判断是否是基础设施-摄像头
const isCamera = ref(false)
if (
list.value[0] &&
list.value[0].arr &&
list.value[0].arr[0] &&
list.value[0].arr[0].type == '基础设施'
) {
isCamera.value = true
}
const formName = reactive({
title: applyAll
? '全部应用资源申请'
: wrjAndDbText.includes(
list.value[0].arr &&
list.value[0].arr[0] &&
list.value[0].arr[0].type
)
? list.value[0].arr[0].type + '申请'
: list.value[0].children
? '申请' +
list.value[0].children
.filter((val) => val.id == list.value[0].checkedList[0])[0]
.resourceName.concat(
num.value > 1 ? '等' + num.value + '项能力' : ''
)
: '申请' + list.value[0].arr[0].resourceName, // 标题
// applicationSystem: '', // 应用系统
applicationScene: [], // 应用领域
applicationBackground: '', // 应用背景
effectWish: '', // 期望效果
user: '',
userId: '',
phone: '',
unit: '',
deptId: '',
system: [],
enclosure: '', //附件
enclosureName: '', //附件
})
const dataList = ref([])
const id = router.currentRoute.value.query.id
const taskId = router.currentRoute.value.query.taskId
const businessKey = ref(router.currentRoute.value.query.id)
if (id) {
getApplyForm(id).then((res) => {
console.log('修改==============>', res.data.data)
formName.applicationSystem = res.data.data.applicationSystem || ''
formName.applicationScene = res.data.data.applicationScene || []
formName.applicationBackground =
res.data.data.applicationBackground || ''
formName.effectWish = res.data.data.effectWish || ''
formName.phone = res.data.data.phone || ''
formName.enclosure = res.data.data.enclosure || ''
formName.enclosureName = res.data.data.enclosureName || ''
if (res.data.data.enclosure) {
fileList.value.push({
name: res.data.data.enclosureName,
url: res.data.data.enclosure,
})
}
})
}
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
if (!formName.unit) {
deptFlage.value = false
//调用查询所有部门名称的接口
getDeptAll().then((res) => {
deptNameAll.value = res.data.data
})
}
})
})
//归属部门选中改变事件
const deptIdChangeFunction = (name) => {
deptNameAll.value.map((item) => {
if (item.name == name) {
formName.deptId = item.id
}
})
console.log(formName)
}
const applicationSceneOpthion = ref([])
getCategoryTreePage({
page: 1,
limit: 20,
dictTypeId: '1513712507692818433',
deFlage: 0,
}).then((res) => {
res.data.data.list.map((val) => {
applicationSceneOpthion.value.push({
value: val.dictLabel,
label: val.dictLabel,
})
})
})
const formRef = ref()
const applySuccess = ref(true)
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 jumpToDetailsPageconetent = () => {
setTimeout(() => {
router.push({
path: '/DetailsPageconetent',
query: {
select: DETAIL_PAGE_CONTENT_DEFAULT_TAB,
},
})
}, 1000)
}
// 提交申请
let submitFlag = true
const processStartHandle = () => {
formRef.value.validate().then(() => {
if (submitFlag) {
submitFlag = false
if (!formUrl) {
return message.error('请设置保存表单的URL')
}
if (!formName) {
return message.error('请设置表单名称')
}
if (id) {
endProcess({ instanceId: taskId }).then((end) => {
if (end.data.code == 0) {
let ids = []
let falgNum = 0
let sxt = true
formName.system = []
console.log('list==================', list.value)
list.value.map((val) => {
val.arr.map((item) => {
if (item.type !== '基础设施') {
falgNum++
}
})
})
list.value.map((val) => {
val.arr.map((item) => {
if (item.type !== '基础设施') {
formName.system.push({
resourceId: item.resourceId,
resourceName: item.resourceName,
})
falgNum++
console.log(item.id)
if (item.id) {
ids.push(item.id)
}
} else {
infrastructureConfirm(item, falgNum, sxt)
}
})
})
if (formName.system.length !== 0) {
if (formName.applicationSystem.length == 0) {
formName.applicationSystem = ''
}
submitApply(formName).then((res) => {
message.success('申请提交成功,请到消息中心查看!')
console.log('能力申请================>', res)
if (res.data.code == 0) {
if (ids && ids.length > 0) {
sgcDel({ ids: ids }).then((res) => {
if (res.data.msg === 'success') {
mybus.emit('getSgcNum')
jumpToDetailsPageconetent()
}
})
} else {
// 融合服务
if (integrationServicesId) {
getIntegrationServicesDeatil(
integrationServicesId
).then((res) => {
updateIntegrationServiceAction()
})
}
jumpToDetailsPageconetent()
}
} else {
message.error('申请失败!')
}
})
}
}
})
} else {
if (!applyAll) {
let ids = []
let falgNum = 0
let sxt = true
formName.system = []
console.log('list==================', list.value)
list.value.map((val) => {
val.arr.map((item) => {
if (item.type !== '基础设施') {
falgNum++
}
})
})
list.value.map((val) => {
val.arr.map((item) => {
if (item.type !== '基础设施') {
formName.system.push({
resourceId: item.resourceId,
resourceName: item.resourceName,
})
falgNum++
console.log(item.id)
if (item.id) {
ids.push(item.id)
}
} else {
infrastructureConfirm(item, falgNum, sxt)
}
})
})
console.log('formName--ids-提交数据--------->', formName, ids)
if (formName.system.length !== 0) {
if (
formName.applicationSystem &&
formName.applicationSystem.length == 0
) {
formName.applicationSystem = ''
}
// 西海岸:单兵设备、无人机单独调取其他接口
if (wrjAndDbText.includes(list.value[0].arr[0].type)) {
handleWrjApply(formName)
return
}
submitApply(formName).then((res) => {
message.success('申请提交成功,请到消息中心查看!')
console.log('能力申请================>', res)
if (res.data.code == 0) {
if (ids && ids.length > 0) {
sgcDel({ ids: ids }).then((res) => {
if (res.data.msg === 'success') {
mybus.emit('getSgcNum')
jumpToDetailsPageconetent()
}
})
} else {
// 融合服务
if (integrationServicesId) {
getIntegrationServicesDeatil(
integrationServicesId
).then((res) => {
updateIntegrationServiceAction()
})
}
jumpToDetailsPageconetent()
}
} else {
message.error('申请失败!')
}
})
}
} else {
formName.applicationSystem = ''
applyAllApplication(formName).then((res) => {
if (res.data.code == 0) {
message.success('申请提交成功,请到消息中心查看!')
jumpToDetailsPageconetent()
} else {
message.error('申请失败!')
}
})
}
}
}
})
}
// 基础设施--数据下发
const infrastructureConfirm = (item, falgNum, sxt) => {
let obj = {}
Object.assign(obj, formName)
console.log('摄像头===============>', obj, item)
obj.system = []
if (item.note1 && typeof item.note1 == 'string') {
item.note1 = JSON.parse(item.note1)
}
item.note1 &&
item.note1.map((jcss) => {
if (!jcss) {
return
}
let _itemData = {
resourceId: (jcss.idtCameraChannel || '') + '',
resourceName: jcss.channelName,
cameraId: jcss.channelId, // 改接口后删除
channelCode: jcss.channelCode,
channelId: jcss.channelId,
channelName: jcss.channelName,
checkStatus: jcss.checkStatus + '',
gpsX: jcss.gpsX,
gpsY: jcss.gpsY,
idtCameraChannel: (jcss.idtCameraChannel || '') + '',
nodeName: jcss.nodeName,
parentId: jcss.parentId,
status: jcss.status + '',
}
// 西海岸
if (isXiHaiAn.value) {
_itemData.managementUnitName = jcss.managementUnitName
_itemData.cameraPointTypeName = jcss.cameraPointTypeName
}
obj.system.push(_itemData)
})
submitApply(obj).then((res) => {
// applySuccess.value = false
console.log('摄像头申请================>', res)
if (item.id) {
sgcDel({ ids: [item.id] }).then((res1) => {
if (res1.data.msg === 'success') {
if (falgNum == 0 && sxt) {
message.success('申请提交成功,请到消息中心查看!')
sxt = false
}
mybus.emit('getSgcNum')
jumpToDetailsPageconetent()
}
})
} else {
if (res.data.msg === 'success' && falgNum == 0 && sxt) {
message.success('申请提交成功,请到消息中心查看!')
sxt = false
}
jumpToDetailsPageconetent()
}
})
}
// 启动流程
const startProcess = (processDefinitionKey, businessKey, formData) => {
var data = {
processDefinitionKey: processDefinitionKey,
businessKey: businessKey,
variables: formData,
}
startOfBusinessKey(data)
.then(({ data: res }) => {
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,
})
updateInstanceId(params).then(() => {})
}
})
.catch(() => {})
}
const options = ref([
{
value: '政法委',
label: '政法委',
},
{
value: '公安局',
label: '公安局',
},
{
value: '卫健委',
label: '卫健委',
},
{
value: '城市管理局',
label: '城市管理局',
},
{
value: '生态环境局',
label: '生态环境局',
},
{
value: '交通运输局',
label: '交通运输局',
},
])
const systemOptions = ref([])
const systemOptions2 = ref([])
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
formName.enclosureName = info.file.name
} 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([])
// 应用系统下拉
const systemHandleChange = (value) => {
console.log(`selected ${value}`)
}
const systemHandleSearch = (value) => {
let valueArray = []
systemOptions.value.map((val) => {
valueArray.push(val.value)
})
if (valueArray.indexOf(value) == -1) {
systemOptions.value.push({
value: value,
label: value,
})
}
}
pageWithAttrs({
pageNum: 1,
pageSize: 99999,
type: '应用资源',
name: '',
infoList: [],
}).then((res) => {
if (res.data.code == 0) {
if (res.data.data.records.length == 0) {
message.warning('该关键词,暂无应用资源!')
} else {
res.data.data.records.map((val) => {
systemOptions2.value.push({
value: val.name,
label: val.name,
})
})
// console.log('第一次获取===================>', systemOptions2.value)
}
} else {
message.error('应用系统获取数据失败!')
}
})
const handleBlur = () => {
console.log('blur')
}
const handleFocus = () => {
console.log('focus')
let arrId = []
for (var valueIndex of systemOptions2.value) {
if (arrId.indexOf(valueIndex['value']) == -1) {
arrId.push(valueIndex['value'])
systemOptions.value.push(valueIndex)
}
}
}
onBeforeUnmount(() => {
mybus.off('reomveOldData')
})
// 融合服务-更新
const updateIntegrationServiceAction = () => {
let _applyCount =
Number(integrationServicesItemInfo.value.applyCount || 0) + 1
let _data = Object.assign({}, integrationServicesItemInfo.value, {
applyCount: _applyCount,
})
updateIntegrationServices(_data)
.then((res) => {
console.log('res---更新--------->', res)
})
.catch((err) => {
console.log('err----更新-------->', err)
})
}
// 融合服务--详情
const getIntegrationServicesDeatil = (id) => {
return new Promise((resolve, reject) => {
getIntegrationDetail(id).then(
(res) => {
resolve(res)
if (res.data.code !== 0) {
return message.error(res.data.msg)
}
integrationServicesItemInfo.value = res.data.data || {}
},
(err) => {
reject(err)
message.error(err)
}
)
})
}
// 西海岸:单兵设备、无人机提交申请
const handleWrjApply = (formName) => {
let _data = {
deviceId:
formName.system &&
formName.system[0] &&
formName.system[0].resourceId,
deviceName:
formName.system &&
formName.system[0] &&
formName.system[0].resourceName,
title: formName.title,
name: formName.user,
phone: formName.phone,
dept: formName.unit, // 单位
applicationSystem: formName.applicationSystem, // 应用系统
applicationArea: JSON.stringify(formName.applicationScene), // 应用领域
demand: formName.applicationBackground, // 需求依据
}
soldierApply(_data)
.then((res) => {
if (res.data.code == 0) {
message.success(res.data.msg)
jumpToDetailsPageconetent()
} else {
message.error('申请失败!')
}
})
.catch((err) => {
message.error(err)
})
}
return {
deptIdChangeFunction,
formRef,
formName,
deptNameAll,
instanceIdUrl,
formUrl,
processStartHandle,
resetFields,
startProcess,
options,
fileList,
list,
deptFlage,
headers: {
authorization: 'authorization-text',
},
handleChange,
applySuccess,
disabled,
baseURL,
beforeUpload,
dataList,
systemHandleChange,
systemHandleSearch,
handleBlur,
handleFocus,
systemOptions,
applicationSceneOpthion,
flag,
applyAll,
getIntegrationServicesDeatil,
isCamera,
isXiHaiAn,
expireDateOptions,
}
},
}
</script>
<style scoped lang="less">
#apply-container {
// background-color: #f5f8fc;
height: 100%;
width: 100%;
margin: 0.8rem 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;
justify-content: space-between;
}
.flex-row-start {
justify-content: flex-start;
align-items: center;
}
: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;
}
}
.applicationScene {
:deep(.ant-select-selector) {
overflow-x: scroll;
}
:deep(.ant-select-selection-overflow) {
flex-wrap: nowrap;
}
}
textarea {
resize: none;
font-size: 14px;
}
.bottom-btn {
display: flex;
justify-content: center;
// position: fixed;
}
</style>