demandDesc.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import React from 'react';
  2. import { Modal, Spin } from 'antd';
  3. import DemandForm from '@/account/demand/demandForm';
  4. class DemandDesc extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. loading: false,
  9. pictureUrl: []
  10. };
  11. }
  12. loadData(id) {
  13. this.setState({
  14. loading: true
  15. });
  16. $.ajax({
  17. method: 'get',
  18. dataType: 'json',
  19. crossDomain: false,
  20. url:
  21. globalConfig.context +
  22. (window.userData.type == '1'
  23. ? '/api/user/demand/orgDemandDetail'
  24. : '/api/user/demand/userDemandDetail'),
  25. data: {
  26. id: id
  27. },
  28. success: function(data) {
  29. let thisData = data.data;
  30. if (!thisData) {
  31. if (data.error && data.error.length) {
  32. message.warning(data.error[0].message);
  33. }
  34. thisData = {};
  35. }
  36. this.setState({
  37. data: thisData,
  38. tags: thisData.keyword ? thisData.keyword.split(',') : [],
  39. pictureUrl: thisData.pictureUrl
  40. ? splitUrl(thisData.pictureUrl, ',', globalConfig.avatarHost + '/upload')
  41. : []
  42. });
  43. }.bind(this)
  44. }).always(
  45. function() {
  46. this.setState({
  47. loading: false
  48. });
  49. }.bind(this)
  50. );
  51. }
  52. handleCancel() {
  53. this.setState({
  54. visible: false
  55. });
  56. }
  57. handOk() {
  58. this.setState({
  59. visible: false
  60. });
  61. this.props.closeDesc(false, true);
  62. }
  63. componentWillReceiveProps(nextProps) {
  64. if (nextProps.showDesc && nextProps.data && nextProps.data.id) {
  65. this.loadData(nextProps.data.id);
  66. }
  67. this.state.visible = nextProps.showDesc;
  68. }
  69. render() {
  70. let data = this.props.data || [];
  71. return (
  72. <div className="patent-desc">
  73. <Modal
  74. maskClosable={false}
  75. visible={this.state.visible}
  76. onOk={this.handOk.bind(this)}
  77. onCancel={this.handleCancel.bind(this)}
  78. width="1000px"
  79. title={!data.id ? '新建需求' : '修改需求'}
  80. footer=""
  81. className="admin-desc-content"
  82. >
  83. <div>
  84. {!data.id ? (
  85. <div>
  86. <DemandForm
  87. closeDesc={this.handleCancel}
  88. visible={this.state.visible}
  89. data={[]}
  90. />
  91. </div>
  92. ) : (
  93. <div>
  94. <DemandForm
  95. closeDesc={this.handleCancel}
  96. visible={this.state.visible}
  97. data={this.props.data}
  98. />
  99. </div>
  100. )}
  101. </div>
  102. </Modal>
  103. </div>
  104. );
  105. }
  106. }
  107. export default DemandDesc;