Commit 95c8f37e authored by 前端-许佳敏's avatar 前端-许佳敏
parents 805a3f69 43a1de49
......@@ -23,6 +23,7 @@ import { GetProductCustomerGetCustomerAttributeResponse } from '@/services';
const treeActions = createTreeActions()
const fetchAttributeTreeData = async (params?) => {
// @ts-ignore
const res = await PublicApi.getProductCustomerGetCustomerAttributeTree({filterInput: true})
return res
}
......
......@@ -303,6 +303,7 @@ const Goods: React.FC<{}> = () => {
ref.current.reload()
})
},
okType: 'danger',
onCancel() {
console.log('Cancel');
},
......
......@@ -136,7 +136,6 @@ const AddProducts: React.FC<{}> = (props) => {
delete _item.goodsId
_item.attributeAndValueList.map(__item => {
delete __item.customerAttributeName
// __item.customerAttributeValueId = __item.id
// **** 新字段结构变更
__item.customerAttribute = { id: __item.customerAttributeId }
__item.customerAttributeValue = { id: __item.id, value: __item.value }
......@@ -145,8 +144,6 @@ const AddProducts: React.FC<{}> = (props) => {
delete __item.customerAttributeId
})
}
// _item.attributeAndValueList = _item.goodsCustomerAttributeList
// delete _item.goodsCustomerAttributeList
if(_item.commodityPic.length>0){
// 编辑情况下兼顾手动添加图片列表属性
_item.commodityPic = _item.commodityPic.map(__item => __item?.response?.data || __item?.url)
......@@ -165,23 +162,23 @@ const AddProducts: React.FC<{}> = (props) => {
return e
}
_params.unitPriceAndPicList = productAttributeAndImageParams
}else{
}else{ // 编辑 没有点击商品图片
_params.unitPriceAndPicList = productInfoByEdit.unitPriceAndPicList
}
if(clickTabIndex.indexOf("3")===-1)
if(clickTabIndex.indexOf("3")===-1) // 商品属性
_params.commodityAttributeList = productInfoByEdit.commodityAttributeList
if(clickTabIndex.indexOf("4")===-1){
if(clickTabIndex.indexOf("4")===-1){ // 价格属性
_params.unitId = productInfoByEdit.unitId
_params.unitName = productInfoByEdit.unitName
_params.minOrder = productInfoByEdit.minOrder
_params.priceType = productInfoByEdit.priceType
_params.isMemberPrice = productInfoByEdit.isMemberPrice
}
if(clickTabIndex.indexOf("6")===-1)
if(clickTabIndex.indexOf("6")===-1) // 商品描述
_params.commodityRemark = productInfoByEdit.commodityRemark
if(clickTabIndex.indexOf("7")===-1)
if(clickTabIndex.indexOf("7")===-1) // 物流
_params.logistics = productInfoByEdit.logistics
if(clickTabIndex.indexOf("8")===-1){
if(clickTabIndex.indexOf("8")===-1){ // 其他
_params.isInvoice = productInfoByEdit.isInvoice
_params.marks = productInfoByEdit.marks
_params.packing = productInfoByEdit.packing
......
......@@ -40,11 +40,17 @@ const OtherForm: React.FC<Iprops> = (props) => {
ref={otherFormRef}
colon={false}
autoComplete="off"
initialValues={history.location.query?.id ? getOtherFormParamsByEdit : { isInvoice: false }}
initialValues={history.location.query?.id ? getOtherFormParamsByEdit : {}}
>
<Form.Item
name="isInvoice"
label="提供发票"
rules={[
{
required: true,
message: '请选择是否提供发票'
}
]}
>
<Radio.Group size="small">
<Radio.Button value={true} style={{ width: 100, textAlign: 'center' }}></Radio.Button>
......
......@@ -9,6 +9,7 @@ import { EyeOutlined, QuestionCircleOutlined, SettingOutlined, PlusOutlined, Min
import { inject, observer } from 'mobx-react'
import { store } from '@/store'
import { IProductSelectAttribute } from '@/module/productModule'
const layout = {
labelCol: {
......@@ -83,20 +84,15 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
console.log('重新构造')
},[productName, selectedGoods, productSelectAttribute, planPrice])
/* 构建表格列和data */
const constructedCallback = () => {
let _col = [];
let col_productName = { title: '商品名称', dataIndex: '商品名称', key: '商品名称' }
_col.push(col_productName)
let _priceAttribute = productSelectAttribute.filter(_item=>_item.isPrice)
let len = _priceAttribute.length
console.log(productName, _priceAttribute, len, productSelectAttribute, _tableDataSource, '---construct---')
/* 生成建表所需要的属性 属性值等数组数据 */
const generateNeedData = (hasAttribute: IProductSelectAttribute[]) => {
let _temp_attributeObjArr = [] // 取id备用
let _temp_attributeValObjArr = [] // 取id备用
let _attributeNameArr = []
let _attributeValueArr = []
if(len){ // 提取价格属性 属性名数组 属性值SKU数组
_priceAttribute.map(_item=>{
if(hasAttribute.length){ // 提取价格属性 属性名数组 属性值SKU数组 /*编辑情况下直接进入此页面length为空 此时需获取调用接口返回的数据生成*/
hasAttribute.map(_item=>{
_attributeNameArr.push(_item.attributeName) // 用于列header
_temp_attributeObjArr.push({attributeName: _item.attributeName, customerAttributeId: _item.customerAttributeId})
let _tempArr = []
......@@ -108,9 +104,83 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
_attributeValueArr.push(_tempArr) // 价格属性的属性值数组 用于SKU组合
_temp_attributeValObjArr.push(_tempObjArr)
})
}else if(history.location.query?.id){ // 此时没有属性并且处于编辑状态 取接口返回的数据
_attributeNameArr = productInfoByEdit.unitPriceAndPicList[0].attributeAndValueList.map(_ => _.customerAttribute.name)
_attributeValueArr = [productInfoByEdit.unitPriceAndPicList.map(item => item.attributeAndValueList.map(_ => _.customerAttributeValue.value))]
_temp_attributeObjArr = productInfoByEdit.unitPriceAndPicList[0].attributeAndValueList.map(item => {
return {
attributeName: item.customerAttribute.name,
customerAttributeId: item.customerAttribute.id
}
})
let allAttributeList = productInfoByEdit.unitPriceAndPicList.map(item => item.attributeAndValueList).reduce(
function(a, b) {
return a.concat(b);
},
[]
);
let fixedAttributeList = allAttributeList.map(_ => {
return {
id: _.customerAttributeValue.id,
value: _.customerAttributeValue.value,
attributeId: _.customerAttribute.id
}
})
let uniqueAttributeList = Object.values(fixedAttributeList.reduce((item, next)=>{
item[next.id] = next
return item
},{}))
_temp_attributeValObjArr = Object.values(groupBy(uniqueAttributeList, 'attributeId'))
// console.log(_attributeNameArr, _attributeValueArr, _temp_attributeObjArr, _temp_attributeValObjArr, '直接进入tab的情况下所需数据')
}
return {
_attributeNameArr,
_attributeValueArr,
_temp_attributeObjArr,
_temp_attributeValObjArr
}
console.log(_priceAttribute, _attributeNameArr, _attributeValueArr, _temp_attributeObjArr, _temp_attributeValObjArr, '---constructimg---') // ..............................
if(selectedGoods.length>0){
}
/* 构建表格列和data */
const constructedCallback = () => {
let _col = [];
let col_productName = { title: '商品名称', dataIndex: '商品名称', key: '商品名称' }
_col.push(col_productName)
let _priceAttribute = productSelectAttribute.filter(_item=>_item.isPrice)
// 生成下文构建表格需要的数据
let needObject = generateNeedData(_priceAttribute)
let { _attributeNameArr, _attributeValueArr, _temp_attributeObjArr, _temp_attributeValObjArr } = needObject
// let len = _priceAttribute.length
// console.log(productName, _priceAttribute, len, productSelectAttribute, _tableDataSource, '---construct data---')
// let _temp_attributeObjArr = [] // 取id备用
// let _temp_attributeValObjArr = [] // 取id备用
// let _attributeNameArr = []
// let _attributeValueArr = []
// if(len){ // 提取价格属性 属性名数组 属性值SKU数组
// _priceAttribute.map(_item=>{
// _attributeNameArr.push(_item.attributeName) // 用于列header
// _temp_attributeObjArr.push({attributeName: _item.attributeName, customerAttributeId: _item.customerAttributeId})
// let _tempArr = []
// let _tempObjArr = [] // 取id备用
// _item.customerAttributeValueList.map(__item => {
// _tempArr.push(__item.value)
// _tempObjArr.push({id: __item.id, value: __item.value})
// })
// _attributeValueArr.push(_tempArr) // 价格属性的属性值数组 用于SKU组合
// _temp_attributeValObjArr.push(_tempObjArr)
// })
// }
console.log(_priceAttribute, _attributeNameArr, _attributeValueArr, _temp_attributeObjArr, _temp_attributeValObjArr, selectedGoods, '---constructimg---') // 编辑直接进入价格设置 都为空数组
if(selectedGoods.length>0){ // 编辑情况下 select货品列表可能会采用接口数据
_col.push({
title: '对应货品',
dataIndex: '对应货品',
......@@ -126,6 +196,27 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
</Select>
</>
})
}else if(history.location.query?.id){ // 此时没有货品并且处于编辑状态 取接口返回的数据
let goodsInApi: any = Object.values(productInfoByEdit.unitPriceAndPicList.map(_ => _.goods).reduce((item, next)=>{
item[next.id] = next
return item
},{}))
_col.push({
title: '对应货品',
dataIndex: '对应货品',
key: '对应货品',
width: 360,
render: (text: any, record: any) => <>
<Select style={{width:'100%'}} defaultValue={text} onChange={(v)=> {tableSelelctChange(v, record) }}>
{
goodsInApi.length>0 && goodsInApi.map(_item => (
<Option key={_item.id} value={_item.id}>{_item.code}/{_item.name}/{_item.type}/¥{_item.costPrice}</Option>
))
}
</Select>
</>
})
}
if(_attributeNameArr.length>0){
......@@ -172,7 +263,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
setAttributeObjArr(_temp_attributeObjArr)
setAttributeValObjArr(_temp_attributeValObjArr)
console.log(combineArray,'combine')
console.log(combineArray, 'combine')
let _tableData: any[] = []
if(combineArray?.length>0){ // length存在 表示表格的行数(有价格属性组合)
combineArray.map((_rowArr: any[], i: any) => { // _rowArr 属性值数组
......@@ -181,8 +272,6 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
_tempObj[_attributeNameArr[index]] = __rowArr
}) : _tempObj[_attributeNameArr[i]||_attributeNameArr[0]] = _rowArr // 当一项变动的时候 找_attributeNameArr可能会找不到 找不到的情况下置为索引0的那项
// _tempObj['对应货品'] = selectedGoods.length > 0 ? selectedGoods[0].id : 0 // 编辑情况下 对应货品id和单价 特殊处理
// _tempObj['单价'] = {}
if(productInfoByEdit?.id){
// 编辑的时候,先指定数据中的货品id,如果是重新组合的不存在id就使用选择的货品中的第一个,如果没有置为0;同理,不存在单价就置为{}
_tempObj['对应货品'] = productInfoByEdit.unitPriceAndPicList[i]?.goods?.id || selectedGoods[0]?.id || 0
......@@ -201,7 +290,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
_tableData.push(_tempObj)
}
console.log(_tableData, '_tableData') // 只有一项 变动情况下表格数据的key获取不到 //..............Bug:再进来这里依旧有数据..................
console.log(_tableData, '_tableData') // 只有一项 变动情况下表格数据的key获取不到
_tableDataSource = _tableData
setTableDataSource(productName ? _tableDataSource : []) // 通过商品名称来判断是否显示表格数据
......@@ -214,15 +303,16 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
/* 生成传输数据 */
const constructedPrarams = () => {
let _paramsArray: any[] = [];
let _paramsArray: any[] = [];
console.log('生成传输数据', combineAttributeArray, attributeObjArr, attributeValObjArr, tableDataSource)
Array.isArray(combineAttributeArray) ? combineAttributeArray.map((item, index)=>{ // 非数组情况下默认无组合 从table数据中获取 // 当属性减少的时候 这个combine数组还是之前的
let _tempArr: any = []
Array.isArray(item) ? item.map((_item, _index)=>{
Array.isArray(item) ? item.map((_item, _index) => {
let _tempObject: any = {};
_tempObject.customerAttributeId = attributeObjArr[_index].customerAttributeId
_tempObject.customerAttributeName = attributeObjArr[_index].attributeName
_tempObject.id = attributeValObjArr[_index].find(__item=>__item.value===item[_index]).id
// _tempObject.id = attributeValObjArr[_index].find(__item=>__item.value===item[_index]).id /** 解决原有 若属性或者属性值顺序错乱无法找到正确值的问题 */
_tempObject.id = attributeValObjArr.map(item =>item.find(_ => _.value===_item)).filter(__ => __)[0].id
_tempObject.value = item[_index]
_tempArr.push(_tempObject)
}) : _tempArr.push({
......@@ -401,6 +491,23 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
setSetPriceModal(true)
}
/**
* 按属性归类
* @param objectArray
* @param {string} property
*/
const groupBy = (objectArray, property) => {
return objectArray.reduce(function (acc, obj) {
let key = obj[property];
if (!acc[key]) {
acc[key] = []
}
acc[key].push(obj)
return acc
}, {})
}
return (<>
<Form
{...layout}
......@@ -409,7 +516,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
labelAlign="left"
ref={priceFormRef}
colon={false}
initialValues={productInfoByEdit?.id ? getPriceAttributeFormParamsByEdit : {isMemberPrice: false}}
initialValues={productInfoByEdit?.id ? getPriceAttributeFormParamsByEdit : {isMemberPrice: false, priceType: planPrice}}
autoComplete="off"
>
<Form.Item
......@@ -485,7 +592,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
required: true,
message: '请选择产品定价类型'
}]}
initialValue={planPrice}
// initialValue={planPrice}
>
<Radio.Group onChange={handlePlanPriceChange}>
<Radio value={1}>现货价格</Radio>
......
......@@ -50,10 +50,8 @@ const ProductImageForm: React.FC<Iprops> = (props) => {
/* 给数据添加图片字段 */
useEffect(()=>{
// console.log('图片111', priceAttributeParams)
let _priceAttributeParams: any = []
if(productInfoByEdit?.id){ // id判断是否新增还是编辑
// console.log('图片222', priceAttributeParams)
setSetImageType(productInfoByEdit.isAllAttributePic)
setIsAllAttributePic(productInfoByEdit.isAllAttributePic)
let _commodityPicList = productInfoByEdit.unitPriceAndPicList.map(_ => _.commodityPic)
......@@ -87,7 +85,7 @@ const ProductImageForm: React.FC<Iprops> = (props) => {
// }
setPriceAttributeParamsByRender(_priceAttributeParams)
setProductAttributeAndImageParams(_priceAttributeParams)
console.log(_priceAttributeParams, priceAttributeParams, '_p') // 这里可能为空数组
console.log(_priceAttributeParams, priceAttributeParams, '_p') // 这里可能为空数组 ** 如果不到此页面 前一个是旧数据 后面的为新数据
// 初始化若是按所有属性共用做显示处理
if(setImageType && _priceAttributeParams.length>0){
setCommonImageList(_priceAttributeParams[0].commodityPic)
......
......@@ -84,13 +84,11 @@ const Products: React.FC<{}> = () => {
{
title: 'ID',
dataIndex: 'id',
align: 'center',
key: 'id',
},
{
title: '商品名称',
dataIndex: 'name',
align: 'center',
key: 'name',
className: 'commonPickColor',
render: (text: any, record: any) => <span className="commonPickColor" onClick={() => handleSee(record)}>{text}&nbsp;<EyeOutlined /></span>
......@@ -98,19 +96,16 @@ const Products: React.FC<{}> = () => {
{
title: '品类',
dataIndex: ['customerCategory', 'name'],
align: 'center',
key: 'customerCategory.name',
},
{
title: '品牌',
dataIndex: ['brand', 'name'],
align: 'center',
key: 'brand.name',
},
{
title: '单位',
dataIndex: 'unitName',
align: 'center',
key: 'unitName',
},
{
......@@ -156,7 +151,6 @@ const Products: React.FC<{}> = () => {
{
title: '审核状态',
dataIndex: 'status',
align: 'center',
key: 'status',
render: (text: any, record: any) => {
let component: ReactNode = null
......@@ -205,40 +199,7 @@ const Products: React.FC<{}> = () => {
{
title: '操作',
dataIndex: 'option',
align: 'center',
render: (text: any, record: any) => renderOptionButton(record)
// {
// return (
// <>
// <Popconfirm
// title="确定要执行这个操作?"
// onConfirm={() => handleBatchDelete([record.id])}
// onCancel={cancel}
// okText="是"
// cancelText="否"
// >
// <Button type='link'>删除</Button>
// </Popconfirm>
// <Dropdown overlay={
// <Menu>
// <Menu.Item>
// {record.status === 1 ? <Button type='link' onClick={()=>clickSubmitCheck(record)}>提交审核</Button> : ''}
// </Menu.Item>
// {(record.status === 4 || record.status === 6) ? <Menu.Item><Button type='link' onClick={() => clickUp(1, record.id)}>上架</Button></Menu.Item> : ''}
// {record.status === 5 ? <Menu.Item><Button type='link' onClick={() => clickUp(0, record.id)}>下架</Button></Menu.Item> : ''}
// {record.status === 3 || record.status === 1 ? <Menu.Item><Button type='link' onClick={() => clickModify(record.id)}>修改</Button></Menu.Item> : ''}
// <Menu.Item>
// <Button type='link' onClick={()=>clickCopy(record)}>复制</Button>
// </Menu.Item>
// </Menu>
// }>
// <a className="ant-dropdown-link" onClick={e => e.preventDefault()}>
// 更多 <CaretDownOutlined />
// </a>
// </Dropdown>
// </>
// )
// }
}
];
......
......@@ -360,7 +360,7 @@ const viewProducts: React.FC<{}> = () => {
<Col span={20}>
<p>
{
productDetail?.commodityAreaList.map(_item => <p>{_item.provinceName+'/'+(_item.cityName||'')}</p>)
productDetail?.commodityAreaList.length>0 ? productDetail?.commodityAreaList.map(_item => <p>{_item.provinceName+'/'+(_item.cityName||'')}</p>) : '全国'
}
</p>
</Col>
......
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