This commit is contained in:
wangsongsole 2022-05-18 18:37:20 +08:00
parent a8148054b5
commit 02e68e93b9
3 changed files with 95 additions and 43 deletions

View File

@ -3,6 +3,7 @@ import React from 'react'
import Ipt from '../../../components/input/main' 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 { deWeightThree } from '../../../utils'
import { import {
Card, Card,
Radio, Radio,
@ -602,14 +603,16 @@ export default class exchangedit extends React.Component {
return item return item
}) })
//select数据
let arr = [] let arr = []
_.map(data, (res) => { _.map(temp.concat(this.state.tempdata), (res) => {
let obj = {} let obj = {}
obj.key = res.product_id obj.key = res.product_id
obj.text = res.product_name obj.text = res.product_name
arr.push(obj) arr.push(obj)
return obj return obj
}) })
arr = deWeightThree(arr, 'key')
this.setState({ rankoptions: arr }) this.setState({ rankoptions: arr })
} else { } else {
/* 处理立减金 */ /* 处理立减金 */
@ -639,29 +642,26 @@ export default class exchangedit extends React.Component {
} }
}) })
//select数据
let arr = [] let arr = []
_.map(data, (res) => { _.map(temp.concat(this.state.tempdata), (res) => {
let obj = {} let obj = {}
obj.key = res.product_id obj.key = res.product_id
obj.text = res.product_name obj.text = res.product_name
arr.push(obj) arr.push(obj)
return obj return obj
}) })
arr = deWeightThree(arr, 'key')
this.setState({ rankoptions: arr }) this.setState({ rankoptions: arr })
} }
const obj = {} let newArray = temp.concat(this.state.tempdata)
const newArray = temp newArray = deWeightThree(newArray, 'product_id')
.concat(this.state.tempdata)
.reduce(function (a, b) {
// eslint-disable-next-line no-unused-expressions
obj[b.product_id] ? '' : (obj[b.product_id] = true && a.push(b))
return a
}, [])
this.setState({ tempdata: newArray }) this.setState({ tempdata: newArray })
}, 500) }, 500)
} }
} }
//
onUploadError = (type, data) => { onUploadError = (type, data) => {
if (type === 'overMaxAmount') { if (type === 'overMaxAmount') {
Notify.error(`最多可上传 ${data.maxAmount} 张图片`) Notify.error(`最多可上传 ${data.maxAmount} 张图片`)

View File

@ -1,12 +1,12 @@
/* 新增商品 */ /* 新增商品 */
import React from 'react' import { Component } from 'react'
import './index.less' import './index.less'
import Ipt from '../../../components/input/main' 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 moment from 'moment' import moment from 'moment'
import { uuid } from './utils' import { uuid, deWeightThree } from '../../../utils'
import { import {
Select, Select,
Button, Button,
@ -29,13 +29,12 @@ const getTimeList = [
{ key: 1, text: '立即生效' }, { key: 1, text: '立即生效' },
{ key: 2, text: '次日生效' } { key: 2, text: '次日生效' }
] ]
export default class adduserinfo extends React.Component { export default class addKnockGold extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {
model: { model: {
// uuid: '', //uuid ---
uuid: '',
channel: '1', // channel: '1', //
entry_time: '', // entry_time: '', //
expire_time: '', // expire_time: '', //
@ -60,8 +59,8 @@ export default class adduserinfo extends React.Component {
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_type: '', //
effect_date: '' // effect_date: '' //
@ -179,6 +178,7 @@ export default class adduserinfo extends React.Component {
temp[index][key] = this.state.model[key] temp[index][key] = this.state.model[key]
} }
sessionStorage.setItem('knockGoldData', JSON.stringify(temp)) sessionStorage.setItem('knockGoldData', JSON.stringify(temp))
return true return true
} }
} else { } else {
@ -186,27 +186,72 @@ export default class adduserinfo extends React.Component {
Notify.error('请选择卡种') Notify.error('请选择卡种')
return false return false
} }
if (this.state.model.early_per.length < 1) { if (this.state.model.early_per.length < 1) {
Notify.error('请选预警百分比') Notify.error('请选预警百分比')
return false return false
} }
if (!this.state.model.usable_time) { if (!this.state.model.usable_time) {
Notify.error('请选择可用时间段类型') Notify.error('请选择可用时间段类型')
return false return false
} }
if (this.state.model.denomination < this.state.model.reduce_amount) {
/* 可用时间段 */
if (this.state.model.usable_time === '1') {
if (
!this.state.model.effect_date_type ||
!this.state.model.effect_date
) {
Notify.error('请完整的填写或选择可用时间段')
return false
}
}
if (
this.state.model.usable_time === '2' &&
this.setTime(this.state.model.fixed_time)
) {
Notify.error('请完整的选择固定时间段')
return false
}
if (
this.state.model.denomination - 0 <
this.state.model.reduce_amount - 0
) {
Notify.error('面额必须大于立减金额') Notify.error('面额必须大于立减金额')
return false return false
} }
if (this.state.model.money > this.state.model.all_budget) {
if (this.state.model.money - 0 > this.state.model.all_budget - 0) {
Notify.error('批次充值金额必须小于总预算') Notify.error('批次充值金额必须小于总预算')
return false return false
} }
if (this.state.model.denomination > this.state.model.all_budget) {
if (
this.state.model.denomination - 0 >
this.state.model.all_budget - 0
) {
Notify.error('面额必须小于总预算') Notify.error('面额必须小于总预算')
return false return false
} }
/* 生效时间段 */
if (this.setTime(this.state.model.entry_time)) {
Notify.error('请选择结束时间或开始时间')
return false
}
/* 领取时间段 */
if (
this.setTime(this.state.model.timer) &&
this.state.model.receive_type === '2'
) {
Notify.error('请选择结束时间或开始时间')
return false
}
// //
let temp = [] let temp = []
if (sessionStorage.getItem('knockGoldData')) { if (sessionStorage.getItem('knockGoldData')) {
@ -221,6 +266,17 @@ export default class adduserinfo extends React.Component {
} }
} }
} }
//
setTime(data) {
if (!isArray(data)) return true
const newData = data.map((item) => item.length > 1)
let blr = null
newData.map((item) => {
if (!item) blr = true
})
return blr
}
// onProductChange(e) { // onProductChange(e) {
// console.log('e ===>', e) // console.log('e ===>', e)
// this.setState({ cur_product: e }) // this.setState({ cur_product: e })
@ -251,8 +307,6 @@ export default class adduserinfo extends React.Component {
// }) // })
// } // }
//
/* 方框单选事件 */ /* 方框单选事件 */
onTypeChange(e, key) { onTypeChange(e, key) {
let model2 = this.state.model let model2 = this.state.model
@ -277,17 +331,6 @@ export default class adduserinfo extends React.Component {
if (newData.length < 1) this.setState({ warningInput: '' }) if (newData.length < 1) this.setState({ warningInput: '' })
} }
/* 预警人去重 */
deWeightThree(data) {
let map = new Map()
for (let item of data) {
if (!map.has(item.key)) {
map.set(item.key, item)
}
}
return [...map.values()]
}
render() { render() {
return ( return (
<div id='addKnockGold'> <div id='addKnockGold'>
@ -391,20 +434,14 @@ 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>
@ -652,6 +689,7 @@ export default class adduserinfo extends React.Component {
// disabled={this.props?.data?.id ? true : false} // disabled={this.props?.data?.id ? true : false}
onChange={({ target }) => { onChange={({ target }) => {
this.onInputChange(target.value, 'usable_time') this.onInputChange(target.value, 'usable_time')
this.onInputChange([], 'fixed_time')
}}> }}>
<Radio value='1'>领取后</Radio> <Radio value='1'>领取后</Radio>
</RadioGroup> </RadioGroup>
@ -694,6 +732,8 @@ export default class adduserinfo extends React.Component {
value={this.state.model.usable_time} value={this.state.model.usable_time}
onChange={({ target }) => { onChange={({ target }) => {
this.onInputChange(target.value, 'usable_time') this.onInputChange(target.value, 'usable_time')
this.onInputChange('', 'effect_date_type')
this.onInputChange('', 'effect_date')
}}> }}>
<Radio value='2'>固定时间</Radio> <Radio value='2'>固定时间</Radio>
</RadioGroup> </RadioGroup>
@ -786,8 +826,9 @@ export default class adduserinfo extends React.Component {
/* 防止清除select时报错 is key undefine */ /* 防止清除select时报错 is key undefine */
if (value) { if (value) {
model.early_notifier.push(value) model.early_notifier.push(value)
model.early_notifier = this.deWeightThree( model.early_notifier = deWeightThree(
model.early_notifier model.early_notifier,
'key'
) )
} }
this.setState({ warningInput: value, model: model }) this.setState({ warningInput: value, model: model })

View File

@ -1,3 +1,14 @@
/* 去重 */
export function deWeightThree(data, key) {
let map = new Map()
for (let item of data) {
if (!map.has(item[key])) {
map.set(item[key], item)
}
}
return [...map.values()]
}
/* uuid生成器 */ /* uuid生成器 */
export function uuid(len, radix) { export function uuid(len, radix) {
var chars = var chars =