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

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

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