Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
merchant-manage-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ui
merchant-manage-ui
Commits
8a5a0130
Commit
8a5a0130
authored
Jul 28, 2022
by
beisir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 生成表格校验
parent
03acb249
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
424 additions
and
185 deletions
+424
-185
env.config.js
config/env.config.js
+7
-7
EditFormTable.tsx
src/pages/ServiceGoods/components/EditFormTable.tsx
+95
-91
FormPriceOrStock.tsx
src/pages/ServiceGoods/components/FormPriceOrStock.tsx
+192
-61
FormRuleSetting.tsx
src/pages/ServiceGoods/components/FormRuleSetting.tsx
+0
-1
context.js
src/pages/ServiceGoods/context.js
+3
-0
index.tsx
src/pages/ServiceGoods/index.tsx
+34
-25
utils.js
src/pages/ServiceGoods/utils.js
+93
-0
No files found.
config/env.config.js
View file @
8a5a0130
...
@@ -2,16 +2,16 @@ const isProduction = process.env.NODE_ENV === 'production';
...
@@ -2,16 +2,16 @@ const isProduction = process.env.NODE_ENV === 'production';
const
isPre
=
process
.
env
.
PRE_ENV
===
'
pre
'
;
const
isPre
=
process
.
env
.
PRE_ENV
===
'
pre
'
;
const
envAPi
=
{
const
envAPi
=
{
api
:
'
//backstms-yxm
.liangkebang.net
'
,
api
:
'
https://backstms-xyqb
.liangkebang.net
'
,
kdspOpApi
:
'
https://kdsp-operation-
yxm
.liangkebang.net
'
,
kdspOpApi
:
'
https://kdsp-operation-
xyqb
.liangkebang.net
'
,
kdspApi
:
'
https://sc-op-api-
yxm
.liangkebang.net
'
,
kdspApi
:
'
https://sc-op-api-
xyqb
.liangkebang.net
'
,
goodsApi
:
'
https://sc-op-api-
yxm
.liangkebang.net
'
,
goodsApi
:
'
https://sc-op-api-
xyqb
.liangkebang.net
'
,
querysApi
:
'
https://sc-settlement-api-
yxm
.liangkebang.net
'
,
querysApi
:
'
https://sc-settlement-api-
xyqb
.liangkebang.net
'
,
// goodsApi: '//192.168.188.111:7000',
// goodsApi: '//192.168.188.111:7000',
prologueDomain
:
'
https://mall-
yxm
.liangkebang.net
'
,
prologueDomain
:
'
https://mall-
xyqb
.liangkebang.net
'
,
// qiniuHost: 'https://appsync.lkbang.net',
// qiniuHost: 'https://appsync.lkbang.net',
qiniuHost
:
'
https://kdspstatic.q-gp.com/
'
,
qiniuHost
:
'
https://kdspstatic.q-gp.com/
'
,
opapiHost
:
'
https://opapi-
yxm
.liangkebang.net
'
,
opapiHost
:
'
https://opapi-
xyqb
.liangkebang.net
'
,
};
};
const
prodApi
=
{
const
prodApi
=
{
...
...
src/pages/ServiceGoods/components/EditFormTable.tsx
View file @
8a5a0130
...
@@ -5,16 +5,38 @@ import React, { useContext, useEffect, useRef, useState } from 'react';
...
@@ -5,16 +5,38 @@ import React, { useContext, useEffect, useRef, useState } from 'react';
const
EditableContext
=
React
.
createContext
<
FormInstance
<
any
>
|
null
>
(
null
);
const
EditableContext
=
React
.
createContext
<
FormInstance
<
any
>
|
null
>
(
null
);
interface
PropType
{
initData
:
any
[];
};
interface
Item
{
interface
Item
{
key
:
string
;
key
:
string
;
name
:
string
;
name
:
string
;
age
:
string
;
age
:
string
;
address
:
string
;
address
:
string
;
}
}
interface
EditableCellProps
{
rowIndex
:
number
;
title
:
React
.
ReactNode
;
editable
:
boolean
;
children
:
React
.
ReactNode
;
dataIndex
:
keyof
Item
;
record
:
Item
;
handleSave
:
(
record
:
Item
)
=>
void
;
}
interface
EditableRowProps
{
interface
EditableRowProps
{
index
:
number
;
index
:
number
;
}
}
interface
DataType
{
rowSpanCount
?:
number
;
supplyPrice
:
number
;
commissionRate
:
number
;
marketPrice
:
number
;
salePrice
:
number
;
stock
:
number
;
productStockWarning
:
number
;
}
type
EditableTableProps
=
Parameters
<
typeof
Table
>
[
0
];
type
ColumnTypes
=
Exclude
<
EditableTableProps
[
'
columns
'
],
undefined
>
;
const
EditableRow
:
React
.
FC
<
EditableRowProps
>
=
({
index
,
...
props
})
=>
{
const
EditableRow
:
React
.
FC
<
EditableRowProps
>
=
({
index
,
...
props
})
=>
{
// console.log('==========> index', props);
// console.log('==========> index', props);
...
@@ -29,15 +51,6 @@ const EditableRow: React.FC<EditableRowProps> = ({ index, ...props }) => {
...
@@ -29,15 +51,6 @@ const EditableRow: React.FC<EditableRowProps> = ({ index, ...props }) => {
);
);
};
};
interface
EditableCellProps
{
rowIndex
:
number
;
title
:
React
.
ReactNode
;
editable
:
boolean
;
children
:
React
.
ReactNode
;
dataIndex
:
keyof
Item
;
record
:
Item
;
handleSave
:
(
record
:
Item
)
=>
void
;
}
const
EditableCell
:
React
.
FC
<
EditableCellProps
>
=
(
props
)
=>
{
const
EditableCell
:
React
.
FC
<
EditableCellProps
>
=
(
props
)
=>
{
const
{
const
{
...
@@ -50,73 +63,61 @@ const EditableCell: React.FC<EditableCellProps> = (props) => {
...
@@ -50,73 +63,61 @@ const EditableCell: React.FC<EditableCellProps> = (props) => {
handleSave
,
handleSave
,
...
restProps
...
restProps
}
=
props
;
}
=
props
;
// console.log(props);
const
form
=
useContext
(
EditableContext
)
!
;
const
form
=
useContext
(
EditableContext
)
!
;
const
save
=
async
()
=>
{
const
save
=
async
()
=>
{
try
{
try
{
console
.
log
(
rowIndex
);
const
tableList
=
form
.
getFieldValue
(
'
tableList
'
);
const
{
tableList
}
=
await
form
.
validateFields
();
handleSave
(
tableList
);
handleSave
(
tableList
);
}
catch
(
errInfo
)
{
}
catch
(
errInfo
)
{
console
.
log
(
'
Save failed:
'
,
errInfo
);
console
.
log
(
'
Save failed:
'
,
errInfo
);
}
}
};
};
const
childNode
=
<
Form
.
Item
let
childNode
=
children
;
if
(
editable
)
{
childNode
=
<
Form
.
Item
style=
{
{
margin
:
0
}
}
style=
{
{
margin
:
0
}
}
name=
{
[
'
tableList
'
,
rowIndex
,
dataIndex
]
}
name=
{
[
'
tableList
'
,
rowIndex
,
dataIndex
]
}
initialValue=
{
record
[
dataIndex
]
}
//
initialValue={record[dataIndex]}
rules=
{
[
{
required
:
true
,
message
:
`${title} is required.`
}]
}
>
rules=
{
[
{
required
:
true
,
message
:
`${title} is required.`
}]
}
>
<
InputNumber
onBlur=
{
save
}
/>
<
InputNumber
onBlur=
{
save
}
/>
</
Form
.
Item
>
</
Form
.
Item
>
}
return
<
td
{
...
restProps
}
>
{
childNode
}
</
td
>;
return
<
td
{
...
restProps
}
>
{
childNode
}
</
td
>;
};
};
type
EditableTableProps
=
Parameters
<
typeof
Table
>
[
0
];
interface
DataType
{
supplyPrice
:
number
;
commissionRate
:
number
;
marketPrice
:
number
;
salePrice
:
number
;
stock
:
number
;
productStockWarning
:
number
;
}
type
ColumnTypes
=
Exclude
<
EditableTableProps
[
'
columns
'
],
undefined
>
;
const
EditFormTable
:
React
.
FC
=
()
=>
{
const
[
dataSource
,
setDataSource
]
=
useState
<
DataType
[]
>
([
const
EditFormTable
=
(
props
:
PropType
)
=>
{
{
supplyPrice
:
100
,
const
{
initData
}
=
props
;
commissionRate
:
20
,
// console.log(initData);
marketPrice
:
32
,
const
[
dataSource
,
setDataSource
]
=
useState
<
DataType
[]
>
([]);
salePrice
:
100
,
stock
:
100
,
productStockWarning
:
100
,
},
{
supplyPrice
:
100
,
commissionRate
:
20
,
marketPrice
:
32
,
salePrice
:
100
,
stock
:
100
,
productStockWarning
:
100
,
}
]);
// const form = useContext(EditableContext)!;
const
[
form
]
=
Form
.
useForm
();
const
[
form
]
=
Form
.
useForm
();
useEffect
(()
=>
{
console
.
log
(
'
==============>坚听initData
'
,
initData
);
const
[
count
,
setCount
]
=
useState
(
2
);
const
handleDelete
=
(
key
:
React
.
Key
)
=>
{
form
.
setFieldsValue
({
const
newData
=
dataSource
.
filter
(
item
=>
item
.
key
!==
key
);
tableList
:
initData
,
setDataSource
(
newData
);
});
};
setDataSource
(
initData
);
},
[
initData
])
const
defaultColumns
:
(
ColumnTypes
[
number
]
&
{
editable
?:
boolean
;
dataIndex
:
string
})[]
=
[
const
defaultColumns
:
(
ColumnTypes
[
number
]
&
{
editable
?:
boolean
;
dataIndex
:
string
})[]
=
[
{
title
:
'
一级规格
'
,
dataIndex
:
'
firstSpecValue
'
,
},
{
title
:
'
二级规格
'
,
dataIndex
:
'
secondSpecValue
'
,
},
{
{
title
:
'
供货价
'
,
title
:
'
供货价
'
,
dataIndex
:
'
supplyPrice
'
,
dataIndex
:
'
supplyPrice
'
,
...
@@ -149,23 +150,17 @@ const EditFormTable: React.FC = () => {
...
@@ -149,23 +150,17 @@ const EditFormTable: React.FC = () => {
},
},
];
];
const
handleAdd
=
()
=>
{
const
handleAdd
=
async
()
=>
{
console
.
log
(
form
.
getFieldsValue
());
try
{
// const newData: DataType = {
const
{
tableList
}
=
await
form
.
validateFields
();
// key: count,
console
.
log
(
tableList
);
// supplyPrice: 200,
}
catch
(
errInfo
)
{
// commissionRate: 20,
console
.
log
(
'
Save failed:
'
,
errInfo
);
// marketPrice: 32,
}
// salePrice: 100,
// stock: 100,
// productStockWarning: 100,
// };
// setDataSource([...dataSource, newData]);
// setCount(count + 1);
};
};
const
handleSave
=
(
row
:
DataType
[])
=>
{
const
handleSave
=
(
row
:
DataType
[])
=>
{
console
.
log
(
'
============>row
'
,
row
);
//
console.log('============>row', row);
// const newData = [...dataSource];
// const newData = [...dataSource];
// const index = newData.findIndex(item => row.key === item.key);
// const index = newData.findIndex(item => row.key === item.key);
// const item = newData[index];
// const item = newData[index];
...
@@ -175,28 +170,32 @@ const EditFormTable: React.FC = () => {
...
@@ -175,28 +170,32 @@ const EditFormTable: React.FC = () => {
// });
// });
setDataSource
([...
row
]);
setDataSource
([...
row
]);
};
};
const
components
=
{
body
:
{
row
:
EditableRow
,
cell
:
EditableCell
,
},
};
// 根据这里做判断渲染表格
// 根据这里做判断渲染表格
const
columns
=
defaultColumns
.
map
((
col
,
colIndex
)
=>
{
const
columns
=
defaultColumns
.
map
((
col
,
colIndex
)
=>
{
if
(
!
col
.
editable
)
{
// if (!col.editable) {
return
col
;
// return col;
}
// }
return
{
return
{
...
col
,
...
col
,
onCell
:
(
record
:
DataType
,
rowIndex
:
number
)
=>
({
onCell
:
(
record
:
DataType
,
rowIndex
:
number
)
=>
{
let
rowSpan
=
null
;
if
(
col
.
dataIndex
===
'
firstSpecValue
'
)
{
// console.log(record, rowSpan);
rowSpan
=
record
.
rowSpanCount
?
record
.
rowSpanCount
:
0
;
}
return
({
rowSpan
,
record
,
record
,
rowIndex
,
rowIndex
,
editable
:
col
.
editable
,
editable
:
col
.
editable
,
dataIndex
:
col
.
dataIndex
,
dataIndex
:
col
.
dataIndex
,
title
:
col
.
title
,
title
:
col
.
title
,
handleSave
,
handleSave
,
}),
});
}
};
};
});
});
...
@@ -205,12 +204,17 @@ const EditFormTable: React.FC = () => {
...
@@ -205,12 +204,17 @@ const EditFormTable: React.FC = () => {
<
Button
onClick=
{
handleAdd
}
type=
"primary"
style=
{
{
marginBottom
:
16
}
}
>
<
Button
onClick=
{
handleAdd
}
type=
"primary"
style=
{
{
marginBottom
:
16
}
}
>
Add a row
Add a row
</
Button
>
</
Button
>
<
Form
form=
{
form
}
component=
{
false
}
>
<
Form
form=
{
form
}
scrollToFirstError
component=
{
false
}
>
<
EditableContext
.
Provider
value=
{
form
}
>
<
EditableContext
.
Provider
value=
{
form
}
>
<
Table
<
Table
pagination=
{
false
}
pagination=
{
false
}
size=
"small"
size=
"small"
components=
{
components
}
components=
{
{
body
:
{
row
:
EditableRow
,
cell
:
EditableCell
,
},
}
}
bordered
bordered
dataSource=
{
dataSource
}
dataSource=
{
dataSource
}
rowKey=
{
(
row
,
rowInd
)
=>
rowInd
}
rowKey=
{
(
row
,
rowInd
)
=>
rowInd
}
...
...
src/pages/ServiceGoods/components/FormPriceOrStock.tsx
View file @
8a5a0130
import
{
ConsoleSqlOutlined
,
MinusCircleOutlined
,
PlusOutlined
}
from
'
@ant-design/icons
'
;
import
{
ConsoleSqlOutlined
,
MinusCircleOutlined
,
PlusOutlined
}
from
'
@ant-design/icons
'
;
import
{
Button
,
Form
,
Input
,
Select
,
Space
,
Modal
}
from
'
antd
'
;
import
{
Button
,
Form
,
Input
,
Select
,
Space
,
Modal
,
notification
}
from
'
antd
'
;
import
React
,
{
useState
,
forwardRef
,
useImperativeHandle
,
useEffect
}
from
'
react
'
;
import
React
,
{
useState
,
forwardRef
,
useImperativeHandle
,
useEffect
}
from
'
react
'
;
import
{
useParams
}
from
'
react-router-dom
'
;
import
{
useParams
}
from
'
react-router-dom
'
;
import
{
formItemLayout
}
from
'
../config
'
;
import
{
formItemLayout
}
from
'
../config
'
;
import
EditFormTable
from
'
./EditFormTable
'
;
import
EditFormTable
from
'
./EditFormTable
'
;
import
{
createProductData
}
from
'
../utils
'
;
import
{
ServiceContext
}
from
'
../context
'
;
const
{
Option
}
=
Select
;
const
{
Option
}
=
Select
;
interface
SpecItem
{
interface
SpecItem
{
specId
:
number
;
specId
:
number
;
specName
:
string
;
specName
:
string
;
...
@@ -17,10 +18,28 @@ interface PropsType {
...
@@ -17,10 +18,28 @@ interface PropsType {
specList
:
Array
<
SpecItem
>
;
specList
:
Array
<
SpecItem
>
;
}
}
const
SpecificationTemplate
=
(
props
,
_
)
=>
{
const
validatorSpecValue
=
(
value
,
list
,
index
,
specName
)
=>
{
const
{
specList
,
label
,
name
,
selectName
,
specName
,
form
}
=
props
;
const
checkList
=
list
.
filter
((
item
,
ind
)
=>
{
if
(
ind
===
index
)
{
return
false
;
}
return
item
[
specName
]
===
value
;
});
return
checkList
.
length
;
};
const
isRepeatProduct
=
(
list
,
message
)
=>
{
const
isRepeat
=
[...
new
Set
(
list
)].
length
!==
list
.
length
;
if
(
isRepeat
)
{
notification
.
warning
({
message
});
}
return
isRepeat
;
};
const
SpecificationTemplate
=
(
props
,
_
)
=>
{
const
{
specList
,
label
,
name
,
selectName
,
specName
,
form
,
specDataList
}
=
props
;
console
.
log
(
'
==============>specDataList
'
,
specDataList
);
const
handleChange
=
(
val
,
option
)
=>
{
const
handleChange
=
(
val
,
option
)
=>
{
const
optionSpecName
=
option
?
option
.
specName
:
null
;
const
optionSpecName
=
option
?
option
.
specName
:
null
;
form
.
setFieldsValue
({
[
selectName
]:
optionSpecName
});
form
.
setFieldsValue
({
[
selectName
]:
optionSpecName
});
...
@@ -37,9 +56,10 @@ const SpecificationTemplate = (props, _) => {
...
@@ -37,9 +56,10 @@ const SpecificationTemplate = (props, _) => {
}
}
console
.
log
(
specId
);
console
.
log
(
specId
);
addCallback
();
addCallback
();
}
}
;
return
<>
return
(
<>
<
Form
.
Item
name=
{
name
}
label=
{
label
}
>
<
Form
.
Item
name=
{
name
}
label=
{
label
}
>
<
Select
<
Select
allowClear
allowClear
...
@@ -48,7 +68,9 @@ const SpecificationTemplate = (props, _) => {
...
@@ -48,7 +68,9 @@ const SpecificationTemplate = (props, _) => {
fieldNames=
{
{
label
:
'
specName
'
,
value
:
'
specId
'
}
}
fieldNames=
{
{
label
:
'
specName
'
,
value
:
'
specId
'
}
}
placeholder=
{
`请选择${label}`
}
placeholder=
{
`请选择${label}`
}
showSearch
showSearch
filterOption=
{
(
input
,
option
)
=>
option
.
specName
.
toLowerCase
().
indexOf
(
input
.
toLowerCase
())
>=
0
}
filterOption=
{
(
input
,
option
)
=>
option
.
specName
.
toLowerCase
().
indexOf
(
input
.
toLowerCase
())
>=
0
}
onChange=
{
handleChange
}
onChange=
{
handleChange
}
/>
/>
</
Form
.
Item
>
</
Form
.
Item
>
...
@@ -56,45 +78,117 @@ const SpecificationTemplate = (props, _) => {
...
@@ -56,45 +78,117 @@ const SpecificationTemplate = (props, _) => {
<
Form
.
List
name=
{
specName
}
>
<
Form
.
List
name=
{
specName
}
>
{
(
fields
,
{
add
,
remove
})
=>
(
{
(
fields
,
{
add
,
remove
})
=>
(
<>
<>
{
/* {fields.map((field, index) => (
<Space key={field.key} align="baseline">
<Form.Item style={{ marginLeft: 10 }} name={[index]}
rules={[{ required: true, message: '请输入规格名称' }]}
>
<Input placeholder="请输入规格名称" />
</Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} />
</Space>
))} */
}
{
fields
.
map
((
field
,
index
)
=>
(
{
fields
.
map
((
field
,
index
)
=>
(
<
Form
.
Item
key=
{
field
.
key
}
noStyle
shouldUpdate=
{
(
prevValues
,
curValues
)
=>
false
}
>
<
Form
.
Item
key=
{
field
.
key
}
noStyle
shouldUpdate=
{
(
prevValues
,
curValues
)
=>
false
}
>
{
()
=>
(
{
()
=>
(
<
Space
key=
{
field
.
key
}
align=
"baseline"
>
<
Space
key=
{
field
.
key
}
align=
"baseline"
>
<
Form
.
Item
style=
{
{
marginLeft
:
10
}
}
name=
{
[
field
.
name
,
specName
]
}
<
Form
.
Item
rules=
{
[{
required
:
true
,
message
:
'
请输入规格名称
'
}]
}
style=
{
{
marginLeft
:
10
}
}
name=
{
[
field
.
name
,
specName
]
}
rules=
{
[
{
required
:
true
,
message
:
'
请输入规格名称
'
},
{
message
:
'
规格名不能重复!
'
,
validator
(
rule
,
value
,
callback
)
{
const
checkList
=
form
.
getFieldValue
(
specName
);
const
check
=
validatorSpecValue
(
value
,
checkList
,
index
,
specName
);
return
check
?
callback
(
'
规格名不能重复!
'
)
:
callback
();
},
},
]
}
>
>
<
Input
placeholder=
"请输入规格名称"
/>
<
Input
disabled=
{
specDataList
[
index
]
&&
specDataList
[
index
].
id
}
placeholder=
"请输入规格名称"
/>
</
Form
.
Item
>
</
Form
.
Item
>
{
!
(
specDataList
[
index
]
&&
specDataList
[
index
].
id
)
&&
(
<
MinusCircleOutlined
onClick=
{
()
=>
remove
(
field
.
name
)
}
/>
<
MinusCircleOutlined
onClick=
{
()
=>
remove
(
field
.
name
)
}
/>
)
}
</
Space
>
</
Space
>
)
}
)
}
</
Form
.
Item
>
</
Form
.
Item
>
))
}
))
}
{
fields
.
length
<
3
&&
<
Form
.
Item
noStyle
>
{
fields
.
length
<
3
&&
(
<
Button
style=
{
{
marginLeft
:
10
,
marginBottom
:
24
}
}
type=
"dashed"
onClick=
{
()
=>
bundlePlusAddSpecEvent
(
add
)
}
icon=
{
<
PlusOutlined
/>
}
/>
<
Form
.
Item
noStyle
>
</
Form
.
Item
>
}
<
Button
style=
{
{
marginLeft
:
10
,
marginBottom
:
24
}
}
type=
"dashed"
onClick=
{
()
=>
bundlePlusAddSpecEvent
(
add
)
}
icon=
{
<
PlusOutlined
/>
}
/>
</
Form
.
Item
>
)
}
</>
</>
)
}
)
}
</
Form
.
List
>
</
Form
.
List
>
</>
</>
}
);
};
const
filterSpecData
=
skuList
=>
skuList
.
reduce
((
originObj
,
item
)
=>
{
const
originItems
=
{
if
(
item
.
firstSpecValue
)
{
originObj
.
firstSpecValue
.
push
({
firstSpecValue
:
item
.
firstSpecValue
});
}
if
(
item
.
secondSpecValue
)
{
originObj
.
secondSpecValue
.
push
({
secondSpecValue
:
item
.
secondSpecValue
});
}
return
originObj
;
},
{
firstSpecValue
:
[],
firstSpecValue
:
[],
secondSpecValue
:
[],
secondSpecValue
:
[],
});
dataSource
:
[],
firstDuplicate
:
[],
secondDuplicate
:
[],
};
const
filterItem
=
skuItem
=>
{
const
{
imageList
,
serviceItem
,
...
argsItem
}
=
skuItem
;
argsItem
.
disabled
=
true
;
return
argsItem
;
};
const
filterSpecData
=
skuList
=>
skuList
.
reduce
((
orgin
,
skuItem
)
=>
{
// console.log(item);
const
item
=
filterItem
(
skuItem
);
const
{
firstSpecValue
,
secondSpecValue
}
=
item
;
if
(
firstSpecValue
&&
!
orgin
.
firstDuplicate
.
includes
(
firstSpecValue
))
{
orgin
.
firstSpecValue
.
push
(
item
);
orgin
.
firstDuplicate
.
push
(
firstSpecValue
);
}
if
(
secondSpecValue
&&
!
orgin
.
secondDuplicate
.
includes
(
secondSpecValue
))
{
orgin
.
secondSpecValue
.
push
(
item
);
orgin
.
secondDuplicate
.
push
(
secondSpecValue
);
}
// orgin.dataSource.push({
// id: item.id,
// firstSpec: item.firstSpec,
// firstSpecId: item.firstSpecId,
// firstSpecValue: item.firstSpecValue,
// secondSpec: item.secondSpec,
// secondSpecId: item.secondSpecId,
// secondSpecValue: item.secondSpecValue,
// commissionRate: item.commissionRate,
// supplyPrice: item.supplyPrice, // 供货价
// marketPrice: item.marketPrice,
// salePrice: item.salePrice,
// stock: item.stock,
// productStockWarning: item.productStockWarning,
// });
return
orgin
;
},
originItems
);
const
createTableData
=
()
=>
{};
const
FormPriceOrStock
=
forwardRef
((
props
:
PropsType
,
ref
)
=>
{
const
FormPriceOrStock
=
forwardRef
((
props
:
PropsType
,
ref
)
=>
{
const
{
specList
,
editData
}
=
props
;
const
{
specList
,
editData
}
=
props
;
console
.
log
(
'
============>000000000000
'
,
props
);
const
[
form
]
=
Form
.
useForm
();
const
[
form
]
=
Form
.
useForm
();
const
[
specInitValue
,
setSpecInitValue
]
=
useState
({
const
[
specInitValue
,
setSpecInitValue
]
=
useState
({
firstSpec
:
''
,
firstSpec
:
''
,
...
@@ -105,8 +199,42 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
...
@@ -105,8 +199,42 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
secondSpecValue
:
[],
secondSpecValue
:
[],
});
});
const
[
tableData
,
setTableData
]
=
useState
([]);
const
onFinish
=
(
values
:
any
)
=>
{
const
onFinish
=
(
values
:
any
)
=>
{
console
.
log
(
'
Received values of form:
'
,
values
);
console
.
log
(
values
);
// const values = form.getFieldsValue();
// const { firstValues = [], secondValues = [], firstSpecId, secondSpecId } = values;
// if ([fisrtIsRepeat, secondIsRepeat].includes(true)) {
// setTableData([]);
// return;
// }
const
cleanValues
=
{
firstValues
:
values
.
firstSpecValue
,
secondValues
:
values
.
secondSpecValue
,
firstSpecId
:
values
.
firstSpecId
,
secondSpecId
:
values
.
secondSpecId
,
};
const
newData
=
createProductData
(
cleanValues
);
// console.log('=============>生成商品数据', newData);
setTableData
(
newData
);
// // const columnsData = createProductColumns(cleanValues, newData);
// form.resetFields('tableArray', []);
// setColumns(columnsData);
// setProductData(newData);
// console.log(newData);
// console.log(columnsData);
if
(
!
values
.
firstSpecId
&&
!
values
.
firstSpecId
)
{
// 如果两个都没有选择默认生成一条数据
// Modal.warning({
// maskClosable: true,
// title: '请先选择规格分类!',
// });
}
};
};
const
onCheck
=
async
()
=>
{
const
onCheck
=
async
()
=>
{
...
@@ -128,7 +256,7 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
...
@@ -128,7 +256,7 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
const
{
skuList
}
=
editData
;
const
{
skuList
}
=
editData
;
const
[
oneItem
]
=
skuList
;
const
[
oneItem
]
=
skuList
;
// 根据接口过滤数据
// 根据接口过滤数据
const
{
firstSpecValue
,
secondSpecValue
}
=
filterSpecData
(
skuList
);
const
{
firstSpecValue
,
secondSpecValue
,
dataSource
}
=
filterSpecData
(
skuList
);
const
specData
=
{
const
specData
=
{
firstSpec
:
oneItem
.
firstSpec
,
firstSpec
:
oneItem
.
firstSpec
,
firstSpecId
:
oneItem
.
firstSpecId
,
firstSpecId
:
oneItem
.
firstSpecId
,
...
@@ -137,13 +265,15 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
...
@@ -137,13 +265,15 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
secondSpecId
:
oneItem
.
secondSpecId
,
secondSpecId
:
oneItem
.
secondSpecId
,
secondSpecValue
,
secondSpecValue
,
};
};
form
.
setFieldsValue
(
specData
);
form
.
setFieldsValue
(
specData
);
// 设置规格数据
setSpecInitValue
(
specData
);
setSpecInitValue
(
specData
);
// 缓存规格数据
setTableData
([...
dataSource
]);
}
}
},
[
id
,
editData
]);
},
[
id
,
editData
]);
return
(
return
(
// {...formItemLayout}
// {...formItemLayout}
<
Form
<
Form
form=
{
form
}
form=
{
form
}
name=
"dynamic_form_nest_item"
name=
"dynamic_form_nest_item"
...
@@ -158,6 +288,7 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
...
@@ -158,6 +288,7 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
selectName=
"firstSpec"
selectName=
"firstSpec"
specName=
"firstSpecValue"
specName=
"firstSpecValue"
specList=
{
specList
}
specList=
{
specList
}
specDataList=
{
specInitValue
.
firstSpecValue
}
/>
/>
<
SpecificationTemplate
<
SpecificationTemplate
form=
{
form
}
form=
{
form
}
...
@@ -166,16 +297,16 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
...
@@ -166,16 +297,16 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
selectName=
"secondSpec"
selectName=
"secondSpec"
specName=
"secondSpecValue"
specName=
"secondSpecValue"
specList=
{
specList
}
specList=
{
specList
}
specDataList=
{
specInitValue
.
secondSpecValue
}
/>
/>
<
Form
.
Item
>
<
Form
.
Item
>
<
Button
type=
"primary"
htmlType=
"submit"
>
<
Button
type=
"primary"
htmlType=
"submit"
>
Submit
生成商品信息
</
Button
>
</
Button
>
</
Form
.
Item
>
</
Form
.
Item
>
<
EditFormTable
/>
<
EditFormTable
initData=
{
tableData
}
/>
</
Form
>
</
Form
>
);
);
});
});
...
...
src/pages/ServiceGoods/components/FormRuleSetting.tsx
View file @
8a5a0130
...
@@ -42,7 +42,6 @@ const FormRuleSetting = forwardRef((props: { editData: any }, ref) => {
...
@@ -42,7 +42,6 @@ const FormRuleSetting = forwardRef((props: { editData: any }, ref) => {
const
[
commonImageList
,
setCommonImageList
]
=
useState
([]);
const
[
commonImageList
,
setCommonImageList
]
=
useState
([]);
const
[
detailImageList
,
setDetailImageList
]
=
useState
([]);
const
[
detailImageList
,
setDetailImageList
]
=
useState
([]);
useEffect
(()
=>
{
useEffect
(()
=>
{
console
.
log
(
id
);
if
(
+
id
!==
0
)
{
if
(
+
id
!==
0
)
{
console
.
log
();
console
.
log
();
if
(
!
Object
.
keys
(
editData
).
length
)
return
;
if
(
!
Object
.
keys
(
editData
).
length
)
return
;
...
...
src/pages/ServiceGoods/context.js
0 → 100644
View file @
8a5a0130
import
React
from
'
react
'
;
export
const
ServiceContext
=
React
.
createContext
(
null
);
src/pages/ServiceGoods/index.tsx
View file @
8a5a0130
...
@@ -12,7 +12,13 @@ import FormPriceOrStock from './components/FormPriceOrStock';
...
@@ -12,7 +12,13 @@ import FormPriceOrStock from './components/FormPriceOrStock';
import
FormRuleSetting
from
'
./components/FormRuleSetting
'
;
import
FormRuleSetting
from
'
./components/FormRuleSetting
'
;
import
FormSettlementOthers
from
'
./components/FormSettlementOthers
'
;
import
FormSettlementOthers
from
'
./components/FormSettlementOthers
'
;
import
commonStyle
from
'
./common.less
'
;
import
commonStyle
from
'
./common.less
'
;
import
{
getProductDetail
,
merchantCategoryGetAll
,
merchantBrandList
,
merchantSpecList
}
from
'
./service
'
;
import
{
getProductDetail
,
merchantCategoryGetAll
,
merchantBrandList
,
merchantSpecList
,
}
from
'
./service
'
;
import
{
ServiceContext
}
from
'
./context
'
;
/**
/**
* 服务商品改造-商品模块
* 服务商品改造-商品模块
...
@@ -28,9 +34,9 @@ const ServiceGoods = options => {
...
@@ -28,9 +34,9 @@ const ServiceGoods = options => {
const
settingRef
=
useRef
(
null
);
const
settingRef
=
useRef
(
null
);
const
settleOtrRef
=
useRef
(
null
);
const
settleOtrRef
=
useRef
(
null
);
const
[
isEdit
,
setIsEdit
]
=
useState
(
false
);
const
[
productType
,
setProductType
]
=
useState
(
1
);
const
[
productType
,
setProductType
]
=
useState
(
1
);
const
[
pageLoading
,
setPageLoading
]
=
useState
(
false
);
const
[
pageLoading
,
setPageLoading
]
=
useState
(
false
);
const
[
categoryList
,
setCategoryList
]
=
useState
([]);
// 获取三级类目
const
[
categoryList
,
setCategoryList
]
=
useState
([]);
// 获取三级类目
const
[
brandList
,
setBrandList
]
=
useState
([]);
// 获取商品牌
const
[
brandList
,
setBrandList
]
=
useState
([]);
// 获取商品牌
const
[
specList
,
setSpecList
]
=
useState
([]);
// 规格列表
const
[
specList
,
setSpecList
]
=
useState
([]);
// 规格列表
...
@@ -91,10 +97,11 @@ const ServiceGoods = options => {
...
@@ -91,10 +97,11 @@ const ServiceGoods = options => {
useEffect
(()
=>
{
useEffect
(()
=>
{
(
async
()
=>
{
(
async
()
=>
{
setPageLoading
(
true
);
setPageLoading
(
true
);
await
getMerchantCategory
();
//
await getMerchantCategory();
await
getMerchantBrandList
();
//
await getMerchantBrandList();
await
getMerchantSpecList
();
await
getMerchantSpecList
();
if
(
pageId
!==
0
)
{
if
(
pageId
!==
0
)
{
setIsEdit
(
true
);
await
getProductDetailResponse
();
await
getProductDetailResponse
();
}
}
setPageLoading
(
false
);
setPageLoading
(
false
);
...
@@ -105,6 +112,7 @@ const ServiceGoods = options => {
...
@@ -105,6 +112,7 @@ const ServiceGoods = options => {
<
Spin
tip=
"正在加载..."
spinning=
{
pageLoading
}
delay=
{
100
}
>
<
Spin
tip=
"正在加载..."
spinning=
{
pageLoading
}
delay=
{
100
}
>
<
PageHeaderWrapper
className=
{
commonStyle
.
header
}
>
<
PageHeaderWrapper
className=
{
commonStyle
.
header
}
>
<
WrapperContainer
>
<
WrapperContainer
>
<
ServiceContext
.
Provider
value=
{
{
pageId
,
isEdit
}
}
>
<
Title
title=
"商品类型"
/>
<
Title
title=
"商品类型"
/>
<
TaskTypeSelect
productType=
{
productType
}
onChange=
{
productChange
}
/>
<
TaskTypeSelect
productType=
{
productType
}
onChange=
{
productChange
}
/>
...
@@ -126,6 +134,7 @@ const ServiceGoods = options => {
...
@@ -126,6 +134,7 @@ const ServiceGoods = options => {
<
Button
type=
"primary"
onClick=
{
submitEvent
}
>
<
Button
type=
"primary"
onClick=
{
submitEvent
}
>
Register
Register
</
Button
>
</
Button
>
</
ServiceContext
.
Provider
>
</
WrapperContainer
>
</
WrapperContainer
>
</
PageHeaderWrapper
>
</
PageHeaderWrapper
>
</
Spin
>
</
Spin
>
...
...
src/pages/ServiceGoods/utils.js
0 → 100644
View file @
8a5a0130
import
{
ConsoleSqlOutlined
}
from
'
@ant-design/icons
'
;
export
const
cleanArray
=
actual
=>
{
const
newArray
=
[];
// eslint-disable-next-line no-plusplus
for
(
let
i
=
0
;
i
<
actual
.
length
;
i
++
)
{
if
(
actual
[
i
])
{
newArray
.
push
(
actual
[
i
]);
}
}
return
newArray
;
};
const
createInitProduct
=
(
skuItem
,
isCreate
)
=>
{
if
(
isCreate
&&
Object
.
keys
(
skuItem
).
length
>
5
)
{
return
skuItem
;
}
return
{
// firstSpecValue: '',
// secondSpecValue: '',
weight
:
null
,
productStockWarning
:
null
,
marketPrice
:
null
,
supplyPrice
:
null
,
stock
:
null
,
thirdSkuNo
:
null
,
skuLink
:
null
,
};
};
const
initData
=
{
// firstSpecValue: '',
// secondSpecValue: '',
weight
:
null
,
productStockWarning
:
null
,
marketPrice
:
null
,
supplyPrice
:
null
,
stock
:
null
,
thirdSkuNo
:
null
,
skuLink
:
null
,
};
const
createSecondProduct
=
(
secondSpecList
,
initItem
,
secondSpec
,
dataSource
,
callback
)
=>
{
secondSpecList
.
forEach
(
secondItem
=>
{
console
.
log
(
'
============>
'
,
Object
.
keys
(
secondItem
));
const
specSecond
=
Object
.
keys
(
secondItem
).
length
<
2
?
{
firstSpecId
:
initItem
.
firstSpecId
,
firstSpecValue
:
initItem
.
firstSpecValue
,
...
initData
,
}
:
Object
.
assign
({},
initItem
);
// 继承fist参数
if
(
callback
)
{
callback
(
specSecond
);
}
specSecond
.
secondSpecId
=
secondSpec
;
specSecond
.
secondSpecValue
=
secondItem
.
secondSpecValue
;
dataSource
.
push
(
specSecond
);
});
};
export
const
createProductData
=
({
firstValues
,
secondValues
,
firstSpecId
,
secondSpecId
})
=>
{
console
.
log
(
firstValues
,
secondValues
);
const
countRowSpan
=
{};
const
dataSource
=
[];
if
(
firstValues
.
length
)
{
firstValues
.
forEach
((
fisrtItem
,
index
)
=>
{
const
specFirst
=
createInitProduct
(
fisrtItem
,
true
);
specFirst
.
firstSpecId
=
firstSpecId
;
specFirst
.
firstSpecValue
=
fisrtItem
.
firstSpecValue
;
if
(
secondValues
.
length
)
{
createSecondProduct
(
secondValues
,
specFirst
,
secondSpecId
,
dataSource
,
specSecond
=>
{
if
(
!
countRowSpan
[
specFirst
.
firstSpecValue
])
{
countRowSpan
[
specFirst
.
firstSpecValue
]
=
true
;
specSecond
.
rowSpanCount
=
secondValues
.
length
;
}
});
return
;
}
dataSource
.
push
(
specFirst
);
});
}
else
if
(
secondValues
.
length
)
{
// const childData = createInitProduct();
createSecondProduct
(
secondValues
,
initData
,
secondSpecId
,
dataSource
);
}
else
{
const
specFirst
=
createInitProduct
();
dataSource
.
push
(
specFirst
);
}
return
dataSource
;
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment