1) 完成新建有回去商品范围联动select
This commit is contained in:
parent
c8f5dab29a
commit
2e73f3d77a
|
@ -89,7 +89,7 @@ const tableColumn = [
|
|||
{
|
||||
title: "类型",
|
||||
name: "goods_type",
|
||||
prop: "type",
|
||||
prop: "goods_type",
|
||||
type: "slot",
|
||||
width: "auto",
|
||||
},
|
||||
|
@ -187,7 +187,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
|
|||
showScopePop: false,
|
||||
scopePopType: "",
|
||||
productData: [],
|
||||
selectGoodsScopeData: [],
|
||||
});
|
||||
|
||||
// 基础信息
|
||||
|
@ -234,9 +233,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
|
|||
let el_setup2 = form_rule_el.current.validator();
|
||||
// console.log("el_setup2 =>", el_setup2);
|
||||
// console.log("发放规则 =>", form_rule_data);
|
||||
|
||||
// 商品范围
|
||||
console.log("用户商品范围 =>", state.selectGoodsScopeData);
|
||||
};
|
||||
|
||||
const onReturn = () => {};
|
||||
|
@ -263,19 +259,33 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
|
|||
};
|
||||
const onPageChange = () => {};
|
||||
const onCountChange = () => {};
|
||||
const selectionFun = (e) => {
|
||||
console.log("e =>", e);
|
||||
let arr = [];
|
||||
_.map(e, (item) => {
|
||||
let obj = {};
|
||||
obj.key = item.product_id;
|
||||
obj.text = item.product_name;
|
||||
arr.push(obj);
|
||||
return obj;
|
||||
});
|
||||
setState({ selectGoodsScopeData: arr });
|
||||
|
||||
// 清除商品和立减金本地存储
|
||||
const clearStorageData = () => {
|
||||
if (state.tableData.length <= 0) {
|
||||
sessionStorage.setItem("productData", "");
|
||||
sessionStorage.setItem("knockGoldData", "");
|
||||
}
|
||||
|
||||
// 新建商品
|
||||
let product_data = state.tableData.filter((item) => item.goods_type === 1);
|
||||
if (product_data.length <= 0) {
|
||||
sessionStorage.setItem("productData", "");
|
||||
} else {
|
||||
sessionStorage.setItem("productData", JSON.stringify(product_data));
|
||||
}
|
||||
|
||||
// 立减金
|
||||
let knockGold_data = state.tableData.filter(
|
||||
(item) => item.goods_type === 2
|
||||
);
|
||||
if (knockGold_data.length <= 0) {
|
||||
sessionStorage.setItem("knockGoldData", "");
|
||||
} else {
|
||||
sessionStorage.setItem("knockGoldData", JSON.stringify(knockGold_data));
|
||||
}
|
||||
};
|
||||
const onRankChange = () => {};
|
||||
|
||||
const addProduct = (type) => {
|
||||
try {
|
||||
// 第一步:获取直连天下的商品数据需要分销商 id
|
||||
|
@ -284,18 +294,16 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
|
|||
Notify.error(`请添加映射分销商`);
|
||||
return;
|
||||
}
|
||||
// 第二步: 区分是新建商品还是立减金
|
||||
// 第二步:清除本地存储数据
|
||||
clearStorageData();
|
||||
|
||||
// 第三步: 区分是新建商品还是立减金
|
||||
if (type === "addProduct") {
|
||||
setState({
|
||||
product_title: "新建商品",
|
||||
addProductBtnLoading: true,
|
||||
scopePopType: "addProduct",
|
||||
});
|
||||
// 兼容本地存储
|
||||
// console.log("--------1", state.tableData);
|
||||
// data = JSON.parse(sessionStorage.getItem('productData')).filter(
|
||||
// (item) => item.type !== 2
|
||||
// )
|
||||
} else {
|
||||
setState({
|
||||
product_title: "新增立减金",
|
||||
|
@ -304,7 +312,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
|
|||
});
|
||||
}
|
||||
|
||||
// 第三步:获取商品数据
|
||||
// 第四步:获取商品数据
|
||||
let param = {
|
||||
reseller_id: direct_reseller_ids,
|
||||
};
|
||||
|
@ -378,25 +386,71 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
|
|||
});
|
||||
};
|
||||
|
||||
const selectionFun = (e) => {
|
||||
let arr = [];
|
||||
_.map(e, (res) => {
|
||||
let obj = {};
|
||||
obj.key = res.only;
|
||||
obj.text = res.product_name;
|
||||
arr.push(obj);
|
||||
return obj;
|
||||
});
|
||||
|
||||
console.log("选中 =>", arr);
|
||||
setState({ rank: arr });
|
||||
};
|
||||
|
||||
const onRankChange = (e) => {
|
||||
console.log("e =>", e);
|
||||
|
||||
let new_table_data = state.tableData.map((item) => {
|
||||
item.checked =
|
||||
e.findIndex((checks) => {
|
||||
return checks.key === item;
|
||||
}) > -1;
|
||||
return item;
|
||||
});
|
||||
console.log("new_table_data =>", new_table_data);
|
||||
setState({ tableData: new_table_data, rank: e });
|
||||
};
|
||||
|
||||
// 优惠券弹窗 提交
|
||||
const scopePopSubmit = (data) => {
|
||||
try {
|
||||
// 格式化表格数据
|
||||
let data_new = data;
|
||||
data_new.key_batch_id = form_info_data.key_batch_id.key;
|
||||
data_new.effectDate = `${form_info_data.date_time[0]} 至 ${form_info_data.date_time[1]}`;
|
||||
let new_table = state.tableData;
|
||||
new_table.push(data_new);
|
||||
console.log("table_data =>", new_table);
|
||||
|
||||
// 设置商品范围选择
|
||||
let select_opt = [];
|
||||
new_table.map((item) => {
|
||||
let obj = {};
|
||||
obj.key = item; // 确保差异
|
||||
obj.text = item.product_name;
|
||||
select_opt.push(obj);
|
||||
});
|
||||
|
||||
// 格式化商品范围
|
||||
setState({
|
||||
tableData: new_table,
|
||||
rankoptions: [],
|
||||
rankoptions: select_opt,
|
||||
});
|
||||
} catch (err) {
|
||||
console.log("err =>", err);
|
||||
}
|
||||
};
|
||||
|
||||
// 商品范围删除
|
||||
const deleteGoodsScope = (index) => {
|
||||
let new_table = state.tableData;
|
||||
new_table = new_table.splice(index, 1);
|
||||
setState({
|
||||
tableData: new_table,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="coupon-box">
|
||||
<Card style={{ margin: "10px auto" }} title={state.setup1_title}>
|
||||
|
@ -607,12 +661,16 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
|
|||
}
|
||||
countChange={(e) => onCountChange(e)}
|
||||
checkChange={(data) => selectionFun(data)}
|
||||
ComponentHandler={(com, rowData) => {
|
||||
ComponentHandler={(com, rowData, rowIndex) => {
|
||||
if (com === "opearo") {
|
||||
return (
|
||||
<div>
|
||||
<span className="grid-link">编辑</span>
|
||||
<span style={{ color: "red" }} className="grid-link">
|
||||
<span
|
||||
style={{ color: "red" }}
|
||||
className="grid-link"
|
||||
onClick={() => deleteGoodsScope(rowIndex)}
|
||||
>
|
||||
删除
|
||||
</span>
|
||||
</div>
|
||||
|
@ -620,7 +678,9 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
|
|||
}
|
||||
|
||||
if (com === "goods_type") {
|
||||
return <span>{rowData.type === 1 ? "商品" : "立减金"}</span>;
|
||||
return (
|
||||
<span>{rowData.goods_type === 1 ? "商品" : "立减金"}</span>
|
||||
);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
import React, { forwardRef, useImperativeHandle, useRef } from "react";
|
||||
import { Card, Drawer, Button } from "zent";
|
||||
|
||||
import { deWeightThree } from "@/utils";
|
||||
|
||||
import Productform from "@/pages/plan/product/add"; /* 商品 */
|
||||
import KnockGold from "@/components/knockGold"; /* 立减金 */
|
||||
|
||||
import _ from "lodash";
|
||||
|
||||
const UseGoodsScopePop = forwardRef((props, ref) => {
|
||||
const { product_title, drawerVisible, onClose, type, productData, submit } =
|
||||
props;
|
||||
|
@ -27,6 +23,7 @@ const UseGoodsScopePop = forwardRef((props, ref) => {
|
|||
form_model.upstream = "直连天下";
|
||||
form_model.all_budget =
|
||||
Number(form_model.contract_price) * Number(form_model.quantity);
|
||||
form_model.effectDate = "-";
|
||||
return form_model;
|
||||
};
|
||||
|
||||
|
@ -40,10 +37,12 @@ const UseGoodsScopePop = forwardRef((props, ref) => {
|
|||
table_obj.product_name = form_model.batch_goods_name; // 商品名
|
||||
table_obj.official_price = form_model.reduce_amount; // 官方价
|
||||
table_obj.contract_price = form_model.price; // 合同价格
|
||||
table_obj.quantity = form_model.quantity; // 库存数量
|
||||
table_obj.key_batch_id = ""; // 批次号
|
||||
table_obj.all_budget = form_model.all_budget; // 总预算
|
||||
table_obj.effectDate = ""; // 有效时间段
|
||||
table_obj.quantity = Math.trunc(
|
||||
form_model.all_budget / form_model.reduce_amount
|
||||
); // 库存数量
|
||||
table_obj.key_batch_id = form_model.channel_activity_id; // 批次号
|
||||
table_obj.all_budget = Number(form_model.all_budget); // 总预算
|
||||
table_obj.effectDate = form_model.entry_time; // 有效时间段
|
||||
table_obj.createDate = ""; // 创建时间
|
||||
table_obj.goods_type = 2; // 类型
|
||||
table_obj.upstream = String(form_model.channel) === "1" ? "支付宝" : "微信"; // 上游平台
|
||||
|
|
Loading…
Reference in New Issue