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

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

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