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 {
/**
* 当前商品值
*/
value: productInfo
value: productInfo,
// dataProps: DataPropsType
editable: boolean,
}
/**
......@@ -109,7 +111,7 @@ export type productSubmitType = {
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 [menu, setMenu] = useState<string[]>([])
const [rangeHeight, setRangeHeight] = useState<number[]>([])
......@@ -219,6 +221,7 @@ const ProductDrawer: React.FC<Iprops> = (props: Iprops) => {
</div>
<div className={styles.body} ref={ref}>
<NiceForm
editable={editable}
value={value}
schema={schema}
components={{
......
This diff is collapsed.
......@@ -166,14 +166,14 @@ const createSchema: ISchema = {
display: false
}
},
{
"type": "value:state",
"target": "source1",
"condition": "{{ $self.value }}",
state: {
value: "{{$self.value}}",
},
}
// {
// "type": "value:state",
// "target": "source1",
// "condition": "{{ $self.value }}",
// state: {
// value: "{{$self.value}}",
// },
// }
]
},
deliveryDate: {
......
......@@ -6,11 +6,12 @@ export type EnterpriceType = {
export type FileType = {
name: string,
url: string,
url?: string,
value?: string,
}
export type submitDataType = {
export type SubmitDataType = {
/** 物流地址id, 显示用,不提交 */
receivefullAddress: number,
receiveAddress: string
......@@ -27,6 +28,8 @@ export type submitDataType = {
processRoleId: number,
/** 来源 1 加工订单, 2 加工商品 */
source: 1 | 2 | number & {},
/** 无用字段 */
source1: 1 | 2 | number & {},
/** 通知单摘要 */
summary: string,
orderList?: {
......@@ -38,34 +41,36 @@ export type submitDataType = {
/** 附件 */
enclosure: FileType[],
/** 订单商品,即下单的商品 唯一id */
id: string,
id: number,
/** 是否是 */
isHasTax: 0 | 1 | number | {},
/** 是否含税、税率,显示用 */
isHasTaxAndTaxRate: string,
/** 商品图片 */
mainPic: string,
mainPic?: string,
/** 商品名 */
name: string,
/** 订单id, 跟上面id 不一样 */
orderId: number,
orderNo: string,
/** 加工数量 */
processNum: string,
processNum: string | number,
/** 加工总价 = 加工数量 * 加工单价 */
processTotalPrice: string,
processTotalPrice: string | number,
/** 加工单价 */
processUnitPrice: string,
processUnitPrice: string | number,
/** 采购数量 或者叫订单数量 */
purchaseCount: number
purchaseCount: number,
/** 采购数量 跟 单位,只做显示用 */
purchaseCountAndUnit: string,
/** skuid, 这里跟commodityId yizhi */
skuid: number
/** 加工剩余数量 */
surplusAndProcessNum: number,
skuid: number,
/** 剩余加工 */
surplusProcessNum: number,
/** 剩余加工数量和加工数量 */
surplusAndProcessNum: string,
/** 税率 */
taxRate: string,
taxRate: string | number,
/** 单位 */
unitName: string,
/** 商品属性 */
......@@ -83,18 +88,18 @@ export type submitDataType = {
enclosure: FileType[],
isHasTax: 0 | 1 | number & {}
isHasTaxAndTaxRate: string,
mainPic: string,
mainPic?: string,
name: string,
processNum: string,
processTotalPrice: string,
processUnitPrice: string,
processNum: string | number,
processTotalPrice: string | number,
processUnitPrice: string | number,
productProps: {
name: string,
value: string,
}[],
/** skuid */
skuid: number,
taxRate: string,
taxRate: string | number,
unitName: string,
}[],
/** 其他说明 */
......@@ -111,3 +116,43 @@ export type submitDataType = {
materialDesc: string,
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 { IRequestSuccess } from '@/index';
/**
* 获取详情
*/
type ParamsType = {
id: number,
}
type HeadersType = {
[key: string]: any,
}
type Ires = {
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} {
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} {
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) => {
setLoading(true)
......
import React, { useState } from 'react';
import React, { useCallback, useState } from 'react';
import { message } from 'antd';
export const useRowSelection = (options) => {
......@@ -7,17 +7,13 @@ export const useRowSelection = (options) => {
const [hasSelectedRows, setSelectedRows] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
const rowSelection = {
type: type,
selectedRowKeys: selectedKeys,
onSelect: async (record: any, selected: boolean, selectedRows: any[], nativeEvent) => {
const onSelect = (async (record: any, selected: boolean, selectedRows: any[]) => {
// const tempKey = record[primaryKey];
if(type === 'radio') {
setSelectedKeys([record[primaryKey]]);
setSelectedRows(selectedRows);
setSelectedKeys([record[primaryKey]]);
return ;
}
let newArray = [];
if(selected) {
newArray = hasSelectedRows.concat(record);
......@@ -35,9 +31,15 @@ export const useRowSelection = (options) => {
return;
}
}
setSelectedKeys(newArray.map((item) => item[primaryKey]));
const keys = newArray.map((item) => item[primaryKey])
setSelectedRows(newArray);
},
setSelectedKeys(keys);
})
const rowSelection = {
type: type,
selectedRowKeys: selectedKeys,
onSelect: onSelect,
onSelectAll: async (selected: boolean, selectedRows: any[], changeRows: any[]) => {
let newArray = [];
if(selected) {
......@@ -58,8 +60,8 @@ export const useRowSelection = (options) => {
}
}
setSelectedKeys(newArray.map((item) => item[primaryKey]));
setSelectedRows(newArray);
setSelectedKeys(newArray.map((item) => item[primaryKey]));
},
...others,
......
......@@ -99,10 +99,8 @@ const ProcessProducts = ({visible, cancel, rowSelection, loading, ...restProps})
visible={visible}
onCancel={cancel}
onOk={onOk}
destroyOnClose
>
{
visible
?
<Spin spinning={loading}>
<SearchForm
request={fetchData}
......@@ -118,10 +116,6 @@ const ProcessProducts = ({visible, cancel, rowSelection, loading, ...restProps})
}}
/>
</Spin>
: null
}
</Modal>
)
}
......
......@@ -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 (
......@@ -187,6 +187,7 @@ const TableModal: React.FC<Iprops> = (props: Iprops) => {
...tableProps,
pagination: false
}}
keepAlive={false}
fetchTableData={fetchData}
currentRef={ref}
rowSelection={{
......
......@@ -16,8 +16,8 @@ import { usePageStatus } from '@/hooks/usePageStatus';
import useInitialValue from '@/pages/handling/common/hooks/useInitialValue';
import { GetMemberAppraisalWaitGradeGetResponse } from '@/services/MemberV2Api';
import { PublicApi } from '@/services/api';
import { findLastIndexFlowState } from '@/utils';
import FlowRecords from '@/components/FlowRecords';
import { IRequestSuccess } from '@/index';
type SubmitDataType = {
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