index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import React, { Component } from 'react';
  2. import { Card, Form, Input, Select, Switch, Tooltip, Button, message } from 'antd';
  3. import { routerRedux } from 'dva/router';
  4. import { connect } from 'dva';
  5. import queryString from 'query-string';
  6. import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
  7. import CampusSelectModal from './campus';
  8. import { Codes, pageSize } from '../../../utils/config';
  9. import { getLocalUser } from '../../../utils/helper';
  10. @Form.create()
  11. @connect(state => ({
  12. terminalDetail: state.terminalDetail,
  13. campus: state.campus,
  14. }))
  15. export default class TerminalProfile extends Component {
  16. handleCampusSelectClick = () => {
  17. const { merchantId } = getLocalUser();
  18. this.props.dispatch({ type: 'terminalDetail/showModal' });
  19. // 获取该渠道下的所属校区
  20. this.props.dispatch({
  21. type: 'campus/query',
  22. payload: { pageNo: 1, pageSize, merchantId },
  23. });
  24. }
  25. handleCampusModalOk = (data) => {
  26. this.props.dispatch({
  27. type: 'terminalDetail/saveCampus',
  28. payload: data,
  29. });
  30. }
  31. handleCampusModalCancel = () => {
  32. this.props.dispatch({ type: 'terminalDetail/hideModal' });
  33. }
  34. handleCampusModalSearch = () => {
  35. }
  36. handleCampusModalTableChange = () => {
  37. }
  38. handlePageCancel = () => {
  39. const { dispatch, terminalDetail } = this.props;
  40. const { filters } = terminalDetail;
  41. dispatch(routerRedux.push({
  42. pathname: '/terminal',
  43. search: queryString.stringify(filters),
  44. }));
  45. }
  46. handlePageSubmit = (e) => {
  47. e.preventDefault();
  48. const { dispatch, form, terminalDetail } = this.props;
  49. const { validateFields, getFieldsValue } = form;
  50. const { currentItem, operType, filters } = terminalDetail;
  51. const { campusId, id, status } = currentItem;
  52. validateFields((errors) => {
  53. if (errors) return;
  54. if (!campusId) {
  55. message.error('请选择校区!');
  56. return;
  57. }
  58. const data = { ...getFieldsValue(), campusId };
  59. if (operType === 'create') {
  60. data.status = Codes.CODE_NORMAL;
  61. } else if (operType === 'update') {
  62. data.status = status;
  63. data.id = id;
  64. }
  65. dispatch({
  66. type: `terminalDetail/${operType}`,
  67. payload: data,
  68. callback: () => {
  69. dispatch(routerRedux.push({
  70. pathname: '/terminal',
  71. search: queryString.stringify(filters),
  72. }));
  73. },
  74. });
  75. });
  76. }
  77. render() {
  78. const { form, terminalDetail, campus } = this.props;
  79. const { currentItem, modalShow, operType } = terminalDetail;
  80. const { name, password, status, campusId, campusName, campusCode } = currentItem;
  81. const { getFieldDecorator } = form;
  82. const formItemLayout = {
  83. labelCol: {
  84. xs: { span: 24 },
  85. sm: { span: 7 },
  86. md: { span: 8 },
  87. },
  88. wrapperCol: {
  89. xs: { span: 24 },
  90. sm: { span: 12 },
  91. md: { span: 10 },
  92. },
  93. };
  94. const submitFormLayout = {
  95. wrapperCol: {
  96. xs: { span: 24, offset: 0 },
  97. sm: { span: 10, offset: 8 },
  98. },
  99. };
  100. return (
  101. <PageHeaderLayout>
  102. <Card title="终端用户">
  103. <Form layout="horizontal" onSubmit={this.handlePageSubmit}>
  104. <Form.Item hasFeedback label="所属校区" {...formItemLayout}>
  105. <Tooltip placement="top" title="点击选择校区">
  106. <Button disabled={operType === 'update'} style={{ marginRight: 20 }} type="primary" size="small" icon="select" onClick={this.handleCampusSelectClick}>选择</Button>
  107. </Tooltip>
  108. {campusName && <strong>{`${campusName}`}</strong>}
  109. </Form.Item>
  110. <Form.Item label="终端名称:" hasFeedback {...formItemLayout}>
  111. {getFieldDecorator('name', {
  112. initialValue: name,
  113. })(<Input placeholder="请输入(例: 教室三/教室四...)" />)}
  114. </Form.Item>
  115. {operType === 'create' ? (
  116. <Form.Item label="终端密码:" hasFeedback {...formItemLayout}>
  117. {getFieldDecorator('password', {
  118. rules: [{ required: true, type: 'string', message: '密码为必填项!' }],
  119. initialValue: password,
  120. })(<Input placeholder="请输入" />)}
  121. </Form.Item>
  122. ) : (
  123. <Form.Item label="终端密码:" hasFeedback {...formItemLayout}>
  124. {getFieldDecorator('password', {
  125. initialValue: password,
  126. })(<Input placeholder="修改密码时填写" />)}
  127. </Form.Item>
  128. )}
  129. <Form.Item label="账号状态:" {...formItemLayout}>
  130. {getFieldDecorator('status', {
  131. valuePropsName: 'checked',
  132. })(
  133. <Switch
  134. defaultChecked={status === Codes.CODE_NORMAL}
  135. checkedChildren="使用中"
  136. unCheckedChildren="禁用中"
  137. />
  138. )}
  139. </Form.Item>
  140. <Form.Item {...submitFormLayout} style={{ marginTop: 32 }}>
  141. <Button onClick={this.handlePageCancel}>取消</Button>
  142. <Button type="primary" style={{ marginLeft: 35 }} htmlType="submit">提交</Button>
  143. </Form.Item>
  144. </Form>
  145. {/* 校区模态选择框 */}
  146. <CampusSelectModal
  147. rowKeyName="id"
  148. modalVisible={modalShow}
  149. style={{ top: 20 }}
  150. width={600}
  151. onOk={this.handleCampusModalOk}
  152. onCancel={this.handleCampusModalCancel}
  153. onSearch={this.handleCampusModalSearch}
  154. fsTableDataSource={campus.list || []}
  155. fsTableLoading={campus.listLoading}
  156. fsTablePagination={campus.pagination}
  157. fsTableOnChange={this.handleCampusModalTableChange}
  158. />
  159. </Card>
  160. </PageHeaderLayout>
  161. );
  162. }
  163. }