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={{
......
import React, { useCallback, useMemo, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { Button, Cascader, message, Space, Table } from 'antd';
import { LinkOutlined, PlusOutlined, SaveOutlined } from '@ant-design/icons';
import NiceForm from '@/components/NiceForm';
......@@ -15,7 +15,6 @@ import useModal from '@/pages/member/memberEvaluate/hooks/useModal';
import { enterprisesColumn } from './common/columns/enterprisesColumn';
import { enterprisesSchema } from './common/schemas/enterprisesSchema';
import { productSchema } from './common/schemas/productSchema';
// import { productColumn } from './common/columns/productColumn';
import { PublicApi } from '@/services/api';
import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch';
import { FORM_FILTER_PATH } from '@/formSchema/const';
......@@ -28,9 +27,11 @@ import ProductDrawer, { productSubmitType, productInfo } from './components/Prod
import { priceFormat } from '@/utils/numberFomat';
import { orderColumns, orderProductColumns } from './common/columns/orderColumn';
import { orderSchema } from './common/schemas/orderSchema'
import { filterExternalStateLabelList } from '@/pages/transaction/common/statusList';
import { GetOrderProcessingOrderListResponseDetail } from '@/services/OrderV2Api';
import { EnterpriceType, FileType, submitDataType } from './types'
import { EnterpriceType, FileType, SubmitDataType, RestDataType, OtherAskType, SelectedProcessProductType } from './types';
import { history } from 'umi';
import moment from 'moment';
import useFormatData from './common/hooks/useFormatData';
const formActions = createFormActions();
const { onFieldInit$, onFieldValueChange$ } = FormEffectHooks
......@@ -80,13 +81,16 @@ const Create = () => {
}
]
}, [])
const { isEdit, cacheInitialValue } = useFormatData();
// console.log(initialValue)
/** ---- 加工企业 ----- */
const { visible, toggle } = useModal();
const [enterprice, setEnterprise] = useState<EnterpriceType[]>([])
/** ---- 加工商品 ---- */
const { visible: processProductVisible, toggle: processProductToggle } = useModal();
const [processProduct, setProcessProduct] = useState([]);
const [processProduct, setProcessProduct] = useState<SelectedProcessProductType[]>([]);
/** ---- 加工商品 ---- */
/** ---- 编辑商品 ---- */
......@@ -103,6 +107,40 @@ const Create = () => {
/** ---- 加工订单end ------- */
/** 订单数据 */
const [fetchedOrderData, setFetchOrderData] = useState<GetOrderProcessingOrderListResponseDetail[]>([])
const [productActionType, setProductActionType] = useState<"view" | "edit">("view");
useEffect(() => {
if (!isEdit) {
return;
}
setEnterprise([{
name: cacheInitialValue?.processName,
memberId: cacheInitialValue?.processMemberId,
roleId: cacheInitialValue?.processRoleId
}])
const isOrder = cacheInitialValue.source === ORDER_SOURCE;
if (!isOrder) {
const productList = cacheInitialValue?.productList?.map((_item) => {
return {
id: _item.skuid,
skuid: _item.skuid,
commodityId: _item.commodityId,
mainPic: _item.mainPic,
name: _item.name,
category: _item.category,
brand: _item.brand,
unitName: _item.unitName,
}
})
setProcessProduct(productList);
} else {
const initialProcessOrder = cacheInitialValue.orderList?.map((_item) => ({id: _item.orderId, productDateilss: _item})) || [];
setProcessOrder(initialProcessOrder as unknown as GetOrderProcessingOrderListResponseDetail[]);
setOrderProductSelectRowRecord(cacheInitialValue.orderList?.map((_item) => ({..._item, productId: _item.commodityId})) || []);
setOrderProductSelectRowKeys(cacheInitialValue.orderList?.map((_item) => `${_item.orderId}_${_item.id}`) || [])
}
}, [isEdit, cacheInitialValue])
/**
* 获取加工企业
*/
......@@ -157,7 +195,11 @@ const Create = () => {
</div>
)
// 根据当前用户角色查询商城
/**
* @tofix
* 根据当前用户角色查询商城 配合memberType, 我也不明白为什么要这么操作 ,
* 商城类型:1-企业商城,2-积分商城,3-渠道商城,4-渠道自有商城,5-渠道积分商城
* */
const ENTERPRISE_MALL = useMemo(() => ({"1": 1, "2": 1, "3": 3, '4': 4}), []);
const productColumn: ColumnsType<any> = useMemo(() => ([
......@@ -174,6 +216,7 @@ const Create = () => {
title: '上架商城',
dataIndex: 'mall',
render: (text, record) => {
/** 后端不返回,要前段判断, 就离谱 */
return MALL_NAME[authInfo.memberType]
}
},
......@@ -195,6 +238,7 @@ const Create = () => {
const { current, pageSize, brandId, ...rest } = params;
const customerCategoryId = params.customerCategoryId && Array.isArray(params.customerCategoryId) && params.customerCategoryId.pop();
const postData = {
...rest,
/** 商城类型:1-企业商城,2-积分商城,3-渠道商城,4-渠道自有商城,5-渠道积分商城 */
shopType: ENTERPRISE_MALL[authInfo.memberType],
/** 商城环境:1-Web,2-H5,3-小程序,4-App */
......@@ -247,30 +291,41 @@ const Create = () => {
type: 5,
}
})
return await checkProcessEnum(postData);
const { flag } = await checkProcessEnum(postData);
return flag;
}, [])
/** @review 总感觉这个接口有大问题,能力中心没办法拿到shopId,不知道这个shopId 的意义在哪里 */
const checkProcessEnum = async (list: { productId: number, memberId: number, memberRoleId: number, shopId: number, type: number }[]) => {
const {code, data, ...rest} = await PublicApi.postOrderGetProcessEnum({list: list}, {ctlType: 'none'});
if (code !== 1000) {
message.error(rest.message);
return false
return {
flag: false,
}
}
const hasNoSetProcessEnum = data.some((_item) => _item.processEnum === 0);
/** 文档是大写, 但返回是小写。。就离谱 */
const hasNoSetProcessEnum = data.some((_item) => (_item as any).processEnum === 0);
if(hasNoSetProcessEnum) {
message.error("当前所选商品没有配置工作流");
return false
return {
flag: false,
}
}
const differentProcessEnumList = new Set(
data.map((_item) => _item.processEnum)
data.map((_item) => (_item as any).processEnum)
)
if (differentProcessEnumList.size > 1) {
message.error("当前所选商品配置的工作流不一致");
return false
return {
flag: false
}
}
return true
return {
flag: true,
processEnum: (data[0] as any).processEnum
}
}
/**
......@@ -315,9 +370,9 @@ const Create = () => {
const renderProductListTableRemove = (index: number) => (
<Space>
<a onClick={() => handleEdit(index)}>修改</a>
<a onClick={() => handleEditOrView(index, "edit")}>修改</a>
<a onClick={() => handleRemove(index)}>删除</a>
<a>查看</a>
<a onClick={() => handleEditOrView(index, "view")}>查看</a>
</Space>
);
......@@ -326,22 +381,21 @@ const Create = () => {
const isOrderSource = source === ORDER_SOURCE
const productList = isOrderSource ? formActions.getFieldValue('detail.layout1.orderList') : formActions.getFieldValue('detail.layout1.productList');
const target = productList[index];
productList.splice(index, 1);
const newList = productList.filter((_item, _itemIndex) => _itemIndex !== index )
if (isOrderSource) {
const key = `${target.orderId}_${target.id}`
setOrderProductSelectRowKeys((prev) => prev.filter((_row) => (_row !== key)));
setOrderProductSelectRowRecord((prev) => prev.filter((_item) => `${_item.orderId}_${_item.id}` !== key ))
formActions.setFieldValue('detail.layout1.orderList', productList)
formActions.setFieldValue('detail.layout1.orderList', newList)
} else {
setProcessProduct((prev) => prev.filter((_item) => _item.skuid !== target.skuid ));
formActions.setFieldValue('detail.layout1.productList', productList)
setProcessProduct((prev) => prev.filter((_item) => _item.id !== target.skuid ));
formActions.setFieldValue('detail.layout1.productList', newList)
}
}
const handleEdit = async (index: number) => {
const handleEditOrView = async (index: number, type: "edit" | "view") => {
const source = formActions.getFieldValue('source')
const productList = source === ORDER_SOURCE ? formActions.getFieldValue('detail.layout1.orderList') : formActions.getFieldValue('detail.layout1.productList');
// 这里理论不需要判断target 存不存在
......@@ -382,10 +436,14 @@ const Create = () => {
}
setCurrentProduct(target);
productDrawerToggle(true);
setProductActionType(type)
}
const handleChangeProduct = (values: productSubmitType) => {
console.log(values)
if (productActionType === 'view') {
productDrawerToggle(false);
return;
}
const source = formActions.getFieldValue('source')
const isOrderSource = source === ORDER_SOURCE
const productList = isOrderSource ? formActions.getFieldValue('detail.layout1.orderList') : formActions.getFieldValue('detail.layout1.productList');
......@@ -395,7 +453,7 @@ const Create = () => {
const newData = productList.map((_item) => {
/** 加工商品的时候用sku, 如果是加工订单商品的话用orderid */
if ((!isOrderSource && _item.skuid === values.skuid) || (isOrderSource && _item.id === values.id)) {
const other = isOrderSource ? { surplusAndProcessNum: _item.purchaseCount - +processNum } : {}
const other = isOrderSource ? { surplusAndProcessNum: `${_item.surplusProcessNum}/${processNum}` } : {}
return {
..._item,
...other,
......@@ -432,21 +490,25 @@ const Create = () => {
} else {
const children = currentOrderData.productDateilss;
const tempData = orderProductselectRowRecord.concat(record);
const keysList = tempData.filter((_item) => _item.includes(record.orderId.toString()));
// const formatData = tempData.map((_item) => {
// return {
// productId: _item.productId,
// memberId: _item.memberId || authInfo.memberId,
// memberRoleId: _item.memberRoleId || authInfo.memberRoleId,
// shopId: ENTERPRISE_MALL[authInfo.memberType],
// /** 1.订单交易流程2.售后换货流程3.售后退货流程4.售后维修流程, @todo 5是后端说的,具体不知道代表什么意思? */
// type: 5,
// }
// })
setOrderProductSelectRowKeys((prev) => prev.concat(key))
setOrderProductSelectRowRecord(tempData)
if (children.length === keysList.length) {
setProcessOrder((prev) => prev.concat(currentOrderData))
const keysList = tempData.filter((_item) => _item.orderId === record.orderId);
const formatData = tempData.map((_item) => {
return {
productId: _item.productId,
memberId: _item.memberId || authInfo.memberId,
memberRoleId: _item.memberRoleId || authInfo.memberRoleId,
shopId: ENTERPRISE_MALL[authInfo.memberType],
/** 1.订单交易流程2.售后换货流程3.售后退货流程4.售后维修流程, @todo 5是后端说的,具体不知道代表什么意思? */
type: 5,
}
})
const { flag } = await checkProcessEnum(formatData);
if (flag) {
setOrderProductSelectRowKeys((prev) => prev.concat(key))
setOrderProductSelectRowRecord(tempData)
/** 父子联动, 这里写的不是很好,但没想到好的办法 */
if (children.length === keysList.length) {
setProcessOrder((prev) => prev.concat(currentOrderData))
}
}
}
};
......@@ -493,8 +555,8 @@ const Create = () => {
type: 5,
}
})
const res =await checkProcessEnum(formatData);
if (res) {
const { flag } =await checkProcessEnum(formatData);
if (flag) {
setOrderProductSelectRowKeys(uniqueKeys);
setOrderProductSelectRowRecord(uniqueList)
setProcessOrder((prev) => prev.concat(record))
......@@ -516,6 +578,7 @@ const Create = () => {
const newAddList = orderProductselectRowRecord
.filter((_item) => !uniqueIdList.has(`${_item.orderId}_${_item.id}`))
.map((_item) => {
const surplusProcessNum = _item.purchaseCount - +_item.processNum
return {
orderNo: _item.orderNo,
orderId: _item.orderId,
......@@ -529,7 +592,9 @@ const Create = () => {
brand: _item.brand,
unitName: _item.unit,
purchaseCount: _item.purchaseCount,
purchaseCountAndUnit: `${_item.purchaseCount}/${_item.unit}`
purchaseCountAndUnit: `${_item.purchaseCount}/${_item.unit}`,
surplusProcessNum: surplusProcessNum,
surplusAndProcessNum: `${surplusProcessNum} / 0`
}
});
......@@ -563,10 +628,11 @@ const Create = () => {
return []
}, [])
const onSubmit = async (value: submitDataType) => {
console.log(value)
const onSubmit = async (value: SubmitDataType) => {
const {
receivefullAddress,
source,
source1,
deliveryDate,
deliveryType,
enclosure,
......@@ -584,6 +650,8 @@ const Create = () => {
receiverAddressId,
...rest
} = value;
const formatDeliveryDate = moment(deliveryDate, 'YYYY-MM-DD').valueOf();
const orderListFormated = orderList?.map((_item) => {
return {
orderId: _item.orderId,
......@@ -591,15 +659,15 @@ const Create = () => {
orderDetailId: _item.id,
productId: _item.commodityId,
purchaseCount: _item.purchaseCount,
surplusProcessNum: _item.surplusAndProcessNum,
surplusProcessNum: _item.surplusProcessNum,
productName: _item.name,
category: _item.category,
brand: _item.brand,
unit: _item.unitName,
processNum: +_item.processNum,
processPrice: +_item.processUnitPrice,
processTotalPrice: +_item.processTotalPrice,
deliveryDate: deliveryDate,
processTotalPrice: +_item.processNum * +_item.processUnitPrice,
deliveryDate: formatDeliveryDate,
isHasTax: _item.isHasTax,
taxRate: _item.taxRate,
property: {
......@@ -608,21 +676,21 @@ const Create = () => {
}
}
})
const productListFormated = productList.map((_item) => {
const productListFormated = productList?.map((_item) => {
return {
/** 采购数量, 加工商品不需要,默认给0 */
purchaseCount: 0,
/** 剩余加工数量, 加工商品不需要 */
surplusProcessNum: 0,
prodcutId: _item.skuid,
productId: _item.skuid,
productName: _item.name,
brand: _item.brand,
category: _item.category,
unit: _item.unitName,
processNum: +_item.processNum,
processPrice: +_item.processUnitPrice,
processTotalPrice: +_item.processTotalPrice,
deliveryDate: deliveryDate,
processTotalPrice: +_item.processNum * +_item.processUnitPrice,
deliveryDate: formatDeliveryDate,
isHasTax: _item.isHasTax,
taxRate: _item.taxRate,
property:{
......@@ -632,17 +700,21 @@ const Create = () => {
}
})
let restData: {
processMemberId: number;
processName: string;
processRoleId: number;
source: 1 | 2 | number & {};
summary: string;
receiveAddress?: string,
receiveUserName?: string,
receiveUserTel?: string,
receiverAddressId?: number,
} = {} as any
const dataList = source === 1 ? orderListFormated : productListFormated;
const formatProcessEnumList = dataList.map((_record) => ({
productId: _record.productId,
memberId: authInfo.memberId,
memberRoleId: authInfo.memberRoleId,
shopId: ENTERPRISE_MALL[authInfo.memberType],
/** 1.订单交易流程2.售后换货流程3.售后退货流程4.售后维修流程, @todo 5是后端说的,具体不知道代表什么意思? */
type: 5,
}))
const processEnumRes = await checkProcessEnum(formatProcessEnumList);
if (!processEnumRes.flag) {
return
}
let restData: RestDataType = {} as RestDataType
if (deliveryType === 1) {
restData = {
...rest,
......@@ -654,7 +726,7 @@ const Create = () => {
}
const postData = {
deliveryDate: deliveryDate,
deliveryDate: formatDeliveryDate,
otherAsk: {
annex: enclosure?.map((item) => ({name: item.name, value: item.url})) || [],
explain: [
......@@ -666,14 +738,18 @@ const Create = () => {
{name: '其他说明', value: otherDesc}
]
},
details: orderListFormated,
details: source === 1 ? orderListFormated : productListFormated,
deliveryType,
...restData
source,
...restData,
outerTaskType: +processEnumRes.processEnum
}
const service = isEdit ? PublicApi.postEnhanceSupplierToBeAddUpdate : PublicApi.postEnhanceSupplierToBeAddAdd
const withId = isEdit ? { id: cacheInitialValue.id, ...postData}: postData;
const { data, code } = await service(withId as any)
if (code === 1000) {
history.goBack()
}
console.info(postData ,orderListFormated);
// const service = pathname.includes("edit") ? PublicApi.postEnhanceSupplierToBeAddUpdate : PublicApi.postEnhanceSupplierToBeAddAdd
// const withId = pathname.includes("edit") ? { id: editInfo.id, ...postData}: postData;
// const { data, code } = await PublicApi.postEnhanceSupplierToBeAddAdd(postData)
}
return (
......@@ -693,16 +769,15 @@ const Create = () => {
>
<NiceForm
onSubmit={onSubmit}
initialValues={
{
source: 1
}
}
value={cacheInitialValue}
effects={($, actions) => {
useAsyncSelect('receivefullAddress', fetchReceiveAddress)
onFieldValueChange$(`*(source,source1)`).subscribe((state) => {
const reverseName = state.name === 'source' ? 'source1' : 'source';
formActions.setFieldValue(reverseName, state.value)
});
onFieldValueChange$('receivefullAddress').subscribe((state) => {
if(state.visible) {
console.log(state);
const options = state.originAsyncData;
const target = options.filter((item) => item.value == state.value)[0];
if(target) {
......@@ -826,6 +901,7 @@ const Create = () => {
/>
<ProductDrawer
visible={productDrawerVisible}
editable={productActionType === 'edit'}
value={currentProduct}
onSubmit={handleChangeProduct}
onClose={() => productDrawerToggle(false)}
......
......@@ -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,37 +7,39 @@ 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 tempKey = record[primaryKey];
if(type === 'radio') {
setSelectedKeys([record[primaryKey]]);
setSelectedRows(selectedRows);
return ;
}
const onSelect = (async (record: any, selected: boolean, selectedRows: any[]) => {
// const tempKey = record[primaryKey];
if(type === 'radio') {
setSelectedRows(selectedRows);
setSelectedKeys([record[primaryKey]]);
return ;
}
let newArray = [];
if(selected) {
newArray = hasSelectedRows.concat(record);
} else {
// 如果是删除, 那么我们直接筛选key
newArray = hasSelectedRows.filter((item) => record[primaryKey] !== item[primaryKey] );
}
let newArray = [];
if(selected) {
newArray = hasSelectedRows.concat(record);
} else {
// 如果是删除, 那么我们直接筛选key
newArray = hasSelectedRows.filter((item) => record[primaryKey] !== item[primaryKey] );
if(func && selected && newArray.length > 0 ) {
setLoading(true)
const {isSuccess, data} = await func(newArray);
setLoading(false);
if(!isSuccess) {
message.info(data.tips);
return;
}
}
const keys = newArray.map((item) => item[primaryKey])
setSelectedRows(newArray);
setSelectedKeys(keys);
})
if(func && selected && newArray.length > 0 ) {
setLoading(true)
const {isSuccess, data} = await func(newArray);
setLoading(false);
if(!isSuccess) {
message.info(data.tips);
return;
}
}
setSelectedKeys(newArray.map((item) => item[primaryKey]));
setSelectedRows(newArray);
},
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,29 +99,23 @@ const ProcessProducts = ({visible, cancel, rowSelection, loading, ...restProps})
visible={visible}
onCancel={cancel}
onOk={onOk}
destroyOnClose
>
{
visible
?
<Spin spinning={loading}>
<SearchForm
request={fetchData}
components={{Cascader}}
schema={schema}
actions={actions}
effects={effects}
expressionScope={{
rowSelection: rowSelection,
columns: columns,
filterBrandOption: filterBrandOption,
onBrandSearch: onBrandSearch.run
}}
/>
</Spin>
: null
}
<Spin spinning={loading}>
<SearchForm
request={fetchData}
components={{Cascader}}
schema={schema}
actions={actions}
effects={effects}
expressionScope={{
rowSelection: rowSelection,
columns: columns,
filterBrandOption: filterBrandOption,
onBrandSearch: onBrandSearch.run
}}
/>
</Spin>
</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: {
......@@ -37,7 +37,7 @@ const TobeEvaluateDetail = () => {
const { visible, toggle } = useModal()
const { id, lastTypeParams } = usePageStatus();
const params = useMemo(() => { return id ? { id: id.toString() } : null }, [id]);
const { loading, initialValue }= useInitialValue<GetMemberAppraisalWaitGradeGetResponse, { id: string }>(PublicApi.getMemberAppraisalWaitGradeGet, params)
const { loading, initialValue }= useInitialValue<GetMemberAppraisalWaitGradeGetResponse, { id: string }>(PublicApi.getMemberAppraisalWaitGradeGet, params)
const { anchorHeader, basicInfoList, evaluateResultColumn, auditProcess } = useGetDetailCommon({blackList: ['result'], initialValue: initialValue})
const [hasScoring, setHasScoring] = useState<boolean>(false);
const [submitLoading, setSubmitLoading] = useState<boolean>(false);
......
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