batchImport.jsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import React from 'react';
  2. import { Input, Modal, Button, message, Select } from 'antd';
  3. import { achievementCategoryList } from '../../dataDic.js';
  4. import ajax from 'jquery/src/ajax/xhr.js';
  5. import $ from 'jquery/src/ajax';
  6. const BatchImport = React.createClass({
  7. getInitialState: function () {
  8. return {
  9. loading: false
  10. };
  11. },
  12. showModal() {
  13. this.setState({
  14. visible: true,
  15. });
  16. },
  17. handleOk(e) {
  18. this.setState({
  19. visible: false,
  20. });
  21. },
  22. handleCancel(e) {
  23. this.setState({
  24. visible: false,
  25. });
  26. },
  27. provinceChange(e) {
  28. let theArr = [];
  29. this.props.provinceList.map((item) => {
  30. if (item.id == e) {
  31. item.cityList.map((city) => {
  32. theArr.push(
  33. <Select.Option key={city.id}>{city.name}</Select.Option>
  34. )
  35. });
  36. }
  37. });
  38. this.setState({
  39. cityOption: theArr,
  40. province: e,
  41. city: undefined
  42. });
  43. },
  44. cityChange(e) {
  45. this.setState({
  46. city: e
  47. });
  48. },
  49. //提交
  50. handleSubmit() {
  51. let theArr = this.state.inputValue.split(/[\r\n]/g);
  52. if (!theArr.length) {
  53. return;
  54. };
  55. if (theArr.length > 999) {
  56. message.warning("数据条数不能多于1000条!");
  57. return;
  58. };
  59. let unitName = theArr.join(',');
  60. this.setState({
  61. loading: true
  62. });
  63. $.ajax({
  64. method: "POST",
  65. dataType: "json",
  66. crossDomain: false,
  67. url: globalConfig.context + '/api/admin/cognizanceRecord/import',
  68. data: {
  69. unitName: unitName,
  70. district: this.state.city || this.state.province,
  71. year: this.state.year
  72. }
  73. }).done(function (data) {
  74. this.setState({
  75. loading: false
  76. });
  77. if (!data.error.length) {
  78. message.success('导入成功!');
  79. this.handleOk();
  80. } else {
  81. message.warning(data.error[0].message);
  82. };
  83. }.bind(this));
  84. },
  85. reset() {
  86. this.setState({
  87. province: undefined,
  88. city: undefined,
  89. year: undefined,
  90. inputValue: undefined
  91. });
  92. },
  93. render() {
  94. return (
  95. <div>
  96. <Button type="primary" onClick={this.showModal}>批量导入</Button>
  97. <Modal
  98. title="批量导入"
  99. visible={this.state.visible}
  100. onCancel={this.handleCancel}
  101. width='1000px'
  102. footer={[
  103. <Button key="ok" className="set-submit" type="primary" loading={this.state.loading} onClick={this.handleSubmit}>保存</Button>,
  104. <Button key="clancel" className="set-submit" type="ghost" onClick={this.handleCancel}>取消</Button>
  105. ]} >
  106. <div>
  107. <span style={{ marginRight: '10px' }}>地区</span>
  108. <Select style={{ width: '100px' }}
  109. value={this.state.province}
  110. placeholder="请选择省份"
  111. notFoundContent="未获取到省份列表"
  112. showSearch
  113. filterOption={this.props.companySearch}
  114. onChange={this.provinceChange}>
  115. {this.props.provinceOption}
  116. </Select>
  117. <Select style={{ width: '120px', marginLeft: '10px' }}
  118. value={this.state.city}
  119. placeholder="请选择城市"
  120. notFoundContent="未获取到城市列表"
  121. showSearch
  122. filterOption={this.props.companySearch}
  123. onChange={this.cityChange}>
  124. {this.state.cityOption}
  125. </Select>
  126. <span style={{ marginLeft: '10px', marginRight: '10px' }}>年份</span>
  127. <Select style={{ width: 80 }}
  128. value={this.state.year}
  129. onChange={(e) => { this.setState({ year: e }) }} >
  130. {this.props.yearOption}
  131. </Select>
  132. <Button style={{ marginLeft: '20px' }} type="ghost" onClick={this.reset}>重置</Button>
  133. </div>
  134. <div style={{ margin: '10px 0' }}>
  135. 公司名称
  136. </div>
  137. <Input type="textarea" rows={12} value={this.state.inputValue}
  138. onChange={(e) => { this.setState({ inputValue: e.target.value }); }} />
  139. </Modal>
  140. </div>
  141. );
  142. }
  143. });
  144. export default BatchImport;