launchinvest.jsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import React, { Component } from "react";
  2. import { message, Modal, Spin, Form, Select, Input, Button, Tag } from "antd";
  3. import $ from "jquery/src/ajax";
  4. // 发起投资
  5. class LaunchInvest extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. loading: false,
  10. alist: [
  11. { lable: "100万", value: "100" },
  12. { lable: "50万", value: "50" },
  13. { lable: "30万", value: "30" },
  14. { lable: "20万", value: "20" },
  15. { lable: "10万", value: "10" },
  16. ],
  17. list: [],
  18. };
  19. this.onChange = this.onChange.bind(this);
  20. this.onBlur = this.onBlur.bind(this);
  21. }
  22. componentDidMount() {
  23. const { details = false } = this.props
  24. this.getList()
  25. if (!!details) {
  26. this.setState({
  27. otherAmbId: details.acceptAmbId, // 对方阿米巴
  28. amount: details.amount.toString(), // 金额
  29. comment: details.comment, // 备注
  30. })
  31. }
  32. }
  33. // 获取下级列表信息
  34. getList() {
  35. $.ajax({
  36. method: "get",
  37. dataType: "json",
  38. crossDomain: false,
  39. url: globalConfig.context + "/api/admin/amb/Invest/getInvestAmbList",
  40. data: {
  41. id: this.props.myAmbId
  42. },
  43. success: function (data) {
  44. if (data.error && data.error.length === 0) {
  45. if (data.data) {
  46. this.setState({
  47. list: data.data || []
  48. });
  49. }
  50. } else {
  51. message.warning(data.error[0].message);
  52. }
  53. }.bind(this),
  54. }).always(
  55. function () {
  56. }.bind(this)
  57. );
  58. }
  59. onChange(e) {
  60. const { value } = e.target;
  61. const reg = /^-?(0|[1-9][0-9]*)(\.[0-9]*)?$/;
  62. if ((!isNaN(value) && reg.test(value)) || value === '') {
  63. this.setState({
  64. amount: value
  65. })
  66. }
  67. }
  68. onBlur() {
  69. const { amount } = this.state
  70. if (!!amount && amount.charAt(amount.length - 1) === '.') {
  71. this.setState({
  72. amount: amount.slice(0, -1)
  73. })
  74. }
  75. }
  76. onSubmit() {
  77. const { myAmbId, onCancel, details = false } = this.props
  78. const { otherAmbId, amount, comment } = this.state
  79. if (!otherAmbId) {
  80. message.warning("请选择您需投人的下级单位");
  81. return
  82. }
  83. if (!amount) {
  84. message.warning("请填写您的投资款");
  85. return
  86. }
  87. if (!comment) {
  88. message.warning("请填写备注说明");
  89. return
  90. }
  91. this.setState({
  92. loading: true
  93. })
  94. // 发起
  95. let infor = {
  96. myAmbId, // 我的阿米巴
  97. otherAmbId, // 对方阿米巴
  98. amount, // 金额
  99. comment, // 备注
  100. status: 1, // 状态 0草稿 1发起
  101. }
  102. // 重新发起
  103. let infor1 = {
  104. myAmbId, // 我的阿米巴
  105. otherAmbId, // 对方阿米巴
  106. amount, // 金额
  107. comment, // 备注
  108. status: 1, // 状态 0草稿 1发起
  109. id: details.id,
  110. }
  111. $.ajax({
  112. method: "POST",
  113. dataType: "json",
  114. crossDomain: false,
  115. url: globalConfig.context +
  116. (
  117. !!details
  118. ? "/api/admin/amb/Invest/updateTransfer"
  119. : "/api/admin/amb/Invest/addTransfer"
  120. ),
  121. data: !!details ? infor1 : infor,
  122. }).done(
  123. function (data) {
  124. this.setState({
  125. loading: false,
  126. });
  127. if (!data.error.length) {
  128. message.success("发起成功!");
  129. onCancel(true)
  130. } else {
  131. message.warning(data.error[0].message);
  132. }
  133. }.bind(this)
  134. );
  135. }
  136. render() {
  137. const { alist, list } = this.state
  138. const { visible, onCancel, details = false } = this.props
  139. const FormItem = Form.Item;
  140. const formItemLayout = {
  141. labelCol: { span: 4 },
  142. wrapperCol: { span: 16 },
  143. };
  144. return (
  145. <Modal
  146. maskClosable={false}
  147. visible={visible == "invest"}
  148. title=""
  149. footer=""
  150. width="800px"
  151. onCancel={() => { onCancel(false) }}
  152. >
  153. <Spin spinning={this.state.loading}>
  154. <div>
  155. <div style={{ textAlign: "center", fontSize: "20px", marginBottom: 40 }}>发起投资</div>
  156. <Form>
  157. <FormItem
  158. {...formItemLayout}
  159. label={<span><span style={{ color: "red" }}>*</span>投入单位</span>}
  160. >
  161. <Select
  162. showSearch
  163. style={{ width: 200 }}
  164. placeholder="请选择您需投人的下级单位"
  165. value={this.state.otherAmbId}
  166. optionFilterProp="children"
  167. onChange={e => { this.setState({ otherAmbId: e }) }}
  168. filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
  169. >
  170. {
  171. list.map((item) =>
  172. <Option value={item.id} key={item.id}>{item.name}</Option>
  173. )
  174. }
  175. </Select>
  176. </FormItem>
  177. <FormItem
  178. {...formItemLayout}
  179. label={<span><span style={{ color: "red" }}>*</span>投资款(万元)</span>}
  180. >
  181. <Input
  182. placeholder="请填写您的投资款"
  183. style={{ width: 200, marginRight: 20 }}
  184. value={this.state.amount}
  185. onChange={this.onChange}
  186. onBlur={this.onBlur}
  187. />
  188. {
  189. alist.map((item) =>
  190. <Tag
  191. key={item.value}
  192. color={this.state.amount == item.value && "#108ee9"}
  193. onClick={() => {
  194. this.setState({
  195. amount: item.value
  196. })
  197. }}
  198. >{item.lable}</Tag>
  199. )
  200. }
  201. </FormItem>
  202. <FormItem
  203. {...formItemLayout}
  204. label={<span><span style={{ color: "red" }}>*</span>备注</span>}
  205. >
  206. <Input
  207. type="textarea"
  208. placeholder="备注说明"
  209. autosize={{ minRows: 4 }}
  210. value={this.state.comment}
  211. onChange={(e) => {
  212. this.setState({ comment: e.target.value });
  213. }}
  214. />
  215. </FormItem>
  216. <FormItem
  217. wrapperCol={{ span: 12, offset: 9 }}
  218. >
  219. <div style={{ marginTop: 30 }}>
  220. <Button
  221. type="primary"
  222. onClick={() => {
  223. this.onSubmit();
  224. }}
  225. >
  226. {!!details ? "重新发起" : "确定投资"}
  227. </Button>
  228. <Button
  229. type="ghost"
  230. style={{ marginLeft: 20 }}
  231. onClick={() => { onCancel(false) }}
  232. >
  233. 取消
  234. </Button>
  235. </div>
  236. </FormItem>
  237. </Form>
  238. </div>
  239. </Spin>
  240. </Modal>
  241. );
  242. }
  243. }
  244. export default LaunchInvest;