index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import PageContent from '@/components/PageContent';
  2. import TabsContent from '@/components/TabsContent';
  3. import { MandateType, OrderType } from '@/pages/TaskManage/constent';
  4. import { getMandateList } from '@/services/TaskManage';
  5. import { CaretLeftFilled, CaretRightFilled } from '@ant-design/icons';
  6. import {
  7. connect,
  8. history,
  9. useLocation,
  10. useNavigate,
  11. useParams,
  12. } from '@umijs/max';
  13. import { List, Spin } from 'antd';
  14. import { useEffect, useState } from 'react';
  15. import styles from './index.less';
  16. const MyTask = (props) => {
  17. const { userList, dispatch } = props;
  18. const { projectId } = useParams();
  19. const project_id = Number(projectId === '' ? '0' : projectId);
  20. const location = useLocation();
  21. const queryParams = new URLSearchParams(location.search);
  22. const userID = queryParams.get('user_id');
  23. const navigate = useNavigate();
  24. const [mandateCount, setMandateCount] = useState([0, 0, 0]);
  25. const [loading, setLoading] = useState(false);
  26. const [tab, setTab] = useState(localStorage.taskTab || '1');
  27. useEffect(() => {
  28. const requests = [];
  29. for (let i = 0; i < 4; i++) {
  30. requests.push(
  31. getMandateList({
  32. project_id,
  33. pageSize: 1,
  34. currentPage: 1,
  35. mandate_type: i + 1,
  36. responsible_people: userID !== null ? Number(userID) : '',
  37. }),
  38. );
  39. }
  40. setLoading(true);
  41. Promise.all(requests)
  42. .then((resList) => {
  43. if (resList.filter((item) => item.code !== 200).length) {
  44. throw new Error('请求错误');
  45. }
  46. const typeCount = [0, 0, 0, 0];
  47. resList.forEach((item, index) => {
  48. typeCount[index] = item.data.pagination?.total;
  49. });
  50. setMandateCount(typeCount);
  51. })
  52. .catch((err) => {
  53. console.log(err);
  54. })
  55. .finally(() => {
  56. setLoading(false);
  57. });
  58. }, []);
  59. useEffect(() => {
  60. if (userList.length === 0) {
  61. dispatch({
  62. type: 'taskUser/fetchUserList',
  63. payload: { project_id },
  64. });
  65. }
  66. }, []);
  67. const onTabChange = (key) => {
  68. setTab(key);
  69. localStorage.setItem('taskTab', key);
  70. };
  71. const goTaskList = (item) => {
  72. navigate(
  73. `/center/my-task/task-list?project_id=${project_id}&mandateType=${item}${
  74. userID !== null ? '&user_id=' + userID : ''
  75. }`,
  76. );
  77. };
  78. const goWorkOrderList = (item) => {
  79. navigate(
  80. `/center/my-task/work-order-list?project_id=${project_id}&order_type=${item}${
  81. userID !== null ? '&user_id=' + userID : ''
  82. }`,
  83. );
  84. };
  85. const makeTaskList = (item, index) => {
  86. return (
  87. <List.Item
  88. className={styles.listItem}
  89. onClick={() => {
  90. goTaskList(item.value);
  91. }}
  92. >
  93. <List.Item.Meta
  94. title={<span className={styles.itemLabel}>{item.label}</span>}
  95. />
  96. {/* <div className={styles.itemCount}>
  97. <div className={styles.countNumber}>{mandateCount[index]}</div>
  98. <div className={styles.counterText}>任务数量</div>
  99. </div> */}
  100. <CaretRightFilled style={{ fontSize: '0.34rem', color: '#BCBABA' }} />
  101. </List.Item>
  102. );
  103. };
  104. const makeWorkOrderList = (item) => {
  105. return (
  106. <List.Item
  107. className={styles.listItem}
  108. onClick={() => {
  109. goWorkOrderList(item.value);
  110. }}
  111. >
  112. <List.Item.Meta
  113. title={<span className={styles.itemLabel}>{item.label}</span>}
  114. />
  115. <CaretRightFilled style={{ fontSize: '0.3rem', color: '#BCBABA' }} />
  116. </List.Item>
  117. );
  118. };
  119. return (
  120. <PageContent closeable={false}>
  121. <CaretLeftFilled
  122. style={{
  123. fontSize: '0.3rem',
  124. cursor: 'pointer',
  125. marginRight: '0.15rem',
  126. color: '#0139F1',
  127. position: 'absolute',
  128. left: '0.5rem',
  129. top: '0.5rem',
  130. }}
  131. onClick={() => history.back()}
  132. />
  133. <TabsContent
  134. defaultActiveKey={tab}
  135. onChange={onTabChange}
  136. items={[
  137. {
  138. label: `我的任务`,
  139. key: '1',
  140. children: (
  141. <div className={styles.container}>
  142. <Spin spinning={loading}>
  143. <List
  144. className={styles.taskList}
  145. bordered
  146. itemLayout="horizontal"
  147. dataSource={MandateType}
  148. renderItem={makeTaskList}
  149. pagination={false}
  150. />
  151. </Spin>
  152. </div>
  153. ),
  154. },
  155. {
  156. label: `我的工单`,
  157. key: '2',
  158. children: (
  159. <div className={styles.container}>
  160. <Spin spinning={false}>
  161. <List
  162. className={styles.taskList}
  163. bordered
  164. itemLayout="horizontal"
  165. dataSource={OrderType}
  166. renderItem={makeWorkOrderList}
  167. pagination={false}
  168. />
  169. </Spin>
  170. </div>
  171. ),
  172. },
  173. ]}
  174. />
  175. </PageContent>
  176. );
  177. };
  178. export default connect(({ taskUser }) => {
  179. return {
  180. userList: taskUser.userList,
  181. };
  182. })(MyTask);