contractAdd.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. import React from 'react';
  2. import { Icon, Modal, Button, Form, message, Input, Spin, Select, Checkbox, InputNumber, DatePicker } from 'antd';
  3. import './contract.less';
  4. import { companySearch } from '../../../tools.js';
  5. import ajax from 'jquery/src/ajax/xhr.js'
  6. import $ from 'jquery/src/ajax';
  7. const ContractAddFrom = Form.create()(React.createClass({
  8. getInitialState() {
  9. return {
  10. loading: false,
  11. companyOption: [],
  12. accelerated: 0,
  13. acceleratedDate: 0,
  14. visible: "visible"
  15. };
  16. },
  17. loadData(id) {
  18. this.setState({
  19. loading: true
  20. });
  21. $.ajax({
  22. method: "get",
  23. dataType: "json",
  24. crossDomain: false,
  25. cache: false,
  26. url: globalConfig.context + "/api/user/contract/detail",
  27. data: {
  28. id: id || this.props.data.id
  29. }
  30. }).done((data) => {
  31. if (!data.data) {
  32. if (data.error && data.error.length) {
  33. message.warning(data.error[0].message);
  34. };
  35. } else {
  36. this.setState({
  37. data: data.data,
  38. patentCheck: data.data.patentNum ? true : false,
  39. copyrightCheck: data.data.copyrightNum ? true : false,
  40. highTechCheck: data.data.cognizanceYear ? true : false,
  41. techProjectCheck: data.data.techProjectNum ? true : false,
  42. });
  43. };
  44. }).always(function () {
  45. this.setState({
  46. loading: false
  47. });
  48. }.bind(this));
  49. },
  50. componentWillMount() {
  51. let d = new Date(), _me = this, theArr = [];
  52. d = d.getFullYear() - 1;
  53. for (let i = d; i < d + 20; i++) {
  54. theArr.push(
  55. <Select.Option key={i.toString()}>{i}</Select.Option>
  56. )
  57. };
  58. this.state.yearOption = theArr;
  59. if (this.props.data && this.props.data.id) {
  60. this.loadData(this.props.data.id);
  61. } else {
  62. this.state.data = {};
  63. this.state.patentCheck = false;
  64. this.state.copyrightCheck = false;
  65. this.state.highTechCheck = false;
  66. this.state.techProjectCheck = false;
  67. };
  68. },
  69. componentWillReceiveProps(nextProps) {
  70. if (!this.props.visible && nextProps.visible) {
  71. if (nextProps.data && nextProps.data.id) {
  72. this.loadData(nextProps.data.id);
  73. } else {
  74. this.state.data = {};
  75. this.state.patentCheck = false;
  76. this.state.copyrightCheck = false;
  77. this.state.highTechCheck = false;
  78. this.state.techProjectCheck = false;
  79. };
  80. this.props.form.resetFields();
  81. };
  82. },
  83. handleSave(e) {
  84. e.preventDefault();
  85. this.props.form.validateFields((err, values) => {
  86. if (!err) {
  87. if (!values.patentNum && !values.copyrightNum && !values.cognizanceYear && !values.techProjectNum) {
  88. message.warning('请至少选择一个申报项目!');
  89. return;
  90. };
  91. this.props.spinState(true);
  92. $.ajax({
  93. method: "POST",
  94. dataType: "json",
  95. crossDomain: false,
  96. url: globalConfig.context + (this.state.data.id ? "/api/user/contract/update" : "/api/user/contract/apply"),
  97. data: {
  98. "id": this.state.data.id,
  99. "contacts": values.contacts, //联系人
  100. "type": values.type, //合同类型
  101. "depict": values.depict, // "合同描述",
  102. "patentNum": this.state.patentCheck ? values.patentNum : 0,
  103. "copyrightNum": this.state.copyrightCheck ? values.copyrightNum : 0,
  104. "cognizanceYear": this.state.highTechCheck ? values.cognizanceYear : undefined,
  105. "techProjectNum": this.state.techProjectCheck ? values.techProjectNum : 0,
  106. "comment": values.comment //"备注"
  107. }
  108. }).done(function (data) {
  109. if (!data.error.length) {
  110. message.success('保存成功!');
  111. this.props.okClick();
  112. this.props.closeModal();
  113. this.props.form.resetFields();
  114. } else {
  115. message.warning(data.error[0].message);
  116. }
  117. }.bind(this)).always(function () {
  118. this.props.spinState(false);
  119. }.bind(this));
  120. }
  121. });
  122. },
  123. render() {
  124. const FormItem = Form.Item;
  125. const { getFieldDecorator } = this.props.form;
  126. const theData = this.state.data || {};
  127. const formItemLayout = {
  128. labelCol: { span: 6 },
  129. wrapperCol: { span: 14 },
  130. };
  131. const _me = this;
  132. return (
  133. <Form horizontal onSubmit={this.handleSave}>
  134. <div className="clearfix">
  135. <FormItem className="half-item"
  136. {...formItemLayout}
  137. label="联系人" >
  138. {getFieldDecorator('contacts', {
  139. initialValue: theData.contacts,
  140. rules: [{ required: true, message: '请选择联系人!' }],
  141. })(
  142. <Select placeholder="请选择联系人"
  143. style={{ width: 260 }}
  144. notFoundContent="未获取到联系人列表">
  145. {this.props.contactsOption}
  146. </Select>
  147. )}
  148. </FormItem>
  149. <FormItem className="half-item"
  150. {...formItemLayout}
  151. label="合同类型" >
  152. {getFieldDecorator('type', {
  153. initialValue: theData.type,
  154. rules: [{ required: true, message: '请选择合同类型!' }],
  155. })(
  156. <Select placeholder="请选择合同类型"
  157. style={{ width: 260 }}>
  158. {this.props.typeOption}
  159. </Select>
  160. )}
  161. </FormItem>
  162. </div>
  163. <FormItem
  164. labelCol={{ span: 3 }}
  165. wrapperCol={{ span: 19 }}
  166. label="合同描述" >
  167. {getFieldDecorator('depict', {
  168. initialValue: theData.depict
  169. })(
  170. <Input type="textarea"
  171. placeholder="多行输入"
  172. rows={4} />
  173. )}
  174. </FormItem>
  175. <div className="clearfix">
  176. <span style={{ float: "left", lineHeight: '32px', marginRight: '20px' }}>
  177. <Checkbox checked={this.state.highTechCheck} onChange={(e) => {
  178. this.setState({ highTechCheck: e.target.checked });
  179. }}></Checkbox>
  180. </span>
  181. <FormItem className="half-item"
  182. {...formItemLayout}
  183. label={"高企申请"} >
  184. {getFieldDecorator('cognizanceYear', {
  185. initialValue: theData.cognizanceYear ? theData.cognizanceYear.toString() : null
  186. })(
  187. <Select placeholder="请选择年份"
  188. style={{ width: 120 }}
  189. onSelect={(e, n) => { this.setState({ year: e }); }}>
  190. {this.state.yearOption}
  191. </Select>
  192. )}
  193. </FormItem>
  194. </div>
  195. <div className="clearfix">
  196. <span style={{ float: "left", lineHeight: '32px', marginRight: '20px' }}>
  197. <Checkbox checked={this.state.patentCheck} onChange={(e) => {
  198. this.setState({ patentCheck: e.target.checked });
  199. }}></Checkbox>
  200. </span>
  201. <FormItem className="half-item"
  202. {...formItemLayout}
  203. label={"专利申请"} >
  204. {getFieldDecorator('patentNum', {
  205. initialValue: theData.patentNum
  206. })(
  207. <InputNumber />
  208. )}
  209. </FormItem>
  210. </div>
  211. <div className="clearfix">
  212. <span style={{ float: "left", lineHeight: '32px', marginRight: '20px' }}>
  213. <Checkbox checked={this.state.copyrightCheck} onChange={(e) => {
  214. this.setState({ copyrightCheck: e.target.checked });
  215. }}></Checkbox>
  216. </span>
  217. <FormItem className="half-item"
  218. {...formItemLayout}
  219. label={"软著申请"} >
  220. {getFieldDecorator('copyrightNum', {
  221. initialValue: theData.copyrightNum
  222. })(
  223. <InputNumber />
  224. )}
  225. </FormItem>
  226. </div>
  227. <div className="clearfix">
  228. <span style={{ float: "left", lineHeight: '32px', marginRight: '20px' }}>
  229. <Checkbox checked={this.state.techProjectCheck} onChange={(e) => {
  230. this.setState({ techProjectCheck: e.target.checked });
  231. }}></Checkbox>
  232. </span>
  233. <FormItem className="half-item"
  234. {...formItemLayout}
  235. label={"科技项目申请"} >
  236. {getFieldDecorator('techProjectNum', {
  237. initialValue: theData.techProjectNum
  238. })(
  239. <InputNumber />
  240. )}
  241. </FormItem>
  242. </div>
  243. <FormItem style={{ paddingLeft: '40px' }}>
  244. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  245. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  246. </FormItem>
  247. </Form >
  248. );
  249. },
  250. }));
  251. const ContractAdd = React.createClass({
  252. getInitialState() {
  253. return {
  254. visible: false,
  255. loading: false
  256. };
  257. },
  258. showModal() {
  259. this.setState({
  260. visible: true,
  261. data: {}
  262. });
  263. },
  264. handleCancel(e) {
  265. this.setState({
  266. visible: false,
  267. });
  268. this.props.closeAdd(false);
  269. },
  270. componentWillReceiveProps(nextProps) {
  271. this.state.visible = nextProps.showAdd;
  272. },
  273. spinChange(e) {
  274. this.setState({
  275. loading: e
  276. });
  277. },
  278. render() {
  279. return (
  280. <div className="patent-addNew">
  281. <Button className="patent-addNew" type="primary" onClick={this.props.onClick}>申请合同<Icon type="plus" /></Button>
  282. <Modal maskClosable={false} title="合同详情"
  283. visible={this.state.visible}
  284. onCancel={this.handleCancel}
  285. width='800px'
  286. footer='' >
  287. <Spin spinning={this.state.loading} className='spin-box'>
  288. <ContractAddFrom
  289. spinState={this.spinChange}
  290. closeModal={this.handleCancel}
  291. visible={this.state.visible}
  292. data={this.props.data}
  293. okClick={() => { this.props.closeAdd(false, true) }}
  294. typeOption={this.props.typeOption}
  295. contactsOption={this.props.contactsOption} />
  296. </Spin>
  297. </Modal>
  298. </div>
  299. );
  300. },
  301. });
  302. export default ContractAdd;