Commit a8085060 authored by Bill's avatar Bill

fix: 加工新建时选择商品后, 删除商品后再勾选会出现重复的商品

parent 436b13df
...@@ -249,8 +249,10 @@ const Add: React.FC<{}> = () => { ...@@ -249,8 +249,10 @@ const Add: React.FC<{}> = () => {
* @param rows * @param rows
*/ */
const processProductSelected = () => { const processProductSelected = () => {
const newRows = getChangeRows(productSelectRowCtl, "id") console.log(productSelectRowCtl);
formActions.setFieldValue('Tabs.tab-2.layout.someLists', newRows) // const newRows = getChangeRows(productSelectRowCtl, "id");
// console.log("newRows", newRows)
formActions.setFieldValue('Tabs.tab-2.layout.someLists', productSelectRowCtl.selectRow)
} }
/** /**
...@@ -258,7 +260,9 @@ const Add: React.FC<{}> = () => { ...@@ -258,7 +260,9 @@ const Add: React.FC<{}> = () => {
* @param row * @param row
*/ */
const processOrderOnok = () => { const processOrderOnok = () => {
console.log(selectRowCtl);
const newRows = getChangeRows(selectRowCtl, "fullId") const newRows = getChangeRows(selectRowCtl, "fullId")
console.log(newRows);
formActions.setFieldValue('Tabs.tab-2.layout.someLists', newRows) formActions.setFieldValue('Tabs.tab-2.layout.someLists', newRows)
} }
...@@ -377,10 +381,13 @@ const Add: React.FC<{}> = () => { ...@@ -377,10 +381,13 @@ const Add: React.FC<{}> = () => {
const newList = currentList.filter((item) => item[primaryKey] !== id); const newList = currentList.filter((item) => item[primaryKey] !== id);
formActions.setFieldValue('Tabs.tab-2.layout.someLists', newList) formActions.setFieldValue('Tabs.tab-2.layout.someLists', newList)
const newSelectedKeys = newList.map((item) => item.id); const newSelectedKeys = newList.map((item) => item.id);
const newSelectedRows = newList;
if(activeSource === '加工订单') { if(activeSource === '加工订单') {
selectRowCtl.setSelectedRowKeys(newSelectedKeys); selectRowCtl.setSelectedRowKeys(newSelectedKeys);
selectRowCtl.setSelectRow(newSelectedRows);
} else { } else {
productSelectRowCtl.setSelectedRowKeys(newSelectedKeys) productSelectRowCtl.setSelectedRowKeys(newSelectedKeys);
productSelectRowCtl.setSelectRow(newSelectedRows)
} }
} }
......
...@@ -55,7 +55,7 @@ const DeliveryInfomation: React.FC<Iprops> = (props) => { ...@@ -55,7 +55,7 @@ const DeliveryInfomation: React.FC<Iprops> = (props) => {
<Row style={{marginBottom: '20px'}}> <Row style={{marginBottom: '20px'}}>
<Col span={5}>{props.deliveryType == 2 ? '自提地址' : '发货地址' }</Col> <Col span={5}>{props.deliveryType == 2 ? '自提地址' : '发货地址' }</Col>
<Col span={19}> <Col span={19}>
<Select style={{width: '100%'}} value={props.activeAddress}> <Select style={{width: '100%'}} value={props.activeAddress} onChange={props.deliverAddressOnChange}>
{ {
props.deliverAddressOption.map((item) => { props.deliverAddressOption.map((item) => {
return ( return (
...@@ -66,6 +66,7 @@ const DeliveryInfomation: React.FC<Iprops> = (props) => { ...@@ -66,6 +66,7 @@ const DeliveryInfomation: React.FC<Iprops> = (props) => {
}) })
} }
</Select> </Select>
<p style={{marginTop: '12px', color: '#ff4d4f', display: props.activeAddress ? 'none' : 'block'}}>请填写地址</p>
</Col> </Col>
</Row> </Row>
</Col> </Col>
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
padding: 10px 24px; padding: 10px 24px;
margin-bottom: 15px; margin-bottom: 15px;
cursor: pointer; cursor: pointer;
border-left: 2px solid transparent;
transition: all 0.2s ease-in-out;
} }
.active { .active {
......
import React, { useState, useRef, useEffect } from 'react'; import React, { useState, useRef, useEffect, useImperativeHandle, useMemo, useCallback } from 'react';
import styles from './content.less'; import styles from './content.less';
import { Row, Col, Anchor } from 'antd'; import { Row, Col } from 'antd';
import classnames from 'classnames'; import classnames from 'classnames';
import {FileList, UploadFile} from '../../components/UploadFile'; import {FileList, UploadFile} from '../../components/UploadFile';
import NiceForm from '@/components/NiceForm'; import NiceForm from '@/components/NiceForm';
import { createFormActions } from '@formily/antd'
import {useScroll, useDebounceFn } from '@umijs/hooks';
import { min } from 'lodash';
const actions = createFormActions();
const schema = { const schema = {
type: 'object', type: 'object',
...@@ -42,50 +46,79 @@ const schema = { ...@@ -42,50 +46,79 @@ const schema = {
} }
} }
const Content = (props) => { interface Iprops {
id: string,
name: string,
category: string,
brand: string,
files: {name: string, url: string}[],
productProps: { name: string, value: string}[],
quantity: number,
unitName: string,
processUnitPrice: number,
formSubmit: (value: any) => void,
type: 'edit' | 'view',
fileOnChange?: (value: any) => void
ref: any
}
const Content: React.FC<Iprops> = React.forwardRef((props, conftentRef) => {
const { id, name, category, brand, unitName, files, productProps, quantity, processUnitPrice } = props; const { id, name, category, brand, unitName, files, productProps, quantity, processUnitPrice } = props;
const [active, setActive] = useState<string>("基本信息"); const [active, setActive] = useState<string>("基本信息");
const [menu, setMenu] = useState([]) const [menu, setMenu] = useState([])
const ref = useRef(null); // const ref = useRef(null);
const [scroll, ref] = useScroll<HTMLDivElement>();
const getMenuItemCs = (name: string) => { const getMenuItemCs = useCallback((minHeight: number, maxHeight: number) => {
return classnames({ return classnames({
[styles.menuItem]: true, [styles.menuItem]: true,
[styles.active]: name === active [styles.active]: scroll.top >= minHeight && scroll.top < maxHeight
}) })
}, [scroll])
useImperativeHandle(conftentRef, () => ({
submit: () => {
actions.submit();
} }
}));
const activeAndScroll = (item) => { const activeAndScroll = (item) => {
setActive(item.name); ref.current.scrollTop = item.min;
ref.current.scrollTop = item.value;
} }
useEffect(() => { useEffect(() => {
const basic = [{name: '基本信息', value: 0}]; // 238
let height = 238; let height = 238;
const basic = [{name: '基本信息', min: 0, max: height}]; // 238
let flag = false; let flag = false;
const attributes = productProps && productProps.map((item) => { const attributes = productProps && productProps.map((item) => {
const prevHeight = height; const prevHeight = height;
height = height + 112; height = height + 112;
flag = true; flag = true;
return { return {
name: item.customerAttribute?.name || item.name, name: item.name,
value: prevHeight min: prevHeight,
max: height
} }
}) || []; }) || [];
const files = [{name: '附件', value: flag ? height : height - 112}]; const aboveFileHeight = flag ? height : height - 112;
height += 130; const maxFileHeight = files.length > 0 && files.reduce((prev, next) => {
const progress = [{name: '加工要求', value: height}]; return prev += 60;
setMenu(basic.concat(attributes, files, progress)); }, aboveFileHeight) || aboveFileHeight + 128;
}, [productProps]) const filesMenu = [{name: '附件', min: aboveFileHeight, max: maxFileHeight}];
const progress = [{name: '加工要求', min: maxFileHeight , max: maxFileHeight + 300}];
setMenu(basic.concat(attributes, filesMenu, progress));
}, [productProps, files])
const handleFormSubmit = (value) => {
props.formSubmit(value);
}
return ( return (
<div className={styles.container}> <div className={styles.container}>
<div className={styles.menu}> <div className={styles.menu}>
{ {
menu.map((item,key) => { menu.map((item,key) => {
return ( return (
<div key={item.name} className={getMenuItemCs(item.name)} onClick={() => activeAndScroll(item)}> <div key={item.name} className={getMenuItemCs(item.min, item.max)} onClick={() => activeAndScroll(item)}>
{item.name} {item.name}
</div> </div>
) )
...@@ -130,7 +163,6 @@ const Content = (props) => { ...@@ -130,7 +163,6 @@ const Content = (props) => {
) )
}) })
} }
<div className={styles.common} id="附件" > <div className={styles.common} id="附件" >
<div className={styles.header}>{"附件"}</div> <div className={styles.header}>{"附件"}</div>
<div className={styles.info}> <div className={styles.info}>
...@@ -161,18 +193,18 @@ const Content = (props) => { ...@@ -161,18 +193,18 @@ const Content = (props) => {
<Col span={12}>{unitName}</Col> <Col span={12}>{unitName}</Col>
</Row> </Row>
</div> </div>
<div className={styles.info}> <div className={styles.info} style={{marginBottom: '450px'}}>
{ {
props.type == 'edit' props.type == 'edit'
? <NiceForm ? <NiceForm
schema={schema} schema={schema}
actions={props.actions} actions={actions}
onSubmit={props.formSubmit} // onSubmit={props.formSubmit}
onSubmit={handleFormSubmit}
initialValues={{ initialValues={{
quantity: quantity, quantity: quantity,
processUnitPrice: processUnitPrice processUnitPrice: processUnitPrice
}} }}
// effects={formEffects()}
/> />
: ( : (
<> <>
...@@ -187,12 +219,11 @@ const Content = (props) => { ...@@ -187,12 +219,11 @@ const Content = (props) => {
</> </>
) )
} }
</div> </div>
</div> </div>
</div> </div>
</div> </div>
) )
} })
export default Content; export default React.memo(Content);
\ No newline at end of file \ No newline at end of file
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { Button, Drawer } from 'antd'; import { Button, Drawer } from 'antd';
import Content from './content'; import Content from './content';
import { PublicApi } from '@/services/api' import { PublicApi } from '@/services/api'
import { createFormActions } from '@formily/antd'
const actions = createFormActions();
interface Iprops { interface Iprops {
type: string, // veiw | edit, type: "view" | "edit", // veiw | edit,
submit?: (params: any) => void, submit?: (params: any) => void,
// id: string, // id: string,
// primaryKey: string // primaryKey: string
...@@ -32,6 +29,7 @@ const ProcessDetail: React.FC<Iprops> = (props) => { ...@@ -32,6 +29,7 @@ const ProcessDetail: React.FC<Iprops> = (props) => {
const [visible, setVisible] = useState<boolean>(false); const [visible, setVisible] = useState<boolean>(false);
const [info, setInfo] = useState<any>({}) const [info, setInfo] = useState<any>({})
const [files, setFiles] = useState<IfileProps[]>([]) const [files, setFiles] = useState<IfileProps[]>([])
const contentRef = useRef(null)
const onClose = () => { const onClose = () => {
setVisible(false) setVisible(false)
...@@ -64,20 +62,23 @@ const ProcessDetail: React.FC<Iprops> = (props) => { ...@@ -64,20 +62,23 @@ const ProcessDetail: React.FC<Iprops> = (props) => {
const handleSubmit = () => { const handleSubmit = () => {
if(props.type == 'edit') { if(props.type == 'edit') {
actions.submit(); contentRef.current.submit();
} else { } else {
setVisible(false); setVisible(false);
} }
} }
const formSubmit = (values) => { const formSubmit = (values) => {
console.log(values);
!!props.submit && props.submit({ !!props.submit && props.submit({
files: files, files: files,
uniqueID: props.uniqueID, uniqueID: props.uniqueID,
process: values, process: values,
productProps: info?.attributes productProps: info?.attributes
}) })
setVisible(false) setVisible(false);
console.log("fuck");
} }
const fileOnChange = (values) => { const fileOnChange = (values) => {
...@@ -104,12 +105,14 @@ const ProcessDetail: React.FC<Iprops> = (props) => { ...@@ -104,12 +105,14 @@ const ProcessDetail: React.FC<Iprops> = (props) => {
取消 取消
</Button> </Button>
<Button onClick={handleSubmit} type="primary"> <Button onClick={handleSubmit} type="primary">
确认 确认{visible}
</Button> </Button>
</div> </div>
} }
> >
<Content {
visible
? <Content
name={info?.name} name={info?.name}
id={info?.productId} id={info?.productId}
brand={info?.brand} brand={info?.brand}
...@@ -122,8 +125,12 @@ const ProcessDetail: React.FC<Iprops> = (props) => { ...@@ -122,8 +125,12 @@ const ProcessDetail: React.FC<Iprops> = (props) => {
files={files} files={files}
fileOnChange={fileOnChange} fileOnChange={fileOnChange}
formSubmit={formSubmit} formSubmit={formSubmit}
actions={actions} ref={contentRef}
// actions={actions}
/> />
: null
}
</Drawer> </Drawer>
</> </>
) )
......
...@@ -18,7 +18,6 @@ import { ...@@ -18,7 +18,6 @@ import {
CONFIRM_PENDING_FIRST, CONFIRM_PENDING_FIRST,
CONFIRM_PENDING_SECOND, CONFIRM_PENDING_SECOND,
CONFIRM_PENDING_CONFIRM, CONFIRM_PENDING_CONFIRM,
SUPPLIER_INNER_STATUS_COLOR,
SUPPLIER_OUTER_STATUS_COLOR, SUPPLIER_OUTER_STATUS_COLOR,
PROCESS_OUTER_STATUS_COLOR PROCESS_OUTER_STATUS_COLOR
} from '../../common' } from '../../common'
......
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