知与行后台管理端

StaffList.jsx 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Input, Button, Icon, Select, message, Table, Divider, Row, Col, Tag, Pagination, Modal, DatePicker } from 'antd';
  3. import { FormattedMessage } from 'umi-plugin-react/locale';
  4. import styles from '../../style/GoodsList.less';
  5. import router from 'umi/router';
  6. import { Card, Avatar } from 'antd';
  7. import apis from '../../../services/apis';
  8. import request from '../../../utils/request'
  9. import Styles from './style.less';
  10. const { Meta } = Card;
  11. const { Option } = Select;
  12. const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
  13. // 跳转到编辑商品
  14. const toEditStaff = (userId) => () => {
  15. router.push({
  16. pathname: '/staff/editStaff',
  17. query: {
  18. userId
  19. },
  20. });
  21. }
  22. /**
  23. *卡片
  24. *
  25. * @returns
  26. */
  27. const CartBody = (props) => {
  28. const { data } = props
  29. const confirm = (data) => () => {
  30. console.log(data,"11111")
  31. if(data.status === 1){
  32. Modal.confirm({
  33. title: '确认停用该角色?',
  34. okText: '确认',
  35. cancelText: '取消',
  36. onOk() {
  37. request({ ...apis.staff.change, urlData: {id:data.userId,type:'off'}}).then((data) => {
  38. message.info("操作成功")
  39. props.onFresh()
  40. })
  41. }
  42. });
  43. }else{
  44. Modal.confirm({
  45. title: '确认启用该角色?',
  46. okText: '确认',
  47. cancelText: '取消',
  48. onOk() {
  49. request({ ...apis.staff.change, urlData: {id:data.userId,type:'on'}}).then((data) => {
  50. message.info("操作成功")
  51. props.onFresh()
  52. })
  53. }
  54. });
  55. }
  56. }
  57. return (
  58. <Card className={Styles.card}>
  59. <div>
  60. <Avatar src={data.avatar} style={{ width: 94, height: 94 }} />
  61. <Button type="link" style={{ marginLeft: '10px', color: '#FF925C', fontSize: '18px' }} onClick={toEditStaff(data.userId)}>
  62. 编辑
  63. <Icon type="form" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
  64. </Button>
  65. <Button type="link" style={{ fontSize: '18px', color: '#cacaca', position: 'absolute', top: '50px', right: '0' }} onClick={confirm(data)}>
  66. {data.status === 1 ? '停用' : '启用'}
  67. <Icon type={data.status===1?'close-circle':'form'} style={{ color: '#C0C4CC', marginLeft: '8px' }} />
  68. </Button>
  69. {/* <Button type="link" style={{ fontSize: '18px', color: '#FF925C', position: 'absolute', top: '50px', right: '0' }} onClick={confirm}>
  70. 启用
  71. <Icon type="form" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
  72. </Button> */}
  73. </div>
  74. <div>
  75. <span>
  76. {
  77. data.taTagsList.map((item, index) => {
  78. return <Tag className={Styles.cardTag} color={item.tagColor}>{item.tagName}</Tag>
  79. })
  80. }
  81. </span>
  82. <p className={Styles.cardText} >姓名 : {data.userName}
  83. </p>
  84. <p className={Styles.statusText} > 状态 : {data.status === 1 ? '启用' : '停用'} </p>
  85. <p className={Styles.phoneText} >
  86. 电话 : {data.phone}
  87. </p>
  88. </div>
  89. </Card>
  90. )
  91. }
  92. const header = (props) => {
  93. const [tempData, setTempData] = useState([])
  94. useEffect(() => {
  95. getList({ pageNum: 1, pageSize: 10 });
  96. }, [])
  97. const getList = (params) => {
  98. request({ ...apis.staff.taUser, params: { ...params } }).then((data) => {
  99. console.log(data, "listData")
  100. setTempData(data.records)
  101. })
  102. }
  103. // 分页
  104. const onChange = (pageNumber) => {
  105. getList({ pageNum: pageNumber, pageSize: 10 });
  106. }
  107. // 提交事件
  108. const handleSubmit = (e, props) => {
  109. e.preventDefault();
  110. props.form.validateFields((err, values) => {
  111. if (!err) {
  112. console.log('提交数据: ', values)
  113. getList({ pageNum: 1, pageSize: 10, ...values })
  114. }
  115. });
  116. }
  117. const { getFieldDecorator } = props.form
  118. return (
  119. <>
  120. <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
  121. <Form.Item>
  122. {getFieldDecorator('userName')(
  123. <Input
  124. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  125. placeholder="姓名"
  126. />,
  127. )}
  128. </Form.Item>
  129. <Form.Item>
  130. {getFieldDecorator('phone')(
  131. <Input
  132. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  133. placeholder="电话"
  134. />,
  135. )}
  136. </Form.Item>
  137. <Form.Item>
  138. {getFieldDecorator('status')(
  139. <Select style={{ width: '180px' }} placeholder="状态" >
  140. <Option value="1">启用</Option>
  141. <Option value="0">停用</Option>
  142. </Select>,
  143. )}
  144. </Form.Item>
  145. <Form.Item>
  146. <Button type="primary" htmlType="submit" className={styles.searchBtn}>
  147. 搜索
  148. </Button>
  149. </Form.Item>
  150. </Form>
  151. <Button type="danger" style={{ margin: '20px 0', padding: '2px 36px' }} onClick={toEditStaff()}>新增</Button>
  152. <Row style={{ padding: ' 0 10px' }}>
  153. {
  154. tempData.map((item, index) => (
  155. <Col span={6}>
  156. <CartBody data={item} onFresh={()=> getList({ pageNum: 1, pageSize: 10 })}/>
  157. </Col>
  158. ))
  159. }
  160. </Row>
  161. {/* 分页 */}
  162. <div style={{ display: 'flex', justifyContent: 'flex-end' }}>
  163. <Pagination showQuickJumper defaultCurrent={1} total={tempData.total} onChange={onChange} />
  164. </div>
  165. </>
  166. )
  167. }
  168. const WrappedHeader = Form.create({ name: 'header' })(header);
  169. export default WrappedHeader