添加立减金 加款弹窗中 金额交互显示以及相关限制

This commit is contained in:
wangsongsole 2022-05-18 16:09:40 +08:00
parent 28bac3845c
commit 339dd038fb
2 changed files with 70 additions and 23 deletions

View File

@ -4,18 +4,25 @@ import Ipt from '../../../components/input/main'
import Form from '../../../components/form/main' import Form from '../../../components/form/main'
import FormItem from '../../../components/form-item/main' import FormItem from '../../../components/form-item/main'
import rules from './rules' import rules from './rules'
import { Button } from 'zent' import { Button, Notify } from 'zent'
export default ({ data, onChangeMoney }) => { export default ({ data, onChangeMoney }) => {
const [stateData, setStateData] = useState({ addNew: '' }) const [stateData, setStateData] = useState({ addNew: '' })
const ref = useRef() const ref = useRef()
useEffect(() => { useEffect(() => {
setStateData({ stateData: data }) setStateData({ ...data })
}, [data]) }, [data])
function submit() { function submit() {
if (ref.current.validator()) { if (ref.current.validator()) {
onChangeMoney(false, stateData.addNew) if (
Number(stateData?.money) + Number(stateData.addNew) <
Number(stateData?.all_budget)
) {
onChangeMoney(false, Number(stateData.addNew))
} else {
Notify.error('加款失败')
}
} }
} }
@ -23,10 +30,16 @@ export default ({ data, onChangeMoney }) => {
<> <>
<div className='dialog_p'> <div className='dialog_p'>
<p> <p>
预估当前消耗余额为<span className='red'> 60000.21</span> 预估当前消耗余额为
<span className='red'> {stateData?.money} </span>
</p> </p>
<p> <p>
预估当前剩余余额为<span className='green'> 60000.21</span> 预估当前剩余余额为
<span className='green'>
{' '}
{stateData?.all_budget - stateData?.money}{' '}
</span>
</p> </p>
<Form ref={ref} model={stateData} rules={rules.addNew}> <Form ref={ref} model={stateData} rules={rules.addNew}>
<FormItem <FormItem
@ -37,10 +50,10 @@ export default ({ data, onChangeMoney }) => {
<Ipt <Ipt
className='addNew' className='addNew'
onChange={(value) => { onChange={(value) => {
setStateData({ addNew: value }) setStateData({ ...stateData, addNew: value })
}} }}
onClearItem={() => { onClearItem={() => {
setStateData({ addNew: '' }) setStateData({ ...stateData, addNew: '' })
}} }}
kind='number' kind='number'
value={stateData.addNew} value={stateData.addNew}
@ -74,10 +87,21 @@ export default ({ data, onChangeMoney }) => {
</Form> </Form>
<p> <p>
预估充值后总充值批次金额为 预估充值后总充值批次金额为
<span className='blue'> 60000.21</span> <span className='blue'>
{' '}
{(Number(stateData?.money) | 0) + (stateData?.addNew | 0)}{' '}
</span>
</p> </p>
<p> <p>
预估充值后剩余余额为<span className='blue'> 60000.21</span> 预估充值后剩余余额为
<span className='blue'>
{' '}
{stateData?.all_budget -
stateData?.money -
(stateData?.addNew | 0)}{' '}
</span>
</p> </p>
</div> </div>
<p className='dflexajce'> <p className='dflexajce'>

View File

@ -25,6 +25,10 @@ import {
import _, { isArray } from 'lodash' import _, { isArray } from 'lodash'
import AddNewDialog from './Dialog' import AddNewDialog from './Dialog'
import MobileComponent from './mobileCmponent' import MobileComponent from './mobileCmponent'
const getTimeList = [
{ key: 1, text: '立即生效' },
{ key: 2, text: '次日生效' }
]
export default class adduserinfo extends React.Component { export default class adduserinfo extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
@ -53,13 +57,14 @@ export default class adduserinfo extends React.Component {
early_notifier: [], //'', early_notifier: [], //'',
create_time: '', // '', create_time: '', // '',
creator: '', // ', creator: '', // ',
addNew: '', //
receive_number: '', // receive_number: '', //
receive_type: '1', // receive_type: '1', //
usable_time: '', // usable_time: '', //
fixed_time: '', // fixed_time: '', //
timer: '', // timer: '', //
timer_type: '2' // timer_type: '2', //
effect_date_type: '', //
effect_date: '' //
}, },
cur_product: {}, cur_product: {},
productOption: [], productOption: [],
@ -193,6 +198,14 @@ export default class adduserinfo extends React.Component {
Notify.error('面额必须大于立减金额') Notify.error('面额必须大于立减金额')
return false return false
} }
if (this.state.model.money > this.state.model.all_budget) {
Notify.error('批次充值金额必须小于总预算')
return false
}
if (this.state.model.denomination > this.state.model.all_budget) {
Notify.error('面额必须小于总预算')
return false
}
// //
let temp = [] let temp = []
@ -378,14 +391,20 @@ export default class adduserinfo extends React.Component {
width={'520px'} width={'520px'}
alignment={'left'} alignment={'left'}
/> />
{this.state.model.id ? ( {/* {this.state.model.id ? (
<Button
onClick={(e) => {
this.setState({ visible: true })
}}>
加款
</Button>
) : null} */}
<Button <Button
onClick={(e) => { onClick={(e) => {
this.setState({ visible: true }) this.setState({ visible: true })
}}> }}>
加款 加款
</Button> </Button>
) : null}
</FormItem> </FormItem>
</Form> </Form>
</Card> </Card>
@ -636,24 +655,28 @@ export default class adduserinfo extends React.Component {
}}> }}>
<Radio value='1'>领取后</Radio> <Radio value='1'>领取后</Radio>
</RadioGroup> </RadioGroup>
<div className='zent-demo-select-basic'> <div className='zent-demo-select-basic select-basic'>
<Select <Select
width='120px'
clearable clearable
options={[]} options={getTimeList}
placeholder='选择一项' placeholder='选择一项'
onChange={(value) => {
this.onInputChange(value, 'effect_date_type')
}}
value={this.state.model.effect_date_type}
className='select-basic'
// disabled={this.props?.data?.id ? true : false} // disabled={this.props?.data?.id ? true : false}
/> />
</div> </div>
<Ipt <Ipt
onChange={(value) => { onChange={(value) => {
this.onInputChange(value, 'product_name') this.onInputChange(value, 'effect_date')
}} }}
onClearItem={() => { onClearItem={() => {
this.onInputChange('', 'product_name') this.onInputChange('', 'effect_date')
}} }}
// disabled={this.props?.data?.id ? true : false} // disabled={this.props?.data?.id ? true : false}
value={this.state.model.product_name} value={this.state.model.effect_date}
placeholder={'请输入'} placeholder={'请输入'}
labelWidth={'0px'} labelWidth={'0px'}
maxLength={16} maxLength={16}
@ -661,7 +684,7 @@ export default class adduserinfo extends React.Component {
height={'36px'} height={'36px'}
unit='天' unit='天'
countShow={false} countShow={false}
width={'292px'} width={'172px'}
alignment={'left'} alignment={'left'}
/> />
</div> </div>
@ -792,10 +815,10 @@ export default class adduserinfo extends React.Component {
onClose={() => this.setState({ visible: false })} onClose={() => this.setState({ visible: false })}
title='加款'> title='加款'>
<AddNewDialog <AddNewDialog
data={''} data={this.state.model}
onChangeMoney={(isVisible, data) => { onChangeMoney={(isVisible, data = 0) => {
const models = this.state.model const models = this.state.model
models.addNew = data models.money = data + Number(models.money)
this.setState({ visible: isVisible, model: models }) this.setState({ visible: isVisible, model: models })
}} }}
/> />