index.jsx 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import React from 'react';
  2. import Taro from '@tarojs/taro';
  3. import { View } from '@tarojs/components';
  4. import { CellGroup, Cell } from '@antmjs/vantui';
  5. import Page from '@/layouts/index';
  6. import { useModel } from '@/store';
  7. import { ROLE_INSPECTOR, ROLE_MANAGER, ROLE_CITIZEN, ROLE_QUERY_PERSON } from '@/utils/user';
  8. import { getTaIssueById } from '@/services/taissue';
  9. import { getSysOrgById } from '@/services/sysorg';
  10. import IssueForm from '../components/Issue';
  11. import Save from './components/Save';
  12. import Edit from './components/Edit';
  13. import Assigned from './components/Assigned';
  14. import Cancel from './components/Cancel';
  15. import { PROCESS_END, PROCESS_START } from '@/utils/biz';
  16. export default (props) => {
  17. const router = Taro.useRouter();
  18. const { id } = router.params;
  19. const { user, duty } = useModel('user');
  20. const [loading, setLoading] = React.useState(false);
  21. const [issue, setIssue] = React.useState();
  22. React.useMemo(() => {
  23. if (id) {
  24. Taro.setNavigationBarTitle({
  25. title: '问题单详情'
  26. })
  27. } else {
  28. Taro.setNavigationBarTitle({
  29. title: '我要上报'
  30. })
  31. }
  32. }, [id]);
  33. // 各按钮状态
  34. const [
  35. readOnly,
  36. showOrg,
  37. canEdit,
  38. canAssigned,
  39. canCancel,
  40. ] = React.useMemo(() => {
  41. // 如果是督查员
  42. if (duty == ROLE_INSPECTOR) {
  43. return [
  44. issue && issue.processNode != PROCESS_START,
  45. false,
  46. issue && issue.processNode == PROCESS_START,
  47. false,
  48. false,
  49. ]
  50. }
  51. // 如果是管理员
  52. if (duty == ROLE_MANAGER) {
  53. return [
  54. issue && issue.processNode != PROCESS_START,
  55. true,
  56. false,
  57. issue && issue.processNode == PROCESS_START,
  58. issue && issue.processNode == PROCESS_START,
  59. ]
  60. }
  61. // 如果是市民 或者查询员
  62. if (duty == ROLE_CITIZEN || duty == ROLE_QUERY_PERSON) {
  63. return [
  64. true,
  65. false,
  66. false,
  67. false,
  68. false,
  69. ]
  70. }
  71. return [];
  72. }, [issue, duty]);
  73. // const onIssueChange = (val = {}) => {
  74. // setIssue({
  75. // ...(issue || {}),
  76. // ...val,
  77. // })
  78. // }
  79. React.useEffect(() => {
  80. if (id) {
  81. setLoading(true)
  82. getTaIssueById(id).then(res => {
  83. setLoading(false);
  84. if (res.orgId) {
  85. getSysOrgById(res.orgId).then(r => {
  86. setIssue({
  87. ...res,
  88. orgName: r?.name
  89. });
  90. }).catch(() => {
  91. setIssue(res);
  92. })
  93. } else {
  94. setIssue(res);
  95. }
  96. }).catch(() => {
  97. setLoading(false);
  98. });
  99. }
  100. }, [id]);
  101. return (
  102. <Page roles={[ROLE_INSPECTOR, ROLE_MANAGER, ROLE_CITIZEN, ROLE_QUERY_PERSON]} loading={loading}>
  103. <IssueForm
  104. issue={issue}
  105. readOnly={readOnly}
  106. showOrg={showOrg}
  107. showExpireDate={showOrg}
  108. renderAction={(formData) => (
  109. <View style={{ padding: 'var(--main-space)', background: '#fff' }}>
  110. {!id && <Save formData={formData} />}
  111. {canEdit && <Edit issue={issue} formData={formData} />}
  112. {canAssigned && <Assigned issue={issue} formData={formData} />}
  113. {canCancel && <Cancel issue={issue} />}
  114. </View>
  115. )}
  116. />
  117. </Page>
  118. )
  119. }