From 1338f0c5ff8817f9badd07f105fdcedcfe5e60fc Mon Sep 17 00:00:00 2001 From: wangsongsole Date: Tue, 1 Aug 2023 09:15:57 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=8A=20fix:=20=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E4=B8=8D=E5=85=81=E8=AE=B8=E5=BC=80=E5=90=AF=E4=BA=91?= =?UTF-8?q?=E9=97=AA=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UseGoodsScopePop/index.jsx | 179 +++++++++++----------- src/components/knockGold/index.jsx | 2 +- 2 files changed, 87 insertions(+), 94 deletions(-) diff --git a/src/components/UseGoodsScopePop/index.jsx b/src/components/UseGoodsScopePop/index.jsx index eb3a3116..b681f746 100644 --- a/src/components/UseGoodsScopePop/index.jsx +++ b/src/components/UseGoodsScopePop/index.jsx @@ -1,10 +1,10 @@ -import React, { forwardRef, useRef } from 'react'; -import { Card, Drawer, Button } from 'zent'; -import KnockGold from '@/components/knockGold'; /* 立减金 */ -import RedPackets from '@/components/redPackets'; /* 红包 */ -import { mulNum } from '@/tools/number'; -import { knockGoldFun, redPacketsFun } from '@/tools/index'; -import UseProductPop from '../UseProductPop'; // 商品 +import React, { forwardRef, useRef } from "react" +import { Card, Drawer, Button } from "zent" +import KnockGold from "@/components/knockGold" /* 立减金 */ +import RedPackets from "@/components/redPackets" /* 红包 */ +import { mulNum } from "@/tools/number" +import { knockGoldFun, redPacketsFun } from "@/tools/index" +import UseProductPop from "../UseProductPop" // 商品 const UseGoodsScopePop = forwardRef((props, ref) => { const { @@ -19,121 +19,114 @@ const UseGoodsScopePop = forwardRef((props, ref) => { directResellerId, productType, checkedProduct - } = props; + } = props // 如果需要 通过ref 控制此组件 放开注释 // useImperativeHandle(ref, () => ({ // getProductData, // })); - const productEl = useRef(null); - const knockGold_el = useRef(null); - const redPackets_el = useRef(null); + const productEl = useRef(null) + const knockGold_el = useRef(null) + const redPackets_el = useRef(null) // 新建商品数据处理 const format_product_model = () => { - let new_tableData = tableData; - let form_model = productEl.current.getFormModel(); - form_model.upstream = '直连天下'; - form_model.type = 1; - form_model.stock = form_model.quantity; - form_model.all_budget = mulNum( - Number(form_model.contract_price), - Number(form_model.quantity) - ); - form_model.effectDate = '-'; - if (product_title === '编辑商品') { + let new_tableData = tableData + let form_model = productEl.current.getFormModel() + form_model.upstream = "直连天下" + form_model.type = 1 + form_model.stock = form_model.quantity + form_model.all_budget = mulNum(Number(form_model.contract_price), Number(form_model.quantity)) + form_model.effectDate = "-" + if (product_title === "编辑商品") { if (table_index !== -1) { - let ck = new_tableData[table_index].checked; - new_tableData[table_index] = form_model; - new_tableData[table_index].checked = ck; + let ck = new_tableData[table_index].checked + new_tableData[table_index] = form_model + new_tableData[table_index].checked = ck } } 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 form_model = knockGold_el.current.state.form_data; - let table_obj = knockGoldFun(form_model); - if (product_title === '编辑立减金') { + let new_tableData = tableData + let form_model = knockGold_el.current.state.form_data + let table_obj = knockGoldFun(form_model) + if (product_title === "编辑立减金") { if (table_index !== -1) { - let ck = new_tableData[table_index].checked; - new_tableData[table_index] = table_obj; - new_tableData[table_index].only = form_model; - new_tableData[table_index].checked = ck; + let ck = new_tableData[table_index].checked + new_tableData[table_index] = table_obj + new_tableData[table_index].only = form_model + new_tableData[table_index].checked = ck } } else { - new_tableData.push(table_obj); + new_tableData.push(table_obj) } - return new_tableData; - }; + return new_tableData + } // 红包数据处理 const format_redPackets_model = () => { - let new_tableData = tableData; - let form_model = redPackets_el.current.state.form_data; - let table_obj = redPacketsFun(form_model); - table_obj.only.copy = false; - if (product_title === '编辑红包') { + let new_tableData = tableData + let form_model = redPackets_el.current.state.form_data + let table_obj = redPacketsFun(form_model) + table_obj.only.copy = false + if (product_title === "编辑红包") { if (table_index !== -1) { - let ck = new_tableData[table_index].checked; - new_tableData[table_index] = table_obj; - new_tableData[table_index].only = form_model; - new_tableData[table_index].checked = ck; + let ck = new_tableData[table_index].checked + new_tableData[table_index] = table_obj + new_tableData[table_index].only = form_model + new_tableData[table_index].checked = ck } } else { - new_tableData.push(table_obj); + new_tableData.push(table_obj) } - return new_tableData; - }; + return new_tableData + } // 提交数据 const submitPop = async () => { try { // 第一步:判断是商品/立减金/红包 - let visible = false; - if (type === 'addProduct') { - visible = await productEl.current.submit(); - } else if (type === 'addKnockGold') { - visible = await knockGold_el.current.submit(); + let visible = false + if (type === "addProduct") { + visible = await productEl.current.submit() + } else if (type === "addKnockGold") { + visible = await knockGold_el.current.submit() } else { - visible = await redPackets_el.current.submit(); + visible = await redPackets_el.current.submit() } if (visible) { // 第二步:获取商品/立减金/红包的数据 并格式化为table一样的字段 以商品数据为准 合并 - let form_data = {}; - if (type === 'addProduct') { - form_data = format_product_model(); - } else if (type === 'addKnockGold') { - form_data = format_knockGold_model(); + let form_data = {} + if (type === "addProduct") { + form_data = format_product_model() + } else if (type === "addKnockGold") { + form_data = format_knockGold_model() } else { - form_data = format_redPackets_model(); + form_data = format_redPackets_model() } - submit(form_data); - onClose(); + submit(form_data) + onClose() } } catch (err) { - console.log('err =>', err); + console.log("err =>", err) } - }; + } /* 切换组件 */ function SwitchComponents() { switch (type) { - case 'addKnockGold': + case "addKnockGold": return ( - - ); - case 'addProduct': + + ) + case "addProduct": return ( { directResellerId={directResellerId} productType={productType} /> - ); - case 'redPackets': - return ; + ) + case "redPackets": + return default: - break; + break } } return ( +
@@ -169,16 +163,15 @@ const UseGoodsScopePop = forwardRef((props, ref) => { } visible={drawerVisible} onClose={(e) => onClose()} - maskClosable={false}> -
- + maskClosable={false} + > +
+ {SwitchComponents()}
- ); -}); + ) +}) -export default UseGoodsScopePop; +export default UseGoodsScopePop diff --git a/src/components/knockGold/index.jsx b/src/components/knockGold/index.jsx index 52d65c8c..a7f7ad76 100644 --- a/src/components/knockGold/index.jsx +++ b/src/components/knockGold/index.jsx @@ -761,7 +761,7 @@ export default class addKnockGold extends Component { > 支付宝 微信 - 云闪付 + {!this.props.ysf && 云闪付}