ResApply.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /**
  2. * Created by FANGlh on 2018/11/9 17:39.
  3. */
  4. import React,{Component} from 'react';
  5. import './ResApply.css';
  6. import nextArrowimg from '../../../style/imgs/next_arrow.png';
  7. import { Select,Upload,Modal,Icon,Button } from 'antd';
  8. import UserItem from './UserItem';
  9. import {Toast,Picker,List} from 'antd-mobile';
  10. import {fetchPost,fetchGet,fetchGetNoSession} from '../../../utils/fetchRequest';
  11. import {API,_baseURL} from '../../../configs/api.config';
  12. import {connect} from 'react-redux';
  13. import {getIntValue, getStrValue, isObjEmpty} from "../../../utils/common";
  14. import TargetSelect from '../../../components/TargetSelect';
  15. // import {getOrganization} from "../../../utils/api.request";
  16. // import {ORGANIZATION_TEACHER} from "../../../utils/api.constants";
  17. import UploadEnclosure from '../../../components/UploadEnclosure';
  18. const Option = Select.Option;
  19. class ResApply extends Component{
  20. componentWillMount() {
  21. document.title = '用品申请'
  22. }
  23. constructor(){
  24. super();
  25. this.state = {
  26. votePerson:[],
  27. targetData: [],
  28. resUser:null, //物品用途
  29. receivingSays:null, //领取说明
  30. Receiver:null, //接收人
  31. selectContentArray: [
  32. {
  33. artName:null,
  34. artCount:null
  35. }
  36. ],
  37. previewVisible: false,
  38. previewImage: '',
  39. fileList: [], //附件,
  40. receiverPerson:[{
  41. label: '吴彦祖',
  42. value: '1'
  43. },{
  44. label: '陈冠希',
  45. value: '2'
  46. },{
  47. label: '古天乐',
  48. value: '3'
  49. }]
  50. }
  51. }
  52. render(){
  53. const targetProps = {
  54. targetData: this.state.targetData,
  55. targetValues: this.state.targetList,
  56. title: '接收人',
  57. targetCount: this.state.targetCount,
  58. onTargetChange: this.onTargetChange.bind(this),
  59. onTargetFocus: this.onTargetFocus.bind(this),
  60. multiple: false,
  61. }
  62. const defaultTargetProps = {
  63. targetData: [],
  64. targetValues: this.state.targetList,
  65. title: '接收人',
  66. targetCount: this.state.targetCount,
  67. onTargetChange: this.onTargetChange.bind(this),
  68. onTargetFocus: this.onTargetFocus.bind(this),
  69. multiple: false,
  70. }
  71. //添加附件按钮
  72. const uploadButton = (
  73. <div>
  74. <Icon type="plus" />
  75. <div className="ant-upload-text">Upload</div>
  76. </div>
  77. );
  78. return(
  79. <div className='common-column-layout' onChange={this.handelValueCom} style={{fontFamily:"PingFangSC-Regular",letterSpacing:2.5}}>
  80. <div className="comhline_sty"></div>
  81. <div className="item_sty">
  82. <div className="left_title">物品用途</div>
  83. <input ref='resUser' className="text-right right_input" type="text" placeholder="请输入" maxLength={20} autoFocus="autoFocus" value={this.state.resUser}/>
  84. </div>
  85. <div >
  86. {this.state.selectContentArray.map((itemata,index) => <UserItem index ={index} itemata = {itemata} handelRItem={this.handelRItem} removeSItem={this.removeSItem}></UserItem>)}
  87. <div onClick={this.addUserItem} className="text-center" style={{color:"#0CE11D",fontSize:12,margin:10}}>+ <span style={{color:"#666666",borderBottom:"1px #000 solid"}}>添加物品明细</span></div>
  88. </div>
  89. <textarea ref='receivingSays' className="form-control textarea_sty" rows="5" placeholder="领取说明" value={this.state.receivingSays} maxLength={100}></textarea>
  90. <div className="comhline_sty1"></div>
  91. {this.state.targetData.length > 0 ? <TargetSelect {...targetProps}/>
  92. : <TargetSelect {...defaultTargetProps}/>}
  93. <div className="comhline_sty"></div>
  94. <UploadEnclosure
  95. action={API.UPLOAD_FILE}
  96. fileList={this.state.fileList}
  97. count={9}
  98. multiple={true}
  99. beforeUpload={this.beforeUpload.bind(this)}
  100. handleChange={this.handleChange.bind(this)}
  101. />
  102. <Button className='commonButton' type='primary' style={{margin: '35px',borderRadius:30}}
  103. onClick={this.doSaveClick}>提交</Button>
  104. {/*<center><button type="button" className="btn btn-primary comBtn_sty" onClick={this.doSaveClick}>提交</button></center>*/}
  105. </div>
  106. )
  107. }
  108. beforeUpload = (file, fileList) => {
  109. }
  110. handleChange = fileList => {
  111. if (fileList) {
  112. fileList.forEach((value, index) => {
  113. value.url = value.response ? (_baseURL + value.response.data) : value.url
  114. value.picUrl = value.response ? value.response.data : value.picUrl
  115. })
  116. this.setState({fileList})
  117. }
  118. }
  119. getOrganization = () => {
  120. Toast.loading('', 0)
  121. fetchGet(API.getAllTeacher, {
  122. schoolId: this.props.userInfo.user.schoolId,
  123. }).then(response => {
  124. Toast.hide()
  125. const {targetData} = this.state
  126. targetData.length = 0
  127. if (response && response.data) {
  128. // const schoolArray = response.data.schools
  129. const teacherArray = response.data
  130. if (!isObjEmpty(teacherArray)) {
  131. const teacherData = []
  132. teacherArray.forEach((teacherObj, index) => {
  133. if (teacherObj) {
  134. teacherData.push({
  135. title: getStrValue(teacherObj, 'teacherName'),
  136. userId: getIntValue(teacherObj, 'teacherId'),
  137. userPhone: getStrValue(teacherObj, 'userPhone'),
  138. value: getStrValue(teacherObj, 'teacherName') + `-0-${index}`,
  139. key: `0-${index}`,
  140. })
  141. }
  142. })
  143. targetData.push({
  144. title: `全体老师`,
  145. value: `0`,
  146. key: `0`,
  147. selectable:false,
  148. children: teacherData,
  149. })
  150. }
  151. }
  152. console.log('targetData', targetData)
  153. this.setState({
  154. targetData,
  155. })
  156. }).catch(error => {
  157. Toast.hide()
  158. if (typeof error === 'string') {
  159. Toast.fail(error, 2)
  160. } else {
  161. Toast.fail('请求异常', 2)
  162. }
  163. })
  164. }
  165. componentWillUnmount() {
  166. Toast.hide()
  167. clearTimeout(this.backTask)
  168. }
  169. onTargetFocus = (e) => {
  170. if (isObjEmpty(this.state.targetData)) {
  171. this.getOrganization()
  172. }
  173. }
  174. onTargetChange = (value, label, checkNodes, count) => {
  175. this.checkNodes = checkNodes
  176. this.setState({
  177. targetList: value,
  178. targetCount: count
  179. });
  180. }
  181. //提交
  182. doSaveClick =() =>{
  183. if(this.isRequesting == true){
  184. return
  185. }
  186. console.log('state',this.state)
  187. if(this.state.resUser == null || this.state.resUser.trim().length == 0){
  188. Toast.show('请输入物品用途',1)
  189. return
  190. }
  191. for(let i=0;i<this.state.selectContentArray.length;i++){
  192. if (this.state.selectContentArray[i].artName == null || this.state.selectContentArray[i].artName.trim().length == 0
  193. || this.state.selectContentArray[i].artCount ==null || this.state.selectContentArray[i].artCount.trim().length == 0){
  194. Toast.show('物品明细存在未输入项')
  195. return
  196. }
  197. }
  198. // if(isObjEmpty(this.state.selectContentArray)){
  199. // Toast.show('物品明细存在未输入项')
  200. // return
  201. // }
  202. if(this.state.receivingSays == null || this.state.receivingSays.trim().length == 0){
  203. Toast.show('请输入领取说明',1)
  204. return
  205. }
  206. if (!isObjEmpty(this.checkNodes)) {
  207. this.checkNodes.forEach((node, index) => {
  208. this.state.votePerson.push(node.userId)
  209. })
  210. }else {
  211. Toast.fail('请选择接收人')
  212. return
  213. }
  214. var approveFiles = []
  215. for(let i=0;i<this.state.fileList.length;i++){
  216. if(this.state.fileList[i].response && this.state.fileList[i].response.success){
  217. approveFiles.push(this.state.fileList[i].response.data)
  218. if(i==this.state.fileList.length-1){
  219. this.setState({
  220. approveFiles:approveFiles
  221. })
  222. console.log('approveFiles',approveFiles)
  223. }
  224. }
  225. }
  226. var params = {
  227. approveTitle: this.state.resUser,
  228. approveDetails:this.state.receivingSays,
  229. approveType: 2,
  230. appType:1,
  231. proposer: this.props.userInfo.user.userFunId,
  232. approveStatus:1,
  233. approver: this.state.votePerson[0],
  234. approveFiles:JSON.stringify(approveFiles),
  235. oaArticlesDOS:this.state.selectContentArray
  236. }
  237. console.log('param',{
  238. oaString:params
  239. })
  240. this.isRequesting = true
  241. fetchPost(API.oaCreate,{
  242. oaString:JSON.stringify(params)
  243. },{})
  244. .then((response)=>{
  245. this.isRequesting = false
  246. console.log('response',response)
  247. if(response.success){
  248. this.isRequesting = true
  249. Toast.show(response.data,1)
  250. this.backTask = setTimeout(() => {
  251. this.props.history.goBack()
  252. }, 1000)
  253. }
  254. })
  255. .catch((error) =>{
  256. this.isRequesting = false
  257. console.log('error',error)
  258. })
  259. }
  260. removeSItem = (index)=>{
  261. if(this.state.selectContentArray.length == 1){
  262. return
  263. }
  264. let selectContentArray = this.state.selectContentArray
  265. selectContentArray.splice(index,1)
  266. this.setState({
  267. selectContentArray
  268. })
  269. }
  270. handelRItem = (itemObject,index)=>{
  271. console.log('itemObject',itemObject)
  272. console.log('index',index)
  273. let selectContentArray = this.state.selectContentArray
  274. selectContentArray[index] = itemObject
  275. this.setState({
  276. selectContentArray:selectContentArray
  277. })
  278. }
  279. addUserItem = (event)=>{
  280. let selectContentArray = [...this.state.selectContentArray,1];
  281. this.setState({
  282. selectContentArray
  283. })
  284. }
  285. handelValueCom = (event)=>{
  286. //获取用户名的值
  287. let resUser = this.refs.resUser.value;
  288. let receivingSays = this.refs.receivingSays.value;
  289. //获得内容的值
  290. this.setState({
  291. resUser:resUser,
  292. receivingSays:receivingSays
  293. })
  294. }
  295. handleSelectChange =(value) =>{
  296. console.log('value',value)
  297. this.setState({
  298. Receiver:value
  299. })
  300. }
  301. handlePreview = (file) => {
  302. this.setState({
  303. previewImage: file.url || file.thumbUrl,
  304. previewVisible: true,
  305. });
  306. }
  307. handleCancel = () => this.setState({ previewVisible: false })
  308. componentDidMount() {
  309. // getOrganization(ORGANIZATION_TEACHER, this.props.userInfo.userId, false)
  310. // .then(organization => {
  311. // this.setState({
  312. // targetData: organization.teachers,
  313. // })
  314. // }).catch(error => {
  315. //
  316. // })
  317. this.getOrganization()
  318. }
  319. }
  320. let mapStateToProps = (state) => ({
  321. userInfo: {...state.redUserInfo}
  322. })
  323. let mapDispatchToProps = (dispatch) => ({})
  324. export default connect(mapStateToProps, mapDispatchToProps)(ResApply)