Browse Source

Merge branch 'master' of http://git.ycjcjy.com/shigongli/client-miniapp into master

zlisen 4 years ago
parent
commit
7fa0e8845c
2 changed files with 54 additions and 23 deletions
  1. 17
    6
      src/pages/customer/index.js
  2. 37
    17
      src/pages/customer/register/index.jsx

+ 17
- 6
src/pages/customer/index.js View File

17
   const user = useSelector(state => state.user)
17
   const user = useSelector(state => state.user)
18
 
18
 
19
   const [pageState, setPageState] = useState('3')
19
   const [pageState, setPageState] = useState('3')
20
+  const [orderInfo, setOrderInfo] = useState()
20
   const [houseInfo, setHouseInfo] = useState()
21
   const [houseInfo, setHouseInfo] = useState()
21
   const [surroundList, setSurroundList] = useState()
22
   const [surroundList, setSurroundList] = useState()
23
+  const [regUnFinished, setRegUnFinished] = useState(true)
24
+
25
+  const handleRegisterFinished = () => {
26
+    setRegUnFinished(false)
27
+  }
22
 
28
 
23
   useEffect(() => {
29
   useEffect(() => {
24
     if(props.orderId){
30
     if(props.orderId){
25
       request({url: `/taHouseOrder/{props.orderId}`,}).then(res=>{
31
       request({url: `/taHouseOrder/{props.orderId}`,}).then(res=>{
26
         const data = res.data.data
32
         const data = res.data.data
27
-        if (data.status !== 1) {
28
-          setPageState('1')
29
-        }
33
+        setOrderInfo(data)
34
+        regUnFinished(data.status !== 1)
30
       })
35
       })
31
     }
36
     }
32
   }, [props.orderId])
37
   }, [props.orderId])
38
+
39
+  useEffect(() => {
40
+    if(props.orderId && regUnFinished){
41
+      setPageState('1')
42
+    }
43
+  }, [props.orderId, regUnFinished])
33
   
44
   
34
   useEffect(() => {
45
   useEffect(() => {
35
-    if(props.houseId){
46
+    if(props.houseId && (!props.orderId || !regUnFinished)){
36
       request({url: `/taHouse/${props.houseId}`,}).then(res=>{
47
       request({url: `/taHouse/${props.houseId}`,}).then(res=>{
37
         const data = res.data.data
48
         const data = res.data.data
38
         setHouseInfo(data)
49
         setHouseInfo(data)
45
         setSurroundList(records)
56
         setSurroundList(records)
46
     })
57
     })
47
 
58
 
48
-  }, [props.houseId])
59
+  }, [props.houseId, props.orderId, regUnFinished])
49
  
60
  
50
   return (
61
   return (
51
     <View className='index'>
62
     <View className='index'>
52
-      {pageState=='1'&&<Register oderId={orderId}></Register>}
63
+      {pageState=='1'&&<Register oderId={orderId} dataSource={orderInfo} onFinished={handleRegisterFinished}></Register>}
53
 
64
 
54
       <Layout>
65
       <Layout>
55
         {pageState=='2'&&<Guide houseId={houseId} dataSource={houseInfo}></Guide>  }
66
         {pageState=='2'&&<Guide houseId={houseId} dataSource={houseInfo}></Guide>  }

+ 37
- 17
src/pages/customer/register/index.jsx View File

5
 import { AtInput } from 'taro-ui'
5
 import { AtInput } from 'taro-ui'
6
 import Tab from '../../../compents/tab'
6
 import Tab from '../../../compents/tab'
7
 import Layout from '../../../layout'
7
 import Layout from '../../../layout'
8
+import request from '@/util/request'
8
 
9
 
9
 
10
 
10
 const InputGroup = props => {
11
 const InputGroup = props => {
11
-  console.log('---------', JSON.stringify(props.dataSource))
12
   const [name, setName] = useState(props.dataSource.name)
12
   const [name, setName] = useState(props.dataSource.name)
13
   const [phone, setPhone] = useState(props.dataSource.phone)
13
   const [phone, setPhone] = useState(props.dataSource.phone)
14
 
14
 
25
   }, [props.dataSource.phone])
25
   }, [props.dataSource.phone])
26
 
26
 
27
   const handeNameChange = e => {
27
   const handeNameChange = e => {
28
-    console.log('333333333333333333')
29
     const v = e.detail.value
28
     const v = e.detail.value
30
     setName(v)
29
     setName(v)
31
     if (props.onChange) {
30
     if (props.onChange) {
72
 
71
 
73
   let [list, setList] = useState([])
72
   let [list, setList] = useState([])
74
   useEffect(() => {
73
   useEffect(() => {
75
-    //   console.log(page,'page')
76
-    const arr = []
77
-    for (let i = 0; i < 4; i++) {
78
-      arr.push({
79
-        name:'',
80
-        phone:'',
81
-      })
74
+    if (props.dataSource) {
75
+      const {personNum} = props.dataSource.houseSetting || {}
76
+
77
+      setList(new Array(personNum || 0).fill('*').map(x => ({name: undefined, phone: undefined})))
82
     }
78
     }
83
-    setList(arr)
84
-  }, [])
79
+  }, [props.dataSource])
85
 
80
 
86
   const onClick = () => {
81
   const onClick = () => {
87
-    console.log(list)
82
+    const hasNull = list.filter(x => !x.name || !x.phone)[0]
83
+    if (hasNull) {
84
+      Taro.showModal({
85
+        title: '请将信息填写完成',
86
+        showCancel: false,
87
+        success: () => {}
88
+      })
89
+
90
+      return
91
+    }
92
+
93
+    const data = {
94
+      orderId: props.dataSource.orderId,
95
+      houseId: props.dataSource.houseSetting.houseId,
96
+      personList: list,
97
+    }
98
+
99
+    request({ url: '/taHousePerson', method: 'POST', data }).then(res => {
100
+      if (props.onFinished) {
101
+        props.onFinished(res)
102
+      }
103
+    }).catch(err => {
104
+      console.error(err)
105
+      const message = err.message || err.errMsg || err
106
+      Taro.showToast({
107
+        title: message,
108
+        icon: 'none',
109
+        duration: 3000
110
+      })
111
+    })
88
   }
112
   }
89
 
113
 
90
-  const onChangeList = index => value =>  {
91
-    console.log(111111111, value, index)
92
- 
114
+  const onChangeList = index => value =>  { 
93
     list[index] = value
115
     list[index] = value
94
-
95
     setList([...list])
116
     setList([...list])
96
-
97
   }
117
   }
98
 
118
 
99
   return <View className='register'>
119
   return <View className='register'>