张延森 4 年前
父节点
当前提交
bd1e00a1d9

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

15
 
15
 
16
 const store = configStore()
16
 const store = configStore()
17
 
17
 
18
+// 清空默认选择
19
+wx.setStorageSync('defaultShop', undefined)
20
+
18
 class App extends Component {
21
 class App extends Component {
19
   componentDidMount() {}
22
   componentDidMount() {}
20
 
23
 
25
   componentDidShow() {
28
   componentDidShow() {
26
     wx.login({
29
     wx.login({
27
       success (res) {
30
       success (res) {
28
-        console.log(res,'22222222222')
31
+        // console.log(res,'22222222222')
29
         if (res.code) {
32
         if (res.code) {
30
           //发起网络请求
33
           //发起网络请求
31
 
34
 

+ 45
- 0
src/compents/Picker/index.jsx 查看文件

1
+import React, { useState, useEffect } from 'react'
2
+
3
+export default props => {
4
+  const [label, setLabel] = useState()
5
+  const [pos, setPos] = useState()
6
+  const { value, range=[], rangeKey, rangeValue, placeholder = '请选择', preTitle = '' } = props
7
+
8
+  const handleChange = e => {
9
+    const inx = e.detail.value - 0
10
+    setPos(inx)
11
+    if (props.onChange) {
12
+      props.onChange(range[inx])
13
+    }
14
+  }
15
+  
16
+  useEffect(() => {
17
+    let inited = false
18
+    for (let i = 0; i < range.length; i ++) {
19
+      const val = range[i][rangeValue]
20
+      if (val === value) {
21
+        setPos(i)
22
+        inited = true
23
+        break
24
+      }
25
+    }
26
+
27
+    if (!inited) {
28
+      setPos()
29
+    }
30
+  }, [value])
31
+
32
+  useEffect(() => {
33
+    if (pos || pos === 0) {
34
+      setLabel(range[pos][rangeKey])
35
+    } else {
36
+      setLabel()
37
+    }
38
+  }, [pos])
39
+
40
+  return (
41
+    <picker value={pos} range={range} range-key={rangeKey} onChange={handleChange}>
42
+      <view>{label ? `${preTitle} ${label}` : placeholder}</view>
43
+    </picker>
44
+  )
45
+}

+ 19
- 38
src/pages/guide/index.jsx 查看文件

19
   // const [detail, setDetail] = useState({})
19
   // const [detail, setDetail] = useState({})
20
   const detail = props.dataSource || {};
20
   const detail = props.dataSource || {};
21
 
21
 
22
-  // useDidShow(() => {
23
-  //     if (houseId) {
24
-  //         getDetail()
25
-  //     }
26
-  // })
27
-
28
-  // useEffect(() => {
29
-  //     console.log(houseId, 'params33')
30
-  //     if (houseId) {
31
-  //         getDetail()
32
-  //     }
33
-
34
-  // }, [])
35
-  // const getDetail = () => {
36
-  //     request({ url: `/taHouse/${houseId}` }).then((res) => {
37
-  //         setDetail(res.data.data)
38
-
39
-  //         wx.setNavigationBarTitle({
40
-  //             title: res.data.data.title
41
-  //         })
42
-  //     })
43
-  // }
44
-
45
   const onOpenLocation = lngLat => {
22
   const onOpenLocation = lngLat => {
46
     const [latitude, longitude] = lngLat.split(",");
23
     const [latitude, longitude] = lngLat.split(",");
47
 
24
 
201
               </View>
178
               </View>
202
             )
179
             )
203
           }
180
           }
204
-          <View className="guide-view">
205
-            <Text className="guide-view-info">wifi信息</Text>
206
-            <ContainerLayout
207
-              className="guide-view-layout guide-view-wifi"
208
-              onClick={() => onToMap("wifi")}
209
-            >
210
-              <View>
211
-                <Text>名称:</Text>
212
-                <Text>{detail.wifiName}</Text>
213
-              </View>
214
-              <View>
215
-                <Text>密码:</Text>
216
-                <Text>{detail.wifiPassword}</Text>
181
+          { detail.wifiName &&
182
+            (
183
+              <View className="guide-view">
184
+                <Text className="guide-view-info">wifi信息</Text>
185
+                <ContainerLayout
186
+                  className="guide-view-layout guide-view-wifi"
187
+                  onClick={() => onToMap("wifi")}
188
+                >
189
+                  <View>
190
+                    <Text>名称:</Text>
191
+                    <Text>{detail.wifiName}</Text>
192
+                  </View>
193
+                  <View>
194
+                    <Text>密码:</Text>
195
+                    <Text>{detail.wifiPassword}</Text>
196
+                  </View>
197
+                </ContainerLayout>
217
               </View>
198
               </View>
218
-            </ContainerLayout>
219
-          </View>
199
+            )
200
+          }
220
           <View className="guide-view">
201
           <View className="guide-view">
221
             <Text className="guide-view-info">其他指引</Text>
202
             <Text className="guide-view-info">其他指引</Text>
222
             {/* <ContainerLayout className='guide-view-layout guide-view-img'> */}
203
             {/* <ContainerLayout className='guide-view-layout guide-view-img'> */}

+ 5
- 7
src/pages/house/addnewhouse/index.jsx 查看文件

15
 
15
 
16
     const user = useSelector(state => state.user)
16
     const user = useSelector(state => state.user)
17
     const { shopKeeperList = [] } = user
17
     const { shopKeeperList = [] } = user
18
-    const shopId = shopKeeperList[0].shopId || ''
18
+    const defaultShop = user.defaultShop
19
+
19
     const [userRole, setUserRole] = useState('1')
20
     const [userRole, setUserRole] = useState('1')
20
     const [pageState, setPageState] = useState('1')
21
     const [pageState, setPageState] = useState('1')
21
     const [list, setList] = useState([])
22
     const [list, setList] = useState([])
55
     }
56
     }
56
     
57
     
57
     const formSubmit = (e) => {
58
     const formSubmit = (e) => {
58
-        // console.log(e.detail, 'formSubmit')
59
-
60
-
61
         if(!e.detail.value?.title){
59
         if(!e.detail.value?.title){
62
             wx.showToast({
60
             wx.showToast({
63
                 title: '请完善房源信息',
61
                 title: '请完善房源信息',
72
             ...value,
70
             ...value,
73
             lngLat: `${address.latitude || ''},${address.longitude || ''}`,
71
             lngLat: `${address.latitude || ''},${address.longitude || ''}`,
74
             parkLngLat: `${parking.latitude || ''},${parking.longitude || ''}`,
72
             parkLngLat: `${parking.latitude || ''},${parking.longitude || ''}`,
75
-            shopId: user.shopId,
76
-            desc:imgUrl,
73
+            shopId: defaultShop,
74
+            desc: imgUrl,
77
         }
75
         }
78
-        console.log(data,e.detail.value,'formSubmit')
76
+        console.log(data, e.detail.value, user, 'formSubmit')
79
         request({ url: '/taHouse', method: 'post', data:{...data} }).then((res) => {
77
         request({ url: '/taHouse', method: 'post', data:{...data} }).then((res) => {
80
             if (res.data.code == 1000)
78
             if (res.data.code == 1000)
81
                 Taro.navigateBack({
79
                 Taro.navigateBack({

+ 14
- 6
src/pages/house/list/index.jsx 查看文件

16
 
16
 
17
 let house = (props, ref) => {
17
 let house = (props, ref) => {
18
   const user = useSelector(state => state.user)
18
   const user = useSelector(state => state.user)
19
+  const defaultShop = user.defaultShop
19
   const [list, setList] = useState([]);
20
   const [list, setList] = useState([]);
20
   const [radioHouse, setRadioHouse] = useState();
21
   const [radioHouse, setRadioHouse] = useState();
21
   const [width, setWidth] = useState();
22
   const [width, setWidth] = useState();
22
   const [height, setHeight] = useState();
23
   const [height, setHeight] = useState();
23
-  const [queryParams, setQueryParams] = useState({ pageNum: 1, pageSize: 10, shopId: user.shopId });
24
+  const [queryParams, setQueryParams] = useState({ pageNum: 1, pageSize: 10, shopId: defaultShop });
24
   const [total, setTotal] = useState(0);
25
   const [total, setTotal] = useState(0);
25
 
26
 
26
   useImperativeHandle(ref, () => ({
27
   useImperativeHandle(ref, () => ({
105
             for (let item of res) {
106
             for (let item of res) {
106
               if (item.height) {
107
               if (item.height) {
107
                 found = true;
108
                 found = true;
108
-                setHeight(
109
-                  Taro.getSystemInfoSync().safeArea.height - item.height - 50
110
-                );
109
+
110
+                let h = Taro.getSystemInfoSync().safeArea.height - item.height - 50
111
+
112
+                // 如果显示了下拉框,要去掉下拉框的高度
113
+                if (user.shopList && user.shopList.length > 1) {
114
+                  h -= 64
115
+                }
116
+
117
+                setHeight(h);
111
                 break;
118
                 break;
112
               }
119
               }
113
             }
120
             }
137
   }, [queryParams]);
144
   }, [queryParams]);
138
 
145
 
139
   useEffect(() => {
146
   useEffect(() => {
140
-      setQueryParams({ ...queryParams, shopId: user.shopId })
141
-  }, [user.shopId])
147
+      setQueryParams({ ...queryParams, shopId: defaultShop })
148
+  }, [defaultShop])
142
 
149
 
143
   // useDidShow(() => {
150
   // useDidShow(() => {
144
   //   setQueryParams({ ...queryParams })
151
   //   setQueryParams({ ...queryParams })
210
     </View>
217
     </View>
211
   );
218
   );
212
 };
219
 };
220
+
213
 house = forwardRef(house);
221
 house = forwardRef(house);
214
 export default house;
222
 export default house;

+ 2
- 1
src/pages/index/index.config.js 查看文件

3
   navigationStyle: "custom",
3
   navigationStyle: "custom",
4
   enableShareAppMessage: true,
4
   enableShareAppMessage: true,
5
   usingComponents: {
5
   usingComponents: {
6
-    "mp-actionSheet": "weui-miniprogram/actionsheet/actionsheet"
6
+    "mp-cells": "weui-miniprogram/cells/cells",
7
+    "mp-cell": "weui-miniprogram/cell/cell"
7
   }
8
   }
8
 }
9
 }

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

17
 
17
 
18
   const dispatch = useDispatch();
18
   const dispatch = useDispatch();
19
 
19
 
20
-  const shopList = (user.shopList || []).map(x => ({text: x.name, value: x.shopId}))
21
-
22
   useEffect(() => {
20
   useEffect(() => {
23
     if (user.role == roleList.landlord) {
21
     if (user.role == roleList.landlord) {
24
       wx.setNavigationBarTitle({
22
       wx.setNavigationBarTitle({
51
     setShowAuthPhone(false);
49
     setShowAuthPhone(false);
52
   };
50
   };
53
 
51
 
54
-  const handleSelectShop = e => {
55
-    const shopId = e.detail.value
56
-    dispatch({ type: "SET_SHOP", shopId });
57
-  }
58
-
59
   return (
52
   return (
60
     <View className="index">
53
     <View className="index">
61
       {user.personId && (
54
       {user.personId && (
73
           )}
66
           )}
74
         </View>
67
         </View>
75
       )}
68
       )}
76
-
77
-      {/* {userRole == 1 ? <Register userRole={userRole} list={list} onChange={(e) => onRegisterChange(e)}></Register> :
78
-          <View>userRole={userRole} list={list} onChange={(e) => onRegisterChange(e)}
79
-            {(userRole == 'guide' || userRole == 2) && <Guide userRole={userRole}/>}
80
-            {userRole == 'recommend' && <Recommend userRole={userRole}/>}
81
-          </View>
82
-        }
83
-        {userRole == 2 ? <Register userRole={userRole} list={list} onChange={(e) => onRegisterChange(e)}></Register> :
84
-          <View>
85
-            {(userRole == 'guide' || userRole == 2) && <Guide userRole={userRole}/>}
86
-            {userRole == 'recommend' && <Recommend userRole={userRole}/>}
87
-          </View>
88
-        }
89
-     <HouseLIst userRole={userRole} list={list} onChange={(e) => onRegisterChange(e)}></HouseLIst>  */}
90
-
91
-      {/* </View>
92
-    </ScrollView>
93
-    <Tab value={userRole} onClick={(e) => onTabClick(e)}></Tab> */}
94
-      {
95
-        shopList.length > 0 && !user.shopId &&
96
-        (
97
-          <mp-actionSheet show actions={shopList} title="请选择店铺" showCancel={false} onActiontap={handleSelectShop}>
98
-          </mp-actionSheet>
99
-        )
100
-      }
101
     </View>
69
     </View>
102
   );
70
   );
103
 };
71
 };

+ 37
- 10
src/pages/landlord/index.jsx 查看文件

1
 import React, { useEffect, useRef, useState } from 'react'
1
 import React, { useEffect, useRef, useState } from 'react'
2
 import Taro, { useDidShow } from "@tarojs/taro";
2
 import Taro, { useDidShow } from "@tarojs/taro";
3
-import { useSelector } from 'react-redux'
3
+import { useSelector, useDispatch } from "react-redux"
4
 import { View, ScrollView, Button } from '@tarojs/components'
4
 import { View, ScrollView, Button } from '@tarojs/components'
5
 import Layout from '../../layout/index'
5
 import Layout from '../../layout/index'
6
 import Tab from '../../compents/tab/index'
6
 import Tab from '../../compents/tab/index'
7
+import Picker from '../../compents/Picker/index'
7
 // import Register from './register/index'
8
 // import Register from './register/index'
8
 import Guide from '../guide/index'
9
 import Guide from '../guide/index'
9
 import Recommend from '../recommend/index'
10
 import Recommend from '../recommend/index'
12
 import request from '@/util/request'
13
 import request from '@/util/request'
13
 import './index.scss'
14
 import './index.scss'
14
 import NavCustom from '../../compents/navcustom'
15
 import NavCustom from '../../compents/navcustom'
15
-const index = (props) => {
16
-
17
 
16
 
17
+const index = (props) => {
18
   const user = useSelector(state => state.user)
18
   const user = useSelector(state => state.user)
19
   const [isOpened, setIsOpened] = useState(false)
19
   const [isOpened, setIsOpened] = useState(false)
20
   const [userRole, setUserRole] = useState('1')
20
   const [userRole, setUserRole] = useState('1')
23
   const [radioHouseData, setRadioHouseData] = useState()
23
   const [radioHouseData, setRadioHouseData] = useState()
24
   const [radioHouseState, setRadioHouseState] = useState(false)
24
   const [radioHouseState, setRadioHouseState] = useState(false)
25
 
25
 
26
+  const shopList = (user.shopList || []).map(x => ({text: x.name, value: x.shopId}))
27
+  const defaultShop = user.defaultShop
26
 
28
 
27
   const childRef = useRef();
29
   const childRef = useRef();
28
 
30
 
31
+  const dispatch = useDispatch()
29
 
32
 
30
   const handleClose = () => {
33
   const handleClose = () => {
31
     setIsOpened(false)
34
     setIsOpened(false)
35
 
38
 
36
   }
39
   }
37
 
40
 
38
-  const onRegisterChange = (e) => {
39
-  }
41
+  const onRegisterChange = (e) => {}
42
+
40
   const onCopy = (e) => {
43
   const onCopy = (e) => {
41
 
44
 
42
     if (radioHouseData.houseId) {
45
     if (radioHouseData.houseId) {
43
 
46
 
44
       const {houseId,...data} = radioHouseData
47
       const {houseId,...data} = radioHouseData
45
 
48
 
46
-      request({ url: '/taHouse', method: 'post', data: { ...data } }).then((res) => {
49
+      request({ url: '/taHouse', method: 'post', data: { ...data, originId: houseId } }).then((res) => {
47
         Taro.showModal({
50
         Taro.showModal({
48
           title: '复制成功',
51
           title: '复制成功',
49
           content: '点击确认按钮,返回上级菜单',
52
           content: '点击确认按钮,返回上级菜单',
80
 
83
 
81
   }
84
   }
82
   const navStyle =  Taro.getMenuButtonBoundingClientRect()
85
   const navStyle =  Taro.getMenuButtonBoundingClientRect()
86
+  
83
 
87
 
84
-  return <View className='index'>
85
-
88
+  const handleSelectShop = shop => {
89
+    dispatch({ type: "SET_SHOP", shopId: shop.value });
90
+  }
86
 
91
 
92
+  return <View className='index'>
87
     <View>
93
     <View>
88
-  
89
-  {pageState == '1' &&<NavCustom houseInfo={{title:'民宿房源管理'}}></NavCustom>}
94
+      {pageState == '1' &&<NavCustom houseInfo={{title:'民宿房源管理'}}></NavCustom>}
95
+
96
+      {
97
+        shopList.length > 1 &&
98
+        (
99
+          <mp-cells>
100
+            <mp-cell>
101
+              <Picker
102
+                value={defaultShop}
103
+                range={shopList}
104
+                rangeKey="text"
105
+                rangeValue="value"
106
+                preTitle="当前店铺"
107
+                placeholder="请选择店铺"
108
+                onChange={handleSelectShop}
109
+              />
110
+            </mp-cell>
111
+          </mp-cells>
112
+          // <mp-actionSheet show actions={shopList} title="请选择店铺" showCancel={false} onActiontap={handleSelectShop}>
113
+          // </mp-actionSheet>
114
+        )
115
+      }
116
+
90
       <Layout type='custom'>
117
       <Layout type='custom'>
91
         {pageState == '1' && <HouseLIst ref={childRef} radioHouseState={radioHouseState} onChange={(e) => setRadioHouseData(e)}></HouseLIst>}
118
         {pageState == '1' && <HouseLIst ref={childRef} radioHouseState={radioHouseState} onChange={(e) => setRadioHouseData(e)}></HouseLIst>}
92
       </Layout>
119
       </Layout>

+ 15
- 8
src/reducers/user.js 查看文件

15
   // role: 'customer'
15
   // role: 'customer'
16
 }
16
 }
17
 
17
 
18
+
19
+function setDefaultShop(shopId) {
20
+  wx.setStorageSync('defaultShop',shopId)
21
+}
22
+
18
 export const login = () => {
23
 export const login = () => {
19
   return {
24
   return {
20
     type: LOGIN
25
     type: LOGIN
35
 export default function user(state = INITIAL_STATE, action) {
40
 export default function user(state = INITIAL_STATE, action) {
36
   switch (action.type) {
41
   switch (action.type) {
37
     case 'LOGIN': {
42
     case 'LOGIN': {
38
-
39
       if (action.user.shopKeeperList && action.user.shopKeeperList.length) {
43
       if (action.user.shopKeeperList && action.user.shopKeeperList.length) {
40
           wx.setNavigationBarTitle({
44
           wx.setNavigationBarTitle({
41
             title: '民宿房源管理'
45
             title: '民宿房源管理'
54
         }, [])
58
         }, [])
55
 
59
 
56
         // 默认当前的, 但是如果有多个, 则需要用户来确定
60
         // 默认当前的, 但是如果有多个, 则需要用户来确定
57
-        const shopId = shopList.length > 1 ? undefined : shopList[0]
58
-
61
+        const shopId = shopList.length > 1 ? undefined : shopList[0].shopId
62
+        const defaultShop = wx.getStorageSync('defaultShop')
63
+        if (shopId && shopId !== defaultShop) {
64
+          setDefaultShop(shopId)
65
+        }
66
+        
59
         return {
67
         return {
60
           ...state,
68
           ...state,
61
           ...action.user,
69
           ...action.user,
62
           role: 'landlord',
70
           role: 'landlord',
71
+          defaultShop: shopId || defaultShop,
63
           shopList,
72
           shopList,
64
-          shopId,
65
           // role: 'customer',
73
           // role: 'customer',
66
         }
74
         }
67
       } else {
75
       } else {
71
           role: 'customer',
79
           role: 'customer',
72
         }
80
         }
73
       }
81
       }
74
-
75
-
76
-
77
     }
82
     }
78
     case 'phone': {
83
     case 'phone': {
79
       return state
84
       return state
84
         return state
89
         return state
85
       }
90
       }
86
 
91
 
92
+      setDefaultShop(shopId)
93
+
87
       return {
94
       return {
88
         ...state,
95
         ...state,
89
-        shopId
96
+        defaultShop: shopId,
90
       }
97
       }
91
     }
98
     }
92
 
99