|
@@ -1,10 +1,12 @@
|
1
|
1
|
import withLayout from '@/layouts'
|
2
|
2
|
import Taro from '@tarojs/taro'
|
3
|
3
|
import CustomNav from '@/components/CustomNav'
|
|
4
|
+import { View, Input, Button, Label, Textarea, Text } from '@tarojs/components';
|
4
|
5
|
import { useEffect, useState } from "react"
|
5
|
|
-import { Button, Label } from '@tarojs/components'
|
6
|
6
|
import { saveRoom, getRoomDetail, updateRoom } from '@/services/landlord'
|
7
|
7
|
import { getExtendContent } from "@/services/home";
|
|
8
|
+import { saveExtend } from '@/services/landlord'
|
|
9
|
+import Popup from '@/components/Popup'
|
8
|
10
|
import Extend from "../../components/Extend";
|
9
|
11
|
import './addRoom.less'
|
10
|
12
|
|
|
@@ -22,6 +24,8 @@ export default withLayout((props) => {
|
22
|
24
|
wifiPassword: '',
|
23
|
25
|
weight: '',
|
24
|
26
|
})
|
|
27
|
+ const [paddress,setpAddress]=useState()
|
|
28
|
+ const [wifiName,setwifiName]=useState()
|
25
|
29
|
const onRoomMap = () => {
|
26
|
30
|
Taro.chooseLocation().then((res) => {
|
27
|
31
|
setRoomModel({ ...roomModel, location: res.longitude + ',' + res.latitude })
|
|
@@ -58,80 +62,162 @@ export default withLayout((props) => {
|
58
|
62
|
}
|
59
|
63
|
}
|
60
|
64
|
const [extend, setExtend] = useState([]);
|
61
|
|
-
|
62
|
65
|
useEffect(() => {
|
63
|
66
|
if (roomId) {
|
64
|
67
|
getRoomDetail(roomId).then((res) => {
|
65
|
68
|
setRoomModel(res)
|
|
69
|
+ setpAddress(res.parkingAddress)
|
|
70
|
+ setwifiName(res.wifiName)
|
66
|
71
|
})
|
67
|
|
- getExtendContent('room', roomId).then((res) => {
|
|
72
|
+ }
|
|
73
|
+ }, [roomId])//这个地方写这个单词的目的是 因为编辑时roomId有可能还没加载成功
|
|
74
|
+ const [reset, setReset] = useState(false)
|
|
75
|
+ useEffect(() => {
|
|
76
|
+ if (roomId) {
|
|
77
|
+ getExtendContent('room', roomId, { pageSize: 999 }).then((res) => {
|
68
|
78
|
setExtend(res.records || []);
|
69
|
79
|
})
|
|
80
|
+ setReset(false)
|
70
|
81
|
}
|
71
|
|
- }, [roomId])//这个地方写这个单词的目的是 因为编辑时roomId有可能还没加载成功
|
|
82
|
+ }, [reset])
|
72
|
83
|
|
|
84
|
+ //新增文字
|
|
85
|
+ const [showCutover, setShowCutover] = useState(false)
|
|
86
|
+ const [cont, setcont] = useState('')
|
|
87
|
+ const onClose = () => {
|
|
88
|
+ setShowCutover(false)
|
|
89
|
+ }
|
|
90
|
+ //判断是否只有空 空格 回车
|
|
91
|
+ const javaTrim = (str) => {
|
|
92
|
+ for (var i = 0; (str.charAt(i) == ' ') && i < str.length; i++);
|
|
93
|
+ if (i == str.length) return ''; //whole string is space
|
|
94
|
+ var newstr = str.substr(i);
|
|
95
|
+ for (var i = newstr.length - 1; newstr.charAt(i) == ' ' && i >= 0; i--);
|
|
96
|
+ newstr = newstr.substr(0, i + 1);
|
|
97
|
+ return newstr;
|
|
98
|
+ }
|
|
99
|
+ const handelAdd = () => {
|
|
100
|
+ var content = document.getElementById('cont').value
|
73
|
101
|
|
|
102
|
+ content = content.replace(/\n/g, '');
|
|
103
|
+ if (javaTrim(content) == '') {
|
|
104
|
+ Taro.showToast({
|
|
105
|
+ title: '您还没有添加文字哦',
|
|
106
|
+ icon: 'none'
|
|
107
|
+ })
|
|
108
|
+ return;
|
|
109
|
+ }
|
|
110
|
+ const date = {
|
|
111
|
+ targetId: roomId,
|
|
112
|
+ targetType: 'room',
|
|
113
|
+ content,
|
|
114
|
+ contentType: 'text'
|
|
115
|
+ }
|
74
|
116
|
|
|
117
|
+ saveExtend(date)
|
|
118
|
+ setcont('')
|
|
119
|
+ onClose()
|
|
120
|
+ setReset(!reset)
|
|
121
|
+ }
|
|
122
|
+ const showText = () => {
|
|
123
|
+ setShowCutover(true)
|
|
124
|
+ setcont('')
|
|
125
|
+ }
|
|
126
|
+ const addImage = () => {
|
|
127
|
+ Taro.chooseImage({
|
|
128
|
+ count: 1,
|
|
129
|
+ success: function (res) {
|
|
130
|
+ const date = {
|
|
131
|
+ targetId: roomId,
|
|
132
|
+ targetType: 'room',
|
|
133
|
+ content: res.tempFilePaths[0],
|
|
134
|
+ contentType: 'image'
|
|
135
|
+ }
|
|
136
|
+ saveExtend(date)
|
|
137
|
+ setReset(!reset)
|
|
138
|
+ }
|
|
139
|
+ })
|
|
140
|
+ }
|
75
|
141
|
return (
|
76
|
142
|
<view className='page-index'>
|
77
|
143
|
<view className="index-navbar">
|
78
|
144
|
<CustomNav title={hotelName} />
|
79
|
145
|
</view>
|
80
|
|
- <view className='from-room' style={{ height: '100%', overflow: "hidden", }} >
|
|
146
|
+ <view className='roomDetail' style={{ height: '100%', overflow: "hidden", }} >
|
81
|
147
|
<scroll-view scrollY style={{ height: '100%' }}>
|
|
148
|
+ <View id='det'>
|
|
149
|
+ <Popup show={showCutover} onClose={onClose}>
|
|
150
|
+ <View className='editword'>
|
|
151
|
+ <View style={{ marginBottom: '25px' }}>
|
|
152
|
+ <View className='rzline' /><Label className='srl mg'>新增文字</Label><View className='rzline' />
|
|
153
|
+ </View>
|
|
154
|
+ <View>
|
|
155
|
+ <Textarea className='storezn' id='cont' value={cont} placeholder='请输入准备新增的文字' />
|
|
156
|
+ </View>
|
|
157
|
+ <View>
|
|
158
|
+ <Button className='cancel' onClick={onClose}>取消</Button>
|
|
159
|
+ <Button className='btn' onClick={handelAdd}>确认增加</Button>
|
|
160
|
+ </View>
|
|
161
|
+ </View>
|
|
162
|
+ </Popup>
|
|
163
|
+ </View>
|
82
|
164
|
<mp-form models={roomModel} >
|
83
|
|
- <mp-cells title='房屋名称' footer=' ' >
|
84
|
|
- <mp-cell extClass='font'>
|
85
|
|
- <input onInput={(e) => setRoomModel({ ...roomModel, roomName: e.detail.value })} value={roomModel.roomName} placeholder='请输入房屋名称(必填)' />
|
|
165
|
+ <mp-cells title='房屋名称' footer='' ext-class='cells' >
|
|
166
|
+ <mp-cell>
|
|
167
|
+ <Input style={{ fontWeight: 'bold' }} onInput={(e) => setRoomModel({ ...roomModel, roomName: e.detail.value })} value={roomModel.roomName} placeholder='请输入房屋名称(必填)' />
|
86
|
168
|
</mp-cell>
|
87
|
169
|
</mp-cells>
|
88
|
170
|
<mp-cells title='房屋位置'>
|
89
|
|
- <mp-cell extClass='font'>
|
90
|
|
- <input onInput={(e) => setRoomModel({ ...roomModel, address: e.detail.value })} value={roomModel.address} placeholder='请输入房屋位置(必填)' />
|
91
|
|
- </mp-cell>
|
92
|
|
- <mp-cell extClass='font'>
|
93
|
|
- <label onClick={onRoomMap}>{roomModel.location == '' ? '房间定位(必填)' : roomModel.location}</label>
|
94
|
|
- </mp-cell>
|
95
|
|
- </mp-cells>
|
96
|
|
- <mp-cells title='停车场位置'>
|
97
|
|
- <mp-cell extClass='font'>
|
98
|
|
- <input onInput={(e) => setRoomModel({ ...roomModel, parkingAddress: e.detail.value })} value={roomModel.parkingAddress} placeholder='请输入停车场位置' />
|
99
|
|
- </mp-cell>
|
100
|
|
- <mp-cell title='停车场经纬度:' extClass='font'>
|
101
|
|
- <label onClick={onParkMap}>{roomModel.parkingLocation == '' ? '停车场定位' : roomModel.parkingLocation}</label>
|
102
|
|
- </mp-cell>
|
103
|
|
- </mp-cells>
|
104
|
|
- <mp-cells title='WiFi'>
|
105
|
|
- <mp-cell title='Wi-Fi名称:' extClass='font'>
|
106
|
|
- <input onInput={(e) => setRoomModel({ ...roomModel, wifiName: e.detail.value })} value={roomModel.wifiName} placeholder='请输入wifi名称' />
|
|
171
|
+ <mp-cell>
|
|
172
|
+ <Input style={{ color: '#000', fontWeight: 'bold', marginBottom: '13px' }} onInput={(e) => setRoomModel({ ...roomModel, address: e.detail.value })} value={roomModel.address} placeholder='请输入房屋位置(必填)' />
|
|
173
|
+ <Label style={{ color: '#666' }} onClick={onRoomMap}>{roomModel.location == '' ? '房间定位(必填)' : roomModel.location}</Label>
|
107
|
174
|
</mp-cell>
|
108
|
|
- <mp-cell title='Wi-Fi密码:' extClass='font'>
|
109
|
|
- <input onInput={(e) => setRoomModel({ ...roomModel, wifiPassword: e.detail.value })} value={roomModel.wifiPassword} placeholder='请输入wifi密码' />
|
110
|
|
- </mp-cell>
|
111
|
|
- </mp-cells>
|
|
175
|
+ </mp-cells>
|
|
176
|
+ {
|
|
177
|
+ paddress != '' ?
|
|
178
|
+ <mp-cells title='停车场位置'>
|
|
179
|
+ <mp-cell>
|
|
180
|
+ <Input onInput={(e) => setRoomModel({ ...roomModel, parkingAddress: e.detail.value })} value={roomModel.parkingAddress} placeholder='请输入停车场位置' />
|
|
181
|
+ <Label style={{ color: '#666', lineHeight: '30px' }} onClick={onParkMap}>{roomModel.parkingLocation == '' ? '停车场定位' : roomModel.parkingLocation}</Label>
|
|
182
|
+ </mp-cell>
|
|
183
|
+ </mp-cells> : null
|
|
184
|
+ }
|
|
185
|
+ {
|
|
186
|
+ wifiName != '' ?
|
|
187
|
+ <mp-cells title='WiFi信息'>
|
|
188
|
+ <mp-cell>
|
|
189
|
+ <View style={{ color: '#666' }}>
|
|
190
|
+ <Input style={{ display: 'inline-block', background: '#fff', width: '20%' }} value='名称:' disabled /><Input style={{ display: 'inline-block', width: '80%' }} onInput={(e) => setRoomModel({ ...roomModel, wifiName: e.detail.value })} value={roomModel.wifiName} placeholder='请输入wifi名称' />
|
|
191
|
+ <Input style={{ display: 'inline-block', background: '#fff', width: '20%' }} value='密码:' disabled /><Input style={{ display: 'inline-block', width: '80%' }} onInput={(e) => setRoomModel({ ...roomModel, wifiPassword: e.detail.value })} value={roomModel.wifiPassword} placeholder='请输入wifi密码' />
|
|
192
|
+ </View>
|
|
193
|
+ </mp-cell>
|
|
194
|
+ </mp-cells> : null
|
|
195
|
+ }
|
112
|
196
|
<mp-cells title='权重'>
|
113
|
|
- <mp-cell extClass='font'>
|
|
197
|
+ <mp-cell>
|
114
|
198
|
<input type='number' value={roomModel.weight} onInput={(e) => setRoomModel({ ...roomModel, weight: e.detail.value })} placeholder='请输入权重(必填)' />
|
115
|
199
|
</mp-cell>
|
116
|
|
-
|
117
|
|
- </mp-cells>
|
118
|
|
- <mp-cells title='更多指引'>
|
|
200
|
+ </mp-cells>
|
|
201
|
+ <mp-cells title='其他指引'>
|
119
|
202
|
{
|
120
|
203
|
extend == '' ? null :
|
121
|
204
|
<mp-cell >
|
122
|
205
|
{extend.map((item) => (
|
123
|
|
- <Extend key={item.extId} item={item} />
|
|
206
|
+ <Extend key={item.extId} item={item} setReset={setReset} />
|
124
|
207
|
))}
|
125
|
208
|
</mp-cell>
|
126
|
209
|
}
|
127
|
|
- <mp-cell extClass='adds'>
|
128
|
|
- <Button className='add'>增加文字</Button><Button className='add'>增加图片</Button>
|
129
|
|
- </mp-cell>
|
130
|
|
- <mp-cell>
|
131
|
|
- <Button className='button-OK' onClick={sumbit}>确定</Button>
|
132
|
|
- </mp-cell>
|
133
|
210
|
</mp-cells>
|
134
|
211
|
</mp-form>
|
|
212
|
+ <View className='adds' >
|
|
213
|
+ <Text className='zuobian'>增加文字</Text>
|
|
214
|
+ <View className='add' onClick={showText}><Text className='jiahao'>+</Text><Text className='zengjia'>添加</Text></View>
|
|
215
|
+ </View>
|
|
216
|
+ <View className='adds' >
|
|
217
|
+ <Text className='zuobian'>增加图片</Text>
|
|
218
|
+ <View className='add' onClick={addImage}><Text className='jiahao'>+</Text><Text className='zengjia'>添加</Text></View>
|
|
219
|
+ </View>
|
|
220
|
+ <Button className='button-OK' onClick={sumbit}>确定</Button>
|
135
|
221
|
</scroll-view>
|
136
|
222
|
</view>
|
137
|
223
|
</view>
|