Commit 2f1affea authored by Bill's avatar Bill

refactor: 重构加工新增修改模块

parent 0864c01d
import { usePageStatus } from '@/hooks/usePageStatus';
import useInitialValue from '@/pages/handling/common/hooks/useInitialValue';
import { PublicApi } from '@/services/api';
import { GetEnhanceSupplierToBeAddDetailsResponse } from '@/services/EnhanceV2Api';
import { priceFormat } from '@/utils/numberFomat';
import moment, { Moment } from 'moment';
import React, { useMemo } from 'react';
import { SubmitDataType } from '../../types';
/** 修改生产通知单时使用 */
type EditInititalValueType = Omit<SubmitDataType,"deliveryDate" | "source1" > & {
deliveryDate: Moment,
id: number,
}
type OtherTypes = {
deliveryDesc: string,
payDesc: string,
taxDesc: string,
materialDesc: string,
packingDesc: string,
otherDesc: string
}
const useFormatData = () => {
const { id, lastTypeParams } = usePageStatus();
const isEdit = useMemo(() => lastTypeParams === '/edit', [lastTypeParams]);
const params = useMemo(() => { return id ? { id: id.toString() } : null }, [id]);
const { loading, initialValue }= useInitialValue<GetEnhanceSupplierToBeAddDetailsResponse, { id: string }>(PublicApi.getEnhanceSupplierToBeAddDetails, params)
const cacheInitialValue = useMemo<EditInititalValueType>(() => {
if(initialValue === null) {
return { source: 1 } as EditInititalValueType
}
const { summary, deliveryType, deliveryDate, processMemberId, processName, processRoleId, receiveAddress, receiveUserName, receiveUserTel, receiverAddressId, source, otherAsk, details } = initialValue;
const isOrder = source === 1;
const explainKeys = ["deliveryDesc", "payDesc", "taxDesc", "materialDesc", "packingDesc", "otherDesc"];
const descValue: OtherTypes = {} as OtherTypes;
(otherAsk as unknown as any).explain?.forEach((item, index) => {
descValue[explainKeys[index]] = item.value
})
const productList = isOrder ? [] : details.map((_item) => {
return {
/** @fix 这里不应该去sku 值 */
commodityId: _item.productId,
brand: _item.brand,
category: _item.category,
skuid: _item.productId,
productProps: (_item.property as any).specs,
processNum: _item.processNum,
processUnitPrice: _item.processPrice,
processTotalPrice: priceFormat(_item.processTotalPrice),
taxRate: _item.taxRate,
unitName: _item.unit,
name: _item.productName,
isHasTax: _item.isHasTax,
isHasTaxAndTaxRate: `${_item.isHasTax ? '是': '否'}/${_item.taxRate}%`,
enclosure: (_item.property as any).annex.map((_row) => {
return {
name: _row.name,
// value: _row.value,
url: _row.value,
}
})
}
})
const orderList = isOrder && details?.map((_item) => {
return {
/** @fix 这里不应该去sku 值 */
commodityId: _item.productId,
brand: _item.brand,
category: _item.category,
skuid: _item.productId,
productProps: (_item.property as any).specs,
processNum: _item.processNum,
processUnitPrice: _item.processPrice,
processTotalPrice: priceFormat(_item.processTotalPrice),
taxRate: _item.taxRate,
unitName: _item.unit,
name: _item.productName,
isHasTax: _item.isHasTax,
isHasTaxAndTaxRate: `${_item.isHasTax ? '是': '否'}/${_item.taxRate}%`,
enclosure: (_item.property as any).annex.map((_row) => {
return {
name: _row.name,
// value: _row.value,
url: _row.value
}
}),
surplusProcessNum: _item.surplusProcessNum,
surplusAndProcessNum: `${_item.surplusProcessNum} / ${_item.processNum}`,
orderNo: _item.orderNo,
orderId: _item.orderId,
id: +_item.orderDetailId,
purchaseCount: _item.purchaseCount,
purchaseCountAndUnit: `${_item.purchaseCount}/${_item.unit}`
}
}) || []
return {
id: initialValue.id,
summary,
deliveryType,
deliveryDate: moment(deliveryDate),
processMemberId,
processName,
processRoleId,
receiveAddress,
receiveUserName,
receiveUserTel,
receiverAddressId,
receivefullAddress: receiverAddressId,
source,
productList,
orderList,
...descValue,
enclosure: (otherAsk as unknown as any).annex.map((_item) => {
return {
name: _item.name,
url: _item.value
}
}),
}
}, [initialValue])
return { cacheInitialValue, isEdit, }
}
export default useFormatData;
...@@ -65,8 +65,10 @@ interface Iprops { ...@@ -65,8 +65,10 @@ interface Iprops {
/** /**
* 当前商品值 * 当前商品值
*/ */
value: productInfo value: productInfo,
// dataProps: DataPropsType // dataProps: DataPropsType
editable: boolean,
} }
/** /**
...@@ -109,7 +111,7 @@ export type productSubmitType = { ...@@ -109,7 +111,7 @@ export type productSubmitType = {
const ProductDrawer: React.FC<Iprops> = (props: Iprops) => { const ProductDrawer: React.FC<Iprops> = (props: Iprops) => {
const { visible, onClose, onSubmit, value } = props; const { visible, onClose, onSubmit, value, editable } = props;
const [scroll, ref] = useScroll<HTMLDivElement>(); const [scroll, ref] = useScroll<HTMLDivElement>();
const [menu, setMenu] = useState<string[]>([]) const [menu, setMenu] = useState<string[]>([])
const [rangeHeight, setRangeHeight] = useState<number[]>([]) const [rangeHeight, setRangeHeight] = useState<number[]>([])
...@@ -219,6 +221,7 @@ const ProductDrawer: React.FC<Iprops> = (props: Iprops) => { ...@@ -219,6 +221,7 @@ const ProductDrawer: React.FC<Iprops> = (props: Iprops) => {
</div> </div>
<div className={styles.body} ref={ref}> <div className={styles.body} ref={ref}>
<NiceForm <NiceForm
editable={editable}
value={value} value={value}
schema={schema} schema={schema}
components={{ components={{
......
This diff is collapsed.
...@@ -166,14 +166,14 @@ const createSchema: ISchema = { ...@@ -166,14 +166,14 @@ const createSchema: ISchema = {
display: false display: false
} }
}, },
{ // {
"type": "value:state", // "type": "value:state",
"target": "source1", // "target": "source1",
"condition": "{{ $self.value }}", // "condition": "{{ $self.value }}",
state: { // state: {
value: "{{$self.value}}", // value: "{{$self.value}}",
}, // },
} // }
] ]
}, },
deliveryDate: { deliveryDate: {
......
...@@ -6,11 +6,12 @@ export type EnterpriceType = { ...@@ -6,11 +6,12 @@ export type EnterpriceType = {
export type FileType = { export type FileType = {
name: string, name: string,
url: string, url?: string,
value?: string,
} }
export type submitDataType = { export type SubmitDataType = {
/** 物流地址id, 显示用,不提交 */ /** 物流地址id, 显示用,不提交 */
receivefullAddress: number, receivefullAddress: number,
receiveAddress: string receiveAddress: string
...@@ -27,6 +28,8 @@ export type submitDataType = { ...@@ -27,6 +28,8 @@ export type submitDataType = {
processRoleId: number, processRoleId: number,
/** 来源 1 加工订单, 2 加工商品 */ /** 来源 1 加工订单, 2 加工商品 */
source: 1 | 2 | number & {}, source: 1 | 2 | number & {},
/** 无用字段 */
source1: 1 | 2 | number & {},
/** 通知单摘要 */ /** 通知单摘要 */
summary: string, summary: string,
orderList?: { orderList?: {
...@@ -38,34 +41,36 @@ export type submitDataType = { ...@@ -38,34 +41,36 @@ export type submitDataType = {
/** 附件 */ /** 附件 */
enclosure: FileType[], enclosure: FileType[],
/** 订单商品,即下单的商品 唯一id */ /** 订单商品,即下单的商品 唯一id */
id: string, id: number,
/** 是否是 */ /** 是否是 */
isHasTax: 0 | 1 | number | {}, isHasTax: 0 | 1 | number | {},
/** 是否含税、税率,显示用 */ /** 是否含税、税率,显示用 */
isHasTaxAndTaxRate: string, isHasTaxAndTaxRate: string,
/** 商品图片 */ /** 商品图片 */
mainPic: string, mainPic?: string,
/** 商品名 */ /** 商品名 */
name: string, name: string,
/** 订单id, 跟上面id 不一样 */ /** 订单id, 跟上面id 不一样 */
orderId: number, orderId: number,
orderNo: string, orderNo: string,
/** 加工数量 */ /** 加工数量 */
processNum: string, processNum: string | number,
/** 加工总价 = 加工数量 * 加工单价 */ /** 加工总价 = 加工数量 * 加工单价 */
processTotalPrice: string, processTotalPrice: string | number,
/** 加工单价 */ /** 加工单价 */
processUnitPrice: string, processUnitPrice: string | number,
/** 采购数量 或者叫订单数量 */ /** 采购数量 或者叫订单数量 */
purchaseCount: number purchaseCount: number,
/** 采购数量 跟 单位,只做显示用 */ /** 采购数量 跟 单位,只做显示用 */
purchaseCountAndUnit: string, purchaseCountAndUnit: string,
/** skuid, 这里跟commodityId yizhi */ /** skuid, 这里跟commodityId yizhi */
skuid: number skuid: number,
/** 加工剩余数量 */ /** 剩余加工 */
surplusAndProcessNum: number, surplusProcessNum: number,
/** 剩余加工数量和加工数量 */
surplusAndProcessNum: string,
/** 税率 */ /** 税率 */
taxRate: string, taxRate: string | number,
/** 单位 */ /** 单位 */
unitName: string, unitName: string,
/** 商品属性 */ /** 商品属性 */
...@@ -83,18 +88,18 @@ export type submitDataType = { ...@@ -83,18 +88,18 @@ export type submitDataType = {
enclosure: FileType[], enclosure: FileType[],
isHasTax: 0 | 1 | number & {} isHasTax: 0 | 1 | number & {}
isHasTaxAndTaxRate: string, isHasTaxAndTaxRate: string,
mainPic: string, mainPic?: string,
name: string, name: string,
processNum: string, processNum: string | number,
processTotalPrice: string, processTotalPrice: string | number,
processUnitPrice: string, processUnitPrice: string | number,
productProps: { productProps: {
name: string, name: string,
value: string, value: string,
}[], }[],
/** skuid */ /** skuid */
skuid: number, skuid: number,
taxRate: string, taxRate: string | number,
unitName: string, unitName: string,
}[], }[],
/** 其他说明 */ /** 其他说明 */
...@@ -111,3 +116,43 @@ export type submitDataType = { ...@@ -111,3 +116,43 @@ export type submitDataType = {
materialDesc: string, materialDesc: string,
enclosure: FileType[] enclosure: FileType[]
} }
export type RestDataType = {
processMemberId: number;
processName: string;
processRoleId: number;
// source: 1 | 2 | number & {};
summary: string;
receiveAddress?: string,
receiveUserName?: string,
receiveUserTel?: string,
receiverAddressId?: number,
}
export type OtherAskType = {
explain: {
name: string,
value: string
}[],
annex: {
name: string,
value: string
}[]
}
export type SelectedProcessProductType = {
skuid: number,
commodityId: number,
mainPic: string | null,
name: string,
category: string,
brand: string,
unitName: string,
/**
* 唯一id 从接口获取数据这个id 就是skuid, 可以直接用skuid
* 这里新增的这个字段是为了记录, 而skuid 是为了阅读
* 此id 就是skuid
* */
id: number,
}
import React, { useCallback, useEffect, useState } from 'react'; import React, { useCallback, useEffect, useState } from 'react';
import { IRequestSuccess } from '@/index';
/** /**
* 获取详情 * 获取详情
*/ */
type ParamsType = {
id: number,
}
type HeadersType = { type HeadersType = {
[key: string]: any, [key: string]: any,
} }
type Ires = { function useInitialValue<T, P extends Object>(api: (params: P, headers?: HeadersType) => Promise<IRequestSuccess<T>>, params: P, headers?: HeadersType): { loading: boolean, initialValue: T, refresh: (params: P) => void} {
code: number,
data: { [key: string]: any },
message: string
}
function useInitialValue<T, P>(api: (params: P, headers?: HeadersType) => Promise<T & Ires>, params: P, headers?: HeadersType): { loading: boolean, initialValue: T, refresh: (params: P) => void} {
const [loading, setLoading] = useState<boolean>(false); const [loading, setLoading] = useState<boolean>(false);
const [initialValue, setInitialValue] = useState<null | Ires["data"]>(null); const [initialValue, setInitialValue] = useState<null | IRequestSuccess<T>["data"]>(null);
const fetchData = useCallback(async (params) => { const fetchData = useCallback(async (params) => {
setLoading(true) setLoading(true)
......
import React, { useState } from 'react'; import React, { useCallback, useState } from 'react';
import { message } from 'antd'; import { message } from 'antd';
export const useRowSelection = (options) => { export const useRowSelection = (options) => {
...@@ -7,17 +7,13 @@ export const useRowSelection = (options) => { ...@@ -7,17 +7,13 @@ export const useRowSelection = (options) => {
const [hasSelectedRows, setSelectedRows] = useState<any[]>([]); const [hasSelectedRows, setSelectedRows] = useState<any[]>([]);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const rowSelection = { const onSelect = (async (record: any, selected: boolean, selectedRows: any[]) => {
type: type,
selectedRowKeys: selectedKeys,
onSelect: async (record: any, selected: boolean, selectedRows: any[], nativeEvent) => {
// const tempKey = record[primaryKey]; // const tempKey = record[primaryKey];
if(type === 'radio') { if(type === 'radio') {
setSelectedKeys([record[primaryKey]]);
setSelectedRows(selectedRows); setSelectedRows(selectedRows);
setSelectedKeys([record[primaryKey]]);
return ; return ;
} }
let newArray = []; let newArray = [];
if(selected) { if(selected) {
newArray = hasSelectedRows.concat(record); newArray = hasSelectedRows.concat(record);
...@@ -35,9 +31,15 @@ export const useRowSelection = (options) => { ...@@ -35,9 +31,15 @@ export const useRowSelection = (options) => {
return; return;
} }
} }
setSelectedKeys(newArray.map((item) => item[primaryKey])); const keys = newArray.map((item) => item[primaryKey])
setSelectedRows(newArray); setSelectedRows(newArray);
}, setSelectedKeys(keys);
})
const rowSelection = {
type: type,
selectedRowKeys: selectedKeys,
onSelect: onSelect,
onSelectAll: async (selected: boolean, selectedRows: any[], changeRows: any[]) => { onSelectAll: async (selected: boolean, selectedRows: any[], changeRows: any[]) => {
let newArray = []; let newArray = [];
if(selected) { if(selected) {
...@@ -58,8 +60,8 @@ export const useRowSelection = (options) => { ...@@ -58,8 +60,8 @@ export const useRowSelection = (options) => {
} }
} }
setSelectedKeys(newArray.map((item) => item[primaryKey]));
setSelectedRows(newArray); setSelectedRows(newArray);
setSelectedKeys(newArray.map((item) => item[primaryKey]));
}, },
...others, ...others,
......
...@@ -99,10 +99,8 @@ const ProcessProducts = ({visible, cancel, rowSelection, loading, ...restProps}) ...@@ -99,10 +99,8 @@ const ProcessProducts = ({visible, cancel, rowSelection, loading, ...restProps})
visible={visible} visible={visible}
onCancel={cancel} onCancel={cancel}
onOk={onOk} onOk={onOk}
destroyOnClose
> >
{
visible
?
<Spin spinning={loading}> <Spin spinning={loading}>
<SearchForm <SearchForm
request={fetchData} request={fetchData}
...@@ -118,10 +116,6 @@ const ProcessProducts = ({visible, cancel, rowSelection, loading, ...restProps}) ...@@ -118,10 +116,6 @@ const ProcessProducts = ({visible, cancel, rowSelection, loading, ...restProps})
}} }}
/> />
</Spin> </Spin>
: null
}
</Modal> </Modal>
) )
} }
......
...@@ -169,7 +169,7 @@ const TableModal: React.FC<Iprops> = (props: Iprops) => { ...@@ -169,7 +169,7 @@ const TableModal: React.FC<Iprops> = (props: Iprops) => {
) )
} }
const otherProps = modalType === 'Drawer' ? { footer: renderFooter() } : { onOk: handleOk} const otherProps = modalType === 'Drawer' ? { footer: renderFooter(), maskClosable: true, onClose: handleOnClose } : { onOk: handleOk}
return ( return (
...@@ -187,6 +187,7 @@ const TableModal: React.FC<Iprops> = (props: Iprops) => { ...@@ -187,6 +187,7 @@ const TableModal: React.FC<Iprops> = (props: Iprops) => {
...tableProps, ...tableProps,
pagination: false pagination: false
}} }}
keepAlive={false}
fetchTableData={fetchData} fetchTableData={fetchData}
currentRef={ref} currentRef={ref}
rowSelection={{ rowSelection={{
......
...@@ -16,8 +16,8 @@ import { usePageStatus } from '@/hooks/usePageStatus'; ...@@ -16,8 +16,8 @@ import { usePageStatus } from '@/hooks/usePageStatus';
import useInitialValue from '@/pages/handling/common/hooks/useInitialValue'; import useInitialValue from '@/pages/handling/common/hooks/useInitialValue';
import { GetMemberAppraisalWaitGradeGetResponse } from '@/services/MemberV2Api'; import { GetMemberAppraisalWaitGradeGetResponse } from '@/services/MemberV2Api';
import { PublicApi } from '@/services/api'; import { PublicApi } from '@/services/api';
import { findLastIndexFlowState } from '@/utils';
import FlowRecords from '@/components/FlowRecords'; import FlowRecords from '@/components/FlowRecords';
import { IRequestSuccess } from '@/index';
type SubmitDataType = { type SubmitDataType = {
items: { items: {
......
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