update 房屋检查

This commit is contained in:
2021-06-23 09:41:27 +08:00
parent f2f71e6695
commit 25fc68fba2
4 changed files with 195 additions and 11 deletions

View File

@@ -75,6 +75,7 @@ export default class drawing extends Component {
this.setState({ showDrawingMaterialText: houseInfo.drawingMaterial.includes('100') })
}
const codes = await getDictData('dic_house_storage_of_drawings')
console.log(codes)
this.setState({ codes })
//#endregion
this.form.current.setFieldsValue(this.record)

View File

@@ -100,7 +100,7 @@ export default class index extends Component {
<Card className="yo-form-page--body">
{parts.map((item, i) => (
<React.Fragment key={i}>
<section id={`form-${i}-${id}`}>
<section id={`form-patrol-${i}-${id}`}>
{item.title && <h5>{item.title}</h5>}
<Spin
spinning={loading}
@@ -131,7 +131,11 @@ export default class index extends Component {
onClick={e => e.preventDefault()}
>
{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>
</Col>

View File

@@ -1,7 +1,9 @@
import React, { Component } from 'react'
import { Form, Spin } from 'antd'
import { AntIcon } from 'components'
import { Col, Form, Input, Row, Spin, Upload } from 'antd'
import { AntIcon, PhotoPreview } from 'components'
import { cloneDeep, isEqual } from 'lodash'
import { BlobToBase64, GetFileName, PreviewFile } from 'util/file'
import { api } from 'common/api'
const initialValues = {}
@@ -10,6 +12,8 @@ const layout = {
wrapperCol: { flex: '1' },
}
const imageUploads = [{ key: 'settlementTiltFiles' }, { key: 'otherInfoFiles' }]
export default class inspection extends Component {
state = {
loading: true,
@@ -20,6 +24,8 @@ export default class inspection extends Component {
// 表单实例
form = React.createRef()
photoPreview = React.createRef()
// 初始化数据
record = {}
@@ -61,6 +67,38 @@ export default class inspection extends Component {
async fillData(params) {
this.record = cloneDeep(params.record)
//#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
this.form.current.setFieldsValue(this.record)
@@ -81,6 +119,13 @@ export default class inspection extends Component {
if (valid) {
const postData = form.getFieldsValue()
//#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
return postData
}
@@ -94,6 +139,52 @@ export default class inspection extends Component {
* @param {*} 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
render() {
@@ -108,7 +199,92 @@ export default class inspection extends Component {
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>
)
}

View File

@@ -7,14 +7,14 @@ const { getState, dispatch } = store
const getDictData = async (...args) => {
const dictData = getState('dictData')
let result = {}
let dict = {}
const code = []
for (let i = 0; i < args.length; i++) {
const codeName = toCamelCase(args[i])
if (!dictData.hasOwnProperty(codeName)) {
code.push(args[i])
} else {
result[codeName] = dictData[codeName]
dict[codeName] = dictData[codeName]
}
}
@@ -29,14 +29,17 @@ const getDictData = async (...args) => {
value
})
result = { ...result, ...value }
return result
dict = { ...dict, ...value }
}
catch { }
}
return dictData
const result = {}
args.forEach(p => {
const codeName = toCamelCase(p)
result[codeName] = dict[codeName]
})
return result
}
export default getDictData