|
|
@ -18,13 +18,17 @@ function Index() { |
|
|
|
const [isPatrol, setIsPatrol] = useState(true) |
|
|
|
const [datePicker, setDatePicker] = useState(moment().format('YYYY-MM-DD')) |
|
|
|
const [listData, setListData] = useState([]) |
|
|
|
const [inputSite, setInputSite] = useState('') |
|
|
|
const [page, setPage] = useState(0) |
|
|
|
const [total, setTotal] = useState(0) |
|
|
|
const [num, setNum] = useState(Math.random()) |
|
|
|
const [showListData, setShowListData] = useState([]) |
|
|
|
const [filterText, setFilterText] = useState('') |
|
|
|
const [systemInfo, setSystemInfo] = useState('') |
|
|
|
|
|
|
|
const userInfo = Taro.getStorageSync('userInfo') || {}; |
|
|
|
useEffect(() => { |
|
|
|
getList() |
|
|
|
}, [datePicker]) |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
setShowListData(listData.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve')) |
|
|
|
}, [isPatrol]) |
|
|
|
|
|
|
|
function dealError(error) { |
|
|
|
Taro.showToast({ |
|
|
@ -34,11 +38,17 @@ function Index() { |
|
|
|
}); |
|
|
|
throw new Error(error); |
|
|
|
} |
|
|
|
useEffect(() => { |
|
|
|
request.get(getReportList(), {}, { hideErrorToast: true, hideLoading: true }).then(res => { |
|
|
|
const getList = () => { |
|
|
|
Taro.showLoading({ title: '加载中' }) |
|
|
|
request.get( |
|
|
|
getReportList(), |
|
|
|
{ startTime: datePicker + ' 00:00:00', endTime: datePicker + ' 23:59:59' }, |
|
|
|
{ hideErrorToast: true, hideLoading: true } |
|
|
|
).then(res => { |
|
|
|
Taro.hideLoading() |
|
|
|
if (res.statusCode == 200) { |
|
|
|
// console.log(res); |
|
|
|
setListData(res.data) |
|
|
|
setShowListData(res.data.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve')) |
|
|
|
return res.data; |
|
|
|
} else { |
|
|
|
dealError(res.data.message || '请求出错'); |
|
|
@ -46,13 +56,11 @@ function Index() { |
|
|
|
}, err => { |
|
|
|
dealError(err.message || '请求出错'); |
|
|
|
}); |
|
|
|
}, []) |
|
|
|
} |
|
|
|
|
|
|
|
useDidShow(() => { |
|
|
|
let refresh = Taro.getStorageSync('refresh'); // 返回列表需要刷新 |
|
|
|
if (refresh) { |
|
|
|
setPage(0) |
|
|
|
setNum(Math.random()) |
|
|
|
Taro.removeStorageSync('refresh'); // 返回列表需要刷新 |
|
|
|
} |
|
|
|
Taro.getSystemInfo({ |
|
|
@ -72,25 +80,21 @@ function Index() { |
|
|
|
setDatePicker(e.detail.value); |
|
|
|
} |
|
|
|
|
|
|
|
const handleConfirm = () => { |
|
|
|
setPage(0) |
|
|
|
setListData([]); |
|
|
|
setTotal(0); |
|
|
|
setNum(Math.random()) |
|
|
|
const handleConfirm = e => { |
|
|
|
let nextList = listData.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve') |
|
|
|
nextList = nextList.filter(item => item.road.includes(e.detail.value)) |
|
|
|
setShowListData(nextList) |
|
|
|
} |
|
|
|
|
|
|
|
const handleInput = e => { |
|
|
|
setInputSite(e.detail.value); |
|
|
|
setFilterText(e.detail.value); |
|
|
|
if (!e.detail.value) { |
|
|
|
setPage(0) |
|
|
|
setListData([]); |
|
|
|
setTotal(0); |
|
|
|
setNum(Math.random()) |
|
|
|
setShowListData(listData.filter(item => isPatrol ? item.reportType === 'patrol' : item.reportType === 'conserve')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const handleDetail = index => { |
|
|
|
Taro.navigateTo({ url: `/packages/patrol/index?type=view&id=${listData[index].id}` }) |
|
|
|
Taro.navigateTo({ url: `/packages/patrol/index?type=view&id=${showListData[index].id}` }) |
|
|
|
} |
|
|
|
|
|
|
|
return ( |
|
|
@ -109,20 +113,27 @@ function Index() { |
|
|
|
<View className='filter-box'> |
|
|
|
<View className='filter-item'> |
|
|
|
<View style={{ float: 'left', marginLeft: '20rpx', color: '#333' }}>日期:</View> |
|
|
|
<Picker className='picker' style={{ overflow: 'hidden', float: 'left' }} mode='date' end={(systemInfo == 'windows' || systemInfo == 'mac') ? moment().add(1, 'd').format('YYYY-MM-DD') : moment().format('YYYY-MM-DD')} onChange={onDateChange}> |
|
|
|
<Picker |
|
|
|
className='picker' |
|
|
|
style={{ overflow: 'hidden', float: 'left' }} |
|
|
|
mode='date' |
|
|
|
end={(systemInfo == 'windows' || systemInfo == 'mac') |
|
|
|
? moment().add(1, 'd').format('YYYY-MM-DD') |
|
|
|
: moment().format('YYYY-MM-DD')} onChange={onDateChange} |
|
|
|
> |
|
|
|
<View className='filter-name'>{datePicker || '请选择'}</View> |
|
|
|
<Image className='filter-img' src={chevronDown} /> |
|
|
|
</Picker> |
|
|
|
</View> |
|
|
|
<View class='head-search'> |
|
|
|
<Image className='search-img' src={searchIcon} /> |
|
|
|
<Input class='heard-search-input' value={inputSite} placeholder='请输入场所名称' onConfirm={handleConfirm} onInput={handleInput} /> |
|
|
|
<Input class='heard-search-input' value={filterText} placeholder='请输入道路名称' onConfirm={handleConfirm} onInput={handleInput} /> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
|
|
|
|
<View style={{ marginTop: '110px' }}> |
|
|
|
{ |
|
|
|
listData && listData.length > 0 ? listData && listData.map((e, index) => { |
|
|
|
showListData && showListData.length > 0 ? showListData && showListData.map((e, index) => { |
|
|
|
return ( |
|
|
|
<View className='cardBox' key={index} onClick={() => handleDetail(index)}> |
|
|
|
<View className='card-item' > |
|
|
@ -144,5 +155,4 @@ function Index() { |
|
|
|
</View> |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
export default Index |
|
|
|