|
|
@ -1,94 +1,211 @@ |
|
|
|
import React, { useState } from 'react' |
|
|
|
import Taro from '@tarojs/taro' |
|
|
|
import { View, Picker } from '@tarojs/components' |
|
|
|
import React, { useState, useEffect } from 'react' |
|
|
|
import Taro, { useRouter } from '@tarojs/taro' |
|
|
|
import { View, Picker, Input } from '@tarojs/components' |
|
|
|
import { AtButton, AtIcon, } from 'taro-ui' |
|
|
|
import request from '@/services/request' |
|
|
|
import { roadSpotPrepare, roadSpotConfirm } from '@/services/api' |
|
|
|
import { roadSpotPrepare, roadSpotConfirm, getTownUrl } from '@/services/api' |
|
|
|
import dayjs from 'dayjs' |
|
|
|
import './index.scss' |
|
|
|
|
|
|
|
function Index() { |
|
|
|
const { item } = useRouter().params |
|
|
|
const spotItem = item ? JSON.parse(decodeURIComponent(item)) : null |
|
|
|
|
|
|
|
const rateArr = ['50%', '75%']; |
|
|
|
const [rate, setRate] = useState('50%') |
|
|
|
const [prepare, setPrepare] = useState({ |
|
|
|
previewId: null, |
|
|
|
spotCountyRoadCount: null, |
|
|
|
spotTownRoadCount: null, |
|
|
|
spotVillageRoadCount: null, |
|
|
|
const [town, setTown] = useState([]) |
|
|
|
const [formValue, setFormValue] = useState({ |
|
|
|
countyRoad: { |
|
|
|
drawPeople: '', // 抽查人 |
|
|
|
countyPresent: null, // 县道实际抽取(公里) |
|
|
|
countyDifferenceValue: null, // 县道比计划多(公里) |
|
|
|
abstractTime: null, // 抽取时间 |
|
|
|
}, |
|
|
|
}) |
|
|
|
|
|
|
|
const startSpotCheck = () => { |
|
|
|
Taro.showLoading({ title: '抽取中' }) |
|
|
|
request.post(roadSpotPrepare(), { countyPercentage: rate === '50%' ? 50 : 75 }).then(res => { |
|
|
|
Taro.hideLoading() |
|
|
|
if (res.statusCode === 200 || res.statusCode === 204) { |
|
|
|
Taro.showToast({ title: '抽取成功', icon: 'success' }) |
|
|
|
setPrepare(res.data) |
|
|
|
} else { |
|
|
|
Taro.showToast({ title: '抽取失败', icon: 'error' }) |
|
|
|
console.log(res.errMsg) |
|
|
|
useEffect(() => { |
|
|
|
getTown() |
|
|
|
if (spotItem) { |
|
|
|
setFormValue(spotItem.gather) |
|
|
|
setRate(spotItem.countyPercentage === 50 ? '50%' : '75%') |
|
|
|
} |
|
|
|
}, []) |
|
|
|
|
|
|
|
const getTown = () => { |
|
|
|
request.get(getTownUrl()).then(res => { |
|
|
|
if (res.statusCode === 200) { |
|
|
|
setTown(res.data?.filter(d => d.code != '360121205000')) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
const onSubmit = () => { |
|
|
|
if (!prepare.previewId) { |
|
|
|
Taro.showToast({ title: '请先抽取道路' }) |
|
|
|
const startSpotCheck = (code) => { |
|
|
|
if (!formValue[code]?.drawPeople) { |
|
|
|
Taro.showToast({ title: '请输入抽取人', icon: 'none' }) |
|
|
|
return |
|
|
|
} |
|
|
|
Taro.showLoading({ title: '提交中' }) |
|
|
|
request.post(roadSpotConfirm(), { previewId: prepare.previewId }).then(res => { |
|
|
|
let body = {} |
|
|
|
if (code === 'countyRoad') { |
|
|
|
body = { |
|
|
|
level: '县', |
|
|
|
countyPercentage: rate === '50%' ? 50 : 75, |
|
|
|
drawPeople: formValue[code].drawPeople |
|
|
|
} |
|
|
|
} else { |
|
|
|
body = { |
|
|
|
code, |
|
|
|
countyPercentage: rate === '50%' ? 50 : 75, |
|
|
|
drawPeople: formValue[code].drawPeople |
|
|
|
} |
|
|
|
} |
|
|
|
Taro.showLoading({ title: '抽取中' }) |
|
|
|
request.post(roadSpotPrepare(), body).then(res => { |
|
|
|
Taro.hideLoading() |
|
|
|
if (res.statusCode === 204) { |
|
|
|
Taro.showToast({ title: '提交成功', icon: 'success' }) |
|
|
|
setTimeout(() => { |
|
|
|
Taro.navigateBack() |
|
|
|
}, 1500) |
|
|
|
if (res.statusCode === 200 || res.statusCode === 204) { |
|
|
|
Taro.showToast({ title: '抽取成功', icon: 'success' }) |
|
|
|
setFormValue(res.data.gather) |
|
|
|
setRate(res.data.countyPercentage === 50 ? '50%' : '75%') |
|
|
|
} else { |
|
|
|
Taro.showToast({ title: '提交失败', icon: 'error' }) |
|
|
|
Taro.showToast({ title: '抽取失败', icon: 'error' }) |
|
|
|
console.log(res.errMsg) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
// const onSubmit = () => { |
|
|
|
// if (!prepare.previewId) { |
|
|
|
// Taro.showToast({ title: '请先抽取道路' }) |
|
|
|
// return |
|
|
|
// } |
|
|
|
// Taro.showLoading({ title: '提交中' }) |
|
|
|
// request.post(roadSpotConfirm(), { previewId: prepare.previewId }).then(res => { |
|
|
|
// Taro.hideLoading() |
|
|
|
// if (res.statusCode === 204) { |
|
|
|
// Taro.showToast({ title: '提交成功', icon: 'success' }) |
|
|
|
// setTimeout(() => { |
|
|
|
// Taro.navigateBack() |
|
|
|
// }, 1500) |
|
|
|
// } else { |
|
|
|
// Taro.showToast({ title: '提交失败', icon: 'error' }) |
|
|
|
// console.log(res.errMsg) |
|
|
|
// } |
|
|
|
// }) |
|
|
|
// } |
|
|
|
|
|
|
|
return ( |
|
|
|
<View className='page'> |
|
|
|
<View className='content'> |
|
|
|
<View className='item'> |
|
|
|
<View className='title'>抽查县道比例(%):</View> |
|
|
|
<Picker mode='selector' |
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View>抽查县道比例(%):</View> |
|
|
|
<Picker |
|
|
|
mode='selector' |
|
|
|
range={rateArr} |
|
|
|
onChange={e => setRate(rateArr[e.detail.value])} |
|
|
|
style={{ marginLeft: 10 }} |
|
|
|
disabled={formValue.countyRoad.abstractTime} |
|
|
|
className={formValue.countyRoad.abstractTime ? 'disabled' : ''} |
|
|
|
> |
|
|
|
<View className='input'> |
|
|
|
{rate || '请选择'} |
|
|
|
<AtIcon value='chevron-down' size='20' color='#ccc' /> |
|
|
|
</View> |
|
|
|
</Picker> |
|
|
|
<AtButton type='primary' className='start-btn' size='small' |
|
|
|
onClick={() => { startSpotCheck('countyRoad') }} |
|
|
|
disabled={formValue.countyRoad.abstractTime} |
|
|
|
>开始抽取</AtButton> |
|
|
|
</View> |
|
|
|
<View className='item'> |
|
|
|
<View className='title'>抽查乡道比例(%):</View> |
|
|
|
<View className='input disabled'>{rate === '50%' ? '25%' : '50%'}</View> |
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View className='title'>抽查人:</View> |
|
|
|
<Input |
|
|
|
className={`input${formValue.countyRoad.abstractTime ? ' disabled' : ''}`} |
|
|
|
disabled={formValue.countyRoad.abstractTime} |
|
|
|
value={formValue.countyRoad.drawPeople} |
|
|
|
onInput={e => setFormValue({ |
|
|
|
...formValue, |
|
|
|
countyRoad: { ...formValue.countyRoad, drawPeople: e.detail.value } |
|
|
|
})} |
|
|
|
/> |
|
|
|
</View> |
|
|
|
<View className='item'> |
|
|
|
<View className='title'>抽查村道比例(%):</View> |
|
|
|
<View className='input disabled'>{rate === '50%' ? '10%' : '20%'}</View> |
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View>县道实际抽取(公里):</View> |
|
|
|
<View className='input disabled'>{formValue.countyRoad.countyPresent?.toFixed(4)}</View> |
|
|
|
</View> |
|
|
|
<AtButton type='primary' className='start-btn' size='small' |
|
|
|
onClick={startSpotCheck} |
|
|
|
>开始抽取</AtButton> |
|
|
|
<View className='item'> |
|
|
|
<View className='title'>抽查县道(公里):</View> |
|
|
|
<View className='input disabled'>{prepare.countryMil}</View> |
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View>县道比计划多(公里):</View> |
|
|
|
<View className='input disabled'>{formValue.countyRoad.countyDifferenceValue?.toFixed(4)}</View> |
|
|
|
</View> |
|
|
|
<View className='item'> |
|
|
|
<View className='title'>抽查乡道(公里):</View> |
|
|
|
<View className='input disabled'>{prepare.townMil}</View> |
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View>抽查时间:</View> |
|
|
|
<View className='input disabled'>{ |
|
|
|
formValue.countyRoad.abstractTime |
|
|
|
? dayjs(formValue.countyRoad.abstractTime).format('YYYY-MM-DD HH:mm:ss') |
|
|
|
: '' |
|
|
|
}</View> |
|
|
|
</View> |
|
|
|
<View className='item'> |
|
|
|
<View className='title'>抽查村道(公里):</View> |
|
|
|
<View className='input disabled'>{prepare.villageMil}</View> |
|
|
|
|
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View>抽查乡道比例(%):</View> |
|
|
|
<View className='input disabled'>{rate === '50%' ? '25%' : '50%'}</View> |
|
|
|
</View> |
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View>抽查村道比例(%):</View> |
|
|
|
<View className='input disabled'>{rate === '50%' ? '10%' : '20%'}</View> |
|
|
|
</View> |
|
|
|
<AtButton type='primary' className='submit-btn' onClick={onSubmit}>提交</AtButton> |
|
|
|
|
|
|
|
{ |
|
|
|
formValue.countyRoad.abstractTime && town.map(t => { |
|
|
|
return <View className='card'> |
|
|
|
<View className='card-item'> |
|
|
|
<View className='title' style={{ fontWeight: 600 }}>{t.name}</View> |
|
|
|
<AtButton type='primary' className='start-btn' size='small' |
|
|
|
onClick={() => { startSpotCheck(t.code) }} |
|
|
|
disabled={formValue[t.code]?.abstractTime} |
|
|
|
>开始抽取</AtButton> |
|
|
|
</View> |
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View className='title'>抽查人:</View> |
|
|
|
<Input |
|
|
|
className={`input${formValue[t.code]?.abstractTime ? ' disabled' : ''}`} |
|
|
|
disabled={formValue[t.code]?.abstractTime} |
|
|
|
value={formValue[t.code]?.drawPeople} |
|
|
|
onInput={e => { |
|
|
|
setFormValue({ |
|
|
|
...formValue, |
|
|
|
[t.code]: { ...formValue[t.code], drawPeople: e.detail.value } |
|
|
|
}) |
|
|
|
}} |
|
|
|
/> |
|
|
|
</View> |
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View>乡道实际抽取(公里):</View> |
|
|
|
<View className='input disabled'>{formValue[t.code]?.townshipPresent?.toFixed(4)}</View> |
|
|
|
</View> |
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View>乡道比计划多(公里):</View> |
|
|
|
<View className='input disabled'>{formValue[t.code]?.townshipDifferenceValue?.toFixed(4)}</View> |
|
|
|
</View> |
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View>村道实际抽取(公里):</View> |
|
|
|
<View className='input disabled'>{formValue[t.code]?.villagePresent?.toFixed(4)}</View> |
|
|
|
</View> |
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View>村道比计划多(公里):</View> |
|
|
|
<View className='input disabled'>{formValue[t.code]?.villageDifferenceValue?.toFixed(4)}</View> |
|
|
|
</View> |
|
|
|
<View className='item flex flex-start'> |
|
|
|
<View>抽查时间:</View> |
|
|
|
<View className='input disabled'>{ |
|
|
|
formValue[t.code]?.abstractTime |
|
|
|
? dayjs(formValue[t.code].abstractTime).format('YYYY-MM-DD HH:mm:ss') |
|
|
|
: '' |
|
|
|
}</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
{/* <AtButton type='primary' className='submit-btn' onClick={onSubmit}>提交</AtButton> */} |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
) |
|
|
|