123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 } from '@/utils/user';
  8. import { getTaIssueById } from '@/services/taissue';
  9. import IssueForm from '../components/Issue';
  10. import Save from './components/Save';
  11. import Edit from './components/Edit';
  12. import Assigned from './components/Assigned';
  13. import Cancel from './components/Cancel';
  14. export default (props) => {
  15. const router = Taro.useRouter();
  16. const { id, act } = router.params;
  17. const { user, duty } = useModel('user');
  18. const [loading, setLoading] = React.useState(false);
  19. const [issue, setIssue] = React.useState();
  20. // 各按钮状态
  21. const [
  22. readOnly,
  23. canEdit,
  24. canAssigned,
  25. canCancel,
  26. ] = React.useMemo(() => {
  27. // 如果是督察员
  28. if (duty == ROLE_INSPECTOR) {
  29. return [
  30. issue && issue.processNode != 'start' && issue.processStatus != 'reject',
  31. issue && (issue.processNode == 'start' || issue.processStatus == 'reject'),
  32. false,
  33. false,
  34. ]
  35. }
  36. // 如果是管理员
  37. if (duty == ROLE_MANAGER) {
  38. return [
  39. issue && issue.processNode != 'start',
  40. false,
  41. issue && issue.processNode == 'start',
  42. issue && issue.processNode == 'start',
  43. ]
  44. }
  45. // 如果是市民
  46. if (duty == ROLE_CITIZEN) {
  47. return [
  48. true,
  49. false,
  50. false,
  51. false,
  52. ]
  53. }
  54. return [];
  55. }, [issue, duty]);
  56. console.log(duty, issue,
  57. readOnly,
  58. canEdit,
  59. canAssigned,
  60. canCancel,)
  61. // const onIssueChange = (val = {}) => {
  62. // setIssue({
  63. // ...(issue || {}),
  64. // ...val,
  65. // })
  66. // }
  67. React.useEffect(() => {
  68. if (id) {
  69. setLoading(true)
  70. getTaIssueById(id).then(res => {
  71. setLoading(false);
  72. setIssue(res);
  73. }).catch(() => {
  74. setLoading(false);
  75. });
  76. }
  77. }, [id]);
  78. return (
  79. <Page roles={[ROLE_INSPECTOR, ROLE_MANAGER, ROLE_CITIZEN]} loading={loading}>
  80. <IssueForm
  81. issue={issue}
  82. readOnly={readOnly}
  83. showOrg={canAssigned}
  84. showExpireDate={canAssigned}
  85. renderAction={(formData) => (
  86. <View style={{ padding: 'var(--main-space)', background: '#fff' }}>
  87. {!id && <Save formData={formData} />}
  88. {canEdit && <Edit issue={issue} formData={formData} />}
  89. {canAssigned && <Assigned issue={issue} formData={formData} />}
  90. {canCancel && <Cancel issue={issue} />}
  91. </View>
  92. )}
  93. />
  94. </Page>
  95. )
  96. }