🎈 per: 整合兑换码-红包代码。并修复红包组件bug

This commit is contained in:
wangsongsole 2023-05-31 14:06:38 +08:00
parent e4c0040df9
commit e76be05a7b
4 changed files with 84 additions and 80 deletions

View File

@ -394,6 +394,7 @@ export default class addKnockGold extends Component {
temp[index] = this.transformDataCode();
}
sessionStorage.setItem('redPacketsData', JSON.stringify(temp));
this.setState({ form_data: temp[index] });
return true;
} else {
/* 校验表单 */

View File

@ -44,8 +44,14 @@ import './index.less';
import moment from 'moment';
import Grid from '@/components/gird/main.js';
import { isSameDay } from 'date-fns';
import { Column2, rulesInfo, codeInfo, init } from './utils.js';
import {
Column2,
rulesInfo,
codeInfo,
init,
redPacketsDataFn,
reductionFn
} from './utils.js';
import { divNum } from '@/tools/number';
const initArray = (targetNum) => {
@ -214,20 +220,9 @@ export default class exchangeAdd extends React.Component {
rank: checkedArray,
rankoptions: arr
});
/* 分类缓存到本地 */
sessionStorage.setItem(
'productData',
JSON.stringify(this.storage(reqCopy.goods, 1))
);
sessionStorage.setItem(
'knockGoldData',
JSON.stringify(this.storage(reqCopy.goods, 2))
);
sessionStorage.setItem(
'redPacketsData',
JSON.stringify(this.storage(reqCopy.goods, 3))
);
this.storage(reqCopy.goods, 1, 'productData');
this.storage(reqCopy.goods, 2, 'knockGoldData');
this.storage(reqCopy.goods, 3, 'redPacketsData');
},
(err) => {}
);
@ -235,14 +230,14 @@ export default class exchangeAdd extends React.Component {
.catch((err) => {});
}
/* 统一缓存数据处理 */
storage(data = [], type) {
return data.filter((item) => {
/* 分类缓存到本地 */
storage(data = [], type, key) {
const filterData = data.map((item) => {
if (item.type === type) {
delete item.origin;
return item;
return item.origin;
}
});
sessionStorage.setItem(key, JSON.stringify(filterData));
}
/* 获取直连天下商品数据 */
@ -886,87 +881,30 @@ export default class exchangeAdd extends React.Component {
/* 处理立减金 */
data = JSON.parse(sessionStorage.getItem('knockGoldData'));
concatData = this.state.tempdata.filter((item) => item.type !== 2);
temp = map(data, (item) => {
let index = this.state.tempdata.findIndex((o) => {
return o.channel_activity_id === item.channel_activity_id;
});
if (index > -1) {
item.checked = this.state.tempdata[index].checked;
}
/* 转换商品结构 */
// temp
const newObj = {};
newObj.product_name = item.batch_goods_name || item.product_name; //
newObj.channel_activity_id = item.channel_activity_id; //
newObj.only = item.channel_activity_id; //
newObj.type = 2; //
newObj.checked = item?.checked;
newObj.upstream = String(item.channel) === '1' ? '支付宝' : '微信'; //
newObj.edit = 'edit';
newObj.all_budget = item.all_budget;
newObj.effectDate =
item.effectDate ||
item.time_limit?.effect_time.start_time +
' 至 ' +
item.time_limit?.effect_time.end_time; //
newObj.contract_price = item.contract_price || item.price; //
newObj.official_price = item.official_price || item.reduce_amount; //
newObj.quantity =
item.quantity ||
parseInt(divNum(item.all_budget, item.reduce_amount)); //
newObj.stock =
item.stock ||
parseInt(divNum(item.all_budget, item.reduce_amount)); //
newObj.usage = item.usage || 0; //使
newObj.origin = item;
newObj.id = item.goods_id || item.id;
newObj.product_id = item.goods_id || item.id;
return newObj;
return reductionFn(item);
});
} else {
/* 处理红包 */
data = JSON.parse(sessionStorage.getItem('redPacketsData'));
concatData = this.state.tempdata.filter((item) => item.type !== 3);
temp = map(data, (item) => {
let index = this.state.tempdata.findIndex((o) => {
return o.cash_activity_id === item.cash_activity_id;
});
if (index > -1) {
item.checked = this.state.tempdata[index].checked;
}
/* 当复制商品被编辑后就删除标识 */
delete item.copy;
/* 转换商品结构 */
const newObj = {};
const price =
item.cash_amount_type === '1'
? item.denomination
: `${item.min_denomination}~${item.max_denomination}`;
newObj.product_name = item.batch_goods_name; //
newObj.channel_activity_id = item.cash_activity_id; //
newObj.cash_activity_id = item.cash_activity_id; //
newObj.only = item.cash_activity_id; //
newObj.type = 3; //
newObj.checked = item?.checked;
newObj.upstream = String(item.channel) === 1 ? '支付宝' : '微信'; //
newObj.edit = 'edit';
newObj.all_budget = item.all_budget;
newObj.effectDate = item.begin_time + ' 至 ' + item.end_time; //
newObj.contract_price = price; //
newObj.cost_price = '-'; //
newObj.official_price = price; //
newObj.quantity = item.num; //
newObj.stock = item.stock || item.num; //
newObj.usage = item.usage || 0; //使
newObj.id = item.goods_id || item.id;
newObj.product_id = item.goods_id || item.id;
newObj.origin = item;
return newObj;
return redPacketsDataFn(item);
});
}
let newArray = deWeightThree(temp.concat(concatData), 'only');

View File

@ -1,3 +1,4 @@
import { divNum } from '@/tools/number';
//基本信息
export const codeInfo = {
code_name: [{ type: 'required', message: '请输入兑换码名称' }],
@ -184,3 +185,62 @@ export const init = () => {
codeStatus: '' /* 兑换码状态 */
};
};
/* 转换红包数据 */
export function redPacketsDataFn(params) {
const newObj = {};
const price =
params.cash_amount_type === '1'
? params.denomination
: `${params.min_denomination}~${params.max_denomination}`;
newObj.product_name = params.batch_goods_name; //名字
newObj.channel_activity_id = params.cash_activity_id; //批次号
newObj.cash_activity_id = params.cash_activity_id; //批次号
newObj.only = params.cash_activity_id; //批次号
newObj.type = 3; //类型
newObj.checked = params?.checked;
newObj.upstream = String(params.channel) === 1 ? '支付宝' : '微信'; //上游
newObj.edit = 'edit';
newObj.all_budget = params.all_budget;
newObj.effectDate = params.begin_time + ' 至 ' + params.end_time; //有效时间
newObj.contract_price = price; //单价
newObj.cost_price = '-'; //单价
newObj.official_price = price; //官方价
newObj.quantity = params.num; //总库
newObj.stock = params.stock || params.num; //剩余
newObj.usage = params.usage || 0; //已使用
newObj.id = params.goods_id || params.id;
newObj.product_id = params.goods_id || params.id;
newObj.origin = params;
return newObj;
}
/* 转换立减金数据 */
export function reductionFn(params) {
const newObj = {};
newObj.product_name = params.batch_goods_name || params.product_name; //名字
newObj.channel_activity_id = params.channel_activity_id; //批次号
newObj.only = params.channel_activity_id; //批次号
newObj.type = 2; //类型
newObj.checked = params?.checked;
newObj.upstream = String(params.channel) === '1' ? '支付宝' : '微信'; //上游
newObj.edit = 'edit';
newObj.all_budget = params.all_budget;
newObj.effectDate =
params.effectDate ||
params.time_limit?.effect_time.start_time +
' 至 ' +
params.time_limit?.effect_time.end_time; //有效时间
newObj.contract_price = params.contract_price || params.price; //单价
newObj.official_price = params.official_price || params.reduce_amount; //官方价
newObj.quantity =
params.quantity ||
parseInt(divNum(params.all_budget, params.reduce_amount)); //总库
newObj.stock =
params.stock || parseInt(divNum(params.all_budget, params.reduce_amount)); //剩余
newObj.usage = params.usage || 0; //已使用
newObj.origin = params;
newObj.id = params.goods_id || params.id;
newObj.product_id = params.goods_id || params.id;
return newObj;
}

View File

@ -45,6 +45,7 @@ export default class acclist extends React.Component {
/* 新建/复制/编辑/兑换码 */
addCodeFunction(type, param) {
sessionStorage.setItem('knockGold_effectDate', JSON.stringify({}));
sessionStorage.setItem('redPackets_effectDate', JSON.stringify({}));
let activerou = [
{
pagetitle: '新建兑换码',
@ -80,6 +81,10 @@ export default class acclist extends React.Component {
'knockGold_effectDate',
JSON.stringify(param.keyBatch.plan)
);
sessionStorage.setItem(
'redPackets_effectDate',
JSON.stringify(param.keyBatch.plan)
);
}
sessionStorage.setItem('code_id', param?.id);