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
pagingEnabled
>
{roadSpotList.length ? roadSpotList.map((item, index) => <View
key={item.id}
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.countryMil?.toFixed(3)}</View>
<View className='item'>抽查乡道公里{item.townMil?.toFixed(3)}</View>
<View className='item'>抽查村道公里{item.villageMil?.toFixed(3)}</View>
<View className='item'>抽查日期{moment(item.date).format('YYYY-MM-DD')}</View>
</View>) : <View style={{ paddingTop: 100 }}><NoData /></View>}
{roadSpotList.length
? roadSpotList.map((item, index) => <View
key={item.id}
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.countryMil?.toFixed(3)}</View>
<View className='item'>抽查乡道公里{item.townMil?.toFixed(3)}</View>
<View className='item'>抽查村道公里{item.villageMil?.toFixed(3)}</View>
<View className='item'>抽查日期{moment(item.date).format('YYYY-MM-DD')}</View>
</View>)
: <View style={{ paddingTop: 100 }}><NoData /></View>}
</ScrollView>
<AtButton
className='to-start-btn'
type='primary'
onClick={() => navigateTo('/packages/maintenanceSpotCheck/startSpotCheck/index')}
>发起抽查</AtButton>
{roadSpotList.length && !roadSpotList[0].abstractFinish
? <AtButton
className='to-start-btn'
type='primary'
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>
)
}

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

@ -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>
)

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

@ -1,7 +1,7 @@
.page {
background-color: #fff;
height: 100vh;
padding: 60px;
height: 100%;
padding: 10px 30px 40px;
box-sizing: border-box;
.content {
@ -9,25 +9,39 @@
width: 100%;
min-height: 60%;
.item {
margin-top: 30px;
.title {}
.card {
border: 1px solid #ccc;
border-radius: 10px;
padding: 10px 20px;
margin-top: 10px;
.input {
margin-top: 10px;
border: 1px solid #ccc;
border-radius: 10px;
padding: 10px 20px;
.card-item {
display: flex;
justify-content: space-between;
height: 42px;
align-items: center;
justify-content: flex-start;
height: 80px;
}
}
.disabled {
background-color: #eee;
}
.item {
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 {
@ -37,7 +51,7 @@
.submit-btn {
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 = () => {
return `/road/spot/confirm`;
};
// 获取抽查城镇
export const getTownUrl = () => {
return `/town`;
};
Loading…
Cancel
Save