张涛 1年前
父节点
当前提交
a48fb949dc

+ 1
- 0
config/prod.js 查看文件

3
     NODE_ENV: '"production"'
3
     NODE_ENV: '"production"'
4
   },
4
   },
5
   defineConstants: {
5
   defineConstants: {
6
+    // HOST: '"http://192.168.89.25:9087"',
6
     HOST: '"https://wmcj.huoshannews.com"',
7
     HOST: '"https://wmcj.huoshannews.com"',
7
     AD_IMAGE: '"https://h5.njyunzhi.com/images/citizen_banner.png"',
8
     AD_IMAGE: '"https://h5.njyunzhi.com/images/citizen_banner.png"',
8
     DEFAULT_POS: '"116.3476917447715,31.409912844296578"', // 霍山县人民政府 gcj02
9
     DEFAULT_POS: '"116.3476917447715,31.409912844296578"', // 霍山县人民政府 gcj02

+ 0
- 1
src/app.config.js 查看文件

28
     "pages/feedback/issuelist/index",
28
     "pages/feedback/issuelist/index",
29
     "pages/user/list/index",
29
     "pages/user/list/index",
30
     "pages/user/add/index",
30
     "pages/user/add/index",
31
-    // "pages/reportList/index",
32
   ],
31
   ],
33
   subpackages: [
32
   subpackages: [
34
     {
33
     {

+ 1
- 0
src/app.js 查看文件

7
   Taro.useLaunch(() => {
7
   Taro.useLaunch(() => {
8
     Taro.login({
8
     Taro.login({
9
       success: (res) => {
9
       success: (res) => {
10
+        console.log(res)
10
         store.getState('user').login(res.code);
11
         store.getState('user').login(res.code);
11
       }
12
       }
12
     });
13
     });

+ 1
- 1
src/layouts/TabBar.jsx 查看文件

83
 
83
 
84
     // 责任单位用户
84
     // 责任单位用户
85
     if (duty == ROLE_ORG_USER || duty == ROLE_ORG_MANAGER) {
85
     if (duty == ROLE_ORG_USER || duty == ROLE_ORG_MANAGER) {
86
-      return [home, notice, mine];
86
+      return [home, notice,feedback, mine];
87
     }
87
     }
88
 
88
 
89
     if (duty == ROLE_CITIZEN) {
89
     if (duty == ROLE_CITIZEN) {

+ 89
- 50
src/pages/feedback/issue/index.jsx 查看文件

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 { Button, Notify, Field, Cell, CellGroup } from '@antmjs/vantui';
6
-import Map from '@/components/map';
7
-import Uploader from '@/components/Uploader/index';
8
-import mapIcon from '@/assets/icons/marker.png';
9
-import { warn } from '@/utils/message';
10
-import { postTaFeedback } from '@/services/tafeedback';
11
-import { geocoder } from '@/utils/map';
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 { Button, Notify, Field, Cell, CellGroup } from "@antmjs/vantui";
6
+import Map from "@/components/map";
7
+import Uploader from "@/components/Uploader/index";
8
+import mapIcon from "@/assets/icons/marker.png";
9
+import { warn } from "@/utils/message";
10
+import { postTaFeedback } from "@/services/tafeedback";
11
+import { geocoder } from "@/utils/map";
12
+// import { authPhone } from "@/services/wxma";
13
+// import { useModel } from "@/store";
12
 
14
 
13
 export default (props) => {
15
 export default (props) => {
16
+  // const { setPerson, person } = useModel("user");
17
+  // console.log(person);
14
   const readOnly = false;
18
   const readOnly = false;
15
-
19
+  // const [phone, setPhone] = React.useState();
16
   const [loading, setLoading] = React.useState(false);
20
   const [loading, setLoading] = React.useState(false);
17
   const fmRef = React.useRef({
21
   const fmRef = React.useRef({
18
     typeId: undefined,
22
     typeId: undefined,
34
 
38
 
35
     fmRef.current = data;
39
     fmRef.current = data;
36
     setFormData(data);
40
     setFormData(data);
37
-  }
41
+  };
38
 
42
 
39
   const onSubmit = () => {
43
   const onSubmit = () => {
40
-    console.log(formData)
41
     try {
44
     try {
42
-      warn(!formData.addr, '请填写地址')
43
-      warn(!formData.content, '请填写问题描述')
44
-      warn(!formData.attachList || formData.attachList.length < 1, '请上传照片')
45
+      warn(!formData.addr, "请填写地址");
46
+      warn(!formData.content, "请填写问题描述");
47
+      warn(
48
+        !formData.attachList || formData.attachList.length < 1,
49
+        "请上传照片"
50
+      );
45
     } catch (e) {
51
     } catch (e) {
46
       return;
52
       return;
47
     }
53
     }
48
 
54
 
49
-    setLoading(true)
50
-    postTaFeedback(formData).then(() => {
51
-      setLoading(false);
52
-      Taro.navigateBack({
53
-        delta: 1,
54
-        fail: () => {
55
-          Taro.reLaunch({
56
-            url: '/pages/home/index'
57
-          })
58
-        } 
55
+    setLoading(true);
56
+    postTaFeedback(formData)
57
+      .then(() => {
58
+        setLoading(false);
59
+        Taro.navigateBack({
60
+          delta: 1,
61
+          fail: () => {
62
+            Taro.reLaunch({
63
+              url: "/pages/home/index",
64
+            });
65
+          },
66
+        });
67
+      })
68
+      .catch(() => {
69
+        setLoading(false);
59
       });
70
       });
60
-    }).catch(() => {
61
-      setLoading(false);
62
-    })
71
+  };
63
 
72
 
64
-  }
65
-    
66
   const onLocationChange = (loc) => {
73
   const onLocationChange = (loc) => {
67
-    setFieldChange('location', loc);
74
+    setFieldChange("location", loc);
68
 
75
 
69
     if (loc) {
76
     if (loc) {
70
       // 交换经纬度位置
77
       // 交换经纬度位置
71
-      const [x, y] = loc.split(',');
72
-      const location = [y, x].join(',');
73
-      geocoder(location).then(e => setFieldChange('addr', e?.address_component?.street_number || e?.address)).catch(console.error)
78
+      const [x, y] = loc.split(",");
79
+      const location = [y, x].join(",");
80
+      geocoder(location)
81
+        .then((e) =>
82
+          setFieldChange(
83
+            "addr",
84
+            e?.address_component?.street_number || e?.address
85
+          )
86
+        )
87
+        .catch(console.error);
74
     }
88
     }
75
-  }
76
-
77
-
89
+  };
90
+
91
+  const onGetPhoneNumber = (e) => {
92
+    // const code = e?.detail?.code;
93
+    // authPhone(code).then((res) => {
94
+    //   setPerson(res.person)
95
+    //   // Taro.setStorage({ key: "phone", data: res.person.phone });
96
+    // });
97
+    // onSubmit();
98
+  };
78
   return (
99
   return (
79
     <Page tabBar="feedback">
100
     <Page tabBar="feedback">
80
       <Map
101
       <Map
89
           value={formData.addr}
110
           value={formData.addr}
90
           leftIcon={mapIcon}
111
           leftIcon={mapIcon}
91
           readonly={readOnly}
112
           readonly={readOnly}
92
-          onChange={e => setFieldChange('addr', e.detail)}
113
+          onChange={(e) => setFieldChange("addr", e.detail)}
93
         />
114
         />
94
       </CellGroup>
115
       </CellGroup>
95
 
116
 
96
-      <CellGroup style={{ marginTop: '20px' }}>
97
-
117
+      <CellGroup style={{ marginTop: "20px" }}>
98
         <Cell title="问题描述" size="large" border={false} />
118
         <Cell title="问题描述" size="large" border={false} />
99
 
119
 
100
         <Field
120
         <Field
101
           type="textarea"
121
           type="textarea"
102
           placeholder="请输入问题描述"
122
           placeholder="请输入问题描述"
103
           readonly={readOnly}
123
           readonly={readOnly}
104
-          autosize={{ minHeight: '120px' }}
124
+          autosize={{ minHeight: "120px" }}
105
           value={formData.content}
125
           value={formData.content}
106
-          onChange={e => setFieldChange('content', e.detail)}
126
+          onChange={(e) => setFieldChange("content", e.detail)}
107
         />
127
         />
108
       </CellGroup>
128
       </CellGroup>
109
 
129
 
110
-      <CellGroup style={{ marginTop: '20px' }}>
130
+      <CellGroup style={{ marginTop: "20px" }}>
111
         <Cell title="拍照" size="large" border={false} />
131
         <Cell title="拍照" size="large" border={false} />
112
 
132
 
113
         <Cell
133
         <Cell
115
             <Uploader
135
             <Uploader
116
               value={formData.attachList}
136
               value={formData.attachList}
117
               disabled={readOnly}
137
               disabled={readOnly}
118
-              onChange={e => setFieldChange('attachList', e)}
138
+              onChange={(e) => setFieldChange("attachList", e)}
119
             />
139
             />
120
           }
140
           }
121
         />
141
         />
122
       </CellGroup>
142
       </CellGroup>
123
 
143
 
124
-      <View style={{ padding: 'var(--main-space)', background: '#fff' }}>
125
-        <Button block type="primary" onClick={onSubmit}>提交</Button>
144
+      <View style={{ padding: "var(--main-space)", background: "#fff" }}>
145
+        {
146
+      //   person?.phone ?
147
+        
148
+      //  : (
149
+      //     <Button
150
+      //       block
151
+      //       type="primary"
152
+      //       openType="getPhoneNumber"
153
+      //       onGetPhoneNumber={onGetPhoneNumber}
154
+      //       // onClick={onSubmit}
155
+      //     >
156
+      //       提交
157
+      //     </Button>
158
+      //   )
159
+        (
160
+          <Button block type="primary" onClick={onSubmit}>
161
+            提交
162
+          </Button>
163
+        )
164
+        }
126
       </View>
165
       </View>
127
     </Page>
166
     </Page>
128
-  )
129
-}
167
+  );
168
+};

+ 1
- 0
src/pages/feedback/issuelist/index.jsx 查看文件

27
   }, [title]);
27
   }, [title]);
28
 
28
 
29
   const onClick = (item) => {
29
   const onClick = (item) => {
30
+    console.log(item)
30
     Taro.navigateTo({
31
     Taro.navigateTo({
31
       url: `/pages/issue/edit/index?id=${item.issueId}`
32
       url: `/pages/issue/edit/index?id=${item.issueId}`
32
     })
33
     })

+ 1
- 0
src/pages/home/components/Head.jsx 查看文件

32
   }
32
   }
33
 
33
 
34
   const onSelect = (e) => {
34
   const onSelect = (e) => {
35
+    console.log(e)
35
     updateDuty(e.detail.value)
36
     updateDuty(e.detail.value)
36
   }
37
   }
37
 
38
 

+ 4
- 3
src/pages/home/index.jsx 查看文件

4
 import { useModel } from '@/store';
4
 import { useModel } from '@/store';
5
 import MenuIcon from '@/components/MenuIcon';
5
 import MenuIcon from '@/components/MenuIcon';
6
 import { ROLE_CITIZEN, ROLE_INSPECTOR, ROLE_MANAGER, ROLE_ORG_MANAGER, ROLE_ORG_USER, ROLE_QUERY_PERSON } from '@/utils/user';
6
 import { ROLE_CITIZEN, ROLE_INSPECTOR, ROLE_MANAGER, ROLE_ORG_MANAGER, ROLE_ORG_USER, ROLE_QUERY_PERSON } from '@/utils/user';
7
-import { PROCESS_APPLY_DELAY, PROCESS_APPLY_END, PROCESS_APPLY_REJECT, PROCESS_APPLY_VERIFY, PROCESS_ASSIGNED, PROCESS_END, PROCESS_START } from '@/utils/biz';
7
+import { PROCESS_APPLY_DELAY, PROCESS_APPLY_END, PROCESS_APPLY_REJECT, PROCESS_APPLY_VERIFY, PROCESS_ASSIGNED, PROCESS_END, PROCESS_START ,APPLY_REJECT} from '@/utils/biz';
8
 import { getApplyNum } from '@/services/taissueapply';
8
 import { getApplyNum } from '@/services/taissueapply';
9
 import Head from './components/Head';
9
 import Head from './components/Head';
10
 import Banner from './components/Banner';
10
 import Banner from './components/Banner';
44
     { icon: 'icon3', text: '已 办 结', link: `/pages/org/issue/list/index?title=已办结&bizStatus=${PROCESS_END}` },
44
     { icon: 'icon3', text: '已 办 结', link: `/pages/org/issue/list/index?title=已办结&bizStatus=${PROCESS_END}` },
45
     { icon: 'icon5', text: '已 逾 期', link: '/pages/org/issue/list/index?title=已逾期&bizStatus=expired' },
45
     { icon: 'icon5', text: '已 逾 期', link: '/pages/org/issue/list/index?title=已逾期&bizStatus=expired' },
46
     { icon: 'icon11', text: '消息通知', link: '/pages/message/list/index'},
46
     { icon: 'icon11', text: '消息通知', link: '/pages/message/list/index'},
47
-    // { icon: 'icon10', text: '我的上报', link: '/pages/reportList/index?title=我的上报'},
47
+    { icon: 'icon10', text: '我的上报', link: `/pages/feedback/issuelist/index?title=我的上报&bizStatus=`},
48
+
48
   ],
49
   ],
49
 
50
 
50
   // 责任交办单位管理员
51
   // 责任交办单位管理员
70
   [ROLE_CITIZEN]: [
71
   [ROLE_CITIZEN]: [
71
     { icon: 'icon1', text: '未处理', link: `/pages/feedback/issuelist/index?title=未处理&bizStatus=${PROCESS_START}` },
72
     { icon: 'icon1', text: '未处理', link: `/pages/feedback/issuelist/index?title=未处理&bizStatus=${PROCESS_START}` },
72
     { icon: 'icon2', text: '已处理', link: `/pages/feedback/issuelist/index?title=已处理&bizStatus=${PROCESS_ASSIGNED}` },
73
     { icon: 'icon2', text: '已处理', link: `/pages/feedback/issuelist/index?title=已处理&bizStatus=${PROCESS_ASSIGNED}` },
73
-    { icon: 'icon12', text: '已打回', link: `/pages/feedback/issuelist/index?title=已打回&bizStatus=reject` },
74
+    { icon: 'icon12', text: '已打回', link: `/pages/feedback/issuelist/index?title=已打回&bizStatus=${APPLY_REJECT}` },
74
   ],
75
   ],
75
 }
76
 }
76
 
77
 

+ 94
- 88
src/pages/issue/edit/index.jsx 查看文件

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

+ 1
- 0
src/pages/login/components/Bottom.jsx 查看文件

9
   const { signinByPhone } = useModel('user');
9
   const { signinByPhone } = useModel('user');
10
 
10
 
11
   const onGetPhoneNumber = (e) => {
11
   const onGetPhoneNumber = (e) => {
12
+    console.log(e)
12
     const code = e.detail.code;
13
     const code = e.detail.code;
13
     signinByPhone(code).then(props.onSuccess);
14
     signinByPhone(code).then(props.onSuccess);
14
   }
15
   }

+ 0
- 12
src/pages/reportList/index.jsx 查看文件

1
-// import React from "react";
2
-// import Taro from "@tarojs/taro";
3
-// import Page from "@/layouts/index";
4
-// import PowerList from "@/components/PowerList";
5
-
6
-// export default (props) => {
7
-//   return (
8
-//     <Page>
9
-//       <PowerList request={}/>
10
-//     </Page>
11
-//   )
12
-// };

+ 42
- 32
src/store/user.js 查看文件

1
-import React from 'react';
2
-import Taro from '@tarojs/taro';
3
-import md5 from 'md5';
4
-import { login, signin, currentUser, authPhone, authUser } from '@/services/wxma';
5
-import { changePassword } from '@/services/sysuser';
6
-import { ROLE_CITIZEN } from '@/utils/user';
1
+import React from "react";
2
+import Taro from "@tarojs/taro";
3
+import md5 from "md5";
4
+import {
5
+  login,
6
+  signin,
7
+  currentUser,
8
+  authPhone,
9
+  authUser,
10
+} from "@/services/wxma";
11
+import { changePassword } from "@/services/sysuser";
12
+import { ROLE_CITIZEN } from "@/utils/user";
7
 
13
 
8
 export default function useUser() {
14
 export default function useUser() {
9
   const [person, setPerson] = React.useState();
15
   const [person, setPerson] = React.useState();
11
   const [duty, setDuty] = React.useState();
17
   const [duty, setDuty] = React.useState();
12
 
18
 
13
   const maLogin = (code) => {
19
   const maLogin = (code) => {
14
-    login(code).then(res => {
20
+    console.log(code);
21
+    login(code).then((res) => {
15
       setPerson(res.person);
22
       setPerson(res.person);
16
-      Taro.setStorage({ key: 'personId', data: res.person.personId })
17
-      Taro.setStorage({ key: 'sessionKey', data: res.sessionKey })
23
+      Taro.setStorage({ key: "personId", data: res.person.personId });
24
+      Taro.setStorage({ key: "sessionKey", data: res.sessionKey });
18
     });
25
     });
19
-  }
26
+  };
20
 
27
 
21
   const updateDuty = (d = ROLE_CITIZEN) => {
28
   const updateDuty = (d = ROLE_CITIZEN) => {
22
     setDuty(d);
29
     setDuty(d);
23
-    Taro.setStorageSync('duty', d);
24
-  }
30
+    Taro.setStorageSync("duty", d);
31
+  };
25
 
32
 
26
   const initDuty = (u) => {
33
   const initDuty = (u) => {
27
-    const d = Taro.getStorageSync('duty');
34
+    console.log(u)
35
+    const d = Taro.getStorageSync("duty");
36
+    console.log(d)
28
     const dutyList = u?.dutyList || [];
37
     const dutyList = u?.dutyList || [];
29
     if (d) {
38
     if (d) {
30
       if (dutyList.indexOf(d) < 0) {
39
       if (dutyList.indexOf(d) < 0) {
35
     } else {
44
     } else {
36
       updateDuty(dutyList[0]);
45
       updateDuty(dutyList[0]);
37
     }
46
     }
38
-  }
47
+  };
39
 
48
 
40
   const maSignIn = (params) => {
49
   const maSignIn = (params) => {
41
     const data = {
50
     const data = {
42
       ...params,
51
       ...params,
43
-      password: md5(params.password)
52
+      password: md5(params.password),
44
     };
53
     };
45
 
54
 
46
-    return signin(data).then(res => {
55
+    return signin(data).then((res) => {
47
       setUser(res.user);
56
       setUser(res.user);
48
       initDuty(res.user);
57
       initDuty(res.user);
49
-    })
50
-  }
58
+    });
59
+  };
51
 
60
 
52
   const current = () => {
61
   const current = () => {
53
-    currentUser().then(res => {
62
+    currentUser().then((res) => {
54
       setUser(res.user);
63
       setUser(res.user);
55
       initDuty(res.user);
64
       initDuty(res.user);
56
-    })
57
-  }
65
+    });
66
+  };
58
 
67
 
59
   const signinByPhone = (code) => {
68
   const signinByPhone = (code) => {
60
-    return authPhone(code).then(res => {
69
+    return authPhone(code).then((res) => {
61
       setUser(res.user);
70
       setUser(res.user);
62
       initDuty(res.user);
71
       initDuty(res.user);
63
       setPerson(res.person);
72
       setPerson(res.person);
64
-    })
65
-  }
73
+    });
74
+  };
66
 
75
 
67
   const authProfile = (data) => {
76
   const authProfile = (data) => {
68
-    const sessionKey = Taro.getStorageSync('sessionKey');
69
-    authUser({ ...data, sessionKey }).then(res => {
77
+    const sessionKey = Taro.getStorageSync("sessionKey");
78
+    authUser({ ...data, sessionKey }).then((res) => {
70
       setPerson(res);
79
       setPerson(res);
71
-    })
72
-  }
80
+    });
81
+  };
73
 
82
 
74
   const signOut = () => {
83
   const signOut = () => {
75
     setUser(null);
84
     setUser(null);
76
     initDuty([]);
85
     initDuty([]);
77
-  }
86
+  };
78
 
87
 
79
   const changePwd = (params) => {
88
   const changePwd = (params) => {
80
     const data = {
89
     const data = {
81
       originPassword: md5(params.originPassword),
90
       originPassword: md5(params.originPassword),
82
       newPassword: md5(params.newPassword),
91
       newPassword: md5(params.newPassword),
83
-    }
92
+    };
84
 
93
 
85
     changePassword(data);
94
     changePassword(data);
86
-  }
95
+  };
87
 
96
 
88
   return {
97
   return {
89
     user,
98
     user,
97
     authProfile,
106
     authProfile,
98
     signOut,
107
     signOut,
99
     changePwd,
108
     changePwd,
100
-  }
109
+    // setPerson,
110
+  };
101
 }
111
 }