diff --git a/src/components/UseGoodsScopePop/index.jsx b/src/components/UseGoodsScopePop/index.jsx index 77dab65b..9932d591 100644 --- a/src/components/UseGoodsScopePop/index.jsx +++ b/src/components/UseGoodsScopePop/index.jsx @@ -1,9 +1,9 @@ -import React, { forwardRef, useImperativeHandle, useRef } from "react" -import { Card, Drawer, Button } from "zent" +import React, { forwardRef, useImperativeHandle, useRef } from "react"; +import { Card, Drawer, Button } from "zent"; -import Productform from "@/pages/plan/product/add" /* 商品 */ -import KnockGold from "@/components/knockGold" /* 立减金 */ -import { divNum } from "@/tools/number" +import Productform from "@/pages/plan/product/add"; /* 商品 */ +import KnockGold from "@/components/knockGold"; /* 立减金 */ +import { divNum } from "@/tools/number"; const UseGoodsScopePop = forwardRef((props, ref) => { const { @@ -14,124 +14,113 @@ const UseGoodsScopePop = forwardRef((props, ref) => { productData, submit, tableData, - table_index - } = props + table_index, + } = props; // 如果需要 通过ref 控制此组件 放开注释 // useImperativeHandle(ref, () => ({ // submit: submitPop, // })); - const product_el = useRef(null) - const knockGold_el = useRef(null) + const product_el = useRef(null); + const knockGold_el = useRef(null); // 新建商品数据处理 const format_product_model = () => { - let new_tableData = tableData + let new_tableData = tableData; - let form_model = product_el.current.state.form_data - form_model.type = 1 - form_model.upstream = "直连天下" + let form_model = product_el.current.state.form_data; + form_model.type = 1; + form_model.upstream = "直连天下"; form_model.all_budget = - Number(form_model.contract_price) * Number(form_model.quantity) - form_model.effectDate = "-" + Number(form_model.contract_price) * Number(form_model.quantity); + form_model.effectDate = "-"; if (product_title === "编辑商品") { if (table_index !== -1) { -<<<<<<< HEAD form_model.checked = false; new_tableData[table_index] = form_model; -======= - form_model.checked = false - new_tableData[table_index] = form_model - console.log("new_tableData =>", new_tableData) ->>>>>>> a888b0572236c8400347da365ad0e0619445cca7 } } else { - new_tableData.push(form_model) + new_tableData.push(form_model); } - return new_tableData - } + return new_tableData; + }; // 立减金数据处理 const format_knockGold_model = () => { - let new_tableData = tableData - let table_obj = {} - let form_model = knockGold_el.current.state.form_data - table_obj.type = 2 // 类型 - table_obj.upstream = String(form_model.channel) === "1" ? "支付宝" : "微信" // 上游平台 + let new_tableData = tableData; + let table_obj = {}; + let form_model = knockGold_el.current.state.form_data; + table_obj.type = 2; // 类型 + table_obj.upstream = String(form_model.channel) === "1" ? "支付宝" : "微信"; // 上游平台 - table_obj.only = form_model // 存储就数据 编辑好用 - table_obj.product_id = form_model.channel_activity_id // 商品编号 - 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.only = form_model; // 存储就数据 编辑好用 + table_obj.product_id = form_model.channel_activity_id; // 商品编号 + 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 = parseInt( divNum(form_model.all_budget, form_model.reduce_amount) - ) // 库存数量 - table_obj.channel_activity_id = form_model.channel_activity_id // 批次号 - table_obj.all_budget = Number(form_model.all_budget) // 总预算 - table_obj.effectDate = `${form_model.time_limit.effect_time.end_time} 至 ${form_model.time_limit.effect_time.start_time}` // 有效时间段 - table_obj.createDate = "" // 创建时间 + ); // 库存数量 + table_obj.channel_activity_id = form_model.channel_activity_id; // 批次号 + table_obj.all_budget = Number(form_model.all_budget); // 总预算 + table_obj.effectDate = `${form_model.time_limit.effect_time.end_time} 至 ${form_model.time_limit.effect_time.start_time}`; // 有效时间段 + table_obj.createDate = ""; // 创建时间 if (product_title === "编辑立减金") { if (table_index !== -1) { - table_obj.checked = false - new_tableData[table_index] = table_obj - new_tableData[table_index].only = form_model + table_obj.checked = false; + new_tableData[table_index] = table_obj; + new_tableData[table_index].only = form_model; } } else { - new_tableData.push(table_obj) + new_tableData.push(table_obj); } - return new_tableData - } + return new_tableData; + }; // 提交数据 const submitPop = async () => { try { // 第一步:判断是立减金还是新建商品 - let visible = false + let visible = false; if (type === "addProduct") { - visible = await product_el.current.submit() + visible = await product_el.current.submit(); } else { - visible = await knockGold_el.current.submit() + visible = await knockGold_el.current.submit(); } if (visible) { // 第二步:获取商品或者立减金的数据 并格式化为table一样的字段 以商品数据为准 合并 - let form_data = {} + let form_data = {}; if (type === "addProduct") { - form_data = format_product_model() + form_data = format_product_model(); } else { - form_data = format_knockGold_model() + form_data = format_knockGold_model(); } -<<<<<<< HEAD submit(form_data); onClose(); -======= - console.log("form_data 1=>", form_data) - submit(form_data) - onClose() ->>>>>>> a888b0572236c8400347da365ad0e0619445cca7 } } catch (err) { - console.log("err =>", err) + console.log("err =>", err); } - } + }; return ( @@ -139,14 +128,16 @@ const UseGoodsScopePop = forwardRef((props, ref) => { } visible={drawerVisible} onClose={(e) => onClose()} - maskClosable={false}> -
+ maskClosable={false} + > +
+ className="borderNone" + style={{ width: "95%", margin: "10px auto" }} + > {type === "addKnockGold" ? ( @@ -156,7 +147,7 @@ const UseGoodsScopePop = forwardRef((props, ref) => {
- ) -}) + ); +}); -export default UseGoodsScopePop +export default UseGoodsScopePop;