diff --git a/src/components/knockGold/index.jsx b/src/components/knockGold/index.jsx index 4abc9e24..175a2f9f 100644 --- a/src/components/knockGold/index.jsx +++ b/src/components/knockGold/index.jsx @@ -1,14 +1,13 @@ /* 新增商品 */ -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 { deWeightThree, timeDiff } from '@/utils' -import { isSameDay } from 'date-fns' -import Bus from '@/assets/eventBus.js' +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 { deWeightThree, timeDiff } from "@/utils" +import { isSameDay } from "date-fns" import { Select, Button, @@ -23,15 +22,15 @@ import { Notify, Tag, TimeRangePicker -} from 'zent' -import _, { isArray } from 'lodash' -import { getVoucherWarningAccount, handelResponse } from '@/assets/api' -import AddNewDialog from './Dialog' -import MobileComponent from './mobileComponent' -import WangEditor from './wangEditor' +} from "zent" +import _, { isArray } from "lodash" +import { getVoucherWarningAccount, handelResponse } from "@/assets/api" +import AddNewDialog from "./Dialog" +import MobileComponent from "./mobileComponent" +import WangEditor from "./wangEditor" const cardTypeList = [ - { key: '1', text: '借记卡' }, - { key: '2', text: '信用卡' } + { key: "1", text: "借记卡" }, + { key: "2", text: "信用卡" } ] const defaultInstructionWx = `1、立减金自领取之日起30天有效,请在有效期内使用 @@ -45,23 +44,23 @@ const defaultInstructionZfb = `1、立减金自领取之日起7天有效,请
4、使用立减金的支付宝支付订单,如发生全额退款,且立减金仍在有效期内,立减金将自动退还给用户,如立减金已过期,则不退还给用户;如发生部分退款,用户支付金额将按比例原路退还,立减金将不退还给用户` const receiveTypeList = [ - { key: 'all', text: '总共' }, - { key: 'month', text: '每月' }, - { key: 'week', text: '每周' }, - { key: 'day', text: '每天' } + { key: "all", text: "总共" }, + { key: "month", text: "每月" }, + { key: "week", text: "每周" }, + { key: "day", text: "每天" } ] const week = [ - { key: 'Mon', text: '周一' }, - { key: 'Tue', text: '周二' }, - { key: 'Wed', text: '周三' }, - { key: 'Thu', text: '周四' }, - { key: 'Fri', text: '周五' }, - { key: 'Sat', text: '周六' }, - { key: 'Sun', text: '周日' } + { key: "Mon", text: "周一" }, + { key: "Tue", text: "周二" }, + { key: "Wed", text: "周三" }, + { key: "Thu", text: "周四" }, + { key: "Fri", text: "周五" }, + { key: "Sat", text: "周六" }, + { key: "Sun", text: "周日" } ] //预警百分比 -const earlyPerList = ['70', '50', '30', '20'] +const earlyPerList = ["70", "50", "30", "20"] const initArray = (targetNum) => { return Array.from({ length: targetNum }, (_, index) => index) } @@ -71,50 +70,50 @@ export default class addKnockGold extends Component { super(props) this.state = { model: { - channel: '1', // 渠道 + channel: "1", // 渠道 entry_time: [], // 生效时间 - batch_goods_name: '', // 批次商品名称 - channel_activity_id: '', // 批次号 - temp_no: '', //模板编号 - weight: '0', //权重 - price: '', // 单价 - recharge_amount: '', // 充值金额 - denomination: '', // 面额 - reduce_amount: '', // 立减额度 - all_budget: '', // 总预算 - day_budget: '', // 单天预算 + batch_goods_name: "", // 批次商品名称 + channel_activity_id: "", // 批次号 + temp_no: "", //模板编号 + weight: "0", //权重 + price: "", // 单价 + recharge_amount: "", // 充值金额 + denomination: "", // 面额 + reduce_amount: "", // 立减额度 + all_budget: "", // 总预算 + day_budget: "", // 单天预算 card_type: [], // '卡种类型', - natural_limit: '1', //'是否开启自然人限制', - brush_limit: '1', //'是否开启防刷限制', + natural_limit: "1", //'是否开启自然人限制', + brush_limit: "1", //'是否开启防刷限制', instruction: defaultInstructionZfb, //'使用说明', early_per: [], //'预警百分比', early_notifier: [], //'预警通知人', - receive_number: '', //领取个数 - receive_type: 'all', //领取类型 - usable_time: '', //可用时间 + receive_number: "", //领取个数 + receive_type: "all", //领取类型 + usable_time: "", //可用时间 fixed_time: [], //固定时间 timer: [], //领取时间段 - timer_type: '1', //领取时间段类型 - effect_date_type: '', //生效日期类型 - effect_date: '', //生效日期 + timer_type: "1", //领取时间段类型 + effect_date_type: "", //生效日期类型 + effect_date: "", //生效日期 irregularDate: [[]], //不规则日期 irregularTime: [[]], //不规则时间 ruleDate: [[]], //规则日期 ruleWeek: [] //规则周 }, - TimeDiffer: '', + TimeDiffer: "", visible: false, //加框弹窗 - warningInput: '', //预警输入框 - input_early_per: '', //预警百分比输入框 + warningInput: "", //预警输入框 + input_early_per: "", //预警百分比输入框 getTimeList: [ { - key: '0', - text: '立即生效', + key: "0", + text: "立即生效", disabled: false }, { - key: '1', - text: '次日生效', + key: "1", + text: "次日生效", disabled: false } ], @@ -135,11 +134,11 @@ export default class addKnockGold extends Component { this.props.data.time_limit.use_time.fiexd_time?.start_time model.fixed_time[1] = this.props.data.time_limit.use_time.fiexd_time?.end_time - if (this.props.data.time_limit.use_time.type === 'week') { + if (this.props.data.time_limit.use_time.type === "week") { model.ruleWeek = this.props.data.time_limit.use_time?.week model.ruleDate = this.props.data.time_limit.use_time?.time } - if (this.props.data.time_limit.use_time.type === 'irregular') { + if (this.props.data.time_limit.use_time.type === "irregular") { model.irregularDate = this.props.data.time_limit.use_time?.day model.irregularTime = this.props.data.time_limit.use_time?.time } @@ -203,8 +202,8 @@ export default class addKnockGold extends Component { model.timer[0] = this.props.data.time_limit.receive_time.start_time model.timer[1] = this.props.data.time_limit.receive_time.end_time model.timer_type = !this.props.data.time_limit.receive_time?.start_time - ? '1' - : '2' + ? "1" + : "2" model.effect_date_type = this.state.getTimeList[ @@ -273,10 +272,10 @@ export default class addKnockGold extends Component { /* x时间控件禁用 */ onDisabledRange = (date, type) => { let disabled = false - if (type == 'end') { - disabled = moment(date.getTime()).add(1, 'days') <= new Date().getTime() + if (type == "end") { + disabled = moment(date.getTime()).add(1, "days") <= new Date().getTime() } - if (type == 'start') { + if (type == "start") { disabled = date.getTime() <= new Date().getTime() } return disabled @@ -284,15 +283,15 @@ export default class addKnockGold extends Component { /* x时间控件禁用 */ onDisabledRange1 = (date, type) => { - let step1 = JSON.parse(sessionStorage.getItem('knockGold_effectDate')) + let step1 = JSON.parse(sessionStorage.getItem("knockGold_effectDate")) let isdisabled = false - let str = moment(date).format('YYYY-MM-DD HH:mm:ss') - const isDay = moment(step1.end_time).format('HH:mm:ss') - if (type == 'start') { - if (isDay < '23:59:59') { + let str = moment(date).format("YYYY-MM-DD HH:mm:ss") + const isDay = moment(step1.end_time).format("HH:mm:ss") + if (type == "start") { + if (isDay < "23:59:59") { isdisabled = moment(str).isBefore(step1.begin_time) || - moment(str).subtract(1, 'days').isAfter(step1.end_time) + moment(str).subtract(1, "days").isAfter(step1.end_time) } else { isdisabled = moment(str).isBefore(step1.begin_time) || @@ -300,9 +299,9 @@ export default class addKnockGold extends Component { } } - if (type == 'end') { + if (type == "end") { isdisabled = - moment(str).add(1, 'days').isBefore(step1.begin_time) || + moment(str).add(1, "days").isBefore(step1.begin_time) || moment(str).isAfter(step1.end_time) } return isdisabled @@ -311,14 +310,14 @@ export default class addKnockGold extends Component { /* x时间控件禁用 */ onDisabledRange2 = (date, type) => { let isdisabled = false - let str = moment(date).format('YYYY-MM-DD HH:mm:ss') - const isDay = moment(this.state.model.entry_time[1]).format('HH:mm:ss') - if (type == 'start') { - if (isDay < '23:59:59') { + let str = moment(date).format("YYYY-MM-DD HH:mm:ss") + const isDay = moment(this.state.model.entry_time[1]).format("HH:mm:ss") + if (type == "start") { + if (isDay < "23:59:59") { isdisabled = moment(str).isBefore(this.state.model.entry_time[0]) || moment(str) - .subtract(1, 'days') + .subtract(1, "days") .isAfter(this.state.model.entry_time[1]) } else { isdisabled = @@ -327,16 +326,16 @@ export default class addKnockGold extends Component { } } - if (type == 'end') { + if (type == "end") { isdisabled = - moment(str).add(1, 'days').isBefore(this.state.model.entry_time[0]) || + moment(str).add(1, "days").isBefore(this.state.model.entry_time[0]) || moment(str).isAfter(this.state.model.entry_time[1]) } return isdisabled } onDisabledTime = (date, type) => { - let step1 = JSON.parse(sessionStorage.getItem('knockGold_effectDate')) + let step1 = JSON.parse(sessionStorage.getItem("knockGold_effectDate")) const min = new Date(step1.begin_time) const hour = min.getHours() const minute = min.getMinutes() @@ -381,7 +380,7 @@ export default class addKnockGold extends Component { const new_early_per = this.state.model.early_per.filter( (item) => item !== this.state.input_early_per ) - this.onHandleChange(new_early_per, 'early_per') + this.onHandleChange(new_early_per, "early_per") } /* 提交 */ @@ -394,8 +393,8 @@ export default class addKnockGold extends Component { ) { if (this.props.data) { let temp = [] - if (sessionStorage.getItem('knockGoldData')) { - temp = JSON.parse(sessionStorage.getItem('knockGoldData')) + if (sessionStorage.getItem("knockGoldData")) { + temp = JSON.parse(sessionStorage.getItem("knockGoldData")) } let index = temp.findIndex((item) => { return ( @@ -417,7 +416,7 @@ export default class addKnockGold extends Component { temp[index] = this.transformDataCode() } - sessionStorage.setItem('knockGoldData', JSON.stringify(temp)) + sessionStorage.setItem("knockGoldData", JSON.stringify(temp)) return true } else { @@ -427,8 +426,8 @@ export default class addKnockGold extends Component { } //缓存 let temp = [] - if (sessionStorage.getItem('knockGoldData')) { - temp = JSON.parse(sessionStorage.getItem('knockGoldData')) + if (sessionStorage.getItem("knockGoldData")) { + temp = JSON.parse(sessionStorage.getItem("knockGoldData")) } let data = temp ? temp : [] @@ -440,12 +439,12 @@ export default class addKnockGold extends Component { ) if (isRepeat) { - Notify.error('不允许输入重复的平台批次号') + Notify.error("不允许输入重复的平台批次号") return false } data.push(models) - sessionStorage.setItem('knockGoldData', JSON.stringify(data)) + sessionStorage.setItem("knockGoldData", JSON.stringify(data)) return true } } @@ -477,7 +476,7 @@ export default class addKnockGold extends Component { if (transformData.channel == 1) { transformData.temp_no = this.state.model.temp_no } else { - transformData.temp_no = '' + transformData.temp_no = "" } transformData.batch_goods_name = this.state.model.batch_goods_name transformData.channel_activity_id = this.state.model.channel_activity_id //确认字段 @@ -529,11 +528,11 @@ export default class addKnockGold extends Component { withTimeFunction(type) { let obj = {} switch (type) { - case 'week': + case "week": obj.time = this.state.model.ruleDate obj.week = this.state.model.ruleWeek break - case 'irregular': + case "irregular": obj.time = this.state.model.irregularTime obj.day = this.state.model.irregularDate break @@ -554,27 +553,27 @@ export default class addKnockGold extends Component { /* 校验表单function */ limitFunction() { if (!this.state.model.card_type) { - Notify.error('请选择卡种') + Notify.error("请选择卡种") return false } if (this.state.model.early_per.filter((item) => item).length < 1) { - Notify.error('请选预警百分比') + Notify.error("请选预警百分比") return false } if (!this.state.model.usable_time) { - Notify.error('请选择可用时间段类型') + Notify.error("请选择可用时间段类型") return false } /* 可用时间段 */ - if (this.state.model.usable_time === 'received') { + if (this.state.model.usable_time === "received") { if ( !this.state.model.effect_date_type?.key || !this.state.model.effect_date ) { - Notify.error('请完整的填写或选择可用时间段') + Notify.error("请完整的填写或选择可用时间段") return false } } @@ -582,7 +581,7 @@ export default class addKnockGold extends Component { if ( (this.state.TimeDiffer < Number(this.state.model.effect_date) || 1 > Number(this.state.model.effect_date)) && - this.state.model.usable_time === 'received' + this.state.model.usable_time === "received" ) { Notify.error( `有限期不允许大于生效时间段 注:当前有效期最小时间为 1 天,最大时间为 ${this.state.TimeDiffer} 天` @@ -591,55 +590,55 @@ export default class addKnockGold extends Component { } if ( - this.state.model.usable_time === 'fiexd' && + this.state.model.usable_time === "fiexd" && this.setTime(this.state.model.fixed_time) ) { - Notify.error('请完整的选择固定时间段') + Notify.error("请完整的选择固定时间段") return false } if ( - (this.state.model.usable_time === 'fiexd' && + (this.state.model.usable_time === "fiexd" && this.state.model.fixed_time[0] > this.state.model.entry_time[1]) || - (this.state.model.usable_time === 'fiexd' && + (this.state.model.usable_time === "fiexd" && this.state.model.fixed_time[1] > this.state.model.entry_time[1]) ) { - Notify.error('固定开始时间或结束时间不允许大于生效结束时间') + Notify.error("固定开始时间或结束时间不允许大于生效结束时间") return false } /* 验证有效期内,规则日期可用 */ - if (this.state.model.usable_time === 'week') { + if (this.state.model.usable_time === "week") { if ( this.testDateFunction(this.state.model.ruleDate).length > 0 || this.state.model.ruleWeek.length < 1 ) { - Notify.error('请完整的选择规则日期和时间') + Notify.error("请完整的选择规则日期和时间") return false } } /* 有效期内,不规则日期可用 */ - if (this.state.model.usable_time === 'irregular') { + if (this.state.model.usable_time === "irregular") { if ( this.testDateFunction(this.state.model.irregularDate).length > 0 || this.testDateFunction(this.state.model.irregularTime).length > 0 ) { - Notify.error('请完整的选择不规则日期和时间') + Notify.error("请完整的选择不规则日期和时间") return false } } if (this.detectTimeConflict(this.state.model.ruleDate)) { - Notify.error('有效期内,规则时间存在交集') + Notify.error("有效期内,规则时间存在交集") return false } if (this.detectTimeConflict(this.state.model.irregularDate)) { - Notify.error('有效期内,不规则日期存在交集') + Notify.error("有效期内,不规则日期存在交集") return false } if (this.detectTimeConflict(this.state.model.irregularTime)) { - Notify.error('有效期内,不规则时间存在交集') + Notify.error("有效期内,不规则时间存在交集") return false } @@ -648,7 +647,7 @@ export default class addKnockGold extends Component { !limitBit.test(this.state.model.denomination) || !limitBit.test(this.state.model.reduce_amount) ) { - Notify.error('请输入正确的面额金额或立减金额(保留两位小数)') + Notify.error("请输入正确的面额金额或立减金额(保留两位小数)") return false } @@ -656,7 +655,7 @@ export default class addKnockGold extends Component { this.state.model.denomination - 0 < this.state.model.reduce_amount - 0 ) { - Notify.error('面额不允许大于满减金额') + Notify.error("面额不允许大于满减金额") return false } @@ -664,17 +663,17 @@ export default class addKnockGold extends Component { this.state.model.recharge_amount - 0 > this.state.model.all_budget - 0 ) { - Notify.error('充值批次金额不允许大于总预算') + Notify.error("充值批次金额不允许大于总预算") return false } if (this.state.model.all_budget - 0 < this.state.model.day_budget - 0) { - Notify.error('单天预算发放上限不允许大于总预算') + Notify.error("单天预算发放上限不允许大于总预算") return false } if (this.state.model.day_budget - 0 < this.state.model.reduce_amount - 0) { - Notify.error('单天预算发放上限不允许小于面额') + Notify.error("单天预算发放上限不允许小于面额") return false } @@ -682,7 +681,7 @@ export default class addKnockGold extends Component { this.state.model.recharge_amount - 0 < this.state.model.reduce_amount - 0 ) { - Notify.error('面额不允许大于批次充值金额') + Notify.error("面额不允许大于批次充值金额") return false } @@ -690,28 +689,28 @@ export default class addKnockGold extends Component { Math.trunc(this.state.model.all_budget / this.state.model.reduce_amount) < this.state.model.receive_number - 0 ) { - Notify.error('用户可领个数不允许大于库存(总预算/面额)') + Notify.error("用户可领个数不允许大于库存(总预算/面额)") return false } /* 生效时间段 */ if (this.setTime(this.state.model.entry_time)) { - Notify.error('请选择结束时间或开始时间') + Notify.error("请选择结束时间或开始时间") return false } /* 领取时间段 */ if ( this.setTime(this.state.model.timer) && - this.state.model.timer_type === '2' + this.state.model.timer_type === "2" ) { - Notify.error('请选择结束时间或开始时间') + Notify.error("请选择结束时间或开始时间") return false } /* 预警人数 */ if (this.state.model.early_notifier.length > 14) { - Notify.error('目前仅支持新增10个预警通知人') + Notify.error("目前仅支持新增10个预警通知人") return false } } @@ -745,7 +744,7 @@ export default class addKnockGold extends Component { this.state.model.entry_time[1] ) const data = this.state.getTimeList.map((item) => { - if (item?.key === '1') { + if (item?.key === "1") { if (TimeDiffer < 2) { item.disabled = true } else { @@ -763,31 +762,31 @@ export default class addKnockGold extends Component { const newData = this.state.model.early_notifier.filter( (items) => items.key !== item.key ) - this.onHandleChange(newData, 'early_notifier') /* 调用公用setState */ + this.onHandleChange(newData, "early_notifier") /* 调用公用setState */ /* 当预警人为0 清除输入框 */ - if (newData.length < 1) this.setState({ warningInput: '' }) + if (newData.length < 1) this.setState({ warningInput: "" }) } render() { return (
{/*
基本信息
*/} - +
{ - this.onHandleChange(target.value, 'channel') + this.onHandleChange(target.value, "channel") if (target.value == 1) { - this.onHandleChange(defaultInstructionZfb, 'instruction') + this.onHandleChange(defaultInstructionZfb, "instruction") } else { - this.onHandleChange(defaultInstructionWx, 'instruction') + this.onHandleChange(defaultInstructionWx, "instruction") } }} value={this.state.model.channel}> - 支付宝 - 微信 + 支付宝 + 微信 { - this.onHandleChange(value, 'channel_activity_id') + this.onHandleChange(value, "channel_activity_id") }} onClearItem={() => { - this.onHandleChange('', 'channel_activity_id') + this.onHandleChange("", "channel_activity_id") }} disabled={this.props?.data?.id ? true : false} value={this.state.model.channel_activity_id} - placeholder={'请输入'} - labelWidth={'0px'} + placeholder={"请输入"} + labelWidth={"0px"} maxLength={50} - height={'36px'} - width={'520px'} - alignment={'left'} + height={"36px"} + width={"520px"} + alignment={"left"} /> {this.state.model.channel == 1 ? ( { - this.onHandleChange(value, 'temp_no') + this.onHandleChange(value, "temp_no") }} onClearItem={() => { - this.onHandleChange('', 'temp_no') + this.onHandleChange("", "temp_no") }} disabled={this.props?.data?.id ? true : false} value={this.state.model.temp_no} - placeholder={'请输入'} - labelWidth={'0px'} + placeholder={"请输入"} + labelWidth={"0px"} maxLength={50} - height={'36px'} - width={'520px'} - alignment={'left'} + height={"36px"} + width={"520px"} + alignment={"left"} /> ) : ( @@ -840,57 +839,57 @@ export default class addKnockGold extends Component { id='batch_goods_name'> { - this.onHandleChange(value, 'batch_goods_name') + this.onHandleChange(value, "batch_goods_name") }} onClearItem={() => { - this.onHandleChange('', 'batch_goods_name') + this.onHandleChange("", "batch_goods_name") }} value={this.state.model.batch_goods_name} disabled={this.props?.data?.id ? true : false} - placeholder={'请输入'} - labelWidth={'0px'} + placeholder={"请输入"} + labelWidth={"0px"} maxLength={30} - height={'36px'} - width={'520px'} - alignment={'left'} + height={"36px"} + width={"520px"} + alignment={"left"} /> { - this.onHandleChange(value, 'weight') + this.onHandleChange(value, "weight") }} onClearItem={() => { - this.onHandleChange('', 'weight') + this.onHandleChange("", "weight") }} value={this.state.model.weight} - placeholder={'请输入'} - labelWidth={'0px'} + placeholder={"请输入"} + labelWidth={"0px"} maxLength={3} - height={'36px'} - width={'520px'} + height={"36px"} + width={"520px"} countShow={false} - alignment={'left'} + alignment={"left"} /> { - this.onHandleChange(value, 'price') + this.onHandleChange(value, "price") }} onClearItem={() => { - this.onHandleChange('', 'price') + this.onHandleChange("", "price") }} value={this.state.model.price} - placeholder={'请输入'} - labelWidth={'0px'} + placeholder={"请输入"} + labelWidth={"0px"} maxLength={7} - height={'36px'} + height={"36px"} disabled={this.props?.data?.id ? true : false} - width={'520px'} + width={"520px"} unit='元' countShow={false} - alignment={'left'} + alignment={"left"} /> { - this.onHandleChange(value, 'recharge_amount') + this.onHandleChange(value, "recharge_amount") }} onClearItem={() => { - this.onHandleChange('', 'recharge_amount') + this.onHandleChange("", "recharge_amount") }} value={this.state.model.recharge_amount} disabled={this.props?.data?.id ? true : false} - placeholder={'请输入'} + placeholder={"请输入"} unit='元' countShow={false} - labelWidth={'0px'} + labelWidth={"0px"} maxLength={9} - height={'36px'} - width={'520px'} - alignment={'left'} + height={"36px"} + width={"520px"} + alignment={"left"} /> {this.state.model.id ? (