websiteAdd.jsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import React from 'react';
  2. import { Button, Input, Select, message, Modal,Spin } from 'antd';
  3. import { companySearch } from '../../../tools.js';
  4. import ajax from 'jquery/src/ajax/xhr.js';
  5. import $ from 'jquery/src/ajax';
  6. const WebsiteAdd = React.createClass({
  7. getInitialState() {
  8. return {
  9. visible: false,
  10. loading: false
  11. };
  12. },
  13. componentWillReceiveProps(nextProps) {
  14. if (!this.state.visible && nextProps.showAdd) {
  15. this.state.unitName = undefined;
  16. this.state.department = undefined;
  17. this.state.website = undefined;
  18. this.state.accountNumber = undefined;
  19. this.state.password = undefined;
  20. };
  21. this.state.visible = nextProps.showAdd
  22. },
  23. showModal() {
  24. this.setState({
  25. visible: true,
  26. });
  27. },
  28. handleOk() {
  29. this.setState({
  30. loading: true
  31. });
  32. if (!this.state.unitName) {
  33. message.warning('请选择一个公司!');
  34. this.setState({
  35. loading: false
  36. });
  37. return;
  38. };
  39. $.ajax({
  40. method: "POST",
  41. dataType: "json",
  42. crossDomain: false,
  43. url: globalConfig.context + "/api/admin/techproject/disposeTechWebsite",
  44. data: {
  45. uid: this.state.unitName,
  46. department: this.state.department,
  47. website: this.state.website,
  48. accountNumber: this.state.accountNumber,
  49. password: this.state.password
  50. }
  51. }).done(function (data) {
  52. if (!data.error.length) {
  53. message.success('保存成功!');
  54. this.setState({
  55. loading: false,
  56. visible: false
  57. });
  58. this.props.closeAdd(false);
  59. } else {
  60. message.warning(data.error[0].message);
  61. this.setState({
  62. loading: false
  63. });
  64. }
  65. }.bind(this));
  66. },
  67. handleCancel(e) {
  68. this.setState({
  69. visible: false,
  70. });
  71. this.props.closeAdd(false);
  72. },
  73. spinChange(e) {
  74. this.setState({
  75. loading: e
  76. });
  77. },
  78. render() {
  79. return (
  80. <div className="cognizance-add">
  81. <Modal maskClosable={false} title="添加科技部门网址" visible={this.state.visible}
  82. onOk={this.handleOk} onCancel={this.handleCancel}
  83. width='500px'
  84. footer={[
  85. <Button key="submit" type="primary" loading={this.state.loading} onClick={this.handleOk}>
  86. 确认
  87. </Button>,
  88. <Button key="back" onClick={this.handleCancel}>
  89. 取消
  90. </Button>,
  91. ]} >
  92. <Spin spinning={this.state.loading} className='spin-box'>
  93. <div>
  94. <span className="item-title">选择公司: </span>
  95. <Select
  96. placeholder="请选择公司"
  97. style={{ width: 200 }}
  98. value={this.state.unitName}
  99. showSearch
  100. filterOption={companySearch}
  101. onChange={(e) => { this.setState({ unitName: e }); }}>
  102. {this.props.companyAddOption}
  103. </Select>
  104. </div>
  105. <div>
  106. <span className="item-title">科技部门名称: </span>
  107. <Input value={this.state.department} onChange={(e) => { this.setState({ department: e.target.value }); }} style={{ width: 200 }} />
  108. </div>
  109. <div>
  110. <span className="item-title">网址: </span>
  111. <Input value={this.state.website} onChange={(e) => { this.setState({ website: e.target.value }); }} style={{ width: 200 }} />
  112. </div>
  113. <div>
  114. <span className="item-title">账号: </span>
  115. <Input value={this.state.accountNumber} onChange={(e) => { this.setState({ accountNumber: e.target.value }); }} style={{ width: 200 }} />
  116. </div>
  117. <div>
  118. <span className="item-title">密码: </span>
  119. <Input value={this.state.password} onChange={(e) => { this.setState({ password: e.target.value }); }} style={{ width: 200 }} />
  120. </div>
  121. </Spin>
  122. </Modal>
  123. </div>
  124. );
  125. }
  126. });
  127. export default WebsiteAdd;