|
@@ -3,9 +3,11 @@ import React,{ useState,useEffect,useRef } from 'react';
|
|
|
import {getCheckItem,getCheckItemTypeList,listAll,delCheckItem,addCheckItem,editCheckItem,
|
|
|
bindCheckItemAndCheckPoint,addCheckItemCheckResult,getCheckItemCheckResultSelecterList,} from "@/api/checkPointManage.js";
|
|
|
import {addCheckItemAttr} from "@/api/checkItem.js";
|
|
|
-import { Button,Form,Input,Select,Tag,Tooltip,message} from 'antd';
|
|
|
+import {uploadFile} from "@/api/common.js";
|
|
|
+import { Button,Form,Input,Select,Tag,Tooltip,message,Upload, Icon} from 'antd';
|
|
|
import EditableFormTable from './table';
|
|
|
import ModalWrap from '@/components/Modal/modal.js';
|
|
|
+import { getToken } from "@/utils/auth";
|
|
|
// import { TAGSVIEW_EMPTY_TAGLIST } from '../../../store/action-types';
|
|
|
|
|
|
const { Option } = Select;
|
|
@@ -22,6 +24,7 @@ class TableForm extends React.Component {
|
|
|
this.state = {
|
|
|
depTypeList:[],
|
|
|
checkPointList:[],
|
|
|
+ fileList:[],
|
|
|
checkTypeList:[],
|
|
|
checkResultList:[],//查核结果配置
|
|
|
addCheckItemResultSelect:[],
|
|
@@ -38,13 +41,15 @@ class TableForm extends React.Component {
|
|
|
return new Promise((resolve,reject)=>{
|
|
|
this.props.form.validateFields((err,values) => {
|
|
|
if (!err) {
|
|
|
+ const imgUrls = this.state.fileList.map(item=>item.url);
|
|
|
let data = {
|
|
|
...this.props.content,
|
|
|
...values,
|
|
|
// checkModelList
|
|
|
- itemAttrs:this.state.checkResultList
|
|
|
+ itemAttrs:this.state.checkResultList,
|
|
|
+ rightAnswerImage:imgUrls.join(',')
|
|
|
}
|
|
|
- console.log({'handleCommit':data});
|
|
|
+ // console.log({data,values,imgUrls});
|
|
|
resolve(data);
|
|
|
}
|
|
|
});
|
|
@@ -53,7 +58,6 @@ class TableForm extends React.Component {
|
|
|
};
|
|
|
|
|
|
handleSelectChange=(value)=>{
|
|
|
- // console.log(value);
|
|
|
const {checkItemId} = this.props.content;
|
|
|
this.setState({
|
|
|
BindStatus:'validating'
|
|
@@ -66,10 +70,7 @@ class TableForm extends React.Component {
|
|
|
}
|
|
|
//当删除查核结果配置
|
|
|
onTagClose=(e)=>{
|
|
|
- // console.log('onTagClose',e);
|
|
|
- // console.log(this.state.checkResultList);
|
|
|
const checkResultListByFilter = this.state.checkResultList.filter(item=>item.attr != e);
|
|
|
- // console.log({checkResultListByFilter});
|
|
|
this.setState({
|
|
|
checkResultList:checkResultListByFilter
|
|
|
})
|
|
@@ -77,6 +78,10 @@ class TableForm extends React.Component {
|
|
|
//更新查核结果配置
|
|
|
updateCheckResultList=()=>{
|
|
|
const {checkResultList,checkResultName,checkResultCount} = this.state;
|
|
|
+ if(checkResultCount<0||checkResultCount>1){
|
|
|
+ message.warning('抱歉,配置项占比只能是0~1之间!');
|
|
|
+ return;
|
|
|
+ }
|
|
|
if(checkResultName&&checkResultCount){
|
|
|
this.setState({
|
|
|
checkResultList:[...checkResultList,{attr:checkResultName,value:checkResultCount}],
|
|
@@ -109,8 +114,24 @@ class TableForm extends React.Component {
|
|
|
})
|
|
|
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ if(content.rightAnswerImage&&content.rightAnswerImage.split(',').length>0){
|
|
|
+ const imgList = content.rightAnswerImage.split(',');
|
|
|
+ const hasUploadFiles = imgList.map((item,index)=>{
|
|
|
+ return {
|
|
|
+ uid: `-${index}`,
|
|
|
+ name: 'image.png',
|
|
|
+ status: 'done',
|
|
|
+ url: item
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setState({
|
|
|
+ fileList:hasUploadFiles
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
onAddCheckItemResultSelectChange=(e)=>{
|
|
|
// console.log({e});
|
|
|
this.setState({
|
|
@@ -131,7 +152,7 @@ class TableForm extends React.Component {
|
|
|
}
|
|
|
|
|
|
componentDidMount(){
|
|
|
- console.log('Form_componentDidMount');
|
|
|
+ // console.log(process.env)
|
|
|
listAll().then(res=>{
|
|
|
// console.log({res});
|
|
|
const temp = res.data.data;
|
|
@@ -156,11 +177,69 @@ class TableForm extends React.Component {
|
|
|
});
|
|
|
|
|
|
this.initData();
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
+ //图片变化回调
|
|
|
+ handleUploadChange = ({file,fileList}) => {
|
|
|
+
|
|
|
+ console.log({file,fileList});
|
|
|
+ if (file.status == 'removed') {
|
|
|
+ this.setState({
|
|
|
+ fileList
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
|
|
|
-
|
|
|
+ // 图片上传
|
|
|
+ imgUpload = (options) => {
|
|
|
+ const { onSuccess, onError, file, onProgress } = options;
|
|
|
+
|
|
|
+ // start:进度条相关
|
|
|
+ // 伪装成 handleChange里面的图片上传状态
|
|
|
+ const key = new Date().getTime();
|
|
|
+ const imgItem = {
|
|
|
+ uid: `-${key}`, // 注意,这个uid一定不能少,否则上传失败
|
|
|
+ name: 'image.png',
|
|
|
+ status: 'uploading',
|
|
|
+ url: '',
|
|
|
+ percent: 99, // 注意不要写100。100表示上传完成
|
|
|
+ };
|
|
|
+
|
|
|
+ this.setState(prevState=>{
|
|
|
+ return {
|
|
|
+ fileList:prevState.fileList.concat([imgItem]),
|
|
|
+ }
|
|
|
+ }); // 更新 imgList
|
|
|
+ // end:进度条相关
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('file',file);
|
|
|
+
|
|
|
+ uploadFile(formData)
|
|
|
+ .then((res) => {
|
|
|
+ console.log('imgUpload:',res);
|
|
|
+ const imgItem = {
|
|
|
+ status: 'done',
|
|
|
+ url: res.data.data, // url 是展示在页面上的绝对链
|
|
|
+ };
|
|
|
+
|
|
|
+ const tempFileList = this.state.fileList;
|
|
|
+ const index = tempFileList.findIndex(item=>item.uid == -key);
|
|
|
+ tempFileList[index] = {
|
|
|
+ ...tempFileList[index],
|
|
|
+ ...imgItem
|
|
|
+ }
|
|
|
+ console.log({tempFileList});
|
|
|
+ this.setState({
|
|
|
+ fileList:tempFileList,
|
|
|
+ }); // 更新 imgList
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ console.log('图片上传失败:' + JSON.stringify(e || ''));
|
|
|
+ message.error('图片上传失败,请重试');
|
|
|
+ });
|
|
|
+
|
|
|
+ };
|
|
|
|
|
|
shouldComponentUpdate(nextProps,nextState){
|
|
|
// console.log({nextProps,nextState})
|
|
@@ -180,8 +259,8 @@ class TableForm extends React.Component {
|
|
|
|
|
|
const { getFieldDecorator } = this.props.form;
|
|
|
const {content,edit} = this.props;
|
|
|
- const {depTypeList,BindStatus,checkPointList,checkTypeList,ifClear,checkResultList,checkResultName,checkResultCount,addCheckItemResultSelect} = this.state;
|
|
|
- const {checkItemName,rightAnswerText,relatedRules,checkModelList,score,itemAttr} = content;
|
|
|
+ const {depTypeList,BindStatus,checkPointList,checkTypeList,ifClear,checkResultList,checkResultName,checkResultCount,addCheckItemResultSelect,fileList} = this.state;
|
|
|
+ const {checkItemName,rightAnswerText,relatedRules,checkModelList,score,itemAttr,rightAnswerImage} = content;
|
|
|
// const bindGroupDefault = groupManaList.length>0?groupManaList[0].name:'bindGroupDefault';
|
|
|
// console.log({content,edit});
|
|
|
const formItemLayout = {
|
|
@@ -194,16 +273,24 @@ class TableForm extends React.Component {
|
|
|
sm: { span: 12 },
|
|
|
},
|
|
|
};
|
|
|
- const config =(key,rules)=>{
|
|
|
+ const config =(key,rules,option)=>{
|
|
|
// console.log({key});
|
|
|
return {
|
|
|
initialValue:edit?key:'',
|
|
|
rules: [
|
|
|
...rules
|
|
|
],
|
|
|
+ ...option
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ const uploadButton = (
|
|
|
+ <div>
|
|
|
+ <Icon type="plus" />
|
|
|
+ <div className="ant-upload-text">上传图片</div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+
|
|
|
return (
|
|
|
<Form {...formItemLayout} >
|
|
|
<Form.Item label="查核项">
|
|
@@ -231,10 +318,19 @@ class TableForm extends React.Component {
|
|
|
{
|
|
|
edit&&<Form.Item label="查核项分数" style={{display:edit?'block':'none'}}>
|
|
|
{
|
|
|
- getFieldDecorator('score',config(score,[{required:false,message: '请输入查核分数!',}]))(<Input />)
|
|
|
+ getFieldDecorator('score',config(score,[{required:false,message: '请输入查核分数!'}],{
|
|
|
+ validator:(rule, value, callback)=>{
|
|
|
+ if(value<=0){
|
|
|
+ callback('分数必需大于0!')
|
|
|
+ }
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ }))(<Input placeholder="" />)
|
|
|
}
|
|
|
</Form.Item>
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
<Form.Item label="查核项查核结果配置" style={{display:edit?'block':'none'}}>
|
|
|
{
|
|
@@ -259,8 +355,8 @@ class TableForm extends React.Component {
|
|
|
}
|
|
|
</Select>
|
|
|
</Tooltip>
|
|
|
- <Tooltip title="请定义查核结果对应的分值占比,如:50">
|
|
|
- <Input style={{ width: '30%' }} onChange={(e)=>{this.setState({checkResultCount:e.target.value})}} value={checkResultCount} placeholder="如:50" />
|
|
|
+ <Tooltip title="请定义查核结果对应的分值占比,如:0.5表示占比50%">
|
|
|
+ <Input style={{ width: '35%' }} onChange={(e)=>{this.setState({checkResultCount:e.target.value})}} value={checkResultCount} placeholder="输入0~1之间,如:0.5" />
|
|
|
</Tooltip>
|
|
|
<Button type="primary" onClick={this.updateCheckResultList}>添加</Button>
|
|
|
</InputGroup>
|
|
@@ -273,7 +369,7 @@ class TableForm extends React.Component {
|
|
|
const tagName = item.attr;
|
|
|
return (
|
|
|
<Tag color="#4E78FF" closable key={index} onClose={this.onTagClose.bind(this,tagName)}>
|
|
|
- {`${item.attr}|${item.value}%`}
|
|
|
+ {`${item.attr}|${Number(item.value*100).toFixed(2)}%`}
|
|
|
</Tag>
|
|
|
)
|
|
|
})
|
|
@@ -291,6 +387,26 @@ class TableForm extends React.Component {
|
|
|
getFieldDecorator('rightAnswerText',config(rightAnswerText,[{required: false,message: '!',}]))(<Input.TextArea autoSize={{minRows:5}} />)
|
|
|
}
|
|
|
</Form.Item>
|
|
|
+ <Form.Item label="应知应会图片">
|
|
|
+ <Upload
|
|
|
+ // action={()=>{
|
|
|
+ // const {REACT_APP_BASE_API} = process.env;
|
|
|
+ // return Promise.resolve(`${REACT_APP_BASE_API}/upload/file`);
|
|
|
+ // }}
|
|
|
+ // headers={{
|
|
|
+ // token:getToken()
|
|
|
+ // }}
|
|
|
+ customRequest={this.imgUpload}
|
|
|
+ withCredentials={true}
|
|
|
+ listType="picture-card"
|
|
|
+ fileList={fileList}
|
|
|
+ onRemove={()=>{console.log('onRemove')}}
|
|
|
+ onChange={this.handleUploadChange}
|
|
|
+ >
|
|
|
+ {fileList.length >= 8 ? null : uploadButton}
|
|
|
+ </Upload>
|
|
|
+
|
|
|
+ </Form.Item>
|
|
|
<Form.Item label="相关条文">
|
|
|
{
|
|
|
getFieldDecorator('relatedRules',config(relatedRules,[{required: false,message: '!',}]))(<Input.TextArea autoSize={{minRows:5}} />)
|
|
@@ -493,7 +609,7 @@ const CheckItem = () => {
|
|
|
"checkModeList":formData.checkModeList, // 查核方式 必填(暂时写死,需要考虑(下拉框选择))
|
|
|
"name":formData.checkItemName,// 查核项目名称 必填
|
|
|
"relatedRules":formData.relatedRules, // 相关条文
|
|
|
- "rightAnswerImage":'', // 正确答案图片url 上传图片接口待定
|
|
|
+ "rightAnswerImage":formData.rightAnswerImage, // 正确答案图片url 上传图片接口待定
|
|
|
"rightAnswerText": formData.rightAnswerText,// 正确答案文字
|
|
|
// "score":formData.score,//查核项分数
|
|
|
}
|
|
@@ -505,31 +621,26 @@ const CheckItem = () => {
|
|
|
}
|
|
|
if(ifEdit){
|
|
|
const currentEditItem = item;
|
|
|
-
|
|
|
- // const checkResultListByFilter = formData.itemAttrs.filter(item=>{
|
|
|
- // let needNoCommitList = JSON.parse(currentEditItem.itemAttrs);
|
|
|
- // let temp = needNoCommitList.filter(v=>v.attr == item.attr);
|
|
|
- // return temp.length==0;
|
|
|
- // });
|
|
|
-
|
|
|
+ console.log({currentEditItem});
|
|
|
const paramForCheckItemresult = {
|
|
|
"checkItemId":item.checkItemId, // 查核项id
|
|
|
"id":item.attrId,
|
|
|
- "score":parseInt(formData.score), // 分数
|
|
|
+ "score":parseFloat(formData.score), // 分数
|
|
|
"itemAttrs":formData.itemAttrs,
|
|
|
}
|
|
|
const param =/^[a-zA-Z]+$/.test(formData.checkModeList)?{
|
|
|
+ //checkModeList为code的情况下
|
|
|
"id":item.checkItemId,
|
|
|
"checkModeList": formData.checkModeList, // 查核方式
|
|
|
"name":formData.checkItemName, // 名称必填
|
|
|
"relatedRules":formData.relatedRules, // 相关条文
|
|
|
- "rightAnswerImage":item.rightAnswerImage,// 应知应会图片url
|
|
|
+ "rightAnswerImage":formData.rightAnswerImage,// 应知应会图片url
|
|
|
"rightAnswerText":formData.rightAnswerText, // 应知应会文字
|
|
|
}:{
|
|
|
"id":item.checkItemId,
|
|
|
"name":formData.checkItemName, // 名称必填
|
|
|
"relatedRules":formData.relatedRules, // 相关条文
|
|
|
- "rightAnswerImage":item.rightAnswerImage,// 应知应会图片url
|
|
|
+ "rightAnswerImage":formData.rightAnswerImage,// 应知应会图片url
|
|
|
"rightAnswerText":formData.rightAnswerText, // 应知应会文字
|
|
|
}
|
|
|
|