Commit 4c35b702 by Zhang Xin

刷新图片获取最新图片

parent 81c73473
......@@ -33,7 +33,7 @@ let json = {
},
{
"id": 1,
"errorCode": null,
"errorCode": 12123,
"type": "OP",
"files": [],
"parentProblemName": "机械故障",
......
import fetch from 'isomorphic-fetch';
import actionTypes from '../actiontype/refreshImg'
const domain = ENV.domain;
let json = {
"meta": {
"code": "200",
"message": "成功",
"success": true
},
"data": [
{
"id": 17,
"filePath": "http://static.mjitech.com/static/sku/0/0/427/1471329704482.jpg"
},
{
"id": 18,
"filePath": "http://static.mjitech.com/static/sku/0/0/427/1471329704482.jpg"
},
{
"id": 19,
"filePath": "http://static.mjitech.com/static/sku/0/0/427/1471329704482.jpg"
}
]
}
const refreshImg = (data)=>{
return{
type:actionTypes.REFRESHIMG,
data
}
};
const getRefreshImg = (errorId,type)=>{
console.log(errorId,type)
return(dispatch)=>{
// fetch(domain + '/web/flush_image.action',{
// credentials : 'include',
// method : 'POST',
// mode : 'cors',
// body : {}
//
// }).then((response)=>response.json())
// .then(json=>{
// console.log(json);
// }).catch(e=>{console.error(e)})
if(json.meta.success && json.data){
let data = {
errorId,
type,
files : json.data
};
dispatch(refreshImg(data))
}
}
}
export {getRefreshImg}
const actionTypes = {
REFRESHIMG : 'REFRESHIMG'
}
export default actionTypes
\ No newline at end of file
......@@ -66,7 +66,7 @@ export default class TroubleItemComponent extends React.Component{
<div className={"plusImg controlBox "} onClick={()=>props.showQrcode(item.errorCode)}>
<img src={UTILPATH.localImg.plusIcon} alt=""/>
</div>
<div className={"refreshImg controlBox "}>
<div className={"refreshImg controlBox "} onClick={()=>props.getRefreshImg(item.id,item.type)}>
<img src={UTILPATH.localImg.refreshIcon} alt=""/>
</div>
</div>
......
......@@ -5,17 +5,16 @@ import { connect } from 'react-redux';
import {getStoreInfo} from "../../actions/getStore";
import {getTroubleList} from "../../actions/getTroubles";
import {intGetOtherProblem} from "../../actions/otherQuestion"
import {getRefreshImg} from "../../actions/refreshImg"
import PopupComponent from '../../components/CommonComponent/PopupComponent/PopupComponent'
import TroubleContainer from '../TroubleContainer/TroubleContainer'
import TextAreaContainer from '../TextAreaContainer/TextAreaContainer'
import ScanBarCodeContainer from '../ScanBarCodeContainer/ScanBarCodeContaienr'
import ReportDamagesListContainer from '../ReportDamagesListContainer/ReportDamagesListContainer'
import OtherQuestionContainer from '../OtherQuestionContainer/OtherQuestionContainer'
import HomeContainer from '../HomeContainer/HomeContainer'
import FinishAskContainer from '../FinishAskContainer/FinishAskContainer'
import ChooseTaskContainer from '../ChooseTaskContainer/ChooseTaskContainer'
import Qrcode from '../Qrcode/Qrcode'
require('./index.css')
......@@ -131,12 +130,14 @@ class PageContainer extends React.Component {
case showPage[1]:
pages = <TroubleContainer
troubleList={state.troubleList}
refreshImg = {state.refreshImg}
storeInfo={state.storeInfo}
userInfo={state.userInfo}
initTroubleList={()=>dispatch(getTroubleList())}
showTextArea={(text)=>this.showTextArea(text)}
showPopup={(info)=>this.showPopup(info)}
hidePopup={()=>this.hidePopup()}
getRefreshImg={(errorId,type)=>dispatch(getRefreshImg(errorId,type))}
/>;
break;
case showPage[2]:
......@@ -151,9 +152,6 @@ class PageContainer extends React.Component {
state = {state}
/>;
break;
case showPage[6]:
pages = <Qrcode />;
break;
case showPage[7]:
pages = <HomeContainer />;
break;
......
......@@ -32,31 +32,7 @@ export default class TroubleContainer extends React.Component{
this.getDefaultDom = this.getDefaultDom.bind(this);
this.getTextAreaDom = this.getTextAreaDom.bind(this);
this.getQrcodeDom = this.getQrcodeDom.bind(this);
}
dealTrouble(){
let {showPopup,hidePopup} = this.props;
let troubleList = this.state.troubleList;
let details = troubleList.details;
let arr = details.filter(d=>{
return ! d.isExistProblem || ! d.explanation
});
if(arr && arr.length > 0){
showPopup({
popupText:'请完成所有需要处理的故障的必填项',
popupButtons:[{text : '关闭',option:hidePopup}]
})
}else{
details.forEach((d)=>{
d.imagesFileId = d.files.map(f=>f.id).join(',');
});
this.setState({
showTrouble : false
})
}
this.updateImg = this.updateImg.bind(this);
}
......@@ -68,8 +44,8 @@ export default class TroubleContainer extends React.Component{
componentWillReceiveProps(nextProps){
let troubleList = nextProps.troubleList;
let nowTroubleList = this.state.troubleList;
let troubleErrorCodeList = Array.isArray(troubleList.details) ? troubleList.details.map(i=>i.errorCode) : []
let nowtroubleErrorCodeList = Array.isArray(nowTroubleList.details) ? nowTroubleList.details.map(i=>i.errorCode) : []
let troubleErrorCodeList = Array.isArray(troubleList.details) ? troubleList.details.map(i=>i.errorCode) : [];
let nowtroubleErrorCodeList = Array.isArray(nowTroubleList.details) ? nowTroubleList.details.map(i=>i.errorCode) : [];
//上一次和这一次不一样
let troubleErrorCodeListStr = troubleErrorCodeList.join(",");
......@@ -83,6 +59,25 @@ export default class TroubleContainer extends React.Component{
})
}
let refreshImg = nextProps.refreshImg;
let nowRefreshImg = this.state.refreshImg;
if(refreshImg && refreshImg.errorId && refreshImg.type && refreshImg.files){
this.updateImg(refreshImg);
}
}
updateImg(info){
let id = info.errorId;
let type = info.type;
let files = info.files;
let troubleList = this.state.troubleList;
let details = troubleList.details;
let indexInfo = details.find(d=>d.id === id && d.type === type);
if(indexInfo && indexInfo.id){
this.setItem(indexInfo.errorCode,"files",files);
}
}
showText(errcode){
......@@ -126,13 +121,12 @@ export default class TroubleContainer extends React.Component{
this.goBack()
})
}
saveText(text){
let errcode = this.state.currentErrorCode;
this.setItem(errcode,'explanation',text);
}
goBack(){
this.setState({
currentErrorCode : 0,
......@@ -142,13 +136,40 @@ export default class TroubleContainer extends React.Component{
})
}
dealTrouble(){
let {showPopup,hidePopup} = this.props;
let troubleList = this.state.troubleList;
let details = troubleList.details;
let arr = details.filter(d=>{
return !d.isExistProblem || ( d.isExistProblem === 1 && ! d.explanation)
});
if(arr && arr.length > 0){
showPopup({
popupText:'请完成所有需要处理的故障的必填项',
popupButtons:[{text : '关闭',option:hidePopup}]
})
}else{
details.forEach((d)=>{
d.imagesFileId = d.files.map(f=>f.id).join(',');
});
console.log(details);
// this.setState({
// showTrouble : false
// })
}
}
getDefaultDom(){
let {userInfo,storeInfo} = this.props;
let {userInfo,storeInfo,getRefreshImg} = this.props;
let troubleList = this.state.troubleList;
let showTrouble = Array.isArray(troubleList.details) && troubleList.details.length > 0;
let details = Array.isArray(troubleList.details) ? troubleList.details : [];
let dom = details.map((i,k)=>{
return <TroubleItem key={k} item={i} num={k+1} setItem={this.setItem} showText={this.showText} showQrcode={this.showQrcode}/>;
return <TroubleItem key={k} item={i} num={k+1} setItem={this.setItem}
showText={this.showText} showQrcode={this.showQrcode}
getRefreshImg={getRefreshImg}
/>;
});
let swiperOptions = {
width : 1396,
......@@ -192,8 +213,7 @@ export default class TroubleContainer extends React.Component{
return <TextArea
text={this.state.tmpText}
goBack={this.goBack}
saveText={this.saveText}
></TextArea>
saveText={this.saveText}/>
}
getQrcodeDom(){
......
......@@ -4,13 +4,14 @@ import storeInfo from './store'
import scanBarCodeContainer from './scanBarCodeContainer'
import otherQuestion from './otherQuestion'
import userInfo from './user'
import refreshImg from './refreshImg'
export default combineReducers({
troubleList,
storeInfo,
scanBarCodeContainer,
otherQuestion,
userInfo
userInfo,
refreshImg
})
import actionTypes from '../actiontype/refreshImg';
const refreshImg = (content,data)=>{
return Object.assign({},content,data);
}
export default function(state={}, action) {
switch (action.type) {
case actionTypes.REFRESHIMG:
return refreshImg(state,action.data)
default:
return state;
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import addIcon from '../image/addIcon.png';
import refreshIcon from '../image/refresh.png';
import plusIcon from '../image/plusIcon.png';
import clockIcon from '../image/clock.png';
import breakImg from '../image/breakImg.png';
const localHost = 'http://localhost:7788';
const devHost = 'http://test.mjitech.com';
......@@ -77,6 +78,6 @@ const handleImgLoad = (ref)=>{
return style;
}
const localImg = {headlogo,defaultImg,addIcon,refreshIcon,plusIcon,clockIcon}
const localImg = {headlogo,defaultImg,addIcon,refreshIcon,plusIcon,clockIcon,breakImg}
module.exports = {localHost,devHost,masterHost,getPic,handleImgError,handleImgLoad,localImg};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment