@ -1,7 +1,7 @@
import React , { useState , useRef , useEffect } from "react" ;
import { connect } from "react-redux" ;
import { Modal , Form , Tag } from "@douyinfe/semi-ui" ;
import { IconAlertCircle } from '@douyinfe/semi-icons' ;
import { Modal , Form , Tag , } from "@douyinfe/semi-ui" ;
import { IconAlertCircle } from '@douyinfe/semi-icons' ;
function adminModal ( props ) {
@ -22,46 +22,95 @@ function adminModal (props) {
appArr , / / 修 改 时 添 加 应 用
bindId ,
mapping , / / 修 改 时 的 映 射 类 型
maintenancePeriod / / 维 保 时 间 段
maintenancePeriod , / / 维 保 时 间 段
editData ,
traitLabel
} = props ;
const { install } = actions ;
const form = useRef ( ) ; / / 表 单
const [ custom , setCustom ] = useState ( false ) ; / / 是 否 是 自 定 义 项 目
const [ myprojectType , setMyprojectType ] = useState ( 'pep' ) ; / / 是 否 是 自 定 义 项 目
const [ structureSensor , setStructureSensor ] = useState ( [ ] )
const [ sendorders , setSendorders ] = useState ( [ ] )
const [ strucId , setStrucId ] = useState ( [ ] )
/ / 初 始 化
useEffect ( ( ) => {
useEffect ( async ( ) => {
if ( pepname ) {
setCustom ( true )
setMyprojectType ( 'axy' )
}
if ( editData ? . id ) {
await getData ( { projectId : anxincloudArr ? . join ( ',' ) + ',-1' } )
setSendorders ( editData ? . sendorders )
if ( editData ? . sendorders ? . includes ( 'emphasis' ) ) {
form . current . setValue ( 'strucId' , editData ? . strucId )
editData ? . strucId ? . forEach ( d => {
form . current . setValue ( 'strucSensor' + d , editData ? . strucSensor [ d ] )
} )
setStrucId ( editData ? . strucId || [ ] )
}
if ( editData ? . sendorders ? . includes ( 'percentage' ) ) {
form . current . setValue ( 'percentage' , editData ? . percentage )
}
}
} , [ ] ) ;
const getData = async ( data = { } ) => {
await dispatch ( install . getStructureStation ( { ... data , traitLabel } ) ) . then ( ( res ) => {
if ( res . success ) {
setStructureSensor ( res . payload . data || [ ] )
}
} )
}
function handleOk ( ) {
/ / 点 击 弹 框 确 定 右 边 按 钮
form . current
. validate ( )
. then ( ( values ) => {
let appArr = [ ]
for ( let i = 0 ; i < values . appId . length ; i ++ ) {
appArr . push ( JSON . parse ( values . appId [ i ] ) . id )
}
console . log ( 22 , values ) ;
let strucSensor = { }
if ( values . sendorders ? . includes ( "emphasis" ) ) {
values . strucId ? . forEach ( d => {
strucSensor [ d ] = values [ 'strucSensor' + d ] || [ ]
} ) ;
}
let data = {
name : values . name ,
pepProjectId : values . pepProjectId ,
anxinProjectId : values . anxinProjectId ,
appId : appArr ,
mappingClass : values . mappingClass ,
maintenancePeriod : values . maintenancePeriod ,
isanchor : values . isanchor ,
sendorders : values . sendorders ,
percentage : values . percentage ,
strucId : values . strucId ,
strucSensor : strucSensor
}
if ( systemEdit ) {
let appArr = [ ]
for ( let i = 0 ; i < values . appId . length ; i ++ ) {
appArr . push ( JSON . parse ( values . appId [ i ] ) . id )
}
let bindObj = JSON . parse ( JSON . stringify ( values ) )
bindObj . appId = appArr
dispatch ( install . postProjectBind ( { ... bindObj , bindId : bindId , msg : '修改映射关系' } ) ) . then ( ( res ) => { / / 获 取 项 企 ( P E P ) 全 部 部 门 及 其 下 用 户
dispatch ( install . postProjectBind ( { ... data , bindId : bindId , msg : '修改映射关系' , } ) ) . then ( ( res ) => { / / 获 取 项 企 ( P E P ) 全 部 部 门 及 其 下 用 户
if ( res . success ) {
close ( ) ;
}
} )
}
else {
let appArr = [ ]
for ( let i = 0 ; i < values . appId . length ; i ++ ) {
appArr . push ( JSON . parse ( values . appId [ i ] ) . id )
}
let bindObj = JSON . parse ( JSON . stringify ( values ) )
bindObj . appId = appArr
dispatch ( install . postProjectBind ( { ... bindObj , msg : '添加映射关系' } ) ) . then ( ( res ) => { / / 获 取 项 企 ( P E P ) 全 部 部 门 及 其 下 用 户
dispatch ( install . postProjectBind ( { ... data , msg : '添加映射关系' } ) ) . then ( ( res ) => { / / 获 取 项 企 ( P E P ) 全 部 部 门 及 其 下 用 户
if ( res . success ) {
close ( ) ;
}
@ -69,6 +118,8 @@ function adminModal (props) {
}
} )
}
function handleCancel ( ) {
cancel ( ) ;
/ / 点 击 弹 框 取 消 左 边 按 钮
@ -86,6 +137,7 @@ function adminModal (props) {
content
} ;
}
return (
< >
< Modal
@ -106,7 +158,7 @@ function adminModal (props) {
allowEmpty
labelPosition = "left"
labelAlign = "right"
labelWidth = "110 px"
labelWidth = "132 px"
onValueChange = { ( values , field ) => {
for ( var key in field ) {
if ( key == 'projectType' ) {
@ -179,6 +231,15 @@ function adminModal (props) {
rules = { [ { required : true , message : "请选择安心云项目" } ] }
initValue = { anxincloudArr || [ ] }
showClear
onChange = { v => {
if ( v . length ) {
getData ( { projectId : v . join ( ',' ) + ',-1' } )
} else {
setStructureSensor ( [ ] )
}
form . current . setValue ( 'strucId' , [ ] )
setStrucId ( [ ] )
} }
>
{
anxincloudList . map ( ( item , index ) => {
@ -245,7 +306,7 @@ function adminModal (props) {
style = { { width : 425 } }
initValue = { mapping }
showClear
>
>
{
[
{ name : '智慧类' , value : 'wisdom' } ,
@ -261,18 +322,82 @@ function adminModal (props) {
< Form.DatePicker
style = { { width : 425 } }
label = '维保期限时间:'
type = { 'dateRange'}
type = 'dateRange'
field = 'maintenancePeriod'
initValue = { maintenancePeriod }
>
< / Form.DatePicker >
< / div >
< Form.RadioGroup field = "isanchor" label = '是否续签:' initValue = { editData ? . isanchor } >
< Form.Radio value = { true } > 续签 < / Form.Radio >
< Form.Radio value = { false } > 不续签 < / Form.Radio >
< / Form.RadioGroup >
< Form.CheckboxGroup
field = "sendorders"
label = '自动派单:'
direction = 'horizontal'
initValue = { editData ? . sendorders || [ ] }
onChange = { v => {
setSendorders ( v )
if ( ! v . includes ( 'emphasis' ) ) {
setStrucId ( [ ] )
}
} }
>
< Form.Checkbox value = "percentage" > 项目中断比例 < / Form.Checkbox >
< Form.Checkbox value = "emphasis" > 重点点位监控 < / Form.Checkbox >
< / Form.CheckboxGroup >
{
sendorders ? . includes ( 'percentage' ) &&
< Form.InputNumber field = 'percentage' label = '项目中断百分比:' min = { 0 } max = { 100 } / >
}
{
sendorders ? . includes ( 'emphasis' ) &&
< >
< Form.Select
label = "选择结构物:"
field = "strucId"
filter
multiple
placeholder = "请选择结构物"
style = { { width : 425 } }
/ / i n i t V a l u e = { [ ] }
showClear
onChange = { v => {
setStrucId ( v )
} }
>
{
structureSensor . map ( item => {
return < Form.Select.Option key = { item . strucId } value = { item . strucId } >
{ item . strucName }
< / Form.Select.Option >
} )
}
< / Form.Select >
{ strucId ? . length ? structureSensor ? . filter ( v => strucId ? . includes ( v . strucId ) ) ? . map ( ( u , index ) => {
return < Form.CheckboxGroup
label = { u . strucName + ':' }
key = { u . strucName + index }
field = { 'strucSensor' + u . strucId }
style = { { width : 420 } }
/ / i n i t V a l u e = { e d i t O b j ? . p o m s S t r u c F a c t o r I d ? e d i t O b j ? . p o m s S t r u c F a c t o r I d [ u . i d ] : ( f a c t o r I t e m | | [ ] ) }
direction = 'horizontal'
showClear
>
{
u . sensor ? . map ( ( v , index ) =>
< Form.Checkbox value = { v . senterId } key = { v . senterId } style = { { width : 200 } } > { v . senterName } ( { v . factorName } ) < / Form.Checkbox > )
}
< / Form.CheckboxGroup >
} ) : ""
}
< / >
}
< / Form >
< / div >
< / Modal >
< / d i v >
< / M o d a l >
< / >
) ;
}
@ -282,7 +407,7 @@ function mapStateToProps (state) {
/ / l o a d i n g : m e m b e r s . i s R e q u e s t i n g ,
user : auth . user ,
actions : global . actions ,
/ / m e m b e r s : m e m b e r s . d a t a ,
traitLabel : global . traitLabel ,
} ;
}