diff --git a/src/pages/exchangecode/edit/edit.js b/src/pages/exchangecode/edit/edit.js index 0cb65dcd..da0f82d7 100644 --- a/src/pages/exchangecode/edit/edit.js +++ b/src/pages/exchangecode/edit/edit.js @@ -3,6 +3,7 @@ import React from 'react' import Ipt from '../../../components/input/main' import Form from '../../../components/form/main' import FormItem from '../../../components/form-item/main' +import { deWeightThree } from '../../../utils' import { Card, Radio, @@ -602,14 +603,16 @@ export default class exchangedit extends React.Component { return item }) + //select数据 let arr = [] - _.map(data, (res) => { + _.map(temp.concat(this.state.tempdata), (res) => { let obj = {} obj.key = res.product_id obj.text = res.product_name arr.push(obj) return obj }) + arr = deWeightThree(arr, 'key') this.setState({ rankoptions: arr }) } else { /* 处理立减金 */ @@ -639,29 +642,26 @@ export default class exchangedit extends React.Component { } }) + //select数据 let arr = [] - _.map(data, (res) => { + _.map(temp.concat(this.state.tempdata), (res) => { let obj = {} obj.key = res.product_id obj.text = res.product_name arr.push(obj) return obj }) + arr = deWeightThree(arr, 'key') this.setState({ rankoptions: arr }) } - const obj = {} - const newArray = temp - .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 - }, []) + let newArray = temp.concat(this.state.tempdata) + newArray = deWeightThree(newArray, 'product_id') this.setState({ tempdata: newArray }) }, 500) } } + // onUploadError = (type, data) => { if (type === 'overMaxAmount') { Notify.error(`最多可上传 ${data.maxAmount} 张图片`) diff --git a/src/pages/plan/knockGold/index.jsx b/src/pages/plan/knockGold/index.jsx index e987f56a..d1c725a9 100644 --- a/src/pages/plan/knockGold/index.jsx +++ b/src/pages/plan/knockGold/index.jsx @@ -1,12 +1,12 @@ /* 新增商品 */ -import React from 'react' +import { Component } from 'react' import './index.less' import Ipt from '../../../components/input/main' import Form from '../../../components/form/main' import FormItem from '../../../components/form-item/main' import rules from './rules' import moment from 'moment' -import { uuid } from './utils' +import { uuid, deWeightThree } from '../../../utils' import { Select, Button, @@ -29,13 +29,12 @@ const getTimeList = [ { key: 1, text: '立即生效' }, { key: 2, text: '次日生效' } ] -export default class adduserinfo extends React.Component { +export default class addKnockGold extends Component { constructor(props) { super(props) this.state = { model: { - //数据模型不可少 - uuid: '', + uuid: '', //uuid ---前端生成辨别 channel: '1', // 渠道 entry_time: '', // 生效时间 expire_time: '', // 过期时间 @@ -60,8 +59,8 @@ export default class adduserinfo extends React.Component { receive_number: '', //领取个数 receive_type: '1', //领取类型 usable_time: '', //可用时间 - fixed_time: '', //固定时间 - timer: '', //领取时间段 + fixed_time: [], //固定时间 + timer: [], //领取时间段 timer_type: '2', //领取时间段类型 effect_date_type: '', //生效日期类型 effect_date: '' //生效日期 @@ -179,6 +178,7 @@ export default class adduserinfo extends React.Component { temp[index][key] = this.state.model[key] } sessionStorage.setItem('knockGoldData', JSON.stringify(temp)) + return true } } else { @@ -186,27 +186,72 @@ export default class adduserinfo extends React.Component { Notify.error('请选择卡种') return false } + if (this.state.model.early_per.length < 1) { Notify.error('请选预警百分比') return false } + if (!this.state.model.usable_time) { Notify.error('请选择可用时间段类型') 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('面额必须大于立减金额') 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('批次充值金额必须小于总预算') 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('面额必须小于总预算') 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 = [] 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) { // console.log('e ===>', e) // this.setState({ cur_product: e }) @@ -251,8 +307,6 @@ export default class adduserinfo extends React.Component { // }) // } - //方形单选框事件 - /* 方框单选事件 */ onTypeChange(e, key) { let model2 = this.state.model @@ -277,17 +331,6 @@ export default class adduserinfo extends React.Component { 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() { return (
@@ -391,20 +434,14 @@ export default class adduserinfo extends React.Component { width={'520px'} alignment={'left'} /> - {/* {this.state.model.id ? ( + {this.state.model.id ? ( - ) : null} */} - + ) : null} @@ -652,6 +689,7 @@ export default class adduserinfo extends React.Component { // disabled={this.props?.data?.id ? true : false} onChange={({ target }) => { this.onInputChange(target.value, 'usable_time') + this.onInputChange([], 'fixed_time') }}> 领取后 @@ -694,6 +732,8 @@ export default class adduserinfo extends React.Component { value={this.state.model.usable_time} onChange={({ target }) => { this.onInputChange(target.value, 'usable_time') + this.onInputChange('', 'effect_date_type') + this.onInputChange('', 'effect_date') }}> 固定时间 @@ -786,8 +826,9 @@ export default class adduserinfo extends React.Component { /* 防止清除select时报错 is key undefine */ if (value) { model.early_notifier.push(value) - model.early_notifier = this.deWeightThree( - model.early_notifier + model.early_notifier = deWeightThree( + model.early_notifier, + 'key' ) } this.setState({ warningInput: value, model: model }) diff --git a/src/pages/plan/knockGold/utils.js b/src/utils.js similarity index 78% rename from src/pages/plan/knockGold/utils.js rename to src/utils.js index f71985b1..e3b846b5 100644 --- a/src/pages/plan/knockGold/utils.js +++ b/src/utils.js @@ -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生成器 */ export function uuid(len, radix) { var chars =