Browse Source

(*) 小程序养护抽查变更

dev
liujiangyong 12 months ago
parent
commit
ae6bbfac3d
  1. 41
      weapp/src/packages/maintenanceSpotCheck/index.jsx
  2. 221
      weapp/src/packages/maintenanceSpotCheck/startSpotCheck/index.jsx
  3. 50
      weapp/src/packages/maintenanceSpotCheck/startSpotCheck/index.scss
  4. 5
      weapp/src/services/api.js

41
weapp/src/packages/maintenanceSpotCheck/index.jsx

@ -87,24 +87,31 @@ function Index() {
enhanced enhanced
pagingEnabled pagingEnabled
> >
{roadSpotList.length ? roadSpotList.map((item, index) => <View {roadSpotList.length
key={item.id} ? roadSpotList.map((item, index) => <View
className='card' key={item.id}
onClick={() => navigateTo(`/packages/maintenanceSpotCheck/spotCheckRoad/index?item=${encodeURIComponent(JSON.stringify(item))}&isOld=${index !== 0}` className='card'
)} onClick={() => navigateTo(`/packages/maintenanceSpotCheck/spotCheckRoad/index?item=${encodeURIComponent(JSON.stringify(item))}&isOld=${index !== 0}`)}
> >
<View className='item'>抽查县道比例%{item.countyPercentage}</View> <View className='item'>抽查县道比例%{item.countyPercentage}</View>
<View className='item'>抽查县道公里{item.countryMil?.toFixed(3)}</View> <View className='item'>抽查县道公里{item.countryMil?.toFixed(3)}</View>
<View className='item'>抽查乡道公里{item.townMil?.toFixed(3)}</View> <View className='item'>抽查乡道公里{item.townMil?.toFixed(3)}</View>
<View className='item'>抽查村道公里{item.villageMil?.toFixed(3)}</View> <View className='item'>抽查村道公里{item.villageMil?.toFixed(3)}</View>
<View className='item'>抽查日期{moment(item.date).format('YYYY-MM-DD')}</View> <View className='item'>抽查日期{moment(item.date).format('YYYY-MM-DD')}</View>
</View>) : <View style={{ paddingTop: 100 }}><NoData /></View>} </View>)
: <View style={{ paddingTop: 100 }}><NoData /></View>}
</ScrollView> </ScrollView>
<AtButton {roadSpotList.length && !roadSpotList[0].abstractFinish
className='to-start-btn' ? <AtButton
type='primary' className='to-start-btn'
onClick={() => navigateTo('/packages/maintenanceSpotCheck/startSpotCheck/index')} type='primary'
>发起抽查</AtButton> onClick={() => navigateTo(`/packages/maintenanceSpotCheck/startSpotCheck/index?item=${encodeURIComponent(JSON.stringify(roadSpotList[0]))}`)}
>继续抽查</AtButton>
: <AtButton
className='to-start-btn'
type='primary'
onClick={() => navigateTo('/packages/maintenanceSpotCheck/startSpotCheck/index')}
>发起抽查</AtButton>}
</View> </View>
) )
} }

221
weapp/src/packages/maintenanceSpotCheck/startSpotCheck/index.jsx

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

50
weapp/src/packages/maintenanceSpotCheck/startSpotCheck/index.scss

@ -1,7 +1,7 @@
.page { .page {
background-color: #fff; background-color: #fff;
height: 100vh; height: 100%;
padding: 60px; padding: 10px 30px 40px;
box-sizing: border-box; box-sizing: border-box;
.content { .content {
@ -9,25 +9,39 @@
width: 100%; width: 100%;
min-height: 60%; min-height: 60%;
.item { .card {
margin-top: 30px; border: 1px solid #ccc;
border-radius: 10px;
padding: 10px 20px;
.title {} margin-top: 10px;
.input { .card-item {
margin-top: 10px;
border: 1px solid #ccc;
border-radius: 10px;
padding: 10px 20px;
display: flex; display: flex;
justify-content: space-between; align-items: center;
height: 42px; justify-content: flex-start;
height: 80px;
} }
}
.disabled { .item {
background-color: #eee; width: 100%;
} height: 80px;
margin-top: 20px;
}
.input {
min-width: 100px;
margin-top: 10px;
border: 1px solid #ccc;
border-radius: 10px;
padding: 10px 20px;
display: flex;
justify-content: space-between;
height: 42px;
}
.disabled {
background-color: #eee;
} }
.start-btn { .start-btn {
@ -37,7 +51,7 @@
.submit-btn { .submit-btn {
width: 70%; width: 70%;
margin: 100px auto 0; margin: 30px auto 0;
} }
} }
} }

5
weapp/src/services/api.js

@ -95,4 +95,9 @@ export const roadSpotPrepare = () => {
// 提交抽查 // 提交抽查
export const roadSpotConfirm = () => { export const roadSpotConfirm = () => {
return `/road/spot/confirm`; return `/road/spot/confirm`;
};
// 获取抽查城镇
export const getTownUrl = () => {
return `/town`;
}; };
Loading…
Cancel
Save