CRM如何过滤查找类型的控件
1.项目场景:
提示:在crm系统中过滤查找类型的控件
# 2.问题描述:
:在一次做项目是发现查找类型的控件过滤在每次过滤时只是在原有的基础上过滤 而不是清空原有的过滤 使用当前的过滤:我原本是这样写的
setEntityOrzOrOffice(entityName: string, isSetFirstValue = false) {
if (ent.type !== 1) return
// 查找多对多关系
var odata = $select=${entityName}id&$filter=systemuserid eq ${util.trimID(ent.getUserId())}
service.retrieveSync(new_systemuser_${entityName}set
, odata, (data: any) => {
console.log(data)
if (data && data.value && data.value.length > 0) {
if (data.value.length > 1) {
// 需要赋值第一个时
this.setOrzOrOfficeValue(isSetFirstValue, data, entityName, false)
// 多个则查找过滤
var ids = data.value.map((item: any) => { return item[${entityName}id
] })
attr(entityName).require().addFilter(<filter ><condition attribute='${entityName}id' operator='in'><value>${ids.join('</value><value>')}</value></condition></filter>
)
} else {
// 只有一个则带出默认值
this.setOrzOrOfficeValue(true, data, entityName, true)
}
}
}, (errMsg: string) => {
dialog.alert(errMsg)
})
}
private setOrzOrOfficeValue(isSetFirstValue: boolean, data: any, entityName: string, isDisable: boolean) {
if (isSetFirstValue === true) {
var currentid = data.value[0][${entityName}id
]
service.retrieveSync(
entityName,$select=${entityName}id,new_name&$filter=${entityName}id eq ${currentid}
,
(orzdata: any) => {
if (orzdata && orzdata.value) {
attr(entityName).disable(isDisable).setLookup(entityName, currentid, orzdata.value[0].new_name)
}
})
}
}
# 3.原因分析:
当我需要点击按钮 重复过滤时,我需要将原来的过滤条件清除掉
**# 4.解决方案:
使用removePreSearch清楚原有的筛选条件
使用addPreSearch添加后面的筛选条件
advancebillingChange() {
attr(‘new_contract’).removePreSearch(preSearchHandler)
var advancebilling = attr(‘new_advancebilling’).val()
if (advancebilling === true) {
attr('new_contract').addPreSearch(preSearchHandler)
} else {
attr('new_contract').addPreSearch(preSearchHandler)
}
}
先定义一个用于清楚筛选条件的function
function preSearchHandler() {
findfetchxml()
}
后面定义的是控件筛选的条件
function findfetchxml() {
var paras
var advancebilling = attr(‘new_advancebilling’).val()
console.log(advancebilling)
if (advancebilling === true) {
paras = {
head: JSON.stringify({ entityId: 0 }),
operate: ‘0’,
Isadvancebilling: ‘1’
}
} else {
paras = {
head: JSON.stringify({ entityId: 0 }),
operate: ‘0’,
Isadvancebilling: ‘0’
}
}
var ids: any
service.execActionSync(‘new_ActionGetContractId’, paras, (data: any) => {
if (data) {
var records = JSON.parse(JSON.parse(data).OutPutResult)
ids = JSON.parse(records.data)
}
}, (errMsg: string) => {
dialog.alert(errMsg)
})
attr('new_contract').addCustomFilter(`<filter ><condition attribute='new_contractid' operator='in'><value>${ids.join('</value><value>')}</value></condition></filter>`)
}
来源:oschina
链接:https://my.oschina.net/u/4280951/blog/4836487