diff --git a/src/pages/exchangecode/edit/edit.js b/src/pages/exchangecode/edit/edit.js index 61ceddaf..c93d6cce 100644 --- a/src/pages/exchangecode/edit/edit.js +++ b/src/pages/exchangecode/edit/edit.js @@ -115,7 +115,6 @@ export default class exchangedit extends React.Component { receive_email: req.receive_email } this.setState({ reseller: resller_obj }) - let codeInfo = { code_name: req.title, issued: req.quantity, @@ -124,7 +123,6 @@ export default class exchangedit extends React.Component { date_time: [req.begin_time, req.end_time], range: req.update_product } - if (req.new_product.length > 0) { req.new_product = _.map(req.new_product, (item) => { item.checked = false @@ -134,7 +132,7 @@ export default class exchangedit extends React.Component { } let new_ids = _.map(req.new_product, (o) => { - return o.product_id + return o.only }) this.setState({ new_product: new_ids }) @@ -148,12 +146,13 @@ export default class exchangedit extends React.Component { codeInfo.stock = req.stock this.setState({ plan_time: req.plan.end_time }) this.setState({ oldTable: req.code_batch_stock }) + console.log(req) let deleteArr = [] for (let i = 0; i < delete_product.length; i++) { let deleteData = req.code_batch_stock.find( - (o) => o.product_id == delete_product[i] + (o) => o.only == delete_product[i] ) deleteData.checked = false deleteArr.push(deleteData) @@ -163,7 +162,7 @@ export default class exchangedit extends React.Component { codeInfo.range = codeInfo.range.concat(deleteArr) let table = _.map(codeInfo.range, (res) => { let obj = req.code_batch_stock.find( - (o) => o.product_id == res.product_id + (o) => o.only == res.only ) res.usage = obj ? obj.usage : 0 @@ -186,14 +185,13 @@ export default class exchangedit extends React.Component { let temp = [] _.map(codeInfo.range, (res) => { let obj = {} - obj.key = res.product_id + obj.key = res.only obj.text = res.product_name - if (new_ids.indexOf(res.product_id) < 0) { - this.state.oldProduct.push(res.product_id) + if (new_ids.indexOf(res.only) < 0) { + this.state.oldProduct.push(res.only) } if ( - table.find((o) => o.product_id == res.product_id) - .checked == true + table.find((o) => o.only == res.only).checked == true ) { temp.push(obj) } @@ -227,17 +225,51 @@ export default class exchangedit extends React.Component { handelResponse( res, (req, msg) => { + let reqCopy = _.cloneDeep(req) + const resData = [] + reqCopy.goods.map((item) => { + /* type 1为商品 2为立减金 转译字符方便处理 */ + /* 此处only 商品为product_id 立减金为channel_activity_id */ + if (item.type === 1) { + item.entity.upstream = '直连天下' + item.entity.only = item.entity.product_id + item.entity.id = item.id + resData.push(item.entity) + } else if (item.type === 2) { + resData.push({ + original: item.entity, + type: item.type, + product_type_text: '立减金', + only: item.entity.channel_activity_id, + id: item.id, + upstream: item.entity.channel === '1' ? '支付宝' : '微信', + code_batch_id: item.code_batch_id, + contract_price: item.entity.price, + create_time: item.create_time, + official_price: item.entity.denomination, + channel_activity_id: item.entity.channel_activity_id, + product_name: item.entity.batch_goods_name, + quantity: item.stock, + effectDate: + item.entity.time_limit.effect_time.start_time + + ' 至 ' + + item.entity.time_limit.effect_time.end_time //有效时间 + }) + } + }) + reqCopy.goods = resData let codeInfo = { - code_name: req.title, - issued: req.quantity, - stock: req.stock, - describe: req.describe, - date_time: [req.begin_time, req.end_time], - range: req.code_batch_stock + code_name: reqCopy.title, + issued: reqCopy.quantity, + stock: reqCopy.stock, + describe: reqCopy.describe, + date_time: [reqCopy.begin_time, reqCopy.end_time], + range: reqCopy.goods } - this.setState({ plan_time: req.plan.end_time }) + + this.setState({ plan_time: reqCopy.plan.end_time }) //获取分销商 - getReseller(req.plan.reseller_id).then((res) => { + getReseller(reqCopy.plan.reseller_id).then((res) => { handelResponse(res, (req1, msg) => { console.log('req ==>1', req1) req1.receive_email = req1.contact_email[0] @@ -252,13 +284,13 @@ export default class exchangedit extends React.Component { this.setState({ codeInfo: codeInfo }) this.setState({ isload: true }) - let table = _.map(req.code_batch_stock, (res) => { + let table = _.map(reqCopy.goods, (res) => { res.checked = true return res }) - this.setState({ tempdata: req.code_batch_stock }) + this.setState({ tempdata: reqCopy.goods || [] }) - let a1 = req.code_batch_stock.map((item) => { + let a1 = reqCopy.goods.map((item) => { let obj = { ...item, in: true @@ -267,11 +299,11 @@ export default class exchangedit extends React.Component { }) sessionStorage.setItem('productData', JSON.stringify(a1)) let arr = [] - _.map(req.code_batch_stock, (res) => { + _.map(reqCopy.goods, (res) => { let obj = {} - obj.key = res.product_id + obj.key = res.only obj.text = res.product_name - this.state.oldProduct.push(res.product_id) + this.state.oldProduct.push(res.only) arr.push(obj) return obj }) @@ -874,7 +906,13 @@ export default class exchangedit extends React.Component { sessionStorage.setItem('productsList', JSON.stringify(data)) /* 区分立减金 */ if (rowData.type === 2) { - const temp = JSON.parse(sessionStorage.getItem('knockGoldData')) + let temp = '' + /* 区分是否为新增编辑 还是原始数据编辑 */ + if (rowData?.original) { + temp = [rowData.original] + } else { + temp = JSON.parse(sessionStorage.getItem('knockGoldData')) + } const editData = temp.filter( (item) => item.channel_activity_id === rowData.only ) diff --git a/src/pages/plan/add/edit.js b/src/pages/plan/add/edit.js index 3423c4f2..04a3aaeb 100644 --- a/src/pages/plan/add/edit.js +++ b/src/pages/plan/add/edit.js @@ -1,37 +1,21 @@ /* 编辑 */ -import ReactDOM from 'react-dom' -import React, { Component } from 'react' -import { HashRouter as Router, Route, Link } from 'react-router-dom' -import { - Button, - Card, - Icon, - Notify, - Radio, - RadioGroup, - smoothScroll, - Sweetalert, - Input -} from 'zent' +import React from 'react' +import { Button, Card, Icon, Notify, Radio, RadioGroup, Sweetalert } from 'zent' import './edit.less' import Step1 from './step1.js' import Step2 from './step2.js' import Step3 from './step3.js' import _ from 'lodash' import { - getThemeChoice, addPlanStep, handelResponse, getReseller, planSend, getDraftInfo, - putPlanStep, - uploadImg, getApprovalsInfo, approvals, terminateApprovals, - getApprovalsStatus, - getCodesDetail + getApprovalsStatus } from '../../../assets/api.js' export default class add extends React.Component { @@ -102,6 +86,7 @@ export default class add extends React.Component { parentComponent: this }) } + componentDidMount(e) { let plan_status = sessionStorage.getItem('plan_status') if (plan_status == 3 || plan_status == 4 || plan_status == 5) { @@ -140,6 +125,7 @@ export default class add extends React.Component { } setTimeout(() => { for (let i = 0; i < this.state.keys.length; i++) { + console.log(req.keys[i]) this.refs['step2-' + i].edit(req.keys[i]) } }, 500) @@ -169,6 +155,7 @@ export default class add extends React.Component { ) }) } else { + debugger //获取草稿信息 console.log('获取草稿信息 ==>') getDraftInfo(plan_id).then((res) => { @@ -593,6 +580,7 @@ export default class add extends React.Component { onStyleChange={(e) => { this.onStyleChange(e) }} + is_Edit={true} whiteStyle={this.state.whiteStyle} keyStyle={this.state.keyStyle} isload={this.state.isload} diff --git a/src/pages/plan/add/step2.js b/src/pages/plan/add/step2.js index 70f97adf..deb6ccb0 100644 --- a/src/pages/plan/add/step2.js +++ b/src/pages/plan/add/step2.js @@ -108,11 +108,9 @@ export default class acclist extends React.Component { componentDidMount(e) { const dom = ReactDOM.findDOMNode(this) - let items = dom.getElementsByClassName('form-Item') let input = items[1].getElementsByTagName('input')[0] input.focus() - if (this.props.name > 0) { this.setState({ whiteStyle: this.props.whiteStyle }) this.setState({ white_visible: this.props.whiteStyle }) @@ -125,6 +123,41 @@ export default class acclist extends React.Component { submit() { let valide = false if (this.refs.form1.validator()) { + /* 处理数据 区分立减金和商品 开始 2022-05-30 13:40*/ + + let reduce = [] + if (sessionStorage.getItem('knockGoldData')) { + reduce = JSON.parse(sessionStorage.getItem('knockGoldData')) + } + const dataCopy = this.refs.tempdata.getSelectData() + + dataCopy.map((item) => { + item.products = item.product + }) + + dataCopy.map((item) => + item.products.map(() => { + item.product = { + legal: item.products.filter((item2) => item2.type === 1), + reduce: item.products + .filter((item3) => item3.type === 2) + .map( + (item4) => + reduce + .map((item5) => { + if (item4.only === item5.channel_activity_id) return item5 + }) + .filter((item6) => item6)[0] + ) + } + }) + ) + + dataCopy.map((item) => { + delete item.products + }) + /* 处理数据 区分立减金和商品 完成 2022-05-30 13:40*/ + let data = {} data.batch_name = this.state.model.batch_name data.style = this.state.model.style @@ -133,7 +166,7 @@ export default class acclist extends React.Component { data.allow_repetition = this.state.model.allow_repetition data.allow_loss = this.state.model.allow_loss data.merge_stock = this.state.model.merge_stock - data.code_batch = this.refs.tempdata.getSelectData() + data.code_batch = dataCopy data.mobile_excel = this.state.mobile_excel data.mobile_repeat = this.state.mobile_repeat return data @@ -655,6 +688,9 @@ export default class acclist extends React.Component { restrict: row.restrict } + /*审核中编辑 转换数据结构立减金和商品结构 */ + const newRowArray = row.product.legal.concat(row.product.reduce) + let arr = _.map(row.product, (res) => { let obj = {} obj.key = res.only diff --git a/src/pages/plan/knockGold/index.jsx b/src/pages/plan/knockGold/index.jsx index fb8e1b1d..7f01ee01 100644 --- a/src/pages/plan/knockGold/index.jsx +++ b/src/pages/plan/knockGold/index.jsx @@ -25,7 +25,8 @@ import { Tag, TimeRangePicker } from 'zent' -import _, { isArray, times } from 'lodash' +import _, { isArray } from 'lodash' +import { getVoucherWarningAccount, handelResponse } from '../../../assets/api' import AddNewDialog from './Dialog' import MobileComponent from './mobileCmponent' const getTimeList = [ @@ -33,6 +34,10 @@ const getTimeList = [ { key: '1', text: '次日生效' }, { key: '2', text: '自定义时间' } ] +const cardTypeList = [ + { key: 1, text: '借记卡' }, + { key: 2, text: '信用卡' } +] const receiveTypeList = [ { key: 'all', text: '总共' }, @@ -61,7 +66,7 @@ export default class addKnockGold extends Component { reduce_amount: '', // 立减额度 all_budget: '', // 总预算 day_budget: '', // 单天预算 - card_type: '', // '卡种类型', + card_type: [], // '卡种类型', natural_limit: '1', //'是否开启自然人限制', brush_limit: '1', //'是否开启防刷限制', instruction: '', //'使用说明', @@ -106,8 +111,22 @@ export default class addKnockGold extends Component { } componentWillMount() { - const UserSelectList = this.getUserSelectList() + /* 此处解决 日期组件不回显问题 提前触发 */ + if (this.props.data) { + let model = this.state.model + model.entry_time[0] = this.props.data.time_limit.effect_time.start_time + model.entry_time[1] = this.props.data.time_limit.effect_time.end_time + model.fixed_time[0] = + 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 + this.setState({ model: model }) + } + this.getUserSelectList() + } + /* 编辑回显 */ + echoFun(UserSelectList) { if (this.props.data) { let model = this.state.model for (let key in this.props.data) { @@ -115,15 +134,11 @@ export default class addKnockGold extends Component { } model.receive_type = this.props.data.receive_conf.type model.receive_number = this.props.data.receive_conf.num - model.entry_time[0] = this.props.data.time_limit.effect_time.start_time - model.entry_time[1] = this.props.data.time_limit.effect_time.end_time 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.fixed_time[0] = - 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 - model.timer_type = this.props.data.time_limit.receive_time.type + model.timer_type = !this.props.data.time_limit.receive_time?.start_time + ? '1' + : '2' if (this.props.data.time_limit.use_time.effect_day) { model.effect_date_type = @@ -137,8 +152,8 @@ export default class addKnockGold extends Component { } model.effect_date = this.props.data.time_limit.use_time.effect_day model.usable_time = this.props.data.time_limit.use_time.type - model.early_notifier = this.props.data.early_notifier.map((item) => { - return UserSelectList.map((items) => { + model.early_notifier = this.props.data.early_notifier?.map((item) => { + return UserSelectList?.map((items) => { if (item.mobile === items.key) return items }).filter((item1) => item1)[0] }) @@ -153,60 +168,39 @@ export default class addKnockGold extends Component { } //获取预警人数据 - getUserSelectList() { - const data = [ - { - real_name: '黎明', - mobile: '18555454545' - }, - { - real_name: '彤彤', - mobile: '18547777744' - }, - { - real_name: '杨洋', - mobile: '15874574122' - }, - { - real_name: '何欢媛', - mobile: '18695241254' - }, - { - real_name: '林青松', - mobile: '15184342032' - }, - { - real_name: '韦多伦', - mobile: '15874747474' - }, - { - real_name: 'zh', - mobile: '15184345036' - } - ] - const defaultDta = ['何欢媛', '韦多伦'] + getUserSelectList(cb) { const model = this.state.model - - const newData = data.map((item) => { - if (defaultDta.indexOf(item.real_name) !== -1) { - const obj = { - key: item.mobile, - text: item.real_name, - disabled: true, - closable: false + getVoucherWarningAccount().then((res) => + handelResponse( + res, + (req, msg) => { + const defaultData = req.default.map((item) => item.real_name) + const newData = req.data.concat(req.default).map((item) => { + if (defaultData.indexOf(item.real_name) !== -1) { + const obj = { + key: item.mobile, + text: item.real_name, + disabled: true, + closable: false + } + model.early_notifier.push(obj) + return obj + } else { + return { + key: item.mobile, + text: item.real_name, + closable: true + } + } + }) + this.setState({ userSelectList: newData, model: model }) + this.echoFun(newData) + }, + (err) => { + Notify.error(err) } - model.early_notifier.push(obj) - return obj - } else { - return { - key: item.mobile, - text: item.real_name, - closable: true - } - } - }) - this.setState({ userSelectList: newData, model: model }) - return newData + ) + ) } /* x时间控件禁用 */ @@ -352,8 +346,7 @@ export default class addKnockGold extends Component { receive_time: { start_time: this.state.model.timer[0], - end_time: this.state.model.timer[1], - type: this.state.model.timer_type + end_time: this.state.model.timer[1] }, use_time: { @@ -397,7 +390,7 @@ export default class addKnockGold extends Component { } if ( - this.state.model.usable_time === 'fixed' && + this.state.model.usable_time === 'fiexd' && this.setTime(this.state.model.fixed_time) ) { Notify.error('请完整的选择固定时间段') @@ -439,6 +432,12 @@ export default class addKnockGold extends Component { Notify.error('请选择结束时间或开始时间') return false } + + /* 预警人数 */ + if (this.state.model.early_notifier.length > 14) { + Notify.error('目前仅支持新增10个预警通知人') + return false + } } //限制时间 @@ -721,8 +720,11 @@ export default class addKnockGold extends Component { onChange={(value) => { this.onHandleChange(value, 'card_type') }}> - 借记卡 - 信用卡 + {cardTypeList.map((item) => ( + + {item.text} + + ))} - 领取后 + 领取后