update 房屋检查
This commit is contained in:
@@ -75,6 +75,7 @@ export default class drawing extends Component {
|
|||||||
this.setState({ showDrawingMaterialText: houseInfo.drawingMaterial.includes('100') })
|
this.setState({ showDrawingMaterialText: houseInfo.drawingMaterial.includes('100') })
|
||||||
}
|
}
|
||||||
const codes = await getDictData('dic_house_storage_of_drawings')
|
const codes = await getDictData('dic_house_storage_of_drawings')
|
||||||
|
console.log(codes)
|
||||||
this.setState({ codes })
|
this.setState({ codes })
|
||||||
//#endregion
|
//#endregion
|
||||||
this.form.current.setFieldsValue(this.record)
|
this.form.current.setFieldsValue(this.record)
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export default class index extends Component {
|
|||||||
<Card className="yo-form-page--body">
|
<Card className="yo-form-page--body">
|
||||||
{parts.map((item, i) => (
|
{parts.map((item, i) => (
|
||||||
<React.Fragment key={i}>
|
<React.Fragment key={i}>
|
||||||
<section id={`form-${i}-${id}`}>
|
<section id={`form-patrol-${i}-${id}`}>
|
||||||
{item.title && <h5>{item.title}</h5>}
|
{item.title && <h5>{item.title}</h5>}
|
||||||
<Spin
|
<Spin
|
||||||
spinning={loading}
|
spinning={loading}
|
||||||
@@ -131,7 +131,11 @@ export default class index extends Component {
|
|||||||
onClick={e => e.preventDefault()}
|
onClick={e => e.preventDefault()}
|
||||||
>
|
>
|
||||||
{parts.map((part, i) => (
|
{parts.map((part, i) => (
|
||||||
<Anchor.Link key={i} href={`#form-${i}-${id}`} title={part.title} />
|
<Anchor.Link
|
||||||
|
key={i}
|
||||||
|
href={`#form-patrol-${i}-${id}`}
|
||||||
|
title={part.title}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</Anchor>
|
</Anchor>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { Form, Spin } from 'antd'
|
import { Col, Form, Input, Row, Spin, Upload } from 'antd'
|
||||||
import { AntIcon } from 'components'
|
import { AntIcon, PhotoPreview } from 'components'
|
||||||
import { cloneDeep, isEqual } from 'lodash'
|
import { cloneDeep, isEqual } from 'lodash'
|
||||||
|
import { BlobToBase64, GetFileName, PreviewFile } from 'util/file'
|
||||||
|
import { api } from 'common/api'
|
||||||
|
|
||||||
const initialValues = {}
|
const initialValues = {}
|
||||||
|
|
||||||
@@ -10,6 +12,8 @@ const layout = {
|
|||||||
wrapperCol: { flex: '1' },
|
wrapperCol: { flex: '1' },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const imageUploads = [{ key: 'settlementTiltFiles' }, { key: 'otherInfoFiles' }]
|
||||||
|
|
||||||
export default class inspection extends Component {
|
export default class inspection extends Component {
|
||||||
state = {
|
state = {
|
||||||
loading: true,
|
loading: true,
|
||||||
@@ -20,6 +24,8 @@ export default class inspection extends Component {
|
|||||||
// 表单实例
|
// 表单实例
|
||||||
form = React.createRef()
|
form = React.createRef()
|
||||||
|
|
||||||
|
photoPreview = React.createRef()
|
||||||
|
|
||||||
// 初始化数据
|
// 初始化数据
|
||||||
record = {}
|
record = {}
|
||||||
|
|
||||||
@@ -61,6 +67,38 @@ export default class inspection extends Component {
|
|||||||
async fillData(params) {
|
async fillData(params) {
|
||||||
this.record = cloneDeep(params.record)
|
this.record = cloneDeep(params.record)
|
||||||
//#region 从后端转换成前段所需格式
|
//#region 从后端转换成前段所需格式
|
||||||
|
if (this.record) {
|
||||||
|
const { patrolInfo } = this.record
|
||||||
|
const keys = imageUploads.map(p => p.key)
|
||||||
|
for (const key of keys) {
|
||||||
|
const fileValue = []
|
||||||
|
const fileList =
|
||||||
|
!patrolInfo[key] || !patrolInfo[key].length ? [] : patrolInfo[key].split(',')
|
||||||
|
for (const fileId of fileList) {
|
||||||
|
try {
|
||||||
|
const file = await PreviewFile(fileId)
|
||||||
|
const base64 = await BlobToBase64(file)
|
||||||
|
fileValue.push({
|
||||||
|
uid: fileId,
|
||||||
|
response: fileId,
|
||||||
|
name: file.name,
|
||||||
|
url: base64,
|
||||||
|
status: 'done',
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
const { data: file } = await api.sysFileInfoDetail({ id: fileId })
|
||||||
|
fileValue.push({
|
||||||
|
uid: fileId,
|
||||||
|
response: '文件已丢失',
|
||||||
|
name: file.fileOriginName,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
patrolInfo[key] = fileValue
|
||||||
|
}
|
||||||
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
this.form.current.setFieldsValue(this.record)
|
this.form.current.setFieldsValue(this.record)
|
||||||
|
|
||||||
@@ -81,6 +119,13 @@ export default class inspection extends Component {
|
|||||||
if (valid) {
|
if (valid) {
|
||||||
const postData = form.getFieldsValue()
|
const postData = form.getFieldsValue()
|
||||||
//#region 从前段转换后端所需格式
|
//#region 从前段转换后端所需格式
|
||||||
|
const { patrolInfo } = postData
|
||||||
|
const keys = imageUploads.map(p => p.key)
|
||||||
|
for (const key of keys) {
|
||||||
|
patrolInfo[key] = patrolInfo[key]
|
||||||
|
.map(item => (item.uid.startsWith('rc-upload') ? item.response : item.uid))
|
||||||
|
.join(',')
|
||||||
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
return postData
|
return postData
|
||||||
}
|
}
|
||||||
@@ -94,6 +139,52 @@ export default class inspection extends Component {
|
|||||||
* @param {*} allValues
|
* @param {*} allValues
|
||||||
*/
|
*/
|
||||||
async onValuesChange(changedValues, allValues) {}
|
async onValuesChange(changedValues, allValues) {}
|
||||||
|
|
||||||
|
async onFileUpload({ file, onProgress, onSuccess, onError }) {
|
||||||
|
onProgress({
|
||||||
|
percent: 0,
|
||||||
|
})
|
||||||
|
const fd = new FormData()
|
||||||
|
fd.append('file', file)
|
||||||
|
try {
|
||||||
|
const { data: fileId } = await api.sysFileInfoUpload(fd)
|
||||||
|
onSuccess(fileId)
|
||||||
|
} catch {
|
||||||
|
onError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async onFilePreview(file, key) {
|
||||||
|
const fileList = this.form.current
|
||||||
|
.getFieldValue(['patrolInfo', key])
|
||||||
|
.filter(p => p.status === 'done')
|
||||||
|
const items = []
|
||||||
|
for (const _file of fileList) {
|
||||||
|
const img = new Image()
|
||||||
|
const src = _file.url || _file.thumbUrl
|
||||||
|
img.src = src
|
||||||
|
items.push({
|
||||||
|
src,
|
||||||
|
w: img.naturalWidth,
|
||||||
|
h: img.naturalHeight,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.photoPreview.current.initPhotoSwipe(items, {
|
||||||
|
index: fileList.indexOf(file),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async onFileDownload(file) {
|
||||||
|
const { data, headers } = await api.sysFileInfoDownload({ id: file.response })
|
||||||
|
const url = window.URL.createObjectURL(data)
|
||||||
|
const fileName = GetFileName(headers['content-disposition'])
|
||||||
|
const a = document.createElement('a')
|
||||||
|
a.href = url
|
||||||
|
a.download = fileName
|
||||||
|
a.click()
|
||||||
|
window.URL.revokeObjectURL(url)
|
||||||
|
a.remove()
|
||||||
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -108,7 +199,92 @@ export default class inspection extends Component {
|
|||||||
onValuesChange={(changedValues, allValues) =>
|
onValuesChange={(changedValues, allValues) =>
|
||||||
this.onValuesChange(changedValues, allValues)
|
this.onValuesChange(changedValues, allValues)
|
||||||
}
|
}
|
||||||
></Form>
|
>
|
||||||
|
<Row gutter={16}>
|
||||||
|
<Col span={12}>
|
||||||
|
<Form.Item label="沉降倾斜情况" name={['patrolInfo', 'settlementTilt']}>
|
||||||
|
<Input.TextArea
|
||||||
|
autoSize={{ minRows: 4 }}
|
||||||
|
placeholder="请输入沉降倾斜情况"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
|
<Col span={12}>
|
||||||
|
<Form.Item
|
||||||
|
name={['patrolInfo', 'settlementTiltFiles']}
|
||||||
|
valuePropName="fileList"
|
||||||
|
getValueFromEvent={e => {
|
||||||
|
if (Array.isArray(e)) {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return e && e.fileList
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Upload
|
||||||
|
listType="picture-card"
|
||||||
|
customRequest={e => this.onFileUpload(e)}
|
||||||
|
showUploadList={{
|
||||||
|
showRemoveIcon: true,
|
||||||
|
showDownloadIcon: true,
|
||||||
|
}}
|
||||||
|
onPreview={file =>
|
||||||
|
this.onFilePreview(file, 'settlementTiltFiles')
|
||||||
|
}
|
||||||
|
onDownload={file => this.onFileDownload(file)}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<AntIcon type="plus" />
|
||||||
|
<div className="ant-upload-text">沉降倾斜照片</div>
|
||||||
|
</div>
|
||||||
|
</Upload>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
|
<Col span={12}>
|
||||||
|
<Form.Item label="其他情况" name={['patrolInfo', 'otherInfo']}>
|
||||||
|
<Input.TextArea
|
||||||
|
autoSize={{ minRows: 4 }}
|
||||||
|
placeholder="请输入其他情况"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
|
<Col span={12}>
|
||||||
|
<Form.Item
|
||||||
|
name={['patrolInfo', 'otherInfoFiles']}
|
||||||
|
valuePropName="fileList"
|
||||||
|
getValueFromEvent={e => {
|
||||||
|
if (Array.isArray(e)) {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return e && e.fileList
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Upload
|
||||||
|
listType="picture-card"
|
||||||
|
customRequest={e => this.onFileUpload(e)}
|
||||||
|
showUploadList={{
|
||||||
|
showRemoveIcon: true,
|
||||||
|
showDownloadIcon: true,
|
||||||
|
}}
|
||||||
|
onPreview={file => this.onFilePreview(file, 'otherInfoFiles')}
|
||||||
|
onDownload={file => this.onFileDownload(file)}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<AntIcon type="plus" />
|
||||||
|
<div className="ant-upload-text">其他情况照片</div>
|
||||||
|
</div>
|
||||||
|
</Upload>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<Form.Item label="主要安全隐患综述" name={['patrolInfo', 'mainSafety']}>
|
||||||
|
<Input.TextArea
|
||||||
|
autoSize={{ minRows: 4 }}
|
||||||
|
placeholder="请输入主要安全隐患综述"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<PhotoPreview ref={this.photoPreview} />
|
||||||
</Spin>
|
</Spin>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ const { getState, dispatch } = store
|
|||||||
|
|
||||||
const getDictData = async (...args) => {
|
const getDictData = async (...args) => {
|
||||||
const dictData = getState('dictData')
|
const dictData = getState('dictData')
|
||||||
let result = {}
|
let dict = {}
|
||||||
const code = []
|
const code = []
|
||||||
for (let i = 0; i < args.length; i++) {
|
for (let i = 0; i < args.length; i++) {
|
||||||
const codeName = toCamelCase(args[i])
|
const codeName = toCamelCase(args[i])
|
||||||
if (!dictData.hasOwnProperty(codeName)) {
|
if (!dictData.hasOwnProperty(codeName)) {
|
||||||
code.push(args[i])
|
code.push(args[i])
|
||||||
} else {
|
} else {
|
||||||
result[codeName] = dictData[codeName]
|
dict[codeName] = dictData[codeName]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,14 +29,17 @@ const getDictData = async (...args) => {
|
|||||||
value
|
value
|
||||||
})
|
})
|
||||||
|
|
||||||
result = { ...result, ...value }
|
dict = { ...dict, ...value }
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
return dictData
|
const result = {}
|
||||||
|
args.forEach(p => {
|
||||||
|
const codeName = toCamelCase(p)
|
||||||
|
result[codeName] = dict[codeName]
|
||||||
|
})
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getDictData
|
export default getDictData
|
||||||
Reference in New Issue
Block a user