tech.jsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import React from 'react';
  2. import { Input, Button, Form, Select, Icon, Spin, InputNumber, Tag, message, Cascader } from 'antd';
  3. import './tech.less';
  4. import ajax from 'jquery/src/ajax/xhr.js';
  5. import $ from 'jquery/src/ajax';
  6. import { techFieldList } from '../../DicTechFieldList';
  7. const TechFrom = Form.create()(React.createClass({
  8. getInitialState() {
  9. return {
  10. loading: false,
  11. techzoneArr: [],
  12. havetechzone: [],
  13. skillArr: [],
  14. haveskill: []
  15. };
  16. },
  17. getData() {
  18. this.props.spinState(true);
  19. $.ajax({
  20. method: "get",
  21. dataType: "json",
  22. url: globalConfig.context + "/api/user/job",
  23. success: function (data) {
  24. if (data.data) {
  25. this.setState({
  26. id: data.data.id,
  27. techpeople: data.data.technicalPeopleNum,
  28. techField: data.data.searchAreaCategory ? data.data.searchAreaCategory.split(",") : [],
  29. haveskill: data.data.specialty ? data.data.specialty.split(",") : []
  30. });
  31. };
  32. }.bind(this),
  33. }).always(function () {
  34. this.props.spinState(false);
  35. }.bind(this));
  36. },
  37. componentWillMount() {
  38. this.getData();
  39. },
  40. handleSubmit(e) {
  41. e.preventDefault();
  42. let specialty = this.state.haveskill.join(",");
  43. this.props.form.validateFields((err, values) => {
  44. if (!err) {
  45. this.props.spinState(true);
  46. $.ajax({
  47. method: "POST",
  48. dataType: "json",
  49. crossDomain: false,
  50. url: globalConfig.context + "/api/user/orgTech",
  51. data: {
  52. "id": this.state.id,
  53. "technicalPeopleNum": values.techpeople,
  54. "searchAreaCategory": values.techField ? values.techField.join(',') : '',
  55. "specialty": specialty
  56. }
  57. }).done(function (data) {
  58. if (!data.error.length) {
  59. message.success('保存成功!');
  60. this.getData();
  61. } else {
  62. message.warning(data.error[0].message);
  63. }
  64. }.bind(this)).always(function () {
  65. this.props.spinState(false);
  66. }.bind(this));
  67. }
  68. });
  69. },
  70. addskill(e) {
  71. let _me = this;
  72. let theSkillArr = _me.state.haveskill;
  73. let theskill = _me.props.form.getFieldValue('skill');
  74. if (theskill !== undefined) {
  75. if (_me.state.haveskill.length > 0) {
  76. let thebool = true;
  77. _me.state.haveskill.map(function (item, i) {
  78. if (item === theskill) {
  79. thebool = false
  80. };
  81. });
  82. if (thebool) {
  83. theSkillArr = _me.state.haveskill.concat(theskill);
  84. }
  85. } else if (_me.state.haveskill.length === 0) {
  86. theSkillArr = _me.state.haveskill.concat(theskill);
  87. };
  88. this.setState({
  89. haveskill: theSkillArr
  90. });
  91. };
  92. },
  93. deleteskill(e) {
  94. let _me = this.state;
  95. _me.haveskill.map(function (item, i) {
  96. if (item === e) {
  97. _me.haveskill.splice(i, 1);
  98. }
  99. });
  100. },
  101. render() {
  102. const FormItem = Form.Item;
  103. const Option = Select.Option;
  104. const { getFieldDecorator } = this.props.form;
  105. const formItemLayout = {
  106. labelCol: { span: 4 },
  107. wrapperCol: { span: 12 },
  108. };
  109. const _me = this;
  110. return (
  111. <Form horizontal onSubmit={this.handleSubmit} className="tech-form">
  112. <FormItem
  113. labelCol={{ span: 4 }}
  114. wrapperCol={{ span: 6 }}
  115. label="技术人员数量"
  116. >
  117. {getFieldDecorator('techpeople', {
  118. initialValue: this.state.techpeople
  119. })(
  120. <InputNumber />
  121. )}
  122. <span>人</span>
  123. </FormItem>
  124. <FormItem
  125. {...formItemLayout}
  126. label="专业领域"
  127. >
  128. {getFieldDecorator('techField', {
  129. initialValue: this.state.techField
  130. })(
  131. <Cascader placeholder="请选择专业领域" options={techFieldList} style={{ width: 380 }} />
  132. )}
  133. </FormItem>
  134. <FormItem
  135. labelCol={{ span: 4 }}
  136. wrapperCol={{ span: 14 }}
  137. label="擅长能力"
  138. >
  139. {getFieldDecorator('skill')(
  140. <div>
  141. 擅长 <Input />的研究
  142. <Button type="primary" onClick={this.addskill}>添加</Button>
  143. </div>
  144. )}
  145. </FormItem>
  146. <div className="set-explain">
  147. {
  148. this.state.haveskill.map(function (item, i) {
  149. return <Tag key={item} closable onClose={_me.deleteskill.bind(this, item)}>{item}</Tag>
  150. }.bind(this))
  151. }
  152. </div>
  153. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  154. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  155. </FormItem>
  156. </Form >
  157. );
  158. },
  159. }));
  160. const Person = React.createClass({
  161. getInitialState() {
  162. return {
  163. loading: false
  164. };
  165. },
  166. spinChange(e) {
  167. this.setState({
  168. loading: e
  169. });
  170. },
  171. render() {
  172. return (
  173. <Spin spinning={this.state.loading} className='spin-box'>
  174. <div className="set-tech">
  175. <div className="acc-title">
  176. <p><span>完善研究领域与擅长能力可加入平台专家,承接技术难题!</span></p>
  177. </div>
  178. <TechFrom spinState={this.spinChange} />
  179. </div>
  180. </Spin>
  181. )
  182. }
  183. });
  184. export default Person;