张延森 vor 4 Jahren
Ursprung
Commit
bd1e00a1d9

+ 4
- 1
src/app.js Datei anzeigen

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

+ 45
- 0
src/compents/Picker/index.jsx Datei anzeigen

@@ -0,0 +1,45 @@
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 Datei anzeigen

@@ -19,29 +19,6 @@ const guide = props => {
19 19
   // const [detail, setDetail] = useState({})
20 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 22
   const onOpenLocation = lngLat => {
46 23
     const [latitude, longitude] = lngLat.split(",");
47 24
 
@@ -201,22 +178,26 @@ const guide = props => {
201 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 198
               </View>
218
-            </ContainerLayout>
219
-          </View>
199
+            )
200
+          }
220 201
           <View className="guide-view">
221 202
             <Text className="guide-view-info">其他指引</Text>
222 203
             {/* <ContainerLayout className='guide-view-layout guide-view-img'> */}

+ 5
- 7
src/pages/house/addnewhouse/index.jsx Datei anzeigen

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

+ 14
- 6
src/pages/house/list/index.jsx Datei anzeigen

@@ -16,11 +16,12 @@ import RecycleList from "@/compents/RecycleList";
16 16
 
17 17
 let house = (props, ref) => {
18 18
   const user = useSelector(state => state.user)
19
+  const defaultShop = user.defaultShop
19 20
   const [list, setList] = useState([]);
20 21
   const [radioHouse, setRadioHouse] = useState();
21 22
   const [width, setWidth] = useState();
22 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 25
   const [total, setTotal] = useState(0);
25 26
 
26 27
   useImperativeHandle(ref, () => ({
@@ -105,9 +106,15 @@ let house = (props, ref) => {
105 106
             for (let item of res) {
106 107
               if (item.height) {
107 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 118
                 break;
112 119
               }
113 120
             }
@@ -137,8 +144,8 @@ let house = (props, ref) => {
137 144
   }, [queryParams]);
138 145
 
139 146
   useEffect(() => {
140
-      setQueryParams({ ...queryParams, shopId: user.shopId })
141
-  }, [user.shopId])
147
+      setQueryParams({ ...queryParams, shopId: defaultShop })
148
+  }, [defaultShop])
142 149
 
143 150
   // useDidShow(() => {
144 151
   //   setQueryParams({ ...queryParams })
@@ -210,5 +217,6 @@ let house = (props, ref) => {
210 217
     </View>
211 218
   );
212 219
 };
220
+
213 221
 house = forwardRef(house);
214 222
 export default house;

+ 2
- 1
src/pages/index/index.config.js Datei anzeigen

@@ -3,6 +3,7 @@ export default {
3 3
   navigationStyle: "custom",
4 4
   enableShareAppMessage: true,
5 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 Datei anzeigen

@@ -17,8 +17,6 @@ const index = props => {
17 17
 
18 18
   const dispatch = useDispatch();
19 19
 
20
-  const shopList = (user.shopList || []).map(x => ({text: x.name, value: x.shopId}))
21
-
22 20
   useEffect(() => {
23 21
     if (user.role == roleList.landlord) {
24 22
       wx.setNavigationBarTitle({
@@ -51,11 +49,6 @@ const index = props => {
51 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 52
   return (
60 53
     <View className="index">
61 54
       {user.personId && (
@@ -73,31 +66,6 @@ const index = props => {
73 66
           )}
74 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 69
     </View>
102 70
   );
103 71
 };

+ 37
- 10
src/pages/landlord/index.jsx Datei anzeigen

@@ -1,9 +1,10 @@
1 1
 import React, { useEffect, useRef, useState } from 'react'
2 2
 import Taro, { useDidShow } from "@tarojs/taro";
3
-import { useSelector } from 'react-redux'
3
+import { useSelector, useDispatch } from "react-redux"
4 4
 import { View, ScrollView, Button } from '@tarojs/components'
5 5
 import Layout from '../../layout/index'
6 6
 import Tab from '../../compents/tab/index'
7
+import Picker from '../../compents/Picker/index'
7 8
 // import Register from './register/index'
8 9
 import Guide from '../guide/index'
9 10
 import Recommend from '../recommend/index'
@@ -12,9 +13,8 @@ import { AtFloatLayout } from "taro-ui"
12 13
 import request from '@/util/request'
13 14
 import './index.scss'
14 15
 import NavCustom from '../../compents/navcustom'
15
-const index = (props) => {
16
-
17 16
 
17
+const index = (props) => {
18 18
   const user = useSelector(state => state.user)
19 19
   const [isOpened, setIsOpened] = useState(false)
20 20
   const [userRole, setUserRole] = useState('1')
@@ -23,9 +23,12 @@ const index = (props) => {
23 23
   const [radioHouseData, setRadioHouseData] = useState()
24 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 29
   const childRef = useRef();
28 30
 
31
+  const dispatch = useDispatch()
29 32
 
30 33
   const handleClose = () => {
31 34
     setIsOpened(false)
@@ -35,15 +38,15 @@ const index = (props) => {
35 38
 
36 39
   }
37 40
 
38
-  const onRegisterChange = (e) => {
39
-  }
41
+  const onRegisterChange = (e) => {}
42
+
40 43
   const onCopy = (e) => {
41 44
 
42 45
     if (radioHouseData.houseId) {
43 46
 
44 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 50
         Taro.showModal({
48 51
           title: '复制成功',
49 52
           content: '点击确认按钮,返回上级菜单',
@@ -80,13 +83,37 @@ const index = (props) => {
80 83
 
81 84
   }
82 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 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 117
       <Layout type='custom'>
91 118
         {pageState == '1' && <HouseLIst ref={childRef} radioHouseState={radioHouseState} onChange={(e) => setRadioHouseData(e)}></HouseLIst>}
92 119
       </Layout>

+ 15
- 8
src/reducers/user.js Datei anzeigen

@@ -15,6 +15,11 @@ const INITIAL_STATE = {
15 15
   // role: 'customer'
16 16
 }
17 17
 
18
+
19
+function setDefaultShop(shopId) {
20
+  wx.setStorageSync('defaultShop',shopId)
21
+}
22
+
18 23
 export const login = () => {
19 24
   return {
20 25
     type: LOGIN
@@ -35,7 +40,6 @@ export function asyncLogina() {
35 40
 export default function user(state = INITIAL_STATE, action) {
36 41
   switch (action.type) {
37 42
     case 'LOGIN': {
38
-
39 43
       if (action.user.shopKeeperList && action.user.shopKeeperList.length) {
40 44
           wx.setNavigationBarTitle({
41 45
             title: '民宿房源管理'
@@ -54,14 +58,18 @@ export default function user(state = INITIAL_STATE, action) {
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 67
         return {
60 68
           ...state,
61 69
           ...action.user,
62 70
           role: 'landlord',
71
+          defaultShop: shopId || defaultShop,
63 72
           shopList,
64
-          shopId,
65 73
           // role: 'customer',
66 74
         }
67 75
       } else {
@@ -71,9 +79,6 @@ export default function user(state = INITIAL_STATE, action) {
71 79
           role: 'customer',
72 80
         }
73 81
       }
74
-
75
-
76
-
77 82
     }
78 83
     case 'phone': {
79 84
       return state
@@ -84,9 +89,11 @@ export default function user(state = INITIAL_STATE, action) {
84 89
         return state
85 90
       }
86 91
 
92
+      setDefaultShop(shopId)
93
+
87 94
       return {
88 95
         ...state,
89
-        shopId
96
+        defaultShop: shopId,
90 97
       }
91 98
     }
92 99