1) 完成新建有回去商品范围联动select

This commit is contained in:
zhangds 2022-09-07 11:51:24 +08:00
parent c8f5dab29a
commit 2e73f3d77a
2 changed files with 97 additions and 38 deletions

View File

@ -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>
);
}
}}
/>

View File

@ -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" ? "支付宝" : "微信"; //