[baozhangchao] 3 vuotta sitten
vanhempi
commit
ebfb6ac971

+ 1
- 1
src/app.config.js Näytä tiedosto

10
     navigationBarTitleText: 'WeChat',
10
     navigationBarTitleText: 'WeChat',
11
     navigationBarTextStyle: 'black'
11
     navigationBarTextStyle: 'black'
12
   }
12
   }
13
-}
13
+}

+ 103
- 41
src/pages/DepartmentSelection/index.jsx Näytä tiedosto

1
-import { View, Text } from "@tarojs/components"
1
+import { View } from "@tarojs/components"
2
 import { useEffect, useState } from "react"
2
 import { useEffect, useState } from "react"
3
 import Taro, { useDidShow } from "@tarojs/taro"
3
 import Taro, { useDidShow } from "@tarojs/taro"
4
-import { TreeSelect } from "@antmjs/vantui";
4
+import { TreeSelect, Button } from "@antmjs/vantui";
5
 import { getDepartmenList } from "../../services/user";
5
 import { getDepartmenList } from "../../services/user";
6
+import { useModel } from "../../store";
6
 
7
 
7
 // import BottomMoadl from '@/components/BottomMoadl/index'
8
 // import BottomMoadl from '@/components/BottomMoadl/index'
8
 
9
 
14
 import './style.less'
15
 import './style.less'
15
 
16
 
16
 export default (props) => {
17
 export default (props) => {
18
+  const [departItem, setDepartItem] = useState([]);
19
+  const [mainActiveIndex, setMainActiveIndex] = useState();
20
+  const [activeId, setActiveId] = useState();
21
+  const { deptName, setDeptName, sessionKey } = useModel('userData')
22
+
23
+
24
+
17
   useEffect(() => {
25
   useEffect(() => {
18
-    getDepartmenList().then((e) => {
19
-      console.log('科室选择', e);
26
+    // setDeptName('连云港第一人民医院')
27
+    getDepartmenList().then((res) => {
28
+
29
+      // res.reduce((acc, item) => {
30
+      //   const parent = res.filter(x => x.id === item.parentId)[0]
31
+      //   if (parent) {
32
+      //     parent.children = (parent.children || []).concat(item)
33
+      //     return acc;
34
+      //   } else {
35
+      //     return acc.concat(item);
36
+      //   }
37
+      // }, [])
38
+
39
+      // const idMapping = res.reduce((acc, el, i) => {
40
+      //   acc[el.id] = i;
41
+      //   return acc;
42
+      // }, []);
43
+      // console.log('idMapping', idMapping);
44
+
45
+
46
+      function array2tree () {
47
+        const newList = []
48
+        for (let i = 0; i < res.length; i++) {
49
+
50
+          res[i].text = res[i].name
51
+          const list = res.filter((item) =>
52
+            item.id == res[i].parentId
53
+          )
54
+          if (list.length > 0) {
55
+            const parent = list[0];
56
+            parent.children = (parent.children || []).concat(res[i])
57
+
58
+          } else {
59
+            newList.push(res[i])
60
+          }
61
+        }
62
+        setDepartItem(newList)
63
+        return newList
64
+      }
65
+      console.log("🚀 ~ file: index.jsx ~ line 43 ~ getDepartmenList ~  array2tree()", array2tree())
20
     })
66
     })
67
+
68
+
69
+
21
   }, [])
70
   }, [])
22
 
71
 
23
-  // {
24
-  //   text: number ¦ string
25
-  //   badge?: number ¦ string
26
-  //   dot?: boolean
27
-  //   disabled?: boolean
28
-  //   children?: {
29
-  //     text: number ¦ string
30
-  //     id: number ¦ string
31
-  //     disabled?: boolean
32
-  //   }[]
33
-  // }[]
34
-  const items = [
35
-    { text: '眼科医院', children: [{ text: '连云港市爱尔眼科' }, { text: '眼科一楼' }], },
36
-    {
37
-      text: '连云港开发区高中',
38
-      children:
39
-        [
40
-          { text: '开发区高一4班' },
41
-          { text: '开发区高一8班' },
42
-          { text: '开发区高一8班' },
43
-          { text: '开发区高二1班' },
44
-          { text: '开发区高二2班' },
45
-          { text: '开发区高二3班' },
46
-          { text: '开发区高二15班' },
47
-          { text: '开发区高三10班' },
48
-          { text: '开发区高三2班' },
49
-
50
-        ]
72
+  const goBack = () => {
73
+    if (deptName) {
74
+      Taro.navigateBack({
75
+        delta: 1
76
+      })
77
+    } else {
78
+      Taro.showToast({
79
+        title: '请选择科室!',
80
+        icon: 'none',
81
+        duration: 2000
82
+      })
83
+    }
84
+
85
+  }
86
+
87
+
88
+
89
+
90
+  const onClickNav = ({ detail }) => {
91
+    setMainActiveIndex(detail.index || 0,)
92
+    console.log("🚀 ~ file: index.jsx ~ line 92 ~ onClickNav ~ detail.index", detail.index)
93
+
94
+    if (departItem[detail.index]?.children) {
95
+      console.log('父级: detail.index || 0', departItem[detail.index]);
96
+
97
+    } else {
98
+      setDeptName(departItem[detail.index]?.name)
99
+      console.log('没有子节点: children || 0', departItem[detail.index]?.name);
100
+
51
     }
101
     }
52
-  ]
53
-  const onClickNav = () => {
54
-    console.log('父级: detail.index || 0',);
102
+
55
   }
103
   }
56
-  const onClickItem = () => {
57
-    console.log('自己: detail.index || 0',);
104
+  const onClickItem = ({ detail }) => {
105
+    const activeIdaa = activeId === detail.id ? null : detail.id
106
+    setActiveId(activeIdaa)
107
+    setDeptName(detail?.name)
108
+    console.log('自己: detail.index || 0', activeId, detail);
58
 
109
 
59
   }
110
   }
60
 
111
 
65
   return (
116
   return (
66
     <View className='page-index'>
117
     <View className='page-index'>
67
       <TreeSelect
118
       <TreeSelect
68
-        items={items}
69
-        mainActiveIndex={items.mainActiveIndex}
70
-        activeId={items.activeId}
119
+        height='80vh'
120
+        items={departItem}
121
+        mainActiveIndex={mainActiveIndex}
122
+        activeId={activeId}
71
         onClickNav={onClickNav}
123
         onClickNav={onClickNav}
72
         onClickItem={onClickItem}
124
         onClickItem={onClickItem}
73
       />
125
       />
74
-
126
+      <View className='buttom-box'>
127
+        <Button
128
+          type='info'
129
+          size='normal'
130
+          formType='submit'
131
+          className='buttom-box-buttonSubmit'
132
+          onClick={goBack}
133
+        >
134
+          确定
135
+        </Button>
136
+      </View>
75
     </View>
137
     </View>
76
   )
138
   )
77
 }
139
 }

+ 9
- 0
src/pages/DepartmentSelection/style.less Näytä tiedosto

57
   bottom: 5vh;
57
   bottom: 5vh;
58
   display: flex;
58
   display: flex;
59
 }
59
 }
60
+
61
+.buttom-box {
62
+  width: 100%;
63
+  text-align: center;
64
+  margin: 5vh 0 0 0;
65
+  &-buttonSubmit {
66
+    width: 90%;
67
+  }
68
+}

+ 27
- 5
src/pages/index/index.jsx Näytä tiedosto

4
 import { Button, Icon } from "@antmjs/vantui";
4
 import { Button, Icon } from "@antmjs/vantui";
5
 import Taro from '@tarojs/taro';
5
 import Taro from '@tarojs/taro';
6
 import BarCode from '@/components/barcode'
6
 import BarCode from '@/components/barcode'
7
-import CountDown from '@/components/CountDown'
7
+import { useModel } from '../../store';
8
 
8
 
9
 import './style.less'
9
 import './style.less'
10
 
10
 
11
 export default (props) => {
11
 export default (props) => {
12
+  const { deptName, person, sessionKey } = useModel('userData')
13
+
12
   const userId = '320888800110023011';
14
   const userId = '320888800110023011';
13
-  
15
+
14
   const goUserInfo = () => {
16
   const goUserInfo = () => {
15
     // 跳转到目的页面,在当前页面打开
17
     // 跳转到目的页面,在当前页面打开
16
     Taro.redirectTo({
18
     Taro.redirectTo({
17
       url: '/pages/setUserInfo/index'
19
       url: '/pages/setUserInfo/index'
18
     })
20
     })
19
   }
21
   }
22
+  useEffect(() => {
23
+    if (deptName) {
24
+      Taro.showModal({
25
+        title: '提示',
26
+        content: '未添加个人信息!',
27
+        success: function (res) {
28
+          if (res.confirm) {
29
+            Taro.redirectTo({
30
+              url: '/pages/setUserInfo/index'
31
+            })
32
+
33
+          } else if (res.cancel) {
34
+            console.log('用户点击取消')
35
+          }
36
+        }
37
+      })
38
+
39
+    }
40
+
41
+  }, [deptName])
20
 
42
 
21
   const today = useMemo(() => dayjs().format('YYYY-MM-DD'))
43
   const today = useMemo(() => dayjs().format('YYYY-MM-DD'))
22
 
44
 
26
       {/* <View className='index-UserQRcode-headerInfo' style={{ backgroundImage: `url(${userBck})` }}> */}
48
       {/* <View className='index-UserQRcode-headerInfo' style={{ backgroundImage: `url(${userBck})` }}> */}
27
       <View className='index-UserQRcode-headerInfo' >
49
       <View className='index-UserQRcode-headerInfo' >
28
         <View className='index-UserQRcode-headerInfo-User'>
50
         <View className='index-UserQRcode-headerInfo-User'>
29
-          <View className='index-UserQRcode-headerInfo-User-NameInfo'>姓名:鲍张抄</View>
51
+          <View className='index-UserQRcode-headerInfo-User-NameInfo'>姓名:{person?.personName ?? '请添加个人信息'}</View>
30
           <View onClick={goUserInfo} className='index-UserQRcode-headerInfo-User-setNameInfo'><Icon name='edit' />修改信息</View>
52
           <View onClick={goUserInfo} className='index-UserQRcode-headerInfo-User-setNameInfo'><Icon name='edit' />修改信息</View>
31
         </View>
53
         </View>
32
-        <View className='index-UserQRcode-headerInfo-UserID'>身份证:{userId.replace(/^(\d{6})\d+(\d{4})$/, "$1******$2")}</View>
54
+        <View className='index-UserQRcode-headerInfo-UserID'>身份证:{person?.idNo.replace(/^(\d{6})\d+(\d{4})$/, "$1******$2")}</View>
33
       </View>
55
       </View>
34
       <View className='index-UserQRcode-cententQR'>
56
       <View className='index-UserQRcode-cententQR'>
35
         <View className='index-UserQRcode-cententQR-Barcode'>
57
         <View className='index-UserQRcode-cententQR-Barcode'>
40
         </View>
62
         </View>
41
       </View>
63
       </View>
42
       <View className='index-UserQRcode-footer'>
64
       <View className='index-UserQRcode-footer'>
43
-      {today}
65
+        {today}
44
       </View>
66
       </View>
45
     </View>
67
     </View>
46
   )
68
   )

+ 54
- 25
src/pages/setUserInfo/index.jsx Näytä tiedosto

1
 import { View, Text, Input } from "@tarojs/components"
1
 import { View, Text, Input } from "@tarojs/components"
2
-import { useEffect, useRef, useState } from "react"
3
 import Taro, { useDidShow } from "@tarojs/taro"
2
 import Taro, { useDidShow } from "@tarojs/taro"
4
 import { Button, Form, FormItem, Icon } from "@antmjs/vantui";
3
 import { Button, Form, FormItem, Icon } from "@antmjs/vantui";
5
 
4
 
6
-
5
+import { useEffect, useState } from "react";
6
+import { useModel } from "../../store";
7
+import { getPhoneuser, setUserInfo } from "../../services/user";
7
 // import BottomMoadl from '@/components/BottomMoadl/index'
8
 // import BottomMoadl from '@/components/BottomMoadl/index'
8
 import './style.less'
9
 import './style.less'
9
 
10
 
11
+
10
 export default (props) => {
12
 export default (props) => {
13
+  const [phone, setPhone] = useState('')
14
+
15
+  const { deptName, person, sessionKey } = useModel('userData')
16
+  let form = null
17
+  const onSubmit = (e) => {
18
+    form.validateFields((errorMessage, fieldValues) => {
19
+      if (errorMessage && errorMessage.length) {
20
+        return console.info('errorMessage', errorMessage)
21
+      } else {
22
+        console.info(fieldValues)
23
+        setUserInfo({ ...fieldValues, person: person?.personId }).then(() => {
24
+          Taro.showToast({
25
+            title: '保存成功',
26
+            icon: 'none',
27
+            duration: 2000
28
+          }).then(() => {
29
+            Taro.redirectTo({
30
+              url: '/pages/index/index'
31
+            })
32
+          })
33
+
34
+        })
35
+
36
+      }
37
+    })
11
 
38
 
12
-  const handleClick = (fieldValues) => {
13
 
39
 
14
-    console.info(fieldValues)
15
   }
40
   }
16
   const goDepartmen = () => {
41
   const goDepartmen = () => {
17
     Taro.navigateTo({
42
     Taro.navigateTo({
19
     })
44
     })
20
 
45
 
21
   }
46
   }
22
-  const getPhone = () => {
23
-    console.log('手机号',);
47
+  const getPhone = (e) => {
48
+    console.log('deptName', deptName);
49
+    console.log('手机号', e);
50
+    const { errMsg, ...data } = e.detail || {}
51
+
52
+    getPhoneuser({ ...data, sessionKey: sessionKey }).then((res) => {
53
+      setPhone(res?.phoneNumber)
54
+    })
24
 
55
 
25
   }
56
   }
26
   return (
57
   return (
27
     <View className='page-index'>
58
     <View className='page-index'>
28
       <Form
59
       <Form
29
         initialValues={{
60
         initialValues={{
30
-          name: '我是初始值',
31
-          singleSelect: '1',
32
-          rate: 2,
33
-          slider: '50',
61
+          phone: phone,
62
+          deptName: deptName,
63
+
34
         }}
64
         }}
35
-        // ref={(el) => (form = el)}
36
-        onFinish={(e) => handleClick(e)}
65
+        ref={(el) => (form = el)}
66
+        onFinish={(e) => onSubmit(e)}
37
       >
67
       >
38
         <FormItem
68
         <FormItem
39
           label='用户名'
69
           label='用户名'
40
-          name='userName'
70
+          name='personName'
41
           required
71
           required
42
-
43
           trigger='onInput'
72
           trigger='onInput'
44
           validateTrigger='onBlur'
73
           validateTrigger='onBlur'
45
           // taro的input的onInput事件返回对应表单的最终值为e.detail.value
74
           // taro的input的onInput事件返回对应表单的最终值为e.detail.value
50
         <FormItem
79
         <FormItem
51
           label='手机号'
80
           label='手机号'
52
           name='phone'
81
           name='phone'
53
-          required
54
           trigger='onInput'
82
           trigger='onInput'
83
+          required
55
           validateTrigger='onBlur'
84
           validateTrigger='onBlur'
56
-          // taro的input的onInput事件返回对应表单的最终值为e.detail.value
57
           valueFormat={(e) => e.detail.value}
85
           valueFormat={(e) => e.detail.value}
58
         >
86
         >
59
-          <Input placeholder='请输入手机号' type='number' />
87
+          <Input placeholder='请输入手机号' type='number' value={phone} maxlength={11} disabled />
60
           <Button
88
           <Button
61
             plain
89
             plain
62
             hairline
90
             hairline
63
             size='small'
91
             size='small'
64
             type='info'
92
             type='info'
93
+            required
94
+
95
+            openType='getPhoneNumber'
65
             onGetPhoneNumber={getPhone}
96
             onGetPhoneNumber={getPhone}
66
           >
97
           >
67
-            一键填写
98
+            授权手机
68
           </Button>
99
           </Button>
69
         </FormItem>
100
         </FormItem>
70
 
101
 
71
         <FormItem
102
         <FormItem
72
           label='身份证'
103
           label='身份证'
73
-          name='id'
104
+          name='idNo'
74
           required
105
           required
75
-
76
           trigger='onInput'
106
           trigger='onInput'
77
           validateTrigger='onBlur'
107
           validateTrigger='onBlur'
78
           // taro的input的onInput事件返回对应表单的最终值为e.detail.value
108
           // taro的input的onInput事件返回对应表单的最终值为e.detail.value
79
           valueFormat={(e) => e.detail.value}
109
           valueFormat={(e) => e.detail.value}
80
         >
110
         >
81
-          <Input placeholder='请输入身份证号' type='number' />
111
+          <Input placeholder='请输入身份证号' type='number' maxlength={18} />
82
         </FormItem>
112
         </FormItem>
83
 
113
 
84
         <FormItem
114
         <FormItem
85
           label='科室'
115
           label='科室'
86
-          name='departmen'
87
-          required
88
-
116
+          name='deptName'
89
           trigger='onInput'
117
           trigger='onInput'
118
+          required
90
           validateTrigger='onBlur'
119
           validateTrigger='onBlur'
91
           // taro的input的onInput事件返回对应表单的最终值为e.detail.value
120
           // taro的input的onInput事件返回对应表单的最终值为e.detail.value
92
           valueFormat={(e) => e.detail.value}
121
           valueFormat={(e) => e.detail.value}
93
         >
122
         >
94
-          <Input placeholder='请选择科室' value='' disabled onClick={goDepartmen} />
123
+          <Input placeholder='请选择科室' value={deptName} disabled onClick={goDepartmen} />
95
         </FormItem>
124
         </FormItem>
96
         <View className='buttom-box'>
125
         <View className='buttom-box'>
97
           <Button
126
           <Button

+ 17
- 1
src/services/user.js Näytä tiedosto

16
  * @returns 
16
  * @returns 
17
  */
17
  */
18
 export const getDepartmenList = (data) => request('/bds-org', { data, method: 'GET' })
18
 export const getDepartmenList = (data) => request('/bds-org', { data, method: 'GET' })
19
-// /api/wx/{clientId}/bds-org
19
+
20
+
21
+/**
22
+ * 手机号
23
+ * @param {*} data 
24
+ * @returns 
25
+ */
26
+export const getPhoneuser = (data) => request('/auth-phone', { data, method: 'PUT' })
27
+
28
+
29
+/**
30
+ * 维护个人信息
31
+ * @param {*} data 
32
+ * @returns 
33
+ */
34
+export const setUserInfo = (data) => request('/person', { data, method: 'PUT' })
35
+

+ 4
- 1
src/store/userData.js Näytä tiedosto

7
   const [person, setPerson] = useState()
7
   const [person, setPerson] = useState()
8
   const [sessionKey, setSessionKey] = useState()
8
   const [sessionKey, setSessionKey] = useState()
9
   const [userPhoneInfo, setUserPhoneInfo] = useState()
9
   const [userPhoneInfo, setUserPhoneInfo] = useState()
10
-
10
+  const [deptName, setDeptName] = useState()
11
 
11
 
12
 
12
 
13
 
13
 
37
     userPhoneInfo,
37
     userPhoneInfo,
38
     setUserPhoneInfo,
38
     setUserPhoneInfo,
39
 
39
 
40
+    deptName,
41
+    setDeptName,
42
+
40
 
43
 
41
     logins,
44
     logins,
42
   }
45
   }

+ 0
- 5
src/utils/request.js Näytä tiedosto

50
 
50
 
51
       fail: (err) => {
51
       fail: (err) => {
52
         console.error(err)
52
         console.error(err)
53
-
54
-
55
-
56
         const message = err.message || err.errMsg || err
53
         const message = err.message || err.errMsg || err
57
-
58
         if (!skipError) {
54
         if (!skipError) {
59
           Taro.showToast({
55
           Taro.showToast({
60
             title: message,
56
             title: message,
61
             icon: 'none',
57
             icon: 'none',
62
           })
58
           })
63
         }
59
         }
64
-
65
         reject(message)
60
         reject(message)
66
       }
61
       }
67
     })
62
     })