/** * Created by FANGlh on 2018/11/9 17:39. */ import React,{Component} from 'react'; import './ResApply.css'; import nextArrowimg from '../../../style/imgs/next_arrow.png'; import { Select,Upload,Modal,Icon,Button } from 'antd'; import UserItem from './UserItem'; import {Toast,Picker,List} from 'antd-mobile'; import {fetchPost,fetchGet,fetchGetNoSession} from '../../../utils/fetchRequest'; import {API,_baseURL} from '../../../configs/api.config'; import {connect} from 'react-redux'; import {getIntValue, getStrValue, isObjEmpty} from "../../../utils/common"; import TargetSelect from '../../../components/TargetSelect'; // import {getOrganization} from "../../../utils/api.request"; // import {ORGANIZATION_TEACHER} from "../../../utils/api.constants"; import UploadEnclosure from '../../../components/UploadEnclosure'; const Option = Select.Option; class ResApply extends Component{ componentWillMount() { document.title = '用品申请' } constructor(){ super(); this.state = { votePerson:[], targetData: [], resUser:null, //物品用途 receivingSays:null, //领取说明 Receiver:null, //接收人 selectContentArray: [ { artName:null, artCount:null } ], previewVisible: false, previewImage: '', fileList: [], //附件, receiverPerson:[{ label: '吴彦祖', value: '1' },{ label: '陈冠希', value: '2' },{ label: '古天乐', value: '3' }] } } render(){ const targetProps = { targetData: this.state.targetData, targetValues: this.state.targetList, title: '接收人', targetCount: this.state.targetCount, onTargetChange: this.onTargetChange.bind(this), onTargetFocus: this.onTargetFocus.bind(this), multiple: false, } const defaultTargetProps = { targetData: [], targetValues: this.state.targetList, title: '接收人', targetCount: this.state.targetCount, onTargetChange: this.onTargetChange.bind(this), onTargetFocus: this.onTargetFocus.bind(this), multiple: false, } //添加附件按钮 const uploadButton = (
Upload
); return(
物品用途
{this.state.selectContentArray.map((itemata,index) => )}
+ 添加物品明细
{this.state.targetData.length > 0 ? : }
{/*
*/}
) } beforeUpload = (file, fileList) => { } handleChange = fileList => { if (fileList) { fileList.forEach((value, index) => { value.url = value.response ? (_baseURL + value.response.data) : value.url value.picUrl = value.response ? value.response.data : value.picUrl }) this.setState({fileList}) } } getOrganization = () => { Toast.loading('', 0) fetchGet(API.getAllTeacher, { schoolId: this.props.userInfo.user.schoolId, }).then(response => { Toast.hide() const {targetData} = this.state targetData.length = 0 if (response && response.data) { // const schoolArray = response.data.schools const teacherArray = response.data if (!isObjEmpty(teacherArray)) { const teacherData = [] teacherArray.forEach((teacherObj, index) => { if (teacherObj) { teacherData.push({ title: getStrValue(teacherObj, 'teacherName'), userId: getIntValue(teacherObj, 'teacherId'), userPhone: getStrValue(teacherObj, 'userPhone'), value: getStrValue(teacherObj, 'teacherName') + `-0-${index}`, key: `0-${index}`, }) } }) targetData.push({ title: `全体老师`, value: `0`, key: `0`, selectable:false, children: teacherData, }) } } console.log('targetData', targetData) this.setState({ targetData, }) }).catch(error => { Toast.hide() if (typeof error === 'string') { Toast.fail(error, 2) } else { Toast.fail('请求异常', 2) } }) } componentWillUnmount() { Toast.hide() clearTimeout(this.backTask) } onTargetFocus = (e) => { if (isObjEmpty(this.state.targetData)) { this.getOrganization() } } onTargetChange = (value, label, checkNodes, count) => { this.checkNodes = checkNodes this.setState({ targetList: value, targetCount: count }); } //提交 doSaveClick =() =>{ if(this.isRequesting == true){ return } console.log('state',this.state) if(this.state.resUser == null || this.state.resUser.trim().length == 0){ Toast.show('请输入物品用途',1) return } for(let i=0;i { this.state.votePerson.push(node.userId) }) }else { Toast.fail('请选择接收人') return } var approveFiles = [] for(let i=0;i{ this.isRequesting = false console.log('response',response) if(response.success){ this.isRequesting = true Toast.show(response.data,1) this.backTask = setTimeout(() => { this.props.history.goBack() }, 1000) } }) .catch((error) =>{ this.isRequesting = false console.log('error',error) }) } removeSItem = (index)=>{ if(this.state.selectContentArray.length == 1){ return } let selectContentArray = this.state.selectContentArray selectContentArray.splice(index,1) this.setState({ selectContentArray }) } handelRItem = (itemObject,index)=>{ console.log('itemObject',itemObject) console.log('index',index) let selectContentArray = this.state.selectContentArray selectContentArray[index] = itemObject this.setState({ selectContentArray:selectContentArray }) } addUserItem = (event)=>{ let selectContentArray = [...this.state.selectContentArray,1]; this.setState({ selectContentArray }) } handelValueCom = (event)=>{ //获取用户名的值 let resUser = this.refs.resUser.value; let receivingSays = this.refs.receivingSays.value; //获得内容的值 this.setState({ resUser:resUser, receivingSays:receivingSays }) } handleSelectChange =(value) =>{ console.log('value',value) this.setState({ Receiver:value }) } handlePreview = (file) => { this.setState({ previewImage: file.url || file.thumbUrl, previewVisible: true, }); } handleCancel = () => this.setState({ previewVisible: false }) componentDidMount() { // getOrganization(ORGANIZATION_TEACHER, this.props.userInfo.userId, false) // .then(organization => { // this.setState({ // targetData: organization.teachers, // }) // }).catch(error => { // // }) this.getOrganization() } } let mapStateToProps = (state) => ({ userInfo: {...state.redUserInfo} }) let mapDispatchToProps = (dispatch) => ({}) export default connect(mapStateToProps, mapDispatchToProps)(ResApply)