Guest User

Untitled

a guest
Aug 15th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.54 KB | None | 0 0
  1. import React, { Component, Fragment } from 'react';
  2. import { connect } from 'dva';
  3. import { parse } from 'qs';
  4. import moment from 'moment';
  5. import { routerRedux } from 'dva/router';
  6. import { Button, Card, Table, Input, Icon, Popover, message } from 'antd';
  7. import StandardTable from '../../../../components/StandardTable';
  8. import { getSampleList, getSampleVersion, editSubmission, newSubmission, getModelDetails } from '../../../../services/model';
  9. import Ellipsis from '../../../../components/Ellipsis';
  10. import styles from './style.less';
  11.  
  12. // 格式化时间
  13. const formatTime = (value) => {
  14. return moment(value).format('YYYY/MM/DD');
  15. };
  16.  
  17. @connect(({
  18. pageGlobal,
  19. modelManage,
  20. loading,
  21. }) => ({
  22. pageGlobal,
  23. modelManage,
  24. loading: loading.models.modelManage,
  25. }))
  26.  
  27.  
  28. export default class Step2 extends Component {
  29. state = {
  30. SampleData: {},
  31. selectedRows: [],
  32. prevSelectedRows: null,
  33. tmpList: [],
  34. check: false,
  35. detailsData: [],
  36. searchName: '', // 存储当前查询参数,查询时保留之前过滤数据
  37. };
  38. // 初始化页面调用获取数据
  39. componentDidMount() {
  40. const { location, dispatch, pageGlobal: { modelManageEditInfo } } = this.props;
  41. const pageId = parse(location.search.substr(1)).recordId;
  42. if (!modelManageEditInfo.refresh) {
  43. if (pageId) {
  44. dispatch(routerRedux.push({
  45. pathname: '/modelManage/addNewModel/modelAttr',
  46. search: `?recordId=${pageId}`,
  47. }));
  48. } else {
  49. dispatch(routerRedux.push('/modelManage/addNewModel/modelAttr'));
  50. }
  51. }
  52. const param = {
  53. modelId: pageId,
  54. name: '',
  55. pageNum: 1,
  56. };
  57. this.getSampelData(param);
  58. this.initSelected();
  59. global.react = this;
  60. }
  61. getSampelData = (param) => {
  62. getSampleList(param).then((result) => {
  63. this.setState({
  64. SampleData: {
  65. list: result.records,
  66. pagination: {
  67. total: result.total,
  68. current: result.current,
  69. pageSize: result.size,
  70. },
  71. },
  72. });
  73. });
  74. };
  75. // 已选样本
  76. initSelected = () => {
  77. const { pageGlobal: { modelManageEditInfo } } = this.props;
  78. const { sample } = modelManageEditInfo;
  79. const { location } = this.props;
  80. const pageId = parse(location.search.substr(1)).recordId;
  81. const getIds = (arr) => {
  82. if (arr.length) {
  83. return arr.map((item) => {
  84. return item.id;
  85. });
  86. } else {
  87. return [];
  88. }
  89. };
  90. if (modelManageEditInfo && modelManageEditInfo.sample) {
  91. this.setState({
  92. ...this.state,
  93. tmpList: sample,
  94. selectedRows: getIds(sample),
  95. });
  96. } else if (pageId) {
  97. getModelDetails(pageId).then((result) => {
  98. const selectedsample = result[0].selectedFeatureSample.obj.selectedSample.records;
  99. if (selectedsample) {
  100. this.setState({
  101. ...this.state,
  102. tmpList: selectedsample,
  103. selectedRows: getIds(selectedsample),
  104. });
  105. }
  106. });
  107. }
  108. }
  109. handleSelectRows = (rows = [], rowKeys = []) => {
  110. this.setState({
  111. ...this.state,
  112. selectedRows: rowKeys, // 回显已选样式
  113. tmpList: rows,
  114. });
  115. }
  116. saveData = () => {
  117. const { dispatch, pageGlobal: { modelManageEditInfo } } = this.props;
  118. const { tmpList } = this.state;
  119. dispatch({
  120. type: 'pageGlobal/setModelManageEditInfo',
  121. payload: {
  122. ...modelManageEditInfo,
  123. sample: tmpList,
  124. },
  125. });
  126. }
  127. // 查看更多
  128. handleVisibleChange = (e, record) => {
  129. if (e) {
  130. const param = {
  131. sampleId: record.id,
  132. };
  133. getSampleVersion(param).then((result) => {
  134. this.setState({
  135. ...this.state,
  136. check: true,
  137. detailsData: result,
  138. prevSelected: record,
  139. });
  140. });
  141. }
  142. };
  143. detailsColumns = [
  144. {
  145. title: '样本名称',
  146. dataIndex: 'name',
  147. align: 'left',
  148. }, {
  149. title: '样本描述',
  150. dataIndex: 'comment',
  151. align: 'left',
  152. render: (text, record) => (
  153. <div>
  154. <p>正样本:{record.posComment}</p>
  155. <p>负样本:{record.negComment}</p>
  156. <Ellipsis lines={2}>{text}</Ellipsis>
  157. </div>
  158. ),
  159. }, {
  160. title: '版本号',
  161. dataIndex: 'version',
  162. align: 'left',
  163. }, {
  164. title: '创建时间',
  165. dataIndex: 'createTime',
  166. align: 'left',
  167. render: text => (
  168. <span>{formatTime(text)}</span>
  169. ),
  170. }];
  171. // 列表查询方法
  172. search = () => {
  173. const { location } = this.props;
  174. const pageId = parse(location.search.substr(1)).recordId;
  175. const param = {
  176. modelId: pageId,
  177. name: this.state.searchName,
  178. pageNum: 1,
  179. };
  180. this.getSampelData(param);
  181. };
  182. // 搜索
  183. handleFormSubmit = (val) => {
  184. this.setState({ searchName: val }, () => {
  185. this.search(this.state.searchName);
  186. });
  187. };
  188. // 页面切换 /状态切换
  189. handleStandardTableChange = (pagination) => {
  190. const { location } = this.props;
  191. const pageId = parse(location.search.substr(1)).recordId;
  192. const param = {
  193. modelId: pageId,
  194. name: this.state.searchName,
  195. pageNum: pagination.current,
  196. pageSize: pagination.pageSize,
  197. };
  198. this.getSampelData(param);
  199. };
  200. prev = () => {
  201. const { dispatch, location } = this.props;
  202. const pageId = parse(location.search.substr(1)).recordId;
  203. this.saveData();
  204. if (pageId) {
  205. dispatch(routerRedux.push({
  206. pathname: '/modelManage/addNewModel/selectFeature',
  207. search: `?recordId=${pageId}`,
  208. }));
  209. } else {
  210. dispatch(routerRedux.push({
  211. pathname: '/modelManage/addNewModel/selectFeature',
  212. }));
  213. }
  214. };
  215. // 提交
  216. next = () => {
  217. const { dispatch, location } = this.props;
  218. const pageId = parse(location.search.substr(1)).recordId;
  219. const { selectedRows } = this.state;
  220. if (selectedRows && selectedRows.length > 0) {
  221. const step1info = global.react.props.pageGlobal.modelManageEditInfo;
  222. // 已选样本id
  223. // const sampleid = this.state.data.list[0].id;
  224. if (pageId) {
  225. const param = {
  226. addIdList: step1info.ids,
  227. model: {
  228. id: pageId,
  229. analysisType: step1info.analysisType,
  230. comment: step1info.comment,
  231. deptId: step1info.deptId,
  232. userId: step1info.userId,
  233. name: step1info.name,
  234. sampleId: selectedRows[0],
  235. },
  236. };
  237. editSubmission(param).then((result) => {
  238. if (result) {
  239. dispatch(routerRedux.push('/modelManage/addNewModel/finish'));
  240. }
  241. });
  242. } else {
  243. const param = {
  244. addIdList: step1info.ids,
  245. model: {
  246. analysisType: step1info.analysisType,
  247. comment: step1info.comment,
  248. deptId: step1info.deptId,
  249. userId: step1info.userId,
  250. name: step1info.name,
  251. sampleId: selectedRows[0],
  252. },
  253. };
  254. newSubmission(param).then((result) => {
  255. if (result) {
  256. dispatch(routerRedux.push('/modelManage/addNewModel/finish'));
  257. }
  258. });
  259. }
  260. } else {
  261. message.warn('请选择样本!');
  262. }
  263. };
  264. render() {
  265. const { selectedRows, SampleData } = this.state;
  266. const data = {
  267. list: this.state.detailsData,
  268. pagination: false,
  269. };
  270. // 处理数据
  271. const displayData = (obj) => {
  272. const { tmpList = [] } = this.state;
  273. // const prevId = prevSelectedRows;
  274. const Id = selectedRows[0] || null;
  275. const newList = obj.list ? [...obj.list] : [];
  276. const newKeysList = newList.map((v) => {
  277. return v.id;
  278. });
  279. if (Id && newKeysList.indexOf(Id) < 0) { // 若当前点击的不包含在源列表中
  280. const lists = newList.map((v) => {
  281. return v.code === tmpList[0].code ? tmpList[0] : v;
  282. });
  283. return {
  284. ...obj,
  285. list: lists,
  286. };
  287. } else {
  288. return obj;
  289. }
  290. };
  291. const content = (
  292. <StandardTable
  293. onSelectRow={this.handleSelectRows}
  294. selectedRows={selectedRows}
  295. data={data}
  296. type="radio"
  297. showTitle={false}
  298. size="small"
  299. columns={this.detailsColumns}
  300. onChange={this.handleStandardTableChange}
  301. rowKey="id"
  302. bordered
  303. />
  304. );
  305. const columns = [{
  306. title: '样本名称',
  307. dataIndex: 'name',
  308. }, {
  309. title: '样本描述',
  310. dataIndex: 'comment',
  311. align: 'left',
  312. render: (text, record) => (
  313. <div>
  314. <p>正样本:{record.posComment}</p>
  315. <p>负样本:{record.negComment}</p>
  316. <Ellipsis lines={2}>{text}</Ellipsis>
  317. </div>
  318. ),
  319. }, {
  320. title: '版本号',
  321. dataIndex: 'version',
  322. align: 'center',
  323. render: text => (
  324. <span>v{text}</span>
  325. ),
  326. }, {
  327. title: '创建时间',
  328. dataIndex: 'createTime',
  329. render: text => (
  330. <span>{formatTime(text)}</span>
  331. ),
  332. }, {
  333. title: '操作',
  334. dataIndex: 'operate',
  335. align: 'left',
  336. render: (text, record) => (
  337. <Popover placement="bottomRight" trigger="click" onVisibleChange={e => this.handleVisibleChange(e, record)} content={content}>
  338. <a>更多<Icon className={styles.linkText} type="down" /></a>
  339. </Popover>
  340. ),
  341. },
  342. ];
  343. const mainSearch = (
  344. <Input.Search
  345. placeholder="请输入样本名称、样本描述"
  346. enterButton="搜索"
  347. onSearch={this.handleFormSubmit}
  348. style={{ width: 300 }}
  349. />
  350. );
  351. return (
  352. <Fragment>
  353. <Card bordered={false}>
  354. <div style={{ textAlign: 'right', marginBottom: 16 }}>
  355. {mainSearch}
  356. </div>
  357. <h3>已选样本</h3>
  358. <Table
  359. dataSource={this.state.tmpList}
  360. columns={columns}
  361. pagination={false}
  362. rowKey="id"
  363. bordered
  364. />
  365. <h3 style={{ marginTop: 16 }}>可选样本 ( 单击以下某一行即可选中您需要的样本 )</h3>
  366. <StandardTable
  367. onSelectRow={this.handleSelectRows}
  368. selectedRows={selectedRows}
  369. type="radio"
  370. data={displayData(SampleData)}
  371. columns={columns}
  372. onChange={this.handleStandardTableChange}
  373. rowKey="id"
  374. bordered
  375. />
  376. </Card>
  377. <Card bordered={false} className={styles.btnGroup}>
  378. <Button onClick={this.prev} >上一步</Button>
  379. <Button type="primary" onClick={this.next} style={{ marginLeft: 32 }}>提交</Button>
  380. </Card>
  381. </Fragment>
  382. );
  383. }
  384. }
Add Comment
Please, Sign In to add comment