PersonalizeList.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* eslint-disable prefer-destructuring */
  2. import React, { Component } from 'react';
  3. import moment from 'moment';
  4. import { connect } from 'dva';
  5. import { routerRedux } from 'dva/router';
  6. import { Card, Modal, Form, Button, message } from 'antd';
  7. import { StandardTableList } from '../../../components/AXList';
  8. import AXRemoteSelect from '../../../components/AXRemoteSelect';
  9. import Ellipsis from '../../../components/Ellipsis';
  10. import { addRowKey, renderStatus, renderBindStatus } from '../../../utils/utils';
  11. const Message = message;
  12. const formItemLayout = {
  13. labelCol: {
  14. xs: { span: 24 },
  15. sm: { span: 7 },
  16. },
  17. wrapperCol: {
  18. xs: { span: 24 },
  19. sm: { span: 15 },
  20. md: { span: 13 },
  21. },
  22. };
  23. function arrayDataFormatter(data) {
  24. return data.map((item) => {
  25. return {
  26. text: item.name,
  27. value: `${item.name}||${item.id}`,
  28. };
  29. });
  30. }
  31. @Form.create()
  32. @connect(({ loading, campus, merchant, terminal }) => ({
  33. campus,
  34. merchant,
  35. terminal,
  36. fetching1: loading.models.merchant,
  37. fetching2: loading.models.campus,
  38. loading: loading.models.terminal,
  39. }))
  40. export default class PersonalizeListPage extends Component {
  41. constructor(props) {
  42. super(props);
  43. const { state } = props.location;
  44. this.state = {
  45. UIParams: (state || {}).UIParams, // 组件的状态参数
  46. Queryers: (state || {}).Queryers, // 查询的条件参数
  47. merchants: (state || {}).merchants || [], // 记录筛选的渠道
  48. campuses: (state || {}).campuses || [], // 记录筛选的校区
  49. filterModalDestroy: true,
  50. };
  51. }
  52. componentWillMount() {
  53. this.props.dispatch({
  54. type: 'terminal/cleanState',
  55. });
  56. }
  57. componentDidMount() {
  58. const { merchants, campuses } = this.state;
  59. let merchantId;
  60. if (merchants && merchants.length) {
  61. merchantId = merchants[0].split('||')[1];
  62. }
  63. let campusId;
  64. if (campuses && campuses.length) {
  65. campusId = campuses[0].split('||')[1];
  66. }
  67. this.props.dispatch({
  68. type: 'terminal/fetchTerminalList',
  69. payload: {
  70. campusId,
  71. merchantId,
  72. ...this.state.Queryers,
  73. },
  74. });
  75. }
  76. handleEditOperation = (item) => {
  77. this.props.dispatch(routerRedux.push({
  78. pathname: `/frontend/personalize/edit/${item.id}`,
  79. state: {
  80. merchantId: item.merchantId,
  81. ...this.state,
  82. },
  83. }));
  84. };
  85. handleFilterOperation = (params, states) => {
  86. this.setState({
  87. UIParams: states,
  88. Queryers: params,
  89. });
  90. const { merchants, campuses } = this.state;
  91. let merchantId;
  92. if (merchants && merchants.length) {
  93. merchantId = merchants[0].split('||')[1];
  94. }
  95. let campusId;
  96. if (campuses && campuses.length) {
  97. campusId = campuses[0].split('||')[1];
  98. }
  99. this.props.dispatch({
  100. type: 'terminal/fetchTerminalList',
  101. payload: {
  102. campusId,
  103. merchantId,
  104. ...params,
  105. },
  106. });
  107. };
  108. handleModalFilterOperation = () => {
  109. const { getFieldsValue } = this.props.form;
  110. const { merchants, campuses } = getFieldsValue();
  111. let merchantId;
  112. if (merchants && merchants.length) {
  113. merchantId = merchants[0].split('||')[1];
  114. }
  115. let campusId;
  116. if (campuses && campuses.length) {
  117. campusId = campuses[0].split('||')[1];
  118. }
  119. this.props.dispatch({
  120. type: 'terminal/fetchTerminalList',
  121. payload: {
  122. ...this.state.Queryers,
  123. merchantId,
  124. campusId,
  125. },
  126. });
  127. this.setState({ merchants, campuses });
  128. this.handleFilterModalDestroy();
  129. };
  130. handleBatchOperation = () => {
  131. Message.info('暂不支持批量操作!');
  132. };
  133. handleFilterModalShow = () => {
  134. this.setState({ filterModalDestroy: false });
  135. };
  136. handleFilterModalDestroy = () => {
  137. this.setState({ filterModalDestroy: true });
  138. };
  139. handleMerchantRemoteSelectSearch = (value) => {
  140. this.props.dispatch({
  141. type: 'merchant/fetchMerchantList',
  142. payload: {
  143. pageSize: 50,
  144. name: value,
  145. },
  146. });
  147. };
  148. handleCampusRemoteSelectSearch = (value) => {
  149. this.props.dispatch({
  150. type: 'campus/fetchCampusList',
  151. payload: {
  152. pageSize: 50,
  153. name: value,
  154. },
  155. });
  156. };
  157. render() {
  158. const { merchants, campuses } = this.state;
  159. const { loading, fetching1, fetching2, form, campus, merchant, terminal } = this.props;
  160. const { list, totalSize, pageSize, pageNo } = terminal;
  161. const { getFieldDecorator } = form;
  162. const renderCampusName = (name) => {
  163. return (
  164. <Ellipsis tooltip lines={1}>{name}</Ellipsis>
  165. );
  166. };
  167. const renderOperation = (item) => {
  168. return (
  169. <div>
  170. <Button
  171. size="small"
  172. className="editBtn"
  173. onClick={() => this.handleEditOperation(item)}
  174. >用户配置
  175. </Button>
  176. </div>
  177. );
  178. };
  179. const batchActions = [{
  180. key: 'config',
  181. name: '批量配置',
  182. }];
  183. const basicSearch = {
  184. keys: [{
  185. name: '终端编号',
  186. field: 'code',
  187. }, {
  188. name: '终端名称',
  189. field: 'name',
  190. }],
  191. };
  192. const pagination = {
  193. pageNo,
  194. pageSize,
  195. totalSize,
  196. };
  197. const columns = [{
  198. title: '终端编号',
  199. key: 1,
  200. dataIndex: 'code',
  201. width: '15%',
  202. }, {
  203. title: '终端名称',
  204. key: 2,
  205. dataIndex: 'name',
  206. width: '12%',
  207. }, {
  208. title: '所属校区',
  209. key: 3,
  210. dataIndex: 'campusName',
  211. render: text => renderCampusName(text),
  212. width: '18%',
  213. }, {
  214. title: '所属渠道',
  215. key: 4,
  216. dataIndex: 'merchantName',
  217. width: '10%',
  218. }, {
  219. title: '账号状态',
  220. key: 5,
  221. dataIndex: 'status',
  222. render: text => renderStatus(text, '已禁用'),
  223. width: '8%',
  224. }, {
  225. title: '绑定状态',
  226. key: 6,
  227. dataIndex: 'deviceStatus',
  228. render: text => renderBindStatus(text),
  229. width: '9%',
  230. }, {
  231. title: '更新时间',
  232. key: 7,
  233. dataIndex: 'gmtModified',
  234. render: text => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  235. width: '15%',
  236. }, {
  237. title: '操作',
  238. key: 8,
  239. dataIndex: 'operation',
  240. render: (_, record) => renderOperation(record),
  241. width: '13%',
  242. align: 'right',
  243. }];
  244. return (
  245. <Card>
  246. <StandardTableList
  247. columns={columns}
  248. loading={loading}
  249. dataSource={addRowKey(list)}
  250. header={{
  251. basicSearch,
  252. onAdvanceFilterClick: this.handleFilterModalShow,
  253. onFilterClick: this.handleFilterOperation,
  254. onCreateClick: this.handleCreateOperation,
  255. }}
  256. footer={{
  257. pagination,
  258. batchActions,
  259. onBatchClick: this.handleBatchOperation,
  260. }}
  261. keepUIState={{ ...this.state.UIParams }}
  262. />
  263. {!this.state.filterModalDestroy && (
  264. <Modal
  265. width={600}
  266. visible
  267. title="高级筛选"
  268. okText="筛选"
  269. cancelText="取消"
  270. maskClosable={false}
  271. onCancel={this.handleFilterModalDestroy}
  272. onOk={this.handleModalFilterOperation}
  273. >
  274. <Form>
  275. <Form.Item label="所属商户" {...formItemLayout}>
  276. {getFieldDecorator('merchants', {
  277. initialValue: merchants,
  278. })(
  279. <AXRemoteSelect
  280. fetching={fetching1}
  281. dataSource={arrayDataFormatter(merchant.list)}
  282. onSearch={this.handleMerchantRemoteSelectSearch}
  283. />
  284. )}
  285. </Form.Item>
  286. <Form.Item label="所属校区" {...formItemLayout}>
  287. {getFieldDecorator('campuses', {
  288. initialValue: campuses,
  289. })(
  290. <AXRemoteSelect
  291. fetching={fetching2}
  292. dataSource={arrayDataFormatter(campus.list)}
  293. onSearch={this.handleCampusRemoteSelectSearch}
  294. />
  295. )}
  296. </Form.Item>
  297. </Form>
  298. </Modal>
  299. )}
  300. </Card>
  301. );
  302. }
  303. }