diff --git a/src/components/UseCouponAddEdit/index.jsx b/src/components/UseCouponAddEdit/index.jsx
index 0a135cd5..07f07002 100644
--- a/src/components/UseCouponAddEdit/index.jsx
+++ b/src/components/UseCouponAddEdit/index.jsx
@@ -871,6 +871,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
product_title: "新建商品",
scopePopType: "addProduct",
productData: null,
+ table_index: -1,
productType: 1,
showScopePop: true,
});
@@ -908,16 +909,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
clearStorageData();
// 第三步:区分是新建商品还是立减金
/* 区分立减金 */
- if (rowData.type === 2) {
- let obj = rowData.only;
- setState({
- product_title: "编辑立减金",
- productData: obj,
- scopePopType: "addKnockGold",
- showScopePop: true,
- table_index: index,
- });
- } else {
+ if (rowData.type === 1) {
setState({
product_title: "编辑商品",
scopePopType: "addProduct",
@@ -933,6 +925,15 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
productData: rowData,
showScopePop: true,
});
+ } else {
+ let obj = rowData.only;
+ setState({
+ product_title: "编辑立减金",
+ productData: obj,
+ scopePopType: "addKnockGold",
+ showScopePop: true,
+ table_index: index,
+ });
}
} catch (err) {
console.log("err =>", err);
diff --git a/src/components/UseProductPop/index.jsx b/src/components/UseProductPop/index.jsx
index b32cc39f..b884fd10 100644
--- a/src/components/UseProductPop/index.jsx
+++ b/src/components/UseProductPop/index.jsx
@@ -13,7 +13,7 @@ import {
Notify,
BlockLoading,
} from "zent";
-import { useSetState } from "ahooks";
+import { useSetState, useUpdateEffect } from "ahooks";
import _ from "lodash";
import Ipt from "@/components/input/main";
@@ -76,13 +76,12 @@ const UseProductPop = forwardRef((props, ref) => {
productDataAll: [], // 商品所有数据
productPic: [],
isUpdatePic: false,
- isProductType: false,
loading: false,
});
const [model, setModel] = useSetState({
cur_product: {},
code_batch_id: "",
- product_type: 1,
+ product_type: productType,
cost_price: "",
weight: "",
quantity: "",
@@ -98,12 +97,26 @@ const UseProductPop = forwardRef((props, ref) => {
});
useEffect(() => {
- (async function init() {
- await getProductData();
- await editFun();
- })();
+ getProductData().then((res) => {
+ if (productData) {
+ // 映射商品
+ let productObj = res.find(
+ (item) => item.key === productData.product_id
+ );
+ if (productObj) {
+ setModel({
+ cur_product: productObj,
+ });
+ }
+ }
+ editFun();
+ });
}, []);
+ useUpdateEffect(() => {
+ getProductData();
+ }, [model.product_type]);
+
useEffect(() => {
setState({
productPic: model.describe_url,
@@ -132,7 +145,7 @@ const UseProductPop = forwardRef((props, ref) => {
if (directResellerId) {
let param = {
reseller_id: directResellerId,
- type: productType,
+ type: model.product_type,
};
setState({
loading: true,
@@ -148,8 +161,16 @@ const UseProductPop = forwardRef((props, ref) => {
setState({
productDataAll: req.data,
});
- productListEl(req.data);
- resolve(true);
+
+ let optArr = req.data.map((item) => {
+ return {
+ key: item.id,
+ text: item.title,
+ };
+ });
+ console.log("映射商品 =>", optArr);
+ setState({ productOption: optArr });
+ resolve(optArr);
},
(err) => {
setState({
@@ -169,6 +190,7 @@ const UseProductPop = forwardRef((props, ref) => {
// 编辑处理
const editFun = () => {
return new Promise((resolve, reject) => {
+ console.log("商品编辑 =>", productData);
// 编辑
if (productData) {
setModel({
@@ -181,7 +203,7 @@ const UseProductPop = forwardRef((props, ref) => {
product_id: productData.product_id,
account_type: productData.account_type,
map_product_name: productData.map_product_name,
- product_type: productType,
+ product_type: model.product_type,
code_batch_id: productData.code_batch_id,
show_url: [
{
@@ -207,6 +229,10 @@ const UseProductPop = forwardRef((props, ref) => {
};
}),
});
+
+ setTimeout(() => {
+ setState({ isUpdatePic: !state.isUpdatePic });
+ }, 300);
resolve(true);
} else {
resolve(false);
@@ -214,34 +240,6 @@ const UseProductPop = forwardRef((props, ref) => {
});
};
- // 商品列表渲染
- const productListEl = (data) => {
- let optArr = [];
- let opt = data;
- _.map(opt, (res) => {
- let obj = {};
- obj.key = res.id;
- obj.text = res.title;
- optArr.push(obj);
- return obj;
- });
-
- // 只有编辑有
- if (productData) {
- // 映射商品
- let productObj = optArr.find(
- (item) => item.key === productData.product_id
- );
- if (productObj) {
- setModel({
- cur_product: productObj,
- });
- }
- }
-
- setState({ productOption: optArr });
- };
-
const clearForm = () => {
setModel({
cur_product: {},
@@ -274,6 +272,7 @@ const UseProductPop = forwardRef((props, ref) => {
cost_price: model.cost_price,
official_price: model.official_price,
quantity: model.quantity,
+ weight: model.weight,
show_url: model.show_url[0].src,
describe_url: model.describe_url.map((item) => item.src),
detail_url: model.detail_url[0] ? model.detail_url[0].src : "",
@@ -484,7 +483,7 @@ const UseProductPop = forwardRef((props, ref) => {
onTypeChange(e);
}}
value={model.product_type}
- disabled={model.code_batch_id ? true : false}
+ disabled={model.code_batch_id || state.loading ? true : false}
>
直充
卡密