From ae7b20d473c687dfefa317f1d112e5abb0ad3832 Mon Sep 17 00:00:00 2001 From: zhangds Date: Tue, 20 Sep 2022 14:29:02 +0800 Subject: [PATCH] =?UTF-8?q?1)=20=E4=BC=98=E6=83=A0=E5=88=B8=E5=BC=B9?= =?UTF-8?q?=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UseGoodsScopePop/index.jsx | 133 ++++++++++------------ 1 file changed, 62 insertions(+), 71 deletions(-) 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;