fix: 修复新建商品映射商品

This commit is contained in:
zhangds 2022-10-24 10:53:07 +08:00
parent e6e61dccc3
commit dc56b584a6
2 changed files with 50 additions and 50 deletions

View File

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

View File

@ -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}
>
<RadioButton value={1}>直充</RadioButton>
<RadioButton value={2}>卡密</RadioButton>