ablt.jsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import React from 'react';
  2. import './ablt.less';
  3. import ajax from 'jquery/src/ajax/xhr.js'
  4. import $ from 'jquery/src/ajax';
  5. import { Tag, Input, Tooltip, Button, Spin, message } from 'antd';
  6. class EditableTagGroup extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. tags: ['我的标签:', '标签1', '标签2'],
  11. inputVisible: false,
  12. inputValue: '',
  13. propsBool: true
  14. }
  15. }
  16. handleClose(removedTag) {
  17. const tags = this.state.tags.filter(tag => tag !== removedTag);
  18. this.props.tagsArr(tags);
  19. this.setState({ tags });
  20. }
  21. showInput() {
  22. this.setState({ inputVisible: true }, () => this.input.focus());
  23. }
  24. handleInputChange(e) {
  25. this.setState({ inputValue: e.target.value });
  26. }
  27. handleInputConfirm() {
  28. const state = this.state;
  29. const inputValue = state.inputValue;
  30. let tags = state.tags;
  31. if (inputValue && tags.indexOf(inputValue) === -1 && inputValue.replace(/(^\s*)|(\s*$)/g, "").length != 0) {
  32. tags = [...tags, inputValue.replace(/(^\s*)|(\s*$)/g, "")];
  33. }
  34. this.props.tagsArr(tags);
  35. this.setState({
  36. tags,
  37. inputVisible: false,
  38. inputValue: '',
  39. });
  40. }
  41. componentWillReceiveProps(nextProps) {
  42. if (nextProps.abltArr && this.state.propsBool) {
  43. nextProps.abltArr.unshift("我的标签:");
  44. this.state.tags = nextProps.abltArr;
  45. this.state.propsBool = false;
  46. };
  47. }
  48. render() {
  49. const { tags, inputVisible, inputValue } = this.state;
  50. return (
  51. <div className="ablt-tips">
  52. {tags.map((tag, index) => {
  53. const isLongTag = tag.length > 11;
  54. const tagElem = (
  55. <Tag key={tag} closable={index !== 0} afterClose={() => this.handleClose(tag)}>
  56. {isLongTag ? `${tag.slice(0, 11)}...` : tag}
  57. </Tag>
  58. );
  59. return isLongTag ? <Tooltip title={tag}>{tagElem}</Tooltip> : tagElem;
  60. })}
  61. {inputVisible && (
  62. <Input
  63. ref={input => this.input = input}
  64. type="text"
  65. style={{ width: 78 }}
  66. value={inputValue}
  67. onChange={this.handleInputChange.bind(this)}
  68. onBlur={this.handleInputConfirm.bind(this)}
  69. onPressEnter={this.handleInputConfirm.bind(this)}
  70. />
  71. )}
  72. {!inputVisible && <Button className="addtips" type="dashed" disabled={tags.length > 10 ? true : false} onClick={this.showInput.bind(this)}>+ 新标签</Button>}
  73. </div>
  74. );
  75. }
  76. };
  77. const Base = React.createClass({
  78. getInitialState() {
  79. return {
  80. loading: false,
  81. tags: []
  82. };
  83. },
  84. loadData() {
  85. this.setState({
  86. loading: true
  87. });
  88. $.ajax({
  89. method: "get",
  90. dataType: "json",
  91. url: globalConfig.context + "/api/user/ability",
  92. success: function (data) {
  93. if (data.data) {
  94. this.setState({
  95. id: data.data.id || null,
  96. abltArr: data.data.abilityLabel ? data.data.abilityLabel.split(",") : [],
  97. intellectRight: data.data.intellectRight,
  98. scienceAchievement: data.data.scienceAchievement,
  99. researchInnovation: data.data.researchInnovation,
  100. personnel: data.data.personnel
  101. });
  102. };
  103. }.bind(this),
  104. }).always(function () {
  105. this.setState({
  106. loading: false
  107. });
  108. }.bind(this));
  109. },
  110. componentWillMount() {
  111. this.loadData();
  112. },
  113. getTagsArr(e) {
  114. this.state.tags = e.slice(1);
  115. },
  116. submit() {
  117. let theTags = this.state.tags.join(",");
  118. this.setState({
  119. loading: true
  120. })
  121. $.ajax({
  122. method: "POST",
  123. dataType: "json",
  124. crossDomain: false,
  125. url: globalConfig.context + "/api/user/userAbility",
  126. data: {
  127. 'id': this.state.id,
  128. 'abilityLabel': theTags,
  129. "intellectRight": this.state.intellectRight,
  130. "scienceAchievement": this.state.scienceAchievement,
  131. "researchInnovation": this.state.researchInnovation,
  132. "personnel": this.state.personnel
  133. }
  134. }).done(function (data) {
  135. if (!data.error.length) {
  136. message.success('保存成功!');
  137. this.loadData();
  138. } else {
  139. message.warning(data.error[0].message);
  140. }
  141. }.bind(this)).always(function () {
  142. this.setState({
  143. loading: false
  144. })
  145. }.bind(this));
  146. },
  147. render() {
  148. return (
  149. <Spin spinning={this.state.loading} className='spin-box'>
  150. <div className="set-ablt">
  151. <div className="acc-detail">
  152. <p className="acc-title">能力标签</p>
  153. <p className="tips-title">最多可设置10个标签。请用简洁明确的关键词来展示你的职业能力。</p>
  154. <EditableTagGroup abltArr={this.state.abltArr} tagsArr={this.getTagsArr} />
  155. </div>
  156. {userData.type == "1" ? <div className="acc-detail clearfix">
  157. <p className="acc-title">能力标签</p>
  158. <div className="acc-area">
  159. <p>知识产权对企业竞争力的作用 (限400字) </p>
  160. <Input type="textarea" rows={6}
  161. value={this.state.intellectRight}
  162. onChange={(e) => {
  163. if (e.target.value.length > 400) {
  164. message.warning("长度超过400字!");
  165. return;
  166. };
  167. this.setState({ intellectRight: e.target.value });
  168. }} />
  169. </div>
  170. <div className="acc-area">
  171. <p>科技成果转化情况 (限400字) </p>
  172. <Input type="textarea" rows={6}
  173. value={this.state.scienceAchievement}
  174. onChange={(e) => {
  175. if (e.target.value.length > 400) {
  176. message.warning("长度超过400字!");
  177. return;
  178. };
  179. this.setState({ scienceAchievement: e.target.value })
  180. }} />
  181. </div>
  182. <div className="acc-area">
  183. <p>研究开发与技术创新组织管理情况 (限400字) </p>
  184. <Input type="textarea" rows={6}
  185. value={this.state.researchInnovation}
  186. onChange={(e) => {
  187. if (e.target.value.length > 400) {
  188. message.warning("长度超过400字!");
  189. return;
  190. };
  191. this.setState({ researchInnovation: e.target.value })
  192. }} />
  193. </div>
  194. <div className="acc-area">
  195. <p>管理与科技人员情况 (限400字) </p>
  196. <Input type="textarea" rows={6}
  197. value={this.state.personnel}
  198. onChange={(e) => {
  199. if (e.target.value.length > 400) {
  200. message.warning("长度超过400字!");
  201. return;
  202. };
  203. this.setState({ personnel: e.target.value })
  204. }} />
  205. </div>
  206. </div> : <div></div>}
  207. <Button className="set-submit" type="primary" onClick={this.submit}>保存</Button>
  208. </div>
  209. </Spin>
  210. )
  211. }
  212. });
  213. export default Base;