Commit 68c48c4e authored by 前端-钟卫鹏's avatar 前端-钟卫鹏

fix:处理仓位中获取仓位货品数量异常,处理采购询价下单删除商品运费变动异常和支付比例不为0的问题

parent b93d4c2d
import React, { useEffect } from 'react'
import { ISchemaFormActions, FormEffectHooks, IFormActions } from '@formily/antd';
import { PublicApi } from '@/services/api';
import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect';
const { onFieldValueChange$ } = FormEffectHooks
export const useWarehouseSelect = (context: ISchemaFormActions) => {
onFieldValueChange$('warehouseId').subscribe(state => {
// 货品ID
const goodsId = context.getFieldValue('productId')
const warehouseId = state.value
PublicApi.getWarehouseInventoryByItemNo({
warehouseId,
itemId: goodsId
}).then(res => {
const { data } = res
context.setFieldValue('NO_SUBMIT3', data.inventory)
})
})
}
export const createAddRepositoryEffect = (context: ISchemaFormActions) => {
const fetchWarehouseAll = async () => {
const { data } = await PublicApi.getWarehouseWarehouseAll()
context.setFieldState('warehouseId', state => {
state.warehouseLists = data
})
return data.map(v => ({
value: v.id,
label: v.name
}))
}
useAsyncSelect('warehouseId', fetchWarehouseAll)
useWarehouseSelect(context)
}
export const useUnitPreview = (initValue, context) => {
useEffect(() => {
if (initValue) {
context.setFieldState('inventory', state => {
if (!state.props['x-props']) {
state.props['x-props'] = {}
}
state.props['x-props'].addonAfter = <div style={{marginLeft: 4}}>{initValue.unit}</div>
})
context.setFieldValue('itemNo', initValue.itemNo)
}
}, [initValue])
}
// 高级筛选schema中用于输入搜索品牌的Effect
export const searchBrandOptionEffect = (context: any, fieldName: string) => {
context.getFieldState(fieldName, state => {
PublicApi.getProductSelectGetSelectBrand({ name: state.props['x-component-props'].searchValue }).then(res => {
context.setFieldState(fieldName, state => {
state.props['x-component-props'].dataoption = res.data
})
})
})
}
// 高级筛选schema中用于输入搜索商品品类的Effect
export const searchCustomerCategoryOptionEffect = (context: any, fieldName: string) => {
context.getFieldState(fieldName, state => {
PublicApi.getProductSelectGetSelectCustomerCategory({ name: state.props['x-component-props'].searchValue }).then(res => {
context.setFieldState(fieldName, state => {
state.props['x-component-props'].dataoption = res.data
})
})
})
}
\ No newline at end of file
import React, { useEffect } from 'react'
import { ISchemaFormActions, FormEffectHooks, IFormActions } from '@formily/antd';
import { PublicApi } from '@/services/api';
import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect';
const { onFieldValueChange$ } = FormEffectHooks
export const useWarehouseSelect = (context: ISchemaFormActions) => {
onFieldValueChange$('warehouseId').subscribe(state => {
// 货品ID
const goodsId = context.getFieldValue('goodsId')
const warehouseId = state.value
PublicApi.getWarehouseInventoryByItemNo({
warehouseId,
itemId: goodsId
}).then(res => {
const { data } = res
context.setFieldValue('NO_SUBMIT3', data.inventory)
})
})
}
export const createAddRepositoryEffect = (context: ISchemaFormActions) => {
const fetchWarehouseAll = async () => {
const { data } = await PublicApi.getWarehouseWarehouseAll()
context.setFieldState('warehouseId', state => {
state.warehouseLists = data
})
return data.map(v => ({
value: v.id,
label: v.name
}))
}
useAsyncSelect('warehouseId', fetchWarehouseAll)
useWarehouseSelect(context)
}
export const useUnitPreview = (initValue, context) => {
useEffect(() => {
if (initValue) {
context.setFieldState('inventory', state => {
if (!state.props['x-props']) {
state.props['x-props'] = {}
}
state.props['x-props'].addonAfter = <div style={{marginLeft: 4}}>{initValue.unit}</div>
})
context.setFieldValue('itemNo', initValue.itemNo)
}
}, [initValue])
}
// 高级筛选schema中用于输入搜索品牌的Effect
export const searchBrandOptionEffect = (context: any, fieldName: string) => {
context.getFieldState(fieldName, state => {
PublicApi.getProductSelectGetSelectBrand({ name: state.props['x-component-props'].searchValue }).then(res => {
context.setFieldState(fieldName, state => {
state.props['x-component-props'].dataoption = res.data
})
})
})
}
// 高级筛选schema中用于输入搜索商品品类的Effect
export const searchCustomerCategoryOptionEffect = (context: any, fieldName: string) => {
context.getFieldState(fieldName, state => {
PublicApi.getProductSelectGetSelectCustomerCategory({ name: state.props['x-component-props'].searchValue }).then(res => {
context.setFieldState(fieldName, state => {
state.props['x-component-props'].dataoption = res.data
})
})
})
}
import React, { useState, useRef, useContext, useEffect } from 'react'
import { Form, Input, Select } from 'antd';
export interface PayInfoCellProps {
title: React.ReactNode;
editable: boolean;
children: React.ReactNode;
dataIndex: string;
record: any;
colIndex: number,
handleChange(record: any, value: any)
handleSave: (record: any) => Promise<any>;
forceEdit: boolean,
formItem: string,
formItemProps: any
}
const EditableContext = React.createContext<any>({});
export const EditableRow: React.FC<any> = (props) => {
const [form] = Form.useForm();
// form.setFieldsValue()
const { options = [] } = props?.children[5]?.props.additionalProps.formItemProps || {}
const [childOptions, setChildOptions] = useState<any[]>(() => {
const { payWay } = props?.children[5]?.props.record || {}
if (payWay) {
return options.find(v => v.payType === payWay)?.payList.map(v => ({
label: v.way,
value: v.id
})) || []
} else {
return []
}
})
const ctx = {
form,
childOptions,
setChildOptions,
originOptions: options
}
return (
<Form form={form} component={false}>
<EditableContext.Provider value={ctx}>
<tr {...props} />
</EditableContext.Provider>
</Form>
);
};
export const PayInfoCell:React.FC<PayInfoCellProps> = ({
title,
editable,
children,
dataIndex,
record,
colIndex,
handleChange,
handleSave,
forceEdit,
formItem,
formItemProps={},
...restProps
}) => {
const formItemRef = useRef<any>();
const { form, childOptions, setChildOptions, originOptions } = useContext(EditableContext);
const save = async e => {
try {
const values = await form.validateFields();
handleSave({ ...record, ...values });
} catch (errInfo) {
console.log('Save failed:', errInfo);
}
};
const handleInputChange = (e) => {
handleChange(record, e.target.value)
}
const chooseFormItem = (type) => {
const formId = dataIndex + colIndex
switch(type) {
case 'input': {
return <Input ref={formItemRef} onPressEnter={save} onBlur={save} onChange={handleInputChange} {...formItemProps} id={formId}/>
}
case 'select': {
const { options, ...rest } = formItemProps
// 支付方式
if (dataIndex === 'payWay') {
return <Select ref={formItemRef}
options={originOptions.map(v => ({label: v.payVal, value: v.payType, disabled: v?.disabled}))} // ?? 仅限线下支付下面只有一种方式
onChange={e => {
const result = originOptions.find(v => e === v.payType)
setChildOptions(result.payList.map(v => ({label: v.way, value: v.id})))
form.setFieldsValue({channel: ''})
save(e)
}}
{...rest}
id={formId}
/>
}
// 需联动的内容
if (dataIndex === 'channel') {
return <Select
ref={formItemRef}
onChange={save}
options={childOptions}
{...rest}
id={formId}
/>
}
}
}
}
let childNode = children;
if (editable) {
childNode = (forceEdit) ? (
<Form.Item
style={{ margin: 0 }}
name={dataIndex}
initialValue={record[dataIndex] || ''}
rules={[
{
required: true,
message: `${title}必须填写`,
},
]}
>
{chooseFormItem(formItem)}
</Form.Item>
) : (
null
);
}
return <td {...restProps}>{childNode}</td>;
}
PayInfoCell.defaultProps = {}
export default PayInfoCell
import React, { useState, useRef, useContext, useEffect } from 'react'
import { Form, Input, Select } from 'antd';
export interface PayInfoCellProps {
title: React.ReactNode;
editable: boolean;
children: React.ReactNode;
dataIndex: string;
record: any;
colIndex: number,
handleChange(record: any, value: any)
handleSave: (record: any) => Promise<any>;
forceEdit: boolean,
formItem: string,
formItemProps: any
}
const EditableContext = React.createContext<any>({});
export const EditableRow: React.FC<any> = (props) => {
const [form] = Form.useForm();
// form.setFieldsValue()
const { options = [] } = props?.children[5]?.props.additionalProps.formItemProps || {}
const [childOptions, setChildOptions] = useState<any[]>(() => {
const { payWay } = props?.children[5]?.props.record || {}
if (payWay) {
return options.find(v => v.payType === payWay)?.payList.map(v => ({
label: v.way,
value: v.id
})) || []
} else {
return []
}
})
const ctx = {
form,
childOptions,
setChildOptions,
originOptions: options
}
return (
<Form form={form} component={false}>
<EditableContext.Provider value={ctx}>
<tr {...props} />
</EditableContext.Provider>
</Form>
);
};
export const PayInfoCell:React.FC<PayInfoCellProps> = ({
title,
editable,
children,
dataIndex,
record,
colIndex,
handleChange,
handleSave,
forceEdit,
formItem,
formItemProps={},
...restProps
}) => {
const formItemRef = useRef<any>();
const { form, childOptions, setChildOptions, originOptions } = useContext(EditableContext);
const save = async e => {
try {
const values = await form.validateFields();
handleSave({ ...record, ...values });
} catch (errInfo) {
console.log('Save failed:', errInfo);
}
};
const handleInputChange = (e) => {
handleChange(record, e.target.value)
}
const chooseFormItem = (type) => {
const formId = dataIndex + colIndex
switch(type) {
case 'input': {
return <Input ref={formItemRef} onPressEnter={save} onBlur={save} onChange={handleInputChange} {...formItemProps} id={formId}/>
}
case 'select': {
const { options, ...rest } = formItemProps
// 支付方式
if (dataIndex === 'payWay') {
return <Select ref={formItemRef}
options={originOptions.map(v => ({label: v.payVal, value: v.payType, disabled: v?.disabled}))} // ?? 仅限线下支付下面只有一种方式
onChange={e => {
const result = originOptions.find(v => e === v.payType)
setChildOptions(result.payList.map(v => ({label: v.way, value: v.id})))
form.setFieldsValue({channel: ''})
save(e)
}}
{...rest}
id={formId}
/>
}
// 需联动的内容
if (dataIndex === 'channel') {
return <Select
ref={formItemRef}
onChange={save}
options={childOptions}
{...rest}
id={formId}
/>
}
}
}
}
let childNode = children;
if (editable) {
childNode = (forceEdit) ? (
<Form.Item
style={{ margin: 0 }}
name={dataIndex}
initialValue={record[dataIndex] || ''}
rules={[
{
required: true,
message: `${title}必须填写`,
},
]}
>
{chooseFormItem(formItem)}
</Form.Item>
) : (
null
);
}
return <td {...restProps}>{childNode}</td>;
}
PayInfoCell.defaultProps = {}
export default PayInfoCell
......@@ -79,6 +79,8 @@ export const MoneyTotalBox = registerVirtualBox('moneyTotalBox', props => {
setFreePrice(res.data)
}
})
} else {
setFreePrice(0)
}
}
}, [data])
......@@ -211,14 +213,14 @@ const PurchaseOrderDetail:React.FC<PurchaseOrderDetailProps> = (props) => {
}
// 校验是否选择支付渠道
let judgementByPay = params.paymentInformationResponses.map(item => {
if(item.channel && item.payWay){
if(item.channel && item.payWay && Number(item.payRatio)){
return true
} else {
return false
}
})
if(judgementByPay.includes(false)){
throw new Error('请选择支付方式或者支付渠道')
throw new Error('请正确填写支付信息')
}
// 校验采购数量
let judgementByCount = params.orderProductRequests.map(item => {
......
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