Commit 042dcec6 authored by 前端-李俊鑫's avatar 前端-李俊鑫

feat: 规则配置字段条件切换调整

parent 354aac69
...@@ -31,14 +31,13 @@ const ConfigDrawer = (props: PropsType, ref) => { ...@@ -31,14 +31,13 @@ const ConfigDrawer = (props: PropsType, ref) => {
const handleOk = useCallback(() => { const handleOk = useCallback(() => {
form.validateFields().then((values) => { form.validateFields().then((values) => {
const { id, ruleEngineConfigFieldRelations } = values const { id, ruleEngineConfigFieldRelations } = values
const params = { const params = {
...paramsRef.current, ...paramsRef.current,
id, id,
ruleEngineConfigFieldRelations: ruleEngineConfigFieldRelations?.map(item => { ruleEngineConfigFieldRelations: ruleEngineConfigFieldRelations?.map(item => {
let temp = item.ruleEngineConfigFields || [] let temp = item.ruleEngineConfigFields || []
// 过滤掉没有选择'所有物料'(isQueryAll)的情况下且字段值未填写的字段数据 // 过滤出字段值不为空的字段数据和选择了'所有物料'(isQueryAll)的字段数据
let ruleEngineConfigFields: any[] = temp?.filter(i => (i.isQueryAll !== 1 && !['', undefined, null].includes(i.value))) let ruleEngineConfigFields: any[] = temp?.filter(i => (!['', undefined, null].includes(i.value) || i.isQueryAll === 1))
return { return {
...item, ...item,
// 若字段配置列表数据的长度为0,则将其置为undefined // 若字段配置列表数据的长度为0,则将其置为undefined
...@@ -46,6 +45,7 @@ const ConfigDrawer = (props: PropsType, ref) => { ...@@ -46,6 +45,7 @@ const ConfigDrawer = (props: PropsType, ref) => {
} }
}) })
} }
console.log('params', params)
setLoading(true) setLoading(true)
postRuleEngineConfigBatchSaveOrUpdate(params).then(({ code }) => { postRuleEngineConfigBatchSaveOrUpdate(params).then(({ code }) => {
if (code === 1000) { if (code === 1000) {
......
...@@ -21,12 +21,13 @@ interface PropsType { ...@@ -21,12 +21,13 @@ interface PropsType {
onOk?: (rows: any[], rowKeys: any[]) => void onOk?: (rows: any[], rowKeys: any[]) => void
onQueryAll?: (value?: any) => void onQueryAll?: (value?: any) => void
fieldCode?: string fieldCode?: string
fieldLabel?: string
selectCache?: any[] selectCache?: any[]
} }
const MaterialDrawer = (props: PropsType, ref) => { const MaterialDrawer = (props: PropsType, ref) => {
const formActions = createFormActions() const formActions = createFormActions()
const { onOk, onQueryAll, fieldCode = 'code', selectCache } = props const { onOk, onQueryAll, fieldCode = 'code', fieldLabel, selectCache } = props
const [selectedRowKeys, setSelectedRowKeys] = useState<any>([]) const [selectedRowKeys, setSelectedRowKeys] = useState<any>([])
const [selectedRows, setSelectedRows] = useState<any>([]) const [selectedRows, setSelectedRows] = useState<any>([])
...@@ -36,10 +37,23 @@ const MaterialDrawer = (props: PropsType, ref) => { ...@@ -36,10 +37,23 @@ const MaterialDrawer = (props: PropsType, ref) => {
const drawRef = useRef<HandleType>() const drawRef = useRef<HandleType>()
const isValuesChangeRef = useRef<boolean>(false) const isValuesChangeRef = useRef<boolean>(false)
const getRealCodeValue = (data: any) => {
const codeArr = fieldCode?.split('.') || []
const len = codeArr.length
if (len) {
let result = data
for (let i = 0; i < len; i++) {
result = result?.[codeArr[i]]
}
return result
}
return data['code']
}
const handleOk = useCallback(() => { const handleOk = useCallback(() => {
isValuesChangeRef.current = false isValuesChangeRef.current = false
onQueryAll?.(isQueryAll) onQueryAll?.(isQueryAll)
onOk?.(selectedRows.map(item => ({ id: item.id, value: item[fieldCode] })) , selectedRowKeys) onOk?.(selectedRows.map(item => ({ id: item.id, value: item.value })) , selectedRowKeys)
}, [selectedRows, selectedRowKeys, isQueryAll]) }, [selectedRows, selectedRowKeys, isQueryAll])
const handleShow = useCallback((params: Object) => { const handleShow = useCallback((params: Object) => {
...@@ -49,7 +63,10 @@ const MaterialDrawer = (props: PropsType, ref) => { ...@@ -49,7 +63,10 @@ const MaterialDrawer = (props: PropsType, ref) => {
return new Promise((resolve) => { return new Promise((resolve) => {
getProductGoodsGetDoesNotFreezeGoodsList(params).then(({ code, data }) => { getProductGoodsGetDoesNotFreezeGoodsList(params).then(({ code, data }) => {
if (code === 1000) { if (code === 1000) {
resolve(data) resolve({
total: data.total,
data: data.data?.map(item => ({ ...item, value: getRealCodeValue(item) }))
})
} }
}) })
}) })
...@@ -119,7 +136,7 @@ const MaterialDrawer = (props: PropsType, ref) => { ...@@ -119,7 +136,7 @@ const MaterialDrawer = (props: PropsType, ref) => {
const columns: ColumnType<any>[] = [ const columns: ColumnType<any>[] = [
{ title: 'ID', dataIndex: 'id', key: 'id', }, { title: 'ID', dataIndex: 'id', key: 'id', },
{ title: '物料编号', dataIndex: fieldCode, key: fieldCode } { title: fieldLabel, dataIndex: 'value', key: 'value' }
] ]
const columns2: ColumnType<any>[] = [ const columns2: ColumnType<any>[] = [
......
...@@ -14,6 +14,7 @@ import SelectRoles from '../SelectRoles' ...@@ -14,6 +14,7 @@ import SelectRoles from '../SelectRoles'
import { getMemberRolePage } from '@/services/MemberV2Api' import { getMemberRolePage } from '@/services/MemberV2Api'
import { conditionOptions, interrelationOptions, Filed_Type, Select_Content_Type, CONDITION_VALUE } from '../../constant' import { conditionOptions, interrelationOptions, Filed_Type, Select_Content_Type, CONDITION_VALUE } from '../../constant'
import StringDatePicker from '../StringDatePicker' import StringDatePicker from '../StringDatePicker'
import moment from 'moment'
type PropsType = { type PropsType = {
form?: FormInstance form?: FormInstance
...@@ -130,15 +131,31 @@ const ProcessRules: React.FC<PropsType> = ({ form, filedTypeOptions, onFormField ...@@ -130,15 +131,31 @@ const ProcessRules: React.FC<PropsType> = ({ form, filedTypeOptions, onFormField
form={form} form={form}
onFieldsChange={(_, _all) => { onFieldsChange={(_, _all) => {
onFormFieldsChange?.(_, _all) onFormFieldsChange?.(_, _all)
let ruleEngineConfigFieldRelations = form.getFieldValue('ruleEngineConfigFieldRelations')
// 当字段类型改变的时候,需要重置一下对应的code/value/condition // 当字段类型改变的时候,需要重置一下对应的code/value/condition
if (_[0]?.name?.[4] === 'code') { if (_[0]?.name?.[4] === 'code') {
let ruleEngineConfigFieldRelations = form.getFieldValue('ruleEngineConfigFieldRelations')
const filedTypeItem = getFiledTypeItem(_[0].value) const filedTypeItem = getFiledTypeItem(_[0].value)
ruleEngineConfigFieldRelations[_[0].name[1]].ruleEngineConfigFields[_[0].name[3]].type = filedTypeItem?.type ruleEngineConfigFieldRelations[_[0].name[1]].ruleEngineConfigFields[_[0].name[3]].type = filedTypeItem?.type
ruleEngineConfigFieldRelations[_[0].name[1]].ruleEngineConfigFields[_[0].name[3]].value = undefined // 日期格式给予'今天'的默认值
ruleEngineConfigFieldRelations[_[0].name[1]].ruleEngineConfigFields[_[0].name[3]].value = filedTypeItem?.type === Filed_Type.DATE ? moment().format('YYYY-MM-DD') : undefined
ruleEngineConfigFieldRelations[_[0].name[1]].ruleEngineConfigFields[_[0].name[3]].condition = conditionOptions[filedTypeItem?.type][0].value ruleEngineConfigFieldRelations[_[0].name[1]].ruleEngineConfigFields[_[0].name[3]].condition = conditionOptions[filedTypeItem?.type][0].value
form.setFieldsValue({ ruleEngineConfigFieldRelations }) form.setFieldsValue({ ruleEngineConfigFieldRelations })
} }
// 当字段条件改变的时候,需要重置一下对应的value
if (_[0]?.name?.[4] === 'condition') {
console.log('_', _)
console.log('ruleEngineConfigFieldRelations[_[0].name[1]].ruleEngineConfigFields[_[0].name[3]].type', ruleEngineConfigFieldRelations[_[0].name[1]].ruleEngineConfigFields[_[0].name[3]].code)
const filedTypeItem = getFiledTypeItem(ruleEngineConfigFieldRelations[_[0].name[1]].ruleEngineConfigFields[_[0].name[3]].code)
console.log('filedTypeItem', filedTypeItem)
// 字符格式切换条件的时候值的格式可能会变化,所以这里需要重置
if (filedTypeItem?.type === Filed_Type.STRING) {
ruleEngineConfigFieldRelations[_[0].name[1]].ruleEngineConfigFields[_[0].name[3]].isQueryAll = 0
ruleEngineConfigFieldRelations[_[0].name[1]].ruleEngineConfigFields[_[0].name[3]].value = undefined
}
form.setFieldsValue({ ruleEngineConfigFieldRelations })
}
}} }}
> >
<Form.Item <Form.Item
...@@ -293,6 +310,7 @@ const ProcessRules: React.FC<PropsType> = ({ form, filedTypeOptions, onFormField ...@@ -293,6 +310,7 @@ const ProcessRules: React.FC<PropsType> = ({ form, filedTypeOptions, onFormField
<SelectMaterial <SelectMaterial
onValueChange={(value) => { onMaterialChange(ruleFieldKey, fieldFieldKey, value) }} onValueChange={(value) => { onMaterialChange(ruleFieldKey, fieldFieldKey, value) }}
fieldCode={filedTypeItem?.codeAlias} fieldCode={filedTypeItem?.codeAlias}
fieldLabel={filedTypeItem?.name}
selectCache={getSelectCache(selectMaterial?.[ruleFieldKey] || {}, fieldFieldKey)} selectCache={getSelectCache(selectMaterial?.[ruleFieldKey] || {}, fieldFieldKey)}
isAll={ruleEngineConfigFields?.isQueryAll === 1} isAll={ruleEngineConfigFields?.isQueryAll === 1}
onQueryAll={(value) => { onQueryAll={(value) => {
...@@ -368,17 +386,21 @@ const ProcessRules: React.FC<PropsType> = ({ form, filedTypeOptions, onFormField ...@@ -368,17 +386,21 @@ const ProcessRules: React.FC<PropsType> = ({ form, filedTypeOptions, onFormField
</ConfigFieldCard> </ConfigFieldCard>
</div> </div>
))} ))}
<div className={styles['add']}> {
<Form.Item> // 限制3个流程规则
<Button ruleFields.length < 3 &&
type="primary" <div className={styles['add']}>
onClick={() => { <Form.Item>
ruleAdd({ relation: interrelationOptions[0].value }) <Button
}}> type="primary"
添加规则 onClick={() => {
</Button> ruleAdd({ relation: interrelationOptions[0].value })
</Form.Item> }}>
</div> 添加规则
</Button>
</Form.Item>
</div>
}
</div> </div>
) )
}} }}
......
import { isJSONString } from '@/utils'
import React, { useState, memo, useCallback, useRef, useEffect } from 'react' import React, { useState, memo, useCallback, useRef, useEffect } from 'react'
import CategoryDrawer from '../CategoryDrawer' import CategoryDrawer from '../CategoryDrawer'
import WrapSelect from '../WrapSelect' import WrapSelect from '../WrapSelect'
...@@ -34,12 +35,10 @@ const SelectMaterial = (props: PropsType) => { ...@@ -34,12 +35,10 @@ const SelectMaterial = (props: PropsType) => {
} }
useEffect(() => { useEffect(() => {
if (value) { // JSON字符串转为原数据
// JSON字符串转为原数据 const keys = value && isJSONString(value) ? JSON.parse(value) : []
const keys = JSON.parse(value) setSelectData(keys)
setSelectData(keys) onValueChange?.(keys)
onValueChange?.(keys)
}
}, [value]) }, [value])
return ( return (
......
import { isJSONString } from '@/utils'
import React, { useState, memo, useCallback, useRef, useEffect } from 'react' import React, { useState, memo, useCallback, useRef, useEffect } from 'react'
import MaterialDrawer, { RefHandleType } from '../MaterialDrawer' import MaterialDrawer, { RefHandleType } from '../MaterialDrawer'
import WrapSelect from '../WrapSelect' import WrapSelect from '../WrapSelect'
...@@ -7,13 +8,14 @@ interface PropsType { ...@@ -7,13 +8,14 @@ interface PropsType {
onValueChange?: (data: any[]) => void onValueChange?: (data: any[]) => void
value?: any value?: any
fieldCode?: string fieldCode?: string
fieldLabel?: string
onQueryAll?: (value?: any) => void onQueryAll?: (value?: any) => void
selectCache?: any[] selectCache?: any[]
isAll?: boolean isAll?: boolean
} }
const SelectMaterial = (props: PropsType) => { const SelectMaterial = (props: PropsType) => {
const { onChange, value, fieldCode = 'code', onQueryAll, onValueChange, isAll, ...rest } = props const { onChange, value, onQueryAll, onValueChange, isAll, ...rest } = props
const [selectData, setSelectData] = useState<any[]>([]) const [selectData, setSelectData] = useState<any[]>([])
const [isQueryAll, setIsQueryAll] = useState<boolean>(false) const [isQueryAll, setIsQueryAll] = useState<boolean>(false)
...@@ -42,12 +44,10 @@ const SelectMaterial = (props: PropsType) => { ...@@ -42,12 +44,10 @@ const SelectMaterial = (props: PropsType) => {
} }
useEffect(() => { useEffect(() => {
if (value) { // JSON字符串转为原数据
// JSON字符串转为原数据 const rows = value && isJSONString(value) ? JSON.parse(value) : []
const rows = JSON.parse(value) setSelectData(rows)
setSelectData(rows) onValueChange?.(rows)
onValueChange?.(rows)
}
}, [value]) }, [value])
useEffect(() => { useEffect(() => {
...@@ -66,7 +66,6 @@ const SelectMaterial = (props: PropsType) => { ...@@ -66,7 +66,6 @@ const SelectMaterial = (props: PropsType) => {
<MaterialDrawer <MaterialDrawer
ref={ref} ref={ref}
onOk={handleOk} onOk={handleOk}
fieldCode={fieldCode}
onQueryAll={_onQueryAll} onQueryAll={_onQueryAll}
{...rest} {...rest}
/> />
......
...@@ -728,6 +728,23 @@ export const downloadFile = (url, fileName) => { ...@@ -728,6 +728,23 @@ export const downloadFile = (url, fileName) => {
x.send(); x.send();
} }
export const isJSONString = (str) => {
if (typeof str == 'string') {
try {
var obj=JSON.parse(str);
if(typeof obj == 'object' && obj ){
return true;
}else{
return false;
}
} catch(e) {
return false;
}
}
return false
}
export default { export default {
isArray, isArray,
isObject, isObject,
......
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