Commit f3b1113d authored by 武广's avatar 武广

fix: 添加商品属性

parent f72e657f
...@@ -215,11 +215,7 @@ export function column() { ...@@ -215,11 +215,7 @@ export function column() {
size="small" size="small"
className={styles.button} className={styles.button}
onClick={() => { onClick={() => {
if (row.type === 4) { this.serviceVisbleChange(row);
this.serviceVisbleChange(row);
} else {
this.onUpdateInfo(row);
}
}} }}
> >
修改 修改
...@@ -364,6 +360,7 @@ export const ProcessEditData = (data, row) => { ...@@ -364,6 +360,7 @@ export const ProcessEditData = (data, row) => {
id: data.id, id: data.id,
productType: data.productType, productType: data.productType,
pageProductType: row.productType, pageProductType: row.productType,
productAttributeApplyList: data.productAttributeApplyList,
infoMation: { infoMation: {
...specsParams, ...specsParams,
brandId: data.brandId, brandId: data.brandId,
......
/* eslint-disable consistent-return */ /* eslint-disable consistent-return */
import React, { forwardRef, useContext, useState, useEffect, useImperativeHandle } from 'react'; import React, { forwardRef, useState, useEffect, useImperativeHandle } from 'react';
import { Form, Select, Row, Col, Button } from 'antd'; import { Form, Row, Col, Button } from 'antd';
import { unstable_batchedUpdates } from 'react-dom';
import { UpOutlined, DownOutlined } from '@ant-design/icons'; import { UpOutlined, DownOutlined } from '@ant-design/icons';
import { ServiceContext } from '../context';
import styles from '../common.less'; import styles from '../common.less';
import { apiGetAttribute } from '../service'; import { apiGetAttribute } from '../service';
import CustomSelect from '@/components/CustomSelect'; import CustomSelect from '@/components/CustomSelect';
const FormAttr = forwardRef((props, ref) => { const FormAttr = forwardRef((props, ref) => {
const customer = useContext(ServiceContext);
const [form] = Form.useForm(); const [form] = Form.useForm();
const [isMore, setIsMome] = useState(false); const [isMore, setIsMome] = useState(false);
const [categoryAttrs, setCategoryAttrs] = useState([]); const [categoryAttrs, setCategoryAttrs] = useState([]);
const [skuOldAttr, setSkuOldAttr] = useState([]); const [skuOldAttr, setSkuOldAttr] = useState([]);
const [initAttrData, setInitAttrData] = useState({});
const formItemAttr = { const formItemAttr = {
labelCol: { span: 6 }, labelCol: { span: 6 },
...@@ -23,58 +23,76 @@ const FormAttr = forwardRef((props, ref) => { ...@@ -23,58 +23,76 @@ const FormAttr = forwardRef((props, ref) => {
setIsMome(!isMore); setIsMome(!isMore);
}; };
// 获取属性
const getAttribute = async categoryId => {
const res = await apiGetAttribute(categoryId);
if (res && res.data && res.data.length) {
setCategoryAttrs(res.data);
}
};
// 验证是否失效属性(已失效的商品不显示) // 验证是否失效属性(已失效的商品不显示)
const checkInAttrList = id => categoryAttrs.some(item => item.valueList.some(v => +v.id === +id)); const checkInAttrList = (id, categoryList) =>
categoryList.some(item => item.valueList.some(v => +v.id === +id));
// 获取初始化属性数据 // 获取初始化属性数据
const getInitAttrValue = () => { const getInitAttrValue = categoryList => {
const skuAttr = props.initData.productAttributeApplyList?.productAttributeApplyList || []; const skuAttr = props.initData.productAttributeApplyList?.productAttributeApplyList || [];
const attrs = []; const obj = {
if (customer.isEdit) { initValue: {},
categoryAttrs.forEach(({ id, supportCustomValue, optionType }) => { };
const v = skuAttr.filter(item => id === item.productAttributeId); const key = 'productAttributeApplyValueList';
let values = '';
const key = 'productAttributeApplyValueList'; skuAttr.forEach(item => {
if (v.length && v[0][key] && v[0][key].length) { if (item[key].length) {
values = []; let values = +item.optionType.code === 1 ? '' : [];
if (+supportCustomValue.code === 1 || +optionType.code === 2) { obj[item.productAttributeId] = [];
v[0][key].forEach(attr => { item[key].forEach(attr => {
if (+attr.attributeValueId) { const { attributeValueId, attributeValueName } = attr;
checkInAttrList(attr.attributeValueId) && const json = {
values.push( attributeValueId,
JSON.stringify({ attributeValueName,
attributeValueId: attr.attributeValueId, name: attributeValueName,
attributeValueName: attr.attributeValueName, };
}), if (attributeValueId === 0 || checkInAttrList(attributeValueId, categoryList)) {
); const v = JSON.stringify(json);
} else { if (attributeValueId === 0) {
values.push(attr.attributeValueName); obj[item.productAttributeId].push(json);
}
});
} else if (v[0][key].length) {
const atvalue = v[0][key][0];
if (checkInAttrList(atvalue.attributeValueId)) {
values = JSON.stringify({
attributeValueId: atvalue.attributeValueId,
attributeValueName: atvalue.attributeValueName,
});
} }
// eslint-disable-next-line no-unused-expressions
+item.optionType.code === 1 ? (values = v) : values.push(v);
} }
}
attrs.push({
[id]: values,
}); });
obj.initValue[item.productAttributeId] = values;
}
});
return obj;
};
// 获取属性
const getAttribute = async categoryId => {
const res = await apiGetAttribute(categoryId);
if (res && res.data && res.data.length) {
let initValue = {
initValue: {},
};
if (props.initData) {
if (props.initData.productAttributeApplyList?.oldProductAttributeApplyList) {
const oattr = props.initData.productAttributeApplyList;
setSkuOldAttr((oattr && oattr.oldProductAttributeApplyList) || []);
}
if (props.initData.productAttributeApplyList?.productAttributeApplyList) {
initValue = getInitAttrValue(res.data);
}
}
res.data.forEach(item => {
item.valueList = item.valueList.map(v => ({
attributeValueId: v.id,
attributeValueName: v.name,
name: v.name,
}));
if (initValue[item.id] && initValue[item.id].length) {
item.valueList.push(...initValue[item.id]);
}
});
unstable_batchedUpdates(() => {
setInitAttrData(initValue.initValue);
setCategoryAttrs(res.data);
}); });
} }
return attrs;
}; };
// 获取下拉框类型 // 获取下拉框类型
...@@ -98,8 +116,7 @@ const FormAttr = forwardRef((props, ref) => { ...@@ -98,8 +116,7 @@ const FormAttr = forwardRef((props, ref) => {
const deal = attr => { const deal = attr => {
try { try {
const json = JSON.parse(attr); const json = JSON.parse(attr);
if (typeof json === 'object') { if (json.attributeValueId) {
json.attributeValueName = json.name;
return json; return json;
} }
return { attributeValueName: json.name }; return { attributeValueName: json.name };
...@@ -114,13 +131,14 @@ const FormAttr = forwardRef((props, ref) => { ...@@ -114,13 +131,14 @@ const FormAttr = forwardRef((props, ref) => {
const attributeApplyList = []; const attributeApplyList = [];
// eslint-disable-next-line no-restricted-syntax // eslint-disable-next-line no-restricted-syntax
for (const key in values) { for (const key in values) {
if (values.hasOwnProperty(key)) { if (values.hasOwnProperty(key) && values[key]) {
let attrs = values[key]; let attrs = values[key];
if (Array.isArray(values[key])) { if (Array.isArray(values[key])) {
attrs = []; attrs = [];
values[key].forEach(attr => { values[key].forEach(attr => {
const json = deal(attr); if (typeof attr !== 'undefined') {
json && attrs.push(json); attrs.push(deal(attr));
}
}); });
} else { } else {
const json = deal(values[key]); const json = deal(values[key]);
...@@ -132,11 +150,10 @@ const FormAttr = forwardRef((props, ref) => { ...@@ -132,11 +150,10 @@ const FormAttr = forwardRef((props, ref) => {
}); });
} }
} }
const v = { return {
temp: 'attributeApplyList', temp: 'attributeApplyList',
attributeApplyList, attributeApplyList,
}; };
return v;
} catch (errorInfo) { } catch (errorInfo) {
return null; return null;
} }
...@@ -149,13 +166,6 @@ const FormAttr = forwardRef((props, ref) => { ...@@ -149,13 +166,6 @@ const FormAttr = forwardRef((props, ref) => {
} }
}, [props.categoryIds]); }, [props.categoryIds]);
useEffect(() => {
if (props.editData && props.editData.productAttributeApplyList?.oldProductAttributeApplyList) {
const oattr = props.editData.productAttributeApplyList;
setSkuOldAttr((oattr && oattr.oldProductAttributeApplyList) || []);
}
}, [props.editData]);
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
onCheck, onCheck,
reset: form.resetFields, reset: form.resetFields,
...@@ -164,10 +174,10 @@ const FormAttr = forwardRef((props, ref) => { ...@@ -164,10 +174,10 @@ const FormAttr = forwardRef((props, ref) => {
return ( return (
<> <>
<div className={styles.attrbox + (isMore ? styles.attrboxMore : '')}> <div className={styles.attrbox + (isMore ? styles.attrboxMore : '')}>
<Form form={form} initialValues={getInitAttrValue()}> {categoryAttrs.length > 0 && (
<Row> <Form form={form} initialValues={initAttrData}>
{categoryAttrs.length > 0 && <Row>
categoryAttrs.map(k => ( {categoryAttrs.map(k => (
<Col span={12} key={k.id}> <Col span={12} key={k.id}>
<Form.Item <Form.Item
label={k.name} label={k.name}
...@@ -184,8 +194,9 @@ const FormAttr = forwardRef((props, ref) => { ...@@ -184,8 +194,9 @@ const FormAttr = forwardRef((props, ref) => {
</Form.Item> </Form.Item>
</Col> </Col>
))} ))}
</Row> </Row>
</Form> </Form>
)}
</div> </div>
{categoryAttrs.length > 12 && ( {categoryAttrs.length > 12 && (
<div className={styles.btnMore}> <div className={styles.btnMore}>
......
...@@ -425,8 +425,8 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -425,8 +425,8 @@ const FormPriceOrStock = forwardRef((props, ref) => {
/> />
{customer.isCard && ( {customer.isCard && (
<> <>
<Title title="套餐内容" /> <Title title="套餐内容" key="tctitle" />
<FormPackage ref={packageRef} initData={tableData} /> <FormPackage ref={packageRef} initData={tableData} key="tc" />
</> </>
)} )}
</> </>
......
import React, { useState, useRef, useEffect, useCallback } from 'react'; import React, { useState, useRef, useEffect, useCallback } from 'react';
import { Spin, Button, Modal, message, notification } from 'antd'; import { Spin, Button, Modal, message, notification } from 'antd';
import { ConsoleSqlOutlined } from '@ant-design/icons';
import { Title, WrapperContainer } from './components/CommonTemplate'; import { Title, WrapperContainer } from './components/CommonTemplate';
import { TaskTypeSelect } from './components/TaskTypeSelect'; import { TaskTypeSelect } from './components/TaskTypeSelect';
import FormInformationBasic from './components/FormInformationBasic'; import FormInformationBasic from './components/FormInformationBasic';
...@@ -14,7 +13,6 @@ import { ...@@ -14,7 +13,6 @@ import {
merchantSpecList, merchantSpecList,
afterSalesAddrsPage, afterSalesAddrsPage,
merchantgetJdPicList, merchantgetJdPicList,
supplierListQuery,
shopGetBySupplierId, shopGetBySupplierId,
merchantProductAdd, merchantProductAdd,
merchantProductEdit, merchantProductEdit,
...@@ -53,7 +51,6 @@ const ServiceGoods = options => { ...@@ -53,7 +51,6 @@ const ServiceGoods = options => {
const [specList, setSpecList] = useState([]); // 规格列表 const [specList, setSpecList] = useState([]); // 规格列表
const [editData, setEditData] = useState({}); // 编辑保存数据 const [editData, setEditData] = useState({}); // 编辑保存数据
const [newCategoryList, setNewCategoryList] = useState({}); const [newCategoryList, setNewCategoryList] = useState({});
// const [shopList, setShopList] = useState([]); // 供应商列表
const [checkFormList] = useState([ const [checkFormList] = useState([
basicRef, basicRef,
attrRef, attrRef,
...@@ -107,13 +104,6 @@ const ServiceGoods = options => { ...@@ -107,13 +104,6 @@ const ServiceGoods = options => {
} }
}; };
// const getSupplierListResponse = async () => {
// if (!shopList.length) {
// const result = await supplierListQuery();
// console.log('=================>result', result);
// setShopList(result.data);
// }
// };
const sendMerchantProductHttpRequest = async sendData => { const sendMerchantProductHttpRequest = async sendData => {
try { try {
setPageLoading(true); setPageLoading(true);
...@@ -138,7 +128,6 @@ const ServiceGoods = options => { ...@@ -138,7 +128,6 @@ const ServiceGoods = options => {
}; };
const shopGetByProductType = async type => { const shopGetByProductType = async type => {
console.log(newCategoryList[type]);
if (!newCategoryList[type]?.length) { if (!newCategoryList[type]?.length) {
const result = await getByProductType(type); const result = await getByProductType(type);
setNewCategoryList({ setNewCategoryList({
...@@ -146,7 +135,6 @@ const ServiceGoods = options => { ...@@ -146,7 +135,6 @@ const ServiceGoods = options => {
[type]: result.data || [], [type]: result.data || [],
}); });
} }
// console.log(result);
}; };
const submitEvent = async () => { const submitEvent = async () => {
...@@ -162,7 +150,7 @@ const ServiceGoods = options => { ...@@ -162,7 +150,7 @@ const ServiceGoods = options => {
if (isEdit) { if (isEdit) {
sendData.id = pageId; sendData.id = pageId;
} }
// console.log('sendData :>> ', sendData); console.log('sendData :>> ', sendData);
sendMerchantProductHttpRequest(sendData); sendMerchantProductHttpRequest(sendData);
} }
}; };
...@@ -178,7 +166,6 @@ const ServiceGoods = options => { ...@@ -178,7 +166,6 @@ const ServiceGoods = options => {
? [...newImageList, ...carouseList] ? [...newImageList, ...carouseList]
: carouseList; : carouseList;
picturesRef.current.setFieldsValue({ picturesRef.current.setFieldsValue({
// [`imageList[${data.firstSpecValue}]`]: this.state.colorImg[data.firstSpecValue],
imageList, imageList,
detailImageList: [...detailImageList, ...detailList], detailImageList: [...detailImageList, ...detailList],
}); });
...@@ -192,7 +179,6 @@ const ServiceGoods = options => { ...@@ -192,7 +179,6 @@ const ServiceGoods = options => {
} }
setPageLoading(true); setPageLoading(true);
await shopGetBySupplierIdResponse(); await shopGetBySupplierIdResponse();
// await getSupplierListResponse();
await getMerchantBrandList(); await getMerchantBrandList();
await getAfterSalesAddrsPage(); await getAfterSalesAddrsPage();
await getMerchantSpecList(); await getMerchantSpecList();
...@@ -201,11 +187,8 @@ const ServiceGoods = options => { ...@@ -201,11 +187,8 @@ const ServiceGoods = options => {
setPageId(SourceData.id); setPageId(SourceData.id);
setProductType(SourceData.productType); setProductType(SourceData.productType);
setCategoryIds(SourceData.infoMation.categoryId || []); setCategoryIds(SourceData.infoMation.categoryId || []);
// changeCheckList(SourceData.productType);
setIsEdit(true); setIsEdit(true);
} }
console.log('111 :>> ', 111);
setPageLoading(false); setPageLoading(false);
})(); })();
}, [SourceData]); }, [SourceData]);
...@@ -217,7 +200,6 @@ const ServiceGoods = options => { ...@@ -217,7 +200,6 @@ const ServiceGoods = options => {
}, [productType, options.visible]); }, [productType, options.visible]);
useEffect(() => { useEffect(() => {
console.log('1---canAddNormal :>> ', canAddNormal);
setProductType(canAddNormal ? 1 : 4); setProductType(canAddNormal ? 1 : 4);
}, [canAddNormal]); }, [canAddNormal]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment