fix: 修复新建商品映射商品
This commit is contained in:
parent
e6e61dccc3
commit
dc56b584a6
|
@ -871,6 +871,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
|
||||||
product_title: "新建商品",
|
product_title: "新建商品",
|
||||||
scopePopType: "addProduct",
|
scopePopType: "addProduct",
|
||||||
productData: null,
|
productData: null,
|
||||||
|
table_index: -1,
|
||||||
productType: 1,
|
productType: 1,
|
||||||
showScopePop: true,
|
showScopePop: true,
|
||||||
});
|
});
|
||||||
|
@ -908,16 +909,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
|
||||||
clearStorageData();
|
clearStorageData();
|
||||||
// 第三步:区分是新建商品还是立减金
|
// 第三步:区分是新建商品还是立减金
|
||||||
/* 区分立减金 */
|
/* 区分立减金 */
|
||||||
if (rowData.type === 2) {
|
if (rowData.type === 1) {
|
||||||
let obj = rowData.only;
|
|
||||||
setState({
|
|
||||||
product_title: "编辑立减金",
|
|
||||||
productData: obj,
|
|
||||||
scopePopType: "addKnockGold",
|
|
||||||
showScopePop: true,
|
|
||||||
table_index: index,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setState({
|
setState({
|
||||||
product_title: "编辑商品",
|
product_title: "编辑商品",
|
||||||
scopePopType: "addProduct",
|
scopePopType: "addProduct",
|
||||||
|
@ -933,6 +925,15 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
|
||||||
productData: rowData,
|
productData: rowData,
|
||||||
showScopePop: true,
|
showScopePop: true,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
let obj = rowData.only;
|
||||||
|
setState({
|
||||||
|
product_title: "编辑立减金",
|
||||||
|
productData: obj,
|
||||||
|
scopePopType: "addKnockGold",
|
||||||
|
showScopePop: true,
|
||||||
|
table_index: index,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("err =>", err);
|
console.log("err =>", err);
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {
|
||||||
Notify,
|
Notify,
|
||||||
BlockLoading,
|
BlockLoading,
|
||||||
} from "zent";
|
} from "zent";
|
||||||
import { useSetState } from "ahooks";
|
import { useSetState, useUpdateEffect } from "ahooks";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
|
||||||
import Ipt from "@/components/input/main";
|
import Ipt from "@/components/input/main";
|
||||||
|
@ -76,13 +76,12 @@ const UseProductPop = forwardRef((props, ref) => {
|
||||||
productDataAll: [], // 商品所有数据
|
productDataAll: [], // 商品所有数据
|
||||||
productPic: [],
|
productPic: [],
|
||||||
isUpdatePic: false,
|
isUpdatePic: false,
|
||||||
isProductType: false,
|
|
||||||
loading: false,
|
loading: false,
|
||||||
});
|
});
|
||||||
const [model, setModel] = useSetState({
|
const [model, setModel] = useSetState({
|
||||||
cur_product: {},
|
cur_product: {},
|
||||||
code_batch_id: "",
|
code_batch_id: "",
|
||||||
product_type: 1,
|
product_type: productType,
|
||||||
cost_price: "",
|
cost_price: "",
|
||||||
weight: "",
|
weight: "",
|
||||||
quantity: "",
|
quantity: "",
|
||||||
|
@ -98,12 +97,26 @@ const UseProductPop = forwardRef((props, ref) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async function init() {
|
getProductData().then((res) => {
|
||||||
await getProductData();
|
if (productData) {
|
||||||
await editFun();
|
// 映射商品
|
||||||
})();
|
let productObj = res.find(
|
||||||
|
(item) => item.key === productData.product_id
|
||||||
|
);
|
||||||
|
if (productObj) {
|
||||||
|
setModel({
|
||||||
|
cur_product: productObj,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editFun();
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useUpdateEffect(() => {
|
||||||
|
getProductData();
|
||||||
|
}, [model.product_type]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setState({
|
setState({
|
||||||
productPic: model.describe_url,
|
productPic: model.describe_url,
|
||||||
|
@ -132,7 +145,7 @@ const UseProductPop = forwardRef((props, ref) => {
|
||||||
if (directResellerId) {
|
if (directResellerId) {
|
||||||
let param = {
|
let param = {
|
||||||
reseller_id: directResellerId,
|
reseller_id: directResellerId,
|
||||||
type: productType,
|
type: model.product_type,
|
||||||
};
|
};
|
||||||
setState({
|
setState({
|
||||||
loading: true,
|
loading: true,
|
||||||
|
@ -148,8 +161,16 @@ const UseProductPop = forwardRef((props, ref) => {
|
||||||
setState({
|
setState({
|
||||||
productDataAll: req.data,
|
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) => {
|
(err) => {
|
||||||
setState({
|
setState({
|
||||||
|
@ -169,6 +190,7 @@ const UseProductPop = forwardRef((props, ref) => {
|
||||||
// 编辑处理
|
// 编辑处理
|
||||||
const editFun = () => {
|
const editFun = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
console.log("商品编辑 =>", productData);
|
||||||
// 编辑
|
// 编辑
|
||||||
if (productData) {
|
if (productData) {
|
||||||
setModel({
|
setModel({
|
||||||
|
@ -181,7 +203,7 @@ const UseProductPop = forwardRef((props, ref) => {
|
||||||
product_id: productData.product_id,
|
product_id: productData.product_id,
|
||||||
account_type: productData.account_type,
|
account_type: productData.account_type,
|
||||||
map_product_name: productData.map_product_name,
|
map_product_name: productData.map_product_name,
|
||||||
product_type: productType,
|
product_type: model.product_type,
|
||||||
code_batch_id: productData.code_batch_id,
|
code_batch_id: productData.code_batch_id,
|
||||||
show_url: [
|
show_url: [
|
||||||
{
|
{
|
||||||
|
@ -207,6 +229,10 @@ const UseProductPop = forwardRef((props, ref) => {
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
setState({ isUpdatePic: !state.isUpdatePic });
|
||||||
|
}, 300);
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} else {
|
} else {
|
||||||
resolve(false);
|
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 = () => {
|
const clearForm = () => {
|
||||||
setModel({
|
setModel({
|
||||||
cur_product: {},
|
cur_product: {},
|
||||||
|
@ -274,6 +272,7 @@ const UseProductPop = forwardRef((props, ref) => {
|
||||||
cost_price: model.cost_price,
|
cost_price: model.cost_price,
|
||||||
official_price: model.official_price,
|
official_price: model.official_price,
|
||||||
quantity: model.quantity,
|
quantity: model.quantity,
|
||||||
|
weight: model.weight,
|
||||||
show_url: model.show_url[0].src,
|
show_url: model.show_url[0].src,
|
||||||
describe_url: model.describe_url.map((item) => item.src),
|
describe_url: model.describe_url.map((item) => item.src),
|
||||||
detail_url: model.detail_url[0] ? model.detail_url[0].src : "",
|
detail_url: model.detail_url[0] ? model.detail_url[0].src : "",
|
||||||
|
@ -484,7 +483,7 @@ const UseProductPop = forwardRef((props, ref) => {
|
||||||
onTypeChange(e);
|
onTypeChange(e);
|
||||||
}}
|
}}
|
||||||
value={model.product_type}
|
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={1}>直充</RadioButton>
|
||||||
<RadioButton value={2}>卡密</RadioButton>
|
<RadioButton value={2}>卡密</RadioButton>
|
||||||
|
|
Loading…
Reference in New Issue