AccountsTerminals.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import React, { Component } from 'react';
  2. import moment from 'moment';
  3. import { connect } from 'dva';
  4. import { Card, Badge, Modal, Form } from 'antd';
  5. import { StandardTableList } from '../../../components/AXList';
  6. import { addRowKey } from '../../../utils/utils';
  7. import styles from './AccountsTerminals.less';
  8. import AXRemoteSelect from '../../../components/AXRemoteSelect';
  9. const formItemLayout = {
  10. labelCol: {
  11. xs: { span: 24 },
  12. sm: { span: 7 },
  13. },
  14. wrapperCol: {
  15. xs: { span: 24 },
  16. sm: { span: 15 },
  17. md: { span: 13 },
  18. },
  19. };
  20. function arrayDataFormatter(data) {
  21. return data.map((item) => {
  22. return {
  23. text: item.name,
  24. value: `${item.name}||${item.id}`,
  25. };
  26. });
  27. }
  28. @Form.create()
  29. @connect(({ loading, accounts, campus }) => ({
  30. accounts,
  31. campus,
  32. loading: loading.models.accounts,
  33. fetching: loading.models.campus,
  34. }))
  35. export default class TerminalsAccountsPage extends Component {
  36. constructor(props) {
  37. super(props);
  38. const { state } = props.location;
  39. this.state = {
  40. UIParams: (state || {}).UIParams, // 组件的状态参数
  41. Queryers: (state || {}).Queryers, // 查询的条件参数
  42. campuses: (state || {}).campuses || [], // 记录筛选的校区
  43. filterModalDestroy: true,
  44. };
  45. }
  46. componentWillMount() {
  47. const { campuses } = this.state;
  48. let campusId;
  49. if (campuses && campuses.length) {
  50. campusId = campuses[0].split('||')[1];
  51. }
  52. this.props.dispatch({
  53. type: 'accounts/fetchTerminalsList',
  54. payload: {
  55. campusId,
  56. ...this.state.Queryers,
  57. },
  58. });
  59. }
  60. handleDownloadOperation = () => {
  61. this.props.dispatch({
  62. type: 'accounts/fetchTerminalsExcel',
  63. });
  64. };
  65. handleFilterOperation = (params, states) => {
  66. this.setState({
  67. UIParams: states,
  68. Queryers: params,
  69. });
  70. this.props.dispatch({
  71. type: 'accounts/fetchTerminalsList',
  72. payload: {
  73. ...params,
  74. },
  75. });
  76. };
  77. handleFilterModalShow = () => {
  78. this.setState({ filterModalDestroy: false });
  79. };
  80. handleFilterModalDestroy = () => {
  81. this.setState({ filterModalDestroy: true });
  82. };
  83. handleModalFilterOperation = () => {
  84. const { getFieldsValue } = this.props.form;
  85. const { campuses } = getFieldsValue();
  86. let campusId;
  87. if (campuses && campuses.length) {
  88. campusId = campuses[0].split('||')[1];
  89. }
  90. this.props.dispatch({
  91. type: 'accounts/fetchTerminalsList',
  92. payload: {
  93. campusId,
  94. ...this.state.Queryers,
  95. },
  96. });
  97. this.handleFilterModalDestroy();
  98. this.setState({ campuses });
  99. };
  100. handleTerminalsRemoteSelectSearch = (value) => {
  101. this.props.dispatch({
  102. type: 'campus/fetchCampusList',
  103. payload: {
  104. pageSize: 50,
  105. name: value,
  106. },
  107. });
  108. };
  109. render() {
  110. const { campuses } = this.state;
  111. const { loading, accounts, fetching, campus, form } = this.props;
  112. const { list, totalSize, pageSize, pageNo } = accounts;
  113. const { getFieldDecorator } = form;
  114. const basicSearch = {
  115. keys: [{
  116. name: '终端编号',
  117. field: 'code',
  118. }],
  119. };
  120. const pagination = {
  121. pageNo,
  122. pageSize,
  123. totalSize,
  124. };
  125. const columns = [{
  126. title: '终端编号',
  127. key: 1,
  128. dataIndex: 'ucode',
  129. width: '15%',
  130. }, {
  131. title: '课程包编号',
  132. key: 2,
  133. dataIndex: 'pcode',
  134. width: '10%',
  135. }, {
  136. title: '课程包名称',
  137. key: 3,
  138. dataIndex: 'pname',
  139. width: '15%',
  140. }, {
  141. title: '权限有效期',
  142. key: 4,
  143. render: (_, record) => {
  144. const { startTimeStr, endTimeStr } = record;
  145. return (
  146. <div className={styles.authDesc}>
  147. <p><span>起始时间:&nbsp;&nbsp;</span>{`${startTimeStr}`}</p>
  148. <p><span>到期时间:&nbsp;&nbsp;</span>{`${endTimeStr}`}</p>
  149. </div>
  150. );
  151. },
  152. dataIndex: 'cityName',
  153. width: '15%',
  154. align: 'center',
  155. }, {
  156. title: '权限有效时长',
  157. key: 5,
  158. dataIndex: 'endTime',
  159. render: (text) => {
  160. const day = moment(text).diff(moment(), 'days');
  161. if (day < 0) {
  162. return <Badge status="error" text="已到期" />;
  163. }
  164. return <span><span style={{ color: '#52c41a', fontWeight: 'bold' }}>{day}</span>天到期</span>;
  165. },
  166. width: '10%',
  167. }, {
  168. title: '校区名称',
  169. key: 6,
  170. dataIndex: 'campusName',
  171. width: '16%',
  172. }, {
  173. title: '联系电话',
  174. key: 7,
  175. dataIndex: 'campusContactWay',
  176. width: '12%',
  177. }, {
  178. title: '联系人',
  179. key: 8,
  180. dataIndex: 'campusContactName',
  181. width: '6%',
  182. }];
  183. return (
  184. <Card>
  185. <StandardTableList
  186. columns={columns}
  187. loading={loading}
  188. dataSource={addRowKey(list)}
  189. header={{
  190. basicSearch,
  191. onAdvanceFilterClick: this.handleFilterModalShow,
  192. onFilterClick: this.handleFilterOperation,
  193. onDownload: this.handleDownloadOperation,
  194. }}
  195. footer={{
  196. pagination,
  197. }}
  198. keepUIState={{ ...this.state.UIParams }}
  199. showStatusSelect={false}
  200. />
  201. {!this.state.filterModalDestroy && (
  202. <Modal
  203. width={600}
  204. visible
  205. title="高级筛选"
  206. okText="筛选"
  207. cancelText="取消"
  208. maskClosable={false}
  209. onCancel={this.handleFilterModalDestroy}
  210. onOk={this.handleModalFilterOperation}
  211. >
  212. <Form>
  213. <Form.Item label="所属校区" {...formItemLayout}>
  214. {getFieldDecorator('campuses', {
  215. initialValue: campuses,
  216. })(
  217. <AXRemoteSelect
  218. fetching={fetching}
  219. dataSource={arrayDataFormatter(campus.list)}
  220. onSearch={this.handleTerminalsRemoteSelectSearch}
  221. />
  222. )}
  223. </Form.Item>
  224. </Form>
  225. </Modal>
  226. )}
  227. </Card>
  228. );
  229. }
  230. }