Auth.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. import React, { useState, useEffect, useMemo } from 'react';
  2. import { Table, Button, Form, Divider, Modal, Popover, Input, Select } from 'antd';
  3. import moment from 'moment';
  4. import router from 'umi/router';
  5. import styles from './List.less';
  6. import AuthModal from './AuthModal';
  7. import DetailModal from './DetailModal';
  8. import RejectModal from '../WorkingHours/RejectModal';
  9. import { connect } from 'dva';
  10. const { Option } = Select;
  11. //状态
  12. const STATUS = [
  13. {
  14. value: 0,
  15. label: '售前',
  16. },
  17. {
  18. value: 1,
  19. label: '转执行',
  20. },
  21. {
  22. value: 2,
  23. label: '转运营',
  24. },
  25. {
  26. value: 3,
  27. label: '转质保',
  28. },
  29. ];
  30. function Auth(props) {
  31. const { industryList, typeList, data, flowList, currentUser, depRole, dispatch, loading } = props;
  32. const [form] = Form.useForm();
  33. const [visible, setVisible] = useState(false);
  34. const [detailVisible, setDetailVisible] = useState(false);
  35. const [rejectVisible, setRejectVisible] = useState(false);
  36. const [currentItem, setCurrentItem] = useState({});
  37. const columns = [
  38. {
  39. title: '项目编号',
  40. dataIndex: 'project_full_code',
  41. },
  42. {
  43. title: '项目名称',
  44. dataIndex: 'project_name',
  45. },
  46. {
  47. title: '分类',
  48. dataIndex: 'TypeInfo',
  49. render: TypeInfo => (TypeInfo ? `${TypeInfo.name}(${TypeInfo.code})` : '-'),
  50. },
  51. /*
  52. {
  53. title: '名称',
  54. dataIndex: 'name',
  55. },
  56. {
  57. title: '行业',
  58. dataIndex: 'IndustryInfo',
  59. render: IndustryInfo => `${IndustryInfo.name}(${IndustryInfo.code})`,
  60. },
  61. {
  62. title: '所在地',
  63. dataIndex: 'location',
  64. render: (location, record) => `${location}(${record.location_code})`,
  65. },
  66. {
  67. title: '期数',
  68. dataIndex: 'version',
  69. render: version => `${version}期`,
  70. },
  71. */
  72. {
  73. title: '流程',
  74. dataIndex: ['FlowInfo', 'name'],
  75. },
  76. {
  77. title: '状态',
  78. dataIndex: 'project_status',
  79. render: project_status => {
  80. // return project_status === 0 ? <>售前</> : <>转执行</>;
  81. //若添加其他状态则启用以下switch case:
  82. switch (project_status) {
  83. case 0:
  84. return <>售前</>;
  85. case 1:
  86. return <>转执行</>;
  87. case 2:
  88. return <>转运营</>;
  89. case 3:
  90. return <>转质保</>;
  91. }
  92. },
  93. },
  94. {
  95. title: '节点',
  96. dataIndex: 'NodeInfo',
  97. render: (nodeInfo, item) => {
  98. let statusDom;
  99. switch (item.audit_status) {
  100. case 0:
  101. statusDom = '待提交';
  102. break;
  103. case 1:
  104. statusDom = <span style={{ color: '#1890ff' }}>审核中</span>;
  105. break;
  106. case 2:
  107. statusDom = (
  108. <Popover content={`拒绝原因: ${item.audit_comment}`}>
  109. <span style={{ color: '#f5222d' }}>审核拒绝</span>
  110. </Popover>
  111. );
  112. break;
  113. case 3:
  114. statusDom = <span style={{ color: '#a0d911' }}>审核通过</span>;
  115. break;
  116. }
  117. return (
  118. <>
  119. {nodeInfo.node}({statusDom})
  120. </>
  121. );
  122. },
  123. },
  124. {
  125. title: '售前项目经理',
  126. dataIndex: 'AuthorUser',
  127. render: AuthorUser => (AuthorUser ? AuthorUser.CName : '-'),
  128. },
  129. {
  130. title: '创建时间',
  131. dataIndex: 'c_time',
  132. render: c_time => moment(c_time).format('YYYY.MM.DD'),
  133. },
  134. {
  135. title: '执行经理',
  136. dataIndex: 'Leader',
  137. render: Leader => (Leader ? Leader.CName : '-'),
  138. },
  139. {
  140. title: '操作',
  141. render: record => (
  142. <>
  143. <a
  144. onClick={() => {
  145. setCurrentItem(record);
  146. setDetailVisible(true);
  147. }}
  148. >
  149. 项目详情
  150. </a>
  151. <Divider type="vertical" />
  152. <a
  153. onClick={() => {
  154. setCurrentItem(record);
  155. setVisible(true);
  156. }}
  157. >
  158. 审核详情
  159. </a>
  160. </>
  161. ),
  162. },
  163. ];
  164. const canAuth = useMemo(() => {
  165. let { NodeInfo, audit_status, project_status } = currentItem;
  166. if (!NodeInfo || flowList.length == 0 || depRole.length == 0) return;
  167. if (audit_status != 1) return;
  168. let flow = flowList.find(item => item.id == NodeInfo.flow_id);
  169. if (!flow) return false;
  170. if (project_status == 2) return currentItem.opt_manager_id == currentUser.ID;
  171. if (project_status == 3) return currentItem.wty_manager_id == currentUser.ID;
  172. let { NodeAudits } = flow.Nodes.find(item => item.id == NodeInfo.id);
  173. const role = depRole.find(item => {
  174. return NodeAudits.find(audit => audit.audit_role == item.ID);
  175. });
  176. console.log(role);
  177. return Boolean(role);
  178. }, [currentItem, flowList, depRole]);
  179. const queryList = page => {
  180. dispatch({
  181. type: 'approval/queryAuth',
  182. payload: {
  183. currentPage: page.current,
  184. },
  185. });
  186. };
  187. const onAuth = type => {
  188. if (type == 3) {
  189. Modal.confirm({
  190. title: '提示',
  191. content: '是否确认通过审批?',
  192. okText: '通过',
  193. cancelText: '取消',
  194. onOk() {
  195. dispatch({
  196. type: 'approval/authApproval',
  197. payload: {
  198. ...currentItem,
  199. audit_status: 3,
  200. audit_comment: '',
  201. },
  202. callback: () => {
  203. setVisible(false);
  204. },
  205. });
  206. },
  207. });
  208. } else {
  209. setRejectVisible(true);
  210. }
  211. };
  212. const onReject = ({ desc }) => {
  213. dispatch({
  214. type: 'approval/authApproval',
  215. payload: {
  216. ...currentItem,
  217. audit_status: 2,
  218. audit_comment: desc,
  219. },
  220. callback: () => {
  221. setRejectVisible(false);
  222. setVisible(false);
  223. },
  224. });
  225. };
  226. const handleSearch = () => {
  227. const { projectName, projectCode, projectStatus } = form.getFieldsValue();
  228. // console.log(error,values);
  229. let params = {};
  230. params.project_name = projectName;
  231. params.project_code = projectCode?.toUpperCase();
  232. params.project_status = projectStatus;
  233. dispatch({
  234. type: 'approval/queryAuth',
  235. payload: params,
  236. });
  237. };
  238. const renderSearch = () => {
  239. return (
  240. <Form
  241. style={{ marginBottom: 20 }}
  242. layout="inline"
  243. initialValues={{ projectName: null, projectCode: null, projectStatus: null }}
  244. form={form}
  245. >
  246. <Form.Item label="项目名称" name="projectName">
  247. <Input style={{ width: 200 }} />
  248. </Form.Item>
  249. <Form.Item label="项目编号" name="projectCode">
  250. <Input style={{ width: 200 }} />
  251. </Form.Item>
  252. <Form.Item label="状态" name="projectStatus">
  253. <Select
  254. showSearch
  255. style={{ width: 120 }}
  256. filterOption={(input, option) =>
  257. option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
  258. }
  259. >
  260. <Option value={null}>全部</Option>
  261. {STATUS.map(item => (
  262. <Option key={item.value}>{item.label}</Option>
  263. ))}
  264. </Select>
  265. </Form.Item>
  266. <Form.Item>
  267. <Button type="primary" loading={loading} onClick={handleSearch}>
  268. 查询
  269. </Button>
  270. </Form.Item>
  271. </Form>
  272. );
  273. };
  274. useEffect(() => {
  275. dispatch({
  276. type: 'approval/queryFlow',
  277. });
  278. dispatch({
  279. type: 'approval/queryAuth',
  280. });
  281. }, []);
  282. useEffect(() => {
  283. if (!currentUser.ID) return;
  284. dispatch({
  285. type: 'user/queryDepRole',
  286. payload: currentUser,
  287. });
  288. }, [currentUser]);
  289. return (
  290. <div>
  291. {renderSearch()}
  292. <Table
  293. loading={loading}
  294. rowKey="id"
  295. dataSource={data.list}
  296. pagination={data.pagination}
  297. columns={columns}
  298. onChange={queryList}
  299. />
  300. <AuthModal
  301. flowList={flowList}
  302. visible={visible}
  303. data={currentItem}
  304. onClose={() => setVisible(false)}
  305. onAuth={onAuth}
  306. canAuth={canAuth}
  307. />
  308. <DetailModal
  309. flowList={flowList}
  310. visible={detailVisible}
  311. data={currentItem}
  312. onClose={() => setDetailVisible(false)}
  313. />
  314. <RejectModal
  315. visible={rejectVisible}
  316. onOk={onReject}
  317. onCancel={() => setRejectVisible(false)}
  318. />
  319. </div>
  320. );
  321. }
  322. export default connect(({ approval, user, loading }) => ({
  323. data: approval.auth,
  324. typeList: approval.typeList,
  325. flowList: approval.flowList,
  326. industryList: approval.industryList,
  327. currentUser: user.currentUser,
  328. depRole: user.depRole,
  329. loading: loading.models.approval,
  330. }))(Auth);