Commit b3b8ced4 authored by 吴春梅's avatar 吴春梅

feat:货源清单——添加供应商物料

parent deb7822b
...@@ -122,4 +122,5 @@ export default { ...@@ -122,4 +122,5 @@ export default {
'material.button.add': 'add', 'material.button.add': 'add',
'material.modal.selectMaterial.title': 'Select material', 'material.modal.selectMaterial.title': 'Select material',
'material.costPrice.pattern': 'Please fill in the number and keep up to four decimal places', 'material.costPrice.pattern': 'Please fill in the number and keep up to four decimal places',
'material.add.supplier.material': 'Add supplier material',
} }
\ No newline at end of file
...@@ -122,4 +122,5 @@ export default { ...@@ -122,4 +122,5 @@ export default {
'material.button.add': '덧붙이다', 'material.button.add': '덧붙이다',
'material.modal.selectMaterial.title': '재료 선택', 'material.modal.selectMaterial.title': '재료 선택',
'material.costPrice.pattern': '숫자를 기입하고 최대 네 자리의 소수를 보존하십시오', 'material.costPrice.pattern': '숫자를 기입하고 최대 네 자리의 소수를 보존하십시오',
'material.add.supplier.material': '공급자 자료 추가',
} }
\ No newline at end of file
...@@ -122,4 +122,5 @@ export default { ...@@ -122,4 +122,5 @@ export default {
'material.button.add': '添加', 'material.button.add': '添加',
'material.modal.selectMaterial.title': '选择物料', 'material.modal.selectMaterial.title': '选择物料',
'material.costPrice.pattern': '请填写数字且最多保留四位小数', 'material.costPrice.pattern': '请填写数字且最多保留四位小数',
'material.add.supplier.material': '添加供应商物料'
} }
\ No newline at end of file
import { ISchema } from "@formily/antd";
import { getIntl } from 'umi';
import { Cascader } from 'antd';
import TableModal from '@/pages/member/components/TableModal';
import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch';
import { FORM_FILTER_PATH } from '@/formSchema/const';
import { getProductGoodsGetSubGoodsList } from '@/services/ProductV2Api'
import { fetchBrand, fetchCategoryData, useAsyncCascader } from '../common/useGetTableSearchData';
import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect';
interface Props {
visible: boolean,
setVisible?: (bool) => void,
handleOnOk?: () => void,
checkedValue?: any
}
export default ((props: Props) => {
const { visible = false, setVisible, handleOnOk, checkedValue = [] } = props
const intl = getIntl();
const handleFetchData = async (params) => {
const { data = {} } = await getProductGoodsGetSubGoodsList(params);
return data
}
const columns = [
{
title: intl.formatMessage({ id: 'material.supplier.name', defaultMessage: '供应商名称' }),
dataIndex: 'userName'
},
{
title: intl.formatMessage({ id: 'material.name', defaultMessage: '物料名称' }),
dataIndex: 'name'
},
{
title: intl.formatMessage({ id: 'material.type', defaultMessage: '规格型号' }),
dataIndex: 'type'
},
{
title: intl.formatMessage({ id: 'material.category', defaultMessage: '品类' }),
dataIndex: 'category',
render: (text, record) => (record?.customerCategory?.category?.name)
},
{
title: intl.formatMessage({ id: 'material.brand', defaultMessage: '品牌' }),
dataIndex: 'brand',
render: (text, record) => (record.brand?.name)
},
{
title: intl.formatMessage({ id: 'material.unit', defaultMessage: '单位' }),
dataIndex: 'unitName'
}
];
const suppilerSchema: ISchema = {
type: 'object',
properties: {
layout: {
type: 'object',
"x-component": 'mega-layout',
properties: {
userName: {
type: 'string',
'x-component': 'Search',
'x-component-props': {
placeholder: intl.formatMessage({ id: 'material.supplier.name', defaultMessage: '供应商名称' }),
align: 'flex-left',
},
},
[FORM_FILTER_PATH]: {
type: 'object',
'x-component': 'flex-layout',
'x-component-props': {
rowStyle: {
justifyContent: "flex-start",
},
colStyle: {
marginRight: 20,
},
},
properties: {
name: {
type: 'string',
'x-component-props': {
placeholder: intl.formatMessage({ id: 'material.name', defaultMessage: '物料名称' }),
allowClear: true,
},
},
categoryId: {
type: 'string',
'x-component': 'Cascader',
'x-component-props': {
placeholder: intl.formatMessage({ id: 'material.category', defaultMessage: '品类' }),
allowClear: true,
style: { width: '150px' },
showSearch: true,
fieldNames: { label: 'title', value: 'id', children: 'children' },
},
},
brandId: {
type: 'string',
enum: [],
'x-component-props': {
placeholder: intl.formatMessage({ id: 'material.brand', defaultMessage: '品牌' }),
allowClear: true,
showSearch: true,
style: { width: '150px' },
},
},
type: {
type: 'string',
'x-component-props': {
placeholder: intl.formatMessage({ id: 'material.type', defaultMessage: '规格型号' }),
allowClear: true,
}
},
submit: {
'x-component': 'Submit',
'x-mega-props': {
span: 1,
},
'x-component-props': {
children: intl.formatMessage({ id: 'balance.accountsReceivable.invoice.schema.submit' }),
},
},
},
},
},
},
}
};
return (
<TableModal
modalType='Drawer'
visible={visible}
onClose={() => setVisible(false)}
title={intl.formatMessage({ id: 'material.add.supplier.material', defaultMessage: '添加供应商物料' })}
columns={columns}
schema={suppilerSchema}
onOk={handleOnOk}
fetchData={handleFetchData}
tableProps={{
rowKey: 'id',
}}
components={{ Cascader }}
effects={($, actions) => {
useStateFilterSearchLinkageEffect($, actions, 'userName', FORM_FILTER_PATH);
useAsyncCascader('categoryId', fetchCategoryData)
useAsyncSelect('brandId', fetchBrand, ["name", "id"])
}}
mode={"radio"}
value={checkedValue}
/>
)
})
\ No newline at end of file
...@@ -22,7 +22,8 @@ const Operation = (props) => { ...@@ -22,7 +22,8 @@ const Operation = (props) => {
const id = props.form.getFieldValue(`datas.${index}.id`); const id = props.form.getFieldValue(`datas.${index}.id`);
const { editable } = props const { editable } = props
const handleEdit = () => { const handleEdit = () => {
props.form.setFieldState(`datas.${index}.*(!id,name)`, (state) => { const str = props.form.getFieldValue('datas')[index]?.supplierMaterial ? `datas.${index}.*(!id,name,goodsNo)` : `datas.${index}.*(!id,name)`
props.form.setFieldState(str, (state) => {
FormPath.setIn(state, 'editable', true); FormPath.setIn(state, 'editable', true);
}) })
} }
......
...@@ -14,6 +14,7 @@ import { getMemberAbilityMaintenanceSubOrdinateMemberList } from '@/services/Mem ...@@ -14,6 +14,7 @@ import { getMemberAbilityMaintenanceSubOrdinateMemberList } from '@/services/Mem
import Operation from './components/operation'; import Operation from './components/operation';
import { schema } from './schema/sourceListSchema'; import { schema } from './schema/sourceListSchema';
import { getIntl } from 'umi'; import { getIntl } from 'umi';
import AddMaterialModal from './addMaterialModal'
const intl = getIntl(); const intl = getIntl();
...@@ -44,13 +45,29 @@ const SourceList = () => { ...@@ -44,13 +45,29 @@ const SourceList = () => {
const [checkedValue, setCheckedValue] = useState([]); const [checkedValue, setCheckedValue] = useState([]);
const [loading, setLoading] = useState<boolean>(false); const [loading, setLoading] = useState<boolean>(false);
const [unsaved, setUnsaved] = useState(false); const [unsaved, setUnsaved] = useState(false);
const [materialVisible, setMaterialVisible] = useState<boolean>(false);
const intl = useIntl(); const intl = useIntl();
const handleOpenModal = () => { const handleOpenModal = (_type: string) => {
const data = formActions.getFieldValue('cacheData'); const data = formActions.getFieldValue('cacheData');
const isEffective = data.filter((_item) => _item.status) //未改变之前的逻辑,把添加供应商、物料数据分开
setCheckedValue(isEffective); let _data = []
setVisible(true); const materialData = data.filter(item => {
if(!item.supplierMaterial) {
_data.push(item)
}
return item.supplierMaterial
})
if( _type === '1') {
const isEffective = data.filter((_item) => _item.status && !_item?.supplierMaterial)
setCheckedValue(_data);
setVisible(true);
} else {
const value = materialData?.length > 0 ?
[{...materialData[0], id: materialData[0]?.materialId || materialData[0]?.goodsId}] : []
setCheckedValue(value)
setMaterialVisible(true)
}
} }
useEffect(() => { useEffect(() => {
...@@ -74,12 +91,20 @@ const SourceList = () => { ...@@ -74,12 +91,20 @@ const SourceList = () => {
}, []) }, [])
const renderAddition = () => ( const renderAddition = () => (
<div className={styles.addition} onClick={handleOpenModal}> <>
<PlusOutlined /> <div className={styles.addition} onClick={() => handleOpenModal('1')}>
<span className={styles.text}> <PlusOutlined />
{intl.formatMessage({ id: 'material.edit.supplier', defaultMessage: '编辑供应商' })} <span className={styles.text}>
</span> {intl.formatMessage({ id: 'material.edit.supplier', defaultMessage: '编辑供应商' })}
</div> </span>
</div>
<div className={styles.addition} onClick={() => handleOpenModal('2')}>
<PlusOutlined />
<span className={styles.text}>
{intl.formatMessage({ id: 'material.add.supplier.material', defaultMessage: '添加供应商物料' })}
</span>
</div>
</>
) )
const handleFetchData = async (params) => { const handleFetchData = async (params) => {
...@@ -141,7 +166,7 @@ const SourceList = () => { ...@@ -141,7 +166,7 @@ const SourceList = () => {
* 勾选数组 [1_1], * 勾选数组 [1_1],
* 那么 [1_2] 就是删除的 * 那么 [1_2] 就是删除的
*/ */
const addList = []; const addList = [];
selectRowRecord.forEach((_item) => { selectRowRecord.forEach((_item) => {
if (!currentMemberIdAndRoleIdList.includes(`${_item.memberId}_${_item.roleId}`)) { if (!currentMemberIdAndRoleIdList.includes(`${_item.memberId}_${_item.roleId}`)) {
...@@ -153,7 +178,9 @@ const SourceList = () => { ...@@ -153,7 +178,9 @@ const SourceList = () => {
const isEnable = selectRow.includes(`${_item.memberId}_${_item.roleId}`) const isEnable = selectRow.includes(`${_item.memberId}_${_item.roleId}`)
return { return {
..._item, ..._item,
status: !isEnable ? 0 : 1 // status: !isEnable ? 0 : 1, ??
status: 1,
supplierMaterial: false, //false——选择供应商,true——添加供应商物料
} }
}); });
...@@ -163,6 +190,48 @@ const SourceList = () => { ...@@ -163,6 +190,48 @@ const SourceList = () => {
setUnsaved(true) setUnsaved(true)
} }
const onAddMaterialOk = (selectRow = [], selectRowRecord = []) => {
if(selectRow?.length === 0 ) {
setMaterialVisible(false)
return
}
const currentData = selectRowRecord[0]
const cacheData = formActions.getFieldValue('cacheData');
const index = cacheData.findIndex(item => (item.supplierMaterial))
let addList = cacheData
if(index !== -1 && cacheData[index]?.materialId == currentData?.id) {
formActions.setFieldValue('cacheData', addList)
formActions.setFieldValue('datas', addList)
setMaterialVisible(false)
setUnsaved(true)
}
//修改之前所选物料||从未加入物料
if((index !== -1 && cacheData[index]?.materialId !== currentData?.id) || index == -1) {
index !== -1 ? addList.splice(index, 1) : ''
addList.push({
id: currentData?.id,
name: currentData?.userName,
goodsNo: currentData?.code,
memberId: currentData?.memberId,
roleId: currentData?.memberRoleId,
userName: currentData?.contactMemberName,
phone: currentData?.contactMemberPhone,
manufacturer: currentData?.materialsManufacturer,
origin: currentData?.materialsOrigin,
departure: currentData?.materialsDeparture,
deliveryCycle: currentData?.materialsDeliverPeriod,
deliveryMethod: currentData?.materialsDeliveryMethod,
goodsId: currentData?.id,
status: 1,
supplierMaterial: true, //false——选择供应商,true——添加供应商物料
})
}
formActions.setFieldValue('cacheData', addList)
formActions.setFieldValue('datas', addList)
setMaterialVisible(false)
setUnsaved(true)
}
const handleSubmit = async (value: any) => { const handleSubmit = async (value: any) => {
const { cacheData } = value; const { cacheData } = value;
setLoading(true) setLoading(true)
...@@ -260,6 +329,12 @@ const SourceList = () => { ...@@ -260,6 +329,12 @@ const SourceList = () => {
mode={"checkbox"} mode={"checkbox"}
value={checkedValue} value={checkedValue}
/> />
{ materialVisible && <AddMaterialModal
visible={materialVisible}
setVisible={setMaterialVisible}
handleOnOk={onAddMaterialOk}
checkedValue={checkedValue}
/>}
<Prompt when={unsaved} message={intl.formatMessage({ id: 'common.tip.save.confirm' }, { default: '您还有未保存的内容,是否确定要离开?' })} /> <Prompt when={unsaved} message={intl.formatMessage({ id: 'common.tip.save.confirm' }, { default: '您还有未保存的内容,是否确定要离开?' })} />
</AnchorPage> </AnchorPage>
) )
......
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