[baozhangchao] 3 лет назад
Родитель
Сommit
ebfb6ac971

+ 1
- 1
src/app.config.js Просмотреть файл

@@ -10,4 +10,4 @@ export default {
10 10
     navigationBarTitleText: 'WeChat',
11 11
     navigationBarTextStyle: 'black'
12 12
   }
13
-}
13
+}

+ 103
- 41
src/pages/DepartmentSelection/index.jsx Просмотреть файл

@@ -1,8 +1,9 @@
1
-import { View, Text } from "@tarojs/components"
1
+import { View } from "@tarojs/components"
2 2
 import { useEffect, useState } from "react"
3 3
 import Taro, { useDidShow } from "@tarojs/taro"
4
-import { TreeSelect } from "@antmjs/vantui";
4
+import { TreeSelect, Button } from "@antmjs/vantui";
5 5
 import { getDepartmenList } from "../../services/user";
6
+import { useModel } from "../../store";
6 7
 
7 8
 // import BottomMoadl from '@/components/BottomMoadl/index'
8 9
 
@@ -14,47 +15,97 @@ import { getDepartmenList } from "../../services/user";
14 15
 import './style.less'
15 16
 
16 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 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,13 +116,24 @@ export default (props) => {
65 116
   return (
66 117
     <View className='page-index'>
67 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 123
         onClickNav={onClickNav}
72 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 137
     </View>
76 138
   )
77 139
 }

+ 9
- 0
src/pages/DepartmentSelection/style.less Просмотреть файл

@@ -57,3 +57,12 @@
57 57
   bottom: 5vh;
58 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 Просмотреть файл

@@ -4,19 +4,41 @@ import dayjs from 'dayjs'
4 4
 import { Button, Icon } from "@antmjs/vantui";
5 5
 import Taro from '@tarojs/taro';
6 6
 import BarCode from '@/components/barcode'
7
-import CountDown from '@/components/CountDown'
7
+import { useModel } from '../../store';
8 8
 
9 9
 import './style.less'
10 10
 
11 11
 export default (props) => {
12
+  const { deptName, person, sessionKey } = useModel('userData')
13
+
12 14
   const userId = '320888800110023011';
13
-  
15
+
14 16
   const goUserInfo = () => {
15 17
     // 跳转到目的页面,在当前页面打开
16 18
     Taro.redirectTo({
17 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 43
   const today = useMemo(() => dayjs().format('YYYY-MM-DD'))
22 44
 
@@ -26,10 +48,10 @@ export default (props) => {
26 48
       {/* <View className='index-UserQRcode-headerInfo' style={{ backgroundImage: `url(${userBck})` }}> */}
27 49
       <View className='index-UserQRcode-headerInfo' >
28 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 52
           <View onClick={goUserInfo} className='index-UserQRcode-headerInfo-User-setNameInfo'><Icon name='edit' />修改信息</View>
31 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 55
       </View>
34 56
       <View className='index-UserQRcode-cententQR'>
35 57
         <View className='index-UserQRcode-cententQR-Barcode'>
@@ -40,7 +62,7 @@ export default (props) => {
40 62
         </View>
41 63
       </View>
42 64
       <View className='index-UserQRcode-footer'>
43
-      {today}
65
+        {today}
44 66
       </View>
45 67
     </View>
46 68
   )

+ 54
- 25
src/pages/setUserInfo/index.jsx Просмотреть файл

@@ -1,17 +1,42 @@
1 1
 import { View, Text, Input } from "@tarojs/components"
2
-import { useEffect, useRef, useState } from "react"
3 2
 import Taro, { useDidShow } from "@tarojs/taro"
4 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 8
 // import BottomMoadl from '@/components/BottomMoadl/index'
8 9
 import './style.less'
9 10
 
11
+
10 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 41
   const goDepartmen = () => {
17 42
     Taro.navigateTo({
@@ -19,27 +44,31 @@ export default (props) => {
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 57
   return (
27 58
     <View className='page-index'>
28 59
       <Form
29 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 68
         <FormItem
39 69
           label='用户名'
40
-          name='userName'
70
+          name='personName'
41 71
           required
42
-
43 72
           trigger='onInput'
44 73
           validateTrigger='onBlur'
45 74
           // taro的input的onInput事件返回对应表单的最终值为e.detail.value
@@ -50,48 +79,48 @@ export default (props) => {
50 79
         <FormItem
51 80
           label='手机号'
52 81
           name='phone'
53
-          required
54 82
           trigger='onInput'
83
+          required
55 84
           validateTrigger='onBlur'
56
-          // taro的input的onInput事件返回对应表单的最终值为e.detail.value
57 85
           valueFormat={(e) => e.detail.value}
58 86
         >
59
-          <Input placeholder='请输入手机号' type='number' />
87
+          <Input placeholder='请输入手机号' type='number' value={phone} maxlength={11} disabled />
60 88
           <Button
61 89
             plain
62 90
             hairline
63 91
             size='small'
64 92
             type='info'
93
+            required
94
+
95
+            openType='getPhoneNumber'
65 96
             onGetPhoneNumber={getPhone}
66 97
           >
67
-            一键填写
98
+            授权手机
68 99
           </Button>
69 100
         </FormItem>
70 101
 
71 102
         <FormItem
72 103
           label='身份证'
73
-          name='id'
104
+          name='idNo'
74 105
           required
75
-
76 106
           trigger='onInput'
77 107
           validateTrigger='onBlur'
78 108
           // taro的input的onInput事件返回对应表单的最终值为e.detail.value
79 109
           valueFormat={(e) => e.detail.value}
80 110
         >
81
-          <Input placeholder='请输入身份证号' type='number' />
111
+          <Input placeholder='请输入身份证号' type='number' maxlength={18} />
82 112
         </FormItem>
83 113
 
84 114
         <FormItem
85 115
           label='科室'
86
-          name='departmen'
87
-          required
88
-
116
+          name='deptName'
89 117
           trigger='onInput'
118
+          required
90 119
           validateTrigger='onBlur'
91 120
           // taro的input的onInput事件返回对应表单的最终值为e.detail.value
92 121
           valueFormat={(e) => e.detail.value}
93 122
         >
94
-          <Input placeholder='请选择科室' value='' disabled onClick={goDepartmen} />
123
+          <Input placeholder='请选择科室' value={deptName} disabled onClick={goDepartmen} />
95 124
         </FormItem>
96 125
         <View className='buttom-box'>
97 126
           <Button

+ 17
- 1
src/services/user.js Просмотреть файл

@@ -16,4 +16,20 @@ export const login = (data) => request('/login', { data, method: 'POST' })
16 16
  * @returns 
17 17
  */
18 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 Просмотреть файл

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

+ 0
- 5
src/utils/request.js Просмотреть файл

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