This commit is contained in:
xuyucheng 2022-01-14 17:52:14 +08:00
parent 9c6163bf20
commit 55487a0e8b
3 changed files with 85 additions and 47 deletions

View File

@ -0,0 +1,3 @@
.simulate-table{
text-align: center;
}

View File

@ -74,7 +74,7 @@ body,
}
.ant-input{
padding: 10px ;
/* padding: 10px ; */
}
.ant-input:focus {
@ -173,11 +173,6 @@ span {
color: #FF5E40;
}
/* 日历样式 */
.ant-picker-calendar {
padding: 20px;
}
/* 两端对齐文字 */
.space-word {
padding: 10px;
@ -209,4 +204,5 @@ span {
.paragraph_content{
display: block;
margin: 20px 0;
}
}

View File

@ -1,7 +1,8 @@
import React, { Component } from 'react'
// import api from "@/api/request"
import React, { Component } from 'react';
import api from "@/api/request"
import text_model from '@/utils/model'
import { Table, Input, Button } from 'antd'
import { Input, Button, Row, Col } from 'antd'
import "@/assets/style/editReport.css"
class EditReport extends Component {
constructor(props) {
@ -12,71 +13,100 @@ class EditReport extends Component {
}
// componentDidMount() {
// api.post("/admin/rating/report_edit_save_delete", { rid: this.props.id })
// .then(res => {
// console.log(res)
// })
// }
analysisColumn(val) {
const data = val[0].map((item, i) => {
return {
title: item, dataIndex: item, align: 'center', key: i, editable: true
}
simulate = (value, i, j, m, n) => {
return value.map((item, index_first) => {
return <Row className="simulate" justify="center">
{
item.map((ele, index_second) => {
return <Col span={parseInt(24 / value[0].length)}>
<Input defaultValue={ele} className="simulate-table" onChange={this.onSimulate.bind(this, i, j, m, n, index_first, index_second)} />
</Col>
})
}
</Row>
})
return data
}
analysisData(val) {
const data = val.map(item => {
return val[0].map((item_child, j) => {
return {
[item_child]: item[j],
}
})
})
var result = []
data.shift()
for (let i in data) {
var obj = {}
for (let j in data[i]) {
Object.assign(obj, data[i][j])
onSimulate = (a, b, c, d, e, f, g) => {
const data = this.state.text_model.filter((item, i) => {
if (a === i) {
return item["章节内容"].filter((ele, j) => {
if (b === j) {
return ele["小节内容"].filter((child, m) => {
if (c === m) {
return Object.keys(child).filter((key, index) => {
if (d === index) {
return child["表格"][e][f] = g.target.value
} else {
return child["表格"][e][f]
}
})
} else {
return child
}
})
} else {
return ele
}
})
} else {
return item
}
result.push(obj)
}
return result
})
this.setState({
text_model: data
})
}
onFinish = () => {
console.log(this.state.text_model)
api.post("/admin/rating/report_edit_save_delete", { rid: this.props.id, text_model: this.state.text_model })
.then(res => {
console.log(res)
})
}
onOutput = (a, b, c, d, e) => {
this.state.text_model.forEach((item, i) => {
const data = this.state.text_model.filter((item, i) => {
if (a === i) {
item["章节内容"].forEach((ele, j) => {
return item["章节内容"].filter((ele, j) => {
if (b === j) {
ele["小节内容"].forEach((child, m) => {
return ele["小节内容"].filter((child, m) => {
if (c === m) {
Object.keys(child).forEach((key, index) => {
return Object.keys(child).filter((key, index) => {
if (d === index) {
child[key] = e.target.value
return child[key] = e.target.value
} else {
return child[key]
}
})
} else {
return child
}
})
} else {
return ele
}
})
} else {
return item
}
})
this.setState({
text_model: data
})
}
render() {
return (
<React.Fragment>
<Button onClick={this.onFinish}>输出</Button>
{this.state.text_model.map((item, i) => {
return <React.Fragment><span className="paragraph_name">
{item["章节"]}
@ -86,8 +116,17 @@ class EditReport extends Component {
{
item_child["小节内容"].map((item_child_child, m) => {
return Object.keys(item_child_child).map((key, n) => {
return key === "表格" ? <React.Fragment><span className="paragraph_name" style={{ marginLeft: 40 }}>{key}:</span><Table bordered style={{ margin: "20px 0", width: "calc(100% - 80px)", marginLeft: "40px" }} dataSource={this.analysisData(item_child_child[key])} columns={this.analysisColumn(item_child_child[key])} pagination={false} /></React.Fragment>
: <React.Fragment><span className="paragraph_name" style={{ marginLeft: 40 }}>{key}:</span><Input.TextArea style={{ marginLeft: 60, width: "calc(100% - 80px)", }} defaultValue={item_child_child[key]} onChange={this.onOutput.bind(this, i, j, m, n)}></Input.TextArea></React.Fragment>
return key === "表格" ? <React.Fragment>
<span className="paragraph_name" style={{ marginLeft: 40 }}>{key}:</span>
{this.simulate(item_child_child[key], i, j, m, n)}
</React.Fragment>
: <React.Fragment>
<span className="paragraph_name" style={{ marginLeft: 40 }}>{key}:</span>
<Input.TextArea
style={{ marginLeft: 60, width: "calc(100% - 80px)", }}
defaultValue={item_child_child[key]}
onChange={this.onOutput.bind(this, i, j, m, n)} />
</React.Fragment>
})
})
} </React.Fragment>