山西督察-superintend-distribute-web react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
4.4 KiB

  1. import React, { useState } from 'react';
  2. import { Tabs } from 'antd';
  3. import { connect, history } from 'umi';
  4. import ProvinceSelect from '@/components/ProvinceSelect';
  5. import { secondTabName } from '@/utils/utils';
  6. import { UserLevel, processTab } from '@/utils/constants';
  7. import TableList from './TableList';
  8. const { TabPane } = Tabs;
  9. const Progress = (props) => {
  10. const { user, isLocationInBu, locationType } = props;
  11. const tabList = processTab(locationType);
  12. const [activeKey, setActiveKey] = useState('department');
  13. const [selectdProvince, setSelectdProvince] = useState('');
  14. const [selectdCity, setSelectdCity] = useState('');
  15. const [showProvinceSelect, setShowProvinceSelect] = useState(isLocationInBu);
  16. const [departmentMsg, setDepartmentMsg] = useState(null);
  17. const [provinceMsg, setProvinceMsg] = useState(null);
  18. const [cityMsg, setCityMsg] = useState(null);
  19. const [ifReload, setIfReload] = useState(null); // 页面是否要重新加载 为从待办跳转过来准备
  20. const changeTab = (key) => {
  21. setActiveKey(key);
  22. setShowProvinceSelect(isLocationInBu);
  23. setDepartmentMsg(null);
  24. setProvinceMsg(null);
  25. setCityMsg(null);
  26. };
  27. if (props.location.params) {
  28. // 监控路由参数 点击消息跳转过来的会带params参数
  29. const { type, msg, reload } = props.location.params; // type: 展示tab类型 msg: 消息带过来的查询条件
  30. if (reload === ifReload) {
  31. // 防止不断循环
  32. return false;
  33. }
  34. setIfReload(reload);
  35. if (type === 'department') {
  36. // 跳转到部级下发
  37. setActiveKey(type);
  38. setDepartmentMsg(msg);
  39. } else if (type === 'province') {
  40. // 跳转到省级下发
  41. setShowProvinceSelect(false);
  42. setActiveKey(type);
  43. setProvinceMsg(msg);
  44. } else if (type === 'city') { // 跳转到市级下发
  45. setShowProvinceSelect(false);
  46. setActiveKey(type);
  47. setCityMsg(msg);
  48. }
  49. history.push('/progresssearch'); // 清空参数 防止误判
  50. }
  51. const onSelectProvince = (key) => {
  52. setSelectdProvince(key);
  53. setActiveKey('province');
  54. setShowProvinceSelect(false);
  55. };
  56. const onSelectCity = (key) => {
  57. setSelectdCity(key);
  58. setActiveKey('city');
  59. setShowProvinceSelect(false);
  60. }
  61. const renderContent = () => {
  62. console.log(props.dispatch);
  63. if (activeKey === 'department') {
  64. return (
  65. <TableList
  66. refesh={Math.random()}
  67. msg={departmentMsg}
  68. isLocationInBu={isLocationInBu}
  69. locationType={locationType}
  70. type="bu"
  71. sysToken={isLocationInBu ? '' : 'bu'}
  72. />
  73. );
  74. }
  75. if (activeKey === 'province') {
  76. if (showProvinceSelect) {
  77. return (
  78. <ProvinceSelect
  79. onSelectProvince={onSelectProvince}
  80. sysToken={isLocationInBu ? selectdProvince : ''}
  81. />
  82. );
  83. } else {
  84. return (
  85. <TableList
  86. msg={provinceMsg}
  87. refesh={Math.random()}
  88. isLocationInBu={isLocationInBu}
  89. locationType={locationType}
  90. type='sheng'
  91. sysToken={isLocationInBu ? selectdProvince : 'sheng'}
  92. />
  93. );
  94. }
  95. }
  96. if (activeKey === 'city'){
  97. return <TableList
  98. msg={cityMsg}
  99. refesh={Math.random()}
  100. isLocationInBu={isLocationInBu}
  101. locationType={locationType}
  102. type='shi'
  103. sysToken={'shi'}
  104. />
  105. }
  106. // return (
  107. // <TableList
  108. // msg={provinceMsg}
  109. // refesh={Math.random()}
  110. // isLocationInBu={isLocationInBu}
  111. // type="sheng"
  112. // sysToken={isLocationInBu ? selectdProvince : ''}
  113. // // sysToken={isLocationInBu ? '' : 'sheng'}
  114. // />
  115. // );
  116. };
  117. return (
  118. <div>
  119. <Tabs activeKey={activeKey} onChange={changeTab}>
  120. {/* <TabPane tab="" key="department"></TabPane>
  121. <TabPane tab={secondTabName(user.departmentOrgLevel)} key="province"></TabPane>
  122. <TabPane tab='省级平台' key='province'></TabPane>
  123. <TabPane tab='市级平台' key='city' forceRender={true} hidden={locationType}></TabPane> */}
  124. {
  125. tabList.map((item) => {
  126. return (
  127. <TabPane key={item.key}></TabPane>
  128. );
  129. })
  130. }
  131. </Tabs>
  132. {renderContent()}
  133. </div>
  134. );
  135. };
  136. export default connect(({ user }) => ({
  137. user: user.currentUser,
  138. isLocationInBu: user.isLocationInBu,
  139. locationType: user.locationType
  140. }))(Progress);