Commit ea167965 authored by GuanHua's avatar GuanHua
parents 82c84dfa 1e892ee4
...@@ -1038,7 +1038,7 @@ export const PurchaseOrderInsideWorkStateTexts = { ...@@ -1038,7 +1038,7 @@ export const PurchaseOrderInsideWorkStateTexts = {
2: '待审核订单(一级)', 2: '待审核订单(一级)',
3: '待审核订单(二级)', 3: '待审核订单(二级)',
4: '待提交订单', 4: '待提交订单',
5: '待确认电子合同', 5: '审核通过',
6: '提交审核订单不通过(一级)', 6: '提交审核订单不通过(一级)',
7: '提交审核订单不通过(二级)', 7: '提交审核订单不通过(二级)',
8: '待支付订单', 8: '待支付订单',
...@@ -1048,7 +1048,9 @@ export const PurchaseOrderInsideWorkStateTexts = { ...@@ -1048,7 +1048,9 @@ export const PurchaseOrderInsideWorkStateTexts = {
14: '订单待入库', 14: '订单待入库',
15: '订单待归档', 15: '订单待归档',
16: '订单入库待审核', 16: '订单入库待审核',
17: '待手工收货' 17: '待手工收货',
18: '已确认收货',
19: '已归档',
} }
// 销售订单内部显示文案 // 销售订单内部显示文案
...@@ -1071,13 +1073,16 @@ export const SaleOrderInsideWorkStateTexts = { ...@@ -1071,13 +1073,16 @@ export const SaleOrderInsideWorkStateTexts = {
19: '待新增物流单', 19: '待新增物流单',
20: '订单发货待确认', 20: '订单发货待确认',
23: '待确认回单', 23: '待确认回单',
24: '订单待归档', 24: '待归档',
25: '待审核发货单', 25: '待审核发货单',
26: '待确认物流单', 26: '待确认物流单',
27: '待手工发货', 27: '待手工发货',
28: '不接受物流单', 28: '不接受物流单',
29: '订单已归档', 29: '订单已归档',
30: '已手工发货', 30: '已手工发货',
31: '已确认发货',
32: '已确认回单',
33: '已归档',
} }
// 订单流转记录外部状态 // 订单流转记录外部状态
......
...@@ -5,6 +5,7 @@ import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect'; ...@@ -5,6 +5,7 @@ import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect';
import { columnsUnitProduct } from '../constant'; import { columnsUnitProduct } from '../constant';
import { GlobalConfig } from '@/global/config'; import { GlobalConfig } from '@/global/config';
const { onFieldValueChange$ } = FormEffectHooks const { onFieldValueChange$ } = FormEffectHooks
import { PageStatus } from '@/hooks/usePageStatus'
// 高级筛选schema中用于输入搜索品牌的Effect // 高级筛选schema中用于输入搜索品牌的Effect
...@@ -32,13 +33,15 @@ export const searchCustomerCategoryOptionEffect = (context: any, fieldName: stri ...@@ -32,13 +33,15 @@ export const searchCustomerCategoryOptionEffect = (context: any, fieldName: stri
// 构建设置价格 table 所需要的data和columns // 构建设置价格 table 所需要的data和columns
export const constructTableData = (data: any, ctx: ISchemaFormActions | ISchemaFormAsyncActions) => { export const constructTableData = (data: any, ctx: ISchemaFormActions | ISchemaFormAsyncActions, pageStatus: any) => {
// 预先对阶梯价格排序 // 预先对阶梯价格排序
data = data.map(item => { data = data.map(item => {
let tempUnit: any = {} let tempUnit: any = {}
Object.keys(item.unitPrice).sort().forEach(function(key) { if(item.unitPrice) {
tempUnit[key] = item.unitPrice[key] Object.keys(item.unitPrice).sort().forEach(function(key) {
}) tempUnit[key] = item.unitPrice[key]
})
}
return { return {
...item, ...item,
unitPrice: tempUnit unitPrice: tempUnit
...@@ -48,7 +51,9 @@ export const constructTableData = (data: any, ctx: ISchemaFormActions | ISchemaF ...@@ -48,7 +51,9 @@ export const constructTableData = (data: any, ctx: ISchemaFormActions | ISchemaF
let col: any = [...columnsUnitProduct] let col: any = [...columnsUnitProduct]
let temp: any = [] let temp: any = []
data[0].attributeAndValueList.map(_item => { // 兼容编辑价格策略 新增使用data 编辑使用data[0].commodityUnitPrice
let _data_column = pageStatus === PageStatus.ADD ? data[0] : data[0]["commodityUnitPrice"]
_data_column.attributeAndValueList.map(_item => {
temp.push({title: _item.customerAttribute.name, dataIndex: [_item.customerAttribute.name, 'value'], key: _item.customerAttribute.name}) temp.push({title: _item.customerAttribute.name, dataIndex: [_item.customerAttribute.name, 'value'], key: _item.customerAttribute.name})
}) })
...@@ -71,20 +76,26 @@ export const constructTableData = (data: any, ctx: ISchemaFormActions | ISchemaF ...@@ -71,20 +76,26 @@ export const constructTableData = (data: any, ctx: ISchemaFormActions | ISchemaF
} }
}) })
// 兼容编辑价格策略 新增使用data 编辑使用data -> item -> commodityUnitPrice
let _tableData: any = [] let _tableData: any = []
data.map((item, index) => { data.map((item, index) => {
let temp: any = {} let temp: any = {}
item.attributeAndValueList.map(_item => { let _item_differ = pageStatus === PageStatus.ADD ? item : item["commodityUnitPrice"]
temp[_item.customerAttribute.name] = {value: _item.customerAttributeValue.value, vId: _item.customerAttributeValue.id, id: _item.customerAttribute.id } console.log(_item_differ, '_item_differ')
_item_differ.attributeAndValueList.map(_item => {
temp[_item.customerAttribute.name] = {
value: _item.customerAttributeValue.value,
vId: _item.customerAttributeValue.id,
id: _item.customerAttribute.id
}
}) })
_tableData.push({ _tableData.push({
"id": item.id, "id": _item_differ.id,
"索引": index, "索引": index,
"货品ID": item.goods?.id || '', "货品ID": _item_differ.goods?.id || '',
"商品名称": ctx.getFieldValue("productName"), "商品名称": ctx.getFieldValue("productName"),
"对应货品": item.goods?.name || '', "对应货品": _item_differ.goods?.name || '',
...temp, ...temp,
"单价": item.unitPrice "单价": item.unitPrice
}) })
...@@ -144,20 +155,11 @@ export const transformDataForNiceForm = (value: any, ctx: ISchemaFormActions | I ...@@ -144,20 +155,11 @@ export const transformDataForNiceForm = (value: any, ctx: ISchemaFormActions | I
let shopInfo = GlobalConfig.web.shopInfo.filter(item => item["type"] === value["type"] && item["environment"] === value["environment"]) let shopInfo = GlobalConfig.web.shopInfo.filter(item => item["type"] === value["type"] && item["environment"] === value["environment"])
initValue["shopId"] = shopInfo[0]["id"] initValue["shopId"] = shopInfo[0]["id"]
// Edit使用
initValue["memberUnitPriceList"] = value["memberUnitPriceList"]
return { return {
initValue initValue
} }
// const { tableUnitData, columsUnit } = constructTableData(value.memberUnitPriceList, ctx)
// initValue["memberUnitPriceList"] = constructTableData(value.memberUnitPriceList, ctx)["tableUnitData"]
// ctx.setFieldState("memberUnitPriceList", state => {
// columsUnit.push({
// dataIndex: 'ctl',
// title: '操作',
// align: 'center',
// render: (_i, _r) => <Button type='link' onClick={() => handleSetProductPrice(_r)}>设置价格</Button>
// })
// state.props["x-component-props"].columns = columsUnit
// })
} }
} }
...@@ -78,6 +78,8 @@ const PriceModal:React.FC<PriceModalProps> = (props) => { ...@@ -78,6 +78,8 @@ const PriceModal:React.FC<PriceModalProps> = (props) => {
useEffect(() => { useEffect(() => {
if(isBatchSetting) { if(isBatchSetting) {
setPriceForm.resetFields() setPriceForm.resetFields()
setPriceForm.setFields([{name: 'ladderPrice', value: false}])
currentRef.current.setLadderPrice(false)
} }
}, [isBatchSetting]) }, [isBatchSetting])
...@@ -137,7 +139,7 @@ const PriceModal:React.FC<PriceModalProps> = (props) => { ...@@ -137,7 +139,7 @@ const PriceModal:React.FC<PriceModalProps> = (props) => {
return ( return (
<Modal <Modal
title="设置价格" title={currentRef.current.isBatchSetting ? "批量设置价格" : "设置价格"}
visible={visible} visible={visible}
onOk={handlePriceOk} onOk={handlePriceOk}
onCancel={() => setVisible(false)} onCancel={() => setVisible(false)}
......
...@@ -36,6 +36,8 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => { ...@@ -36,6 +36,8 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
const [visibleMember, setVisibleMember] = useState(false) const [visibleMember, setVisibleMember] = useState(false)
const [memberRowSelection, memberRowCtl] = useRowSelectionTable({ customKey: 'memberId' }) const [memberRowSelection, memberRowCtl] = useRowSelectionTable({ customKey: 'memberId' })
const [initFormValue, setInitialFormValue] = useState({}); const [initFormValue, setInitialFormValue] = useState({});
const dataRef = useRef({})
const [priceType, setPriceType] = useState(1)
const [membersLength, setMembersLength] = useState(0); const [membersLength, setMembersLength] = useState(0);
const { const {
...@@ -49,6 +51,7 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => { ...@@ -49,6 +51,7 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
PublicApi.getProductCommodityGetUnitPriceStrategy({id}).then(res => { PublicApi.getProductCommodityGetUnitPriceStrategy({id}).then(res => {
const { initValue } = transformDataForNiceForm(res.data, addSchemaAction) const { initValue } = transformDataForNiceForm(res.data, addSchemaAction)
setInitialFormValue(initValue) setInitialFormValue(initValue)
dataRef.current = initValue
addSchemaAction.setFieldState('commodityMemberList', state => { addSchemaAction.setFieldState('commodityMemberList', state => {
state.dataSource = initValue.commodityMemberList state.dataSource = initValue.commodityMemberList
}) })
...@@ -115,36 +118,57 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => { ...@@ -115,36 +118,57 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
if (addSchemaAction.getFieldValue("productId")) { if (addSchemaAction.getFieldValue("productId")) {
priceRef.current.setIsBatchSetting(true) priceRef.current.setIsBatchSetting(true)
priceRef.current.setVisible(true) priceRef.current.setVisible(true)
priceRef.current.setLadderPrice(false)
} else { } else {
message.error('请先选择适用商城或商品') message.error('请先选择适用商城或商品')
} }
} }
const searchMember = (value) => { const searchMember = (value) => {
let commodityMemberList = addSchemaAction.getFieldValue("commodityMemberList").filter(item => item.name === value)
addSchemaAction.setFieldValue("commodityMemberList", commodityMemberList)
if(!value) { if(!value) {
addSchemaAction.setFieldValue("commodityMemberList", addSchemaAction.getFieldState("commodityMemberList")["dataSource"]) addSchemaAction.setFieldValue("commodityMemberList", addSchemaAction.getFieldState("commodityMemberList")["dataSource"])
return ;
} }
}
let commodityMemberList = addSchemaAction.getFieldValue("commodityMemberList").filter(item => item.name.indexOf(value) !== -1)
addSchemaAction.setFieldValue("commodityMemberList", commodityMemberList)
}
// const paginationChange = async (page: number, size: number) => { /**
// if(id !== '') { * 生成价格设置 table 和会员 column
// const result = await getBindingMember({id, current: page.toString(), pageSize: size.toString()}); * @param pId 商品id
// addSchemaAction.setFieldValue('commodityMemberList', result.data); * @param ctx action
// } * @param priceType 价格类型(可选)1现货2询价
// } */
const producePriceTableMemerColumn = async (pId, ctx, priceType?) => {
const res = await PublicApi.getProductCommodityGetCommodityUnitPrice({ id: pId,})
// 填充价格设置table(编辑采用initValue数据)
let source = pageStatus === PageStatus.ADD ? res.data : dataRef.current["memberUnitPriceList"]
const { columsUnit, tableUnitData } = constructTableData(source, ctx, pageStatus)
ctx.setFieldState("memberUnitPriceList", state => {
state.dataSource = source // 存源数据
priceType !== 2 ? columsUnit.push({
dataIndex: 'ctl',
title: '操作',
align: 'center',
render: (_i, _r) => <Button disabled={pageStatus === PageStatus.PREVIEW} type='link' onClick={() => handleSetProductPrice(_r)}>设置价格</Button>
})
:
columsUnit.pop()
state.props["x-component-props"].columns = columsUnit
})
ctx.setFieldValue("memberUnitPriceList", priceType === 2 ? tableUnitData.map(item => { delete item["单价"]; return item }) : tableUnitData)
// // 拿到绑定会员 console.log(columsUnit, tableUnitData, source)
// const getBindingMember = async ({id = '1', current = '1', pageSize = '10'}) => {
// const res = await PublicApi.getWarehouseFreightSpaceMamberList({id, current, pageSize});
// return res.data
// }
// 填充适用会员table
ctx.setFieldState("commodityMemberList", state => {
memberColumns[memberColumns.length -1].render = (text, record) => {
return <Button disabled={pageStatus === PageStatus.PREVIEW} type='link' onClick={() => handleDeleteMemberTable(record)}>删除</Button>
}
state.props["x-component-props"].columns = memberColumns
})
}
// 新增会员 // 新增会员
const tableAddMemberButton = pageStatus !== PageStatus.PREVIEW && <> const tableAddMemberButton = pageStatus !== PageStatus.PREVIEW && <>
...@@ -159,10 +183,10 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => { ...@@ -159,10 +183,10 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
</> </>
// 批量设置价格按钮 // 批量设置价格按钮
const batchPriceButton = pageStatus !== PageStatus.PREVIEW && <Button type="text" onClick={clickBatchSetPrice} style={{marginBottom: 12, float: "right"}}><SettingOutlined /> 批量设置价格</Button> const batchPriceButton = pageStatus!==PageStatus.PREVIEW && priceType!==2 && <Button type="text" onClick={clickBatchSetPrice} style={{marginBottom: 12, float: "right"}}><SettingOutlined /> 批量设置价格</Button>
// 选择商品 // 选择商品
const connectProduct = pageStatus !== PageStatus.PREVIEW && <div className='connectBtn' onClick={handleAddProductBtn}><LinkOutlined style={{marginRight: 4}}/>选择</div> const connectProduct = pageStatus === PageStatus.ADD && <div className='connectBtn' onClick={handleAddProductBtn}><LinkOutlined style={{marginRight: 4}}/>选择</div>
return ( return (
<> <>
...@@ -196,40 +220,56 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => { ...@@ -196,40 +220,56 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
if(pageStatus === PageStatus.EDIT) { if(pageStatus === PageStatus.EDIT) {
state.props['x-component-props'].disabled = true; state.props['x-component-props'].disabled = true;
} }
})
ctx.setFieldState('priceType', state => {
if(pageStatus === PageStatus.EDIT) {
state.props['x-component-props'].disabled = true;
}
}); });
} }
}) })
$('onFieldValueChange', 'productId').subscribe(async parentState => { $('onFieldValueChange', 'productId').subscribe(async parentState => {
if (parentState.value) { if (parentState.value) {
const res = await PublicApi.getProductCommodityGetCommodityUnitPrice({ // const res = await PublicApi.getProductCommodityGetCommodityUnitPrice({
id: parentState.value, // id: parentState.value,
}) // })
if(res.code === 1000) { // if(res.code === 1000) {
// 填充价格设置table // // 填充价格设置table
const { columsUnit, tableUnitData } = constructTableData(res.data, ctx) // const { columsUnit, tableUnitData } = constructTableData(res.data, ctx)
ctx.setFieldState("memberUnitPriceList", state => { // ctx.setFieldState("memberUnitPriceList", state => {
state.dataSource = res.data // 存源数据 // state.dataSource = res.data // 存源数据
columsUnit.push({ // columsUnit.push({
dataIndex: 'ctl', // dataIndex: 'ctl',
title: '操作', // title: '操作',
align: 'center', // align: 'center',
render: (_i, _r) => <Button disabled={pageStatus === PageStatus.PREVIEW} type='link' onClick={() => handleSetProductPrice(_r)}>设置价格</Button> // render: (_i, _r) => <Button disabled={pageStatus === PageStatus.PREVIEW} type='link' onClick={() => handleSetProductPrice(_r)}>设置价格</Button>
}) // })
state.props["x-component-props"].columns = columsUnit // state.props["x-component-props"].columns = columsUnit
}) // })
ctx.setFieldValue("memberUnitPriceList", tableUnitData) // ctx.setFieldValue("memberUnitPriceList", tableUnitData)
console.log(columsUnit, tableUnitData, res.data) // console.log(columsUnit, tableUnitData, res.data)
// 填充适用会员table // // 填充适用会员table
ctx.setFieldState("commodityMemberList", state => { // ctx.setFieldState("commodityMemberList", state => {
memberColumns[memberColumns.length -1].render = (text, record) => { // memberColumns[memberColumns.length -1].render = (text, record) => {
return <Button disabled={pageStatus === PageStatus.PREVIEW} type='link' onClick={() => handleDeleteMemberTable(record)}>删除</Button> // return <Button disabled={pageStatus === PageStatus.PREVIEW} type='link' onClick={() => handleDeleteMemberTable(record)}>删除</Button>
} // }
state.props["x-component-props"].columns = memberColumns // state.props["x-component-props"].columns = memberColumns
}) // })
} // }
producePriceTableMemerColumn(parentState.value, ctx)
}
})
$("onFieldValueChange", "priceType").subscribe(parentState => {
let pId = ctx.getFieldValue("productId")
if(pId) {
producePriceTableMemerColumn(pId, ctx, parentState.value)
} }
setPriceType(parentState.value)
}) })
}} }}
......
...@@ -10,8 +10,11 @@ import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilte ...@@ -10,8 +10,11 @@ import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilte
import { FORM_FILTER_PATH } from '@/formSchema/const' import { FORM_FILTER_PATH } from '@/formSchema/const'
import ModalSearch from '@/components/NiceForm/components/Search' import ModalSearch from '@/components/NiceForm/components/Search'
import Submit from '@/components/NiceForm/components/Submit' import Submit from '@/components/NiceForm/components/Submit'
import CustomCategorySearch from '@/components/NiceForm/components/CustomCategorySearch'
import SearchSelect from '@/components/NiceForm/components/SearchSelect' import SearchSelect from '@/components/NiceForm/components/SearchSelect'
import { clearModalParams } from '@/utils' import { clearModalParams } from '@/utils'
import { FormEffectHooks } from '@formily/antd'
import { searchCustomerCategoryOptionEffect } from '../../effect'
export interface ProductModalProps { export interface ProductModalProps {
type?: 'radio' | 'checkbox', type?: 'radio' | 'checkbox',
...@@ -87,7 +90,8 @@ const ProductModal:React.FC<ProductModalProps> = (props) => { ...@@ -87,7 +90,8 @@ const ProductModal:React.FC<ProductModalProps> = (props) => {
schema: formProduct, schema: formProduct,
components: { components: {
ModalSearch, ModalSearch,
SearchSelect, Submit SearchSelect, Submit,
CustomCategorySearch
}, },
effects: ($, actions) => { effects: ($, actions) => {
actions.reset() actions.reset()
...@@ -97,6 +101,9 @@ const ProductModal:React.FC<ProductModalProps> = (props) => { ...@@ -97,6 +101,9 @@ const ProductModal:React.FC<ProductModalProps> = (props) => {
'name', 'name',
FORM_FILTER_PATH, FORM_FILTER_PATH,
); );
FormEffectHooks.onFieldChange$('customerCategoryId').subscribe(state => {
searchCustomerCategoryOptionEffect(actions, 'customerCategoryId')
})
} }
} }
} }
......
...@@ -152,7 +152,13 @@ const PriceManage: React.FC<{}> = () => { ...@@ -152,7 +152,13 @@ const PriceManage: React.FC<{}> = () => {
} }
const handleUpdateState = (record: any) => { const handleUpdateState = (record: any) => {
PublicApi.postProductCommodityUpdateUnitPriceStrategyStatus({id: record.id, isEnable: !record.isEnable}) PublicApi.postProductCommodityUpdateUnitPriceStrategyStatus({id: record.id, isEnable: !record.isEnable}).then(res => {
if(res.code === 1000) {
setTimeout(() => {
ref.current.reload()
}, 1000)
}
})
} }
const handleModify = (record: any) => { const handleModify = (record: any) => {
......
...@@ -248,7 +248,10 @@ export const setPriceSchema: ISchema = { ...@@ -248,7 +248,10 @@ export const setPriceSchema: ISchema = {
value: 2 value: 2
} }
], ],
default: 1 default: 1,
"x-component-props": {
disabled: false,
},
}, },
} }
} }
...@@ -393,15 +396,15 @@ export const formProduct: ISchema = { ...@@ -393,15 +396,15 @@ export const formProduct: ISchema = {
properties: { properties: {
customerCategoryId: { customerCategoryId: {
type: 'string', type: 'string',
"x-component": 'SearchSelect', 'x-component': 'CustomCategorySearch',
"x-component-props": { 'x-component-props': {
placeholder: '请选择品类', placeholder: '商品品类',
className: 'fixed-ant-selected-down', // 该类强制将显示的下拉框出现在select下, 只有这里出现问题, ?? showSearch: true,
fetchSearch: PublicApi.getProductSelectGetSelectCustomerCategory, notFoundContent: null,
style: { style: { width: '174px' },
width: 160 dataoption: [],
} fieldNames: { label: 'title', value: 'id', children: 'children' },
} },
}, },
brandId: { brandId: {
type: 'string', type: 'string',
......
...@@ -34,9 +34,9 @@ const OrderPayTabs:React.FC<OrderPayTabsProps> = (props) => { ...@@ -34,9 +34,9 @@ const OrderPayTabs:React.FC<OrderPayTabsProps> = (props) => {
const processEnum = data.processEnum const processEnum = data.processEnum
useEffect(() => { useEffect(() => {
// 过滤支付信息 取第一个待支付的id // 过滤支付信息 取第一个待支付或者未到账的id
if(data?.paymentInformationResponses?.length) { if(data?.paymentInformationResponses?.length) {
let payments = data.paymentInformationResponses.filter(item => item.externalState === 1) let payments = data.paymentInformationResponses.filter(item => item.externalState === 1 || item.externalState === 4)
if(payments.length) { if(payments.length) {
ctl.setPayId(payments[0].id) ctl.setPayId(payments[0].id)
} }
......
...@@ -109,7 +109,7 @@ const PurchaseOrder: React.FC<PurchaseOrderProps> = (props) => { ...@@ -109,7 +109,7 @@ const PurchaseOrder: React.FC<PurchaseOrderProps> = (props) => {
render: (text, record) => <> render: (text, record) => <>
{ record.externalState === PurchaseOrderOutWorkState.FINISH_ORDER && !record.procurementEevaluateState && <Button type='link' onClick={() => handleEvaluate(record.id)}>评价</Button> } { record.externalState === PurchaseOrderOutWorkState.FINISH_ORDER && !record.procurementEevaluateState && <Button type='link' onClick={() => handleEvaluate(record.id)}>评价</Button> }
{ {
record.receivingTimes >= 1 || record.externalState === PurchaseOrderOutWorkState.FINISH_ORDER && <Button type='link' onClick={() => handleSaleAfter(record.id)}>售后</Button> (record.receivingTimes >= 1 || record.externalState === PurchaseOrderOutWorkState.FINISH_ORDER) && <Button type='link' onClick={() => handleSaleAfter(record.id)}>售后</Button>
} }
</> </>
} }
......
...@@ -49,7 +49,20 @@ export const EditableRow: React.FC<any> = (props) => { ...@@ -49,7 +49,20 @@ export const EditableRow: React.FC<any> = (props) => {
); );
}; };
const validatorNumber = (rule, value, callback) => {
try {
let n = Number(value);
if(isNaN(n)) {
throw new Error('请正确输入支付比例');
} else if(n < 0 || !Number.isInteger(n)) {
throw new Error('支付比例为大于0的整数');
} else {
callback()
}
} catch (err) {
callback(err)
}
}
export const PayInfoCell:React.FC<PayInfoCellProps> = ({ export const PayInfoCell:React.FC<PayInfoCellProps> = ({
title, title,
...@@ -145,6 +158,10 @@ export const PayInfoCell:React.FC<PayInfoCellProps> = ({ ...@@ -145,6 +158,10 @@ export const PayInfoCell:React.FC<PayInfoCellProps> = ({
required: true, required: true,
message: `${title}必须填写`, message: `${title}必须填写`,
}, },
// 支付比例大于0
formItem === 'input' && {
validator: validatorNumber
}
]} ]}
> >
{chooseFormItem(formItem)} {chooseFormItem(formItem)}
......
import React, { useState, useRef, useContext, useEffect } from 'react' import React, { useState, useRef, useContext, useEffect } from 'react'
import { Form, Input, Select } from 'antd'; import { Form, Input, Select } from 'antd';
export interface ProductTableCellProps { export interface ProductTableCellProps {
title: React.ReactNode; title: React.ReactNode;
editable: boolean; editable: boolean;
children: React.ReactNode; children: React.ReactNode;
dataIndex: string; dataIndex: string;
record: any; record: any;
handleSave: (record: any) => Promise<any>; handleSave: (record: any) => Promise<any>;
forceEdit: boolean, forceEdit: boolean,
formItem: string, formItem: string,
formItemProps: any formItemProps: any
} }
const EditableContext = React.createContext<any>({}); const EditableContext = React.createContext<any>({});
export const ProductEditableRow: React.FC<any> = ({...props }) => { export const ProductEditableRow: React.FC<any> = ({...props }) => {
const [form] = Form.useForm(); const [form] = Form.useForm();
const ctx = { const ctx = {
form form
} }
return ( return (
<Form form={form} component={false}> <Form form={form} component={false}>
<EditableContext.Provider value={ctx}> <EditableContext.Provider value={ctx}>
<tr {...props} /> <tr {...props} />
</EditableContext.Provider> </EditableContext.Provider>
</Form> </Form>
); );
}; };
export const ProductTableCell:React.FC<ProductTableCellProps> = ({ export const ProductTableCell:React.FC<ProductTableCellProps> = ({
title, title,
editable, editable,
children, children,
dataIndex, dataIndex,
record, record,
handleSave, handleSave,
forceEdit, forceEdit,
formItem, formItem,
formItemProps={}, formItemProps={},
...restProps ...restProps
}) => { }) => {
const formItemRef = useRef<any>(); const formItemRef = useRef<any>();
const { form } = useContext(EditableContext); const { form } = useContext(EditableContext);
const save = async e => { const save = async e => {
try { try {
const values = await form.validateFields(); const values = await form.validateFields();
values.purchaseCount = Number(values.purchaseCount) || 0 values.purchaseCount = Number(values.purchaseCount) || 0
handleSave({ ...record, ...values }); handleSave({ ...record, ...values });
} catch (errInfo) { } catch (errInfo) {
console.log('Save failed:', errInfo); console.log('Save failed:', errInfo);
} }
}; };
const chooseFormItem = (type) => { const chooseFormItem = (type) => {
switch(type) { switch(type) {
case 'input': { case 'input': {
return <Input style={{width: 140}} type='number' ref={formItemRef} onChange={save} {...formItemProps} id={dataIndex + record.id}/> return <Input style={{width: 140}} type='number' ref={formItemRef} onChange={save} {...formItemProps} id={dataIndex + record.id}/>
} }
} }
} }
let childNode = children; let childNode = children;
if (editable) { if (editable) {
childNode = childNode =
<Form.Item <Form.Item
style={{ margin: 0 }} style={{ margin: 0 }}
name={dataIndex} name={dataIndex}
initialValue={record[dataIndex] || ''} initialValue={record[dataIndex] || ''}
rules={[ rules={[
{ {
required: true, required: true,
message: `${title}必须填写`, message: `${title}必须填写`,
}, },
]} {
> pattern: /^\d+(\.\d{1,3})?$/,
{chooseFormItem(formItem)} message: '采购数量仅限三位小数',
</Form.Item> },
} ]}
>
return <td {...restProps}>{childNode}</td>; {chooseFormItem(formItem)}
} </Form.Item>
}
ProductTableCell.defaultProps = {}
return <td {...restProps}>{childNode}</td>;
export default ProductTableCell }
\ No newline at end of file
ProductTableCell.defaultProps = {}
export default ProductTableCell
...@@ -316,11 +316,10 @@ const PurchaseOrderDetail:React.FC<PurchaseOrderDetailProps> = (props) => { ...@@ -316,11 +316,10 @@ const PurchaseOrderDetail:React.FC<PurchaseOrderDetailProps> = (props) => {
if(params.needTheInvoice && !params.theInvoiceId) { if(params.needTheInvoice && !params.theInvoiceId) {
throw new Error('请新增或选择需要使用的发票') throw new Error('请新增或选择需要使用的发票')
} }
// logistics render字段字符串化 @to fix bug // logistics render字段字符串化
params.orderProductRequests = params.orderProductRequests.map(item => { params.orderProductRequests = params.orderProductRequests.map(item => {
let logistics: any = { let logistics: any = {
...item.logistics, ...item.logistics,
// render: item.logistics?.render ? JSON.stringify(item.logistics.render.replace(/\"/g, '')) : null
render: JSON.stringify(typeof item.logistics.render === "object" ? item.logistics.render : item.logistics.render.replace(/\"/g, '')) render: JSON.stringify(typeof item.logistics.render === "object" ? item.logistics.render : item.logistics.render.replace(/\"/g, ''))
}; };
return { return {
......
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