index.jsx 3.7KB

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