张延森 4 년 전
부모
커밋
c3fedfa1ae
2개의 변경된 파일54개의 추가작업 그리고 23개의 파일을 삭제
  1. 17
    6
      src/pages/customer/index.js
  2. 37
    17
      src/pages/customer/register/index.jsx

+ 17
- 6
src/pages/customer/index.js 파일 보기

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

+ 37
- 17
src/pages/customer/register/index.jsx 파일 보기

@@ -5,10 +5,10 @@ import ContainerLayout from '../../../compents/container/index'
5 5
 import { AtInput } from 'taro-ui'
6 6
 import Tab from '../../../compents/tab'
7 7
 import Layout from '../../../layout'
8
+import request from '@/util/request'
8 9
 
9 10
 
10 11
 const InputGroup = props => {
11
-  console.log('---------', JSON.stringify(props.dataSource))
12 12
   const [name, setName] = useState(props.dataSource.name)
13 13
   const [phone, setPhone] = useState(props.dataSource.phone)
14 14
 
@@ -25,7 +25,6 @@ const InputGroup = props => {
25 25
   }, [props.dataSource.phone])
26 26
 
27 27
   const handeNameChange = e => {
28
-    console.log('333333333333333333')
29 28
     const v = e.detail.value
30 29
     setName(v)
31 30
     if (props.onChange) {
@@ -72,28 +71,49 @@ const register = (props) => {
72 71
 
73 72
   let [list, setList] = useState([])
74 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 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 115
     list[index] = value
94
-
95 116
     setList([...list])
96
-
97 117
   }
98 118
 
99 119
   return <View className='register'>