//атрибуты
"NrbContractNumber": {
    "contentType": this.Terrasoft.ContentType.SEARCHABLE_TEXT,
    "searchableTextConfig": {
        "listAttribute": "ContractNumberSearchList",
        "prepareListMethod": "prepareContractNumberSearchList",
        "listViewItemRenderMethod": "onContractNumberSearchListViewItemRender",
        "itemSelectedMethod": "onContractSearchItemSelected"
    },
},
"ContractNumberSearchList": {
    "dataValueType": Terrasoft.DataValueType.COLLECTION
},
 
//методы
init: function () {
    this.callParent(arguments);
    this.set("ContractNumberSearchList", new Terrasoft.Collection());
},
 
prepareContractNumberSearchList: function (filterValue) {
    if (filterValue.length >= 3) {
        this.searchContractByNumber(filterValue, this.loadSearchList, this);
    } else {
        this.clearSearchList("ContractNumberSearchList");
    }
},
 
searchContractByNumber: function (contractNumber, callback, scope) {
    const esq = Ext.create("Terrasoft.EntitySchemaQuery", {
        rootSchemaName: "NrbContract",
        rowCount: 10
    });
 
    esq.addColumn("Id", "Id");
    esq.addColumn("NrbNumber", "NrbNumber");
    esq.addColumn("NrbAccount.Id", "AccountId");
    esq.addColumn("NrbAccount.Name", "AccountName");
    esq.addColumn("NrbAccount.NrbKpp", "AccountKpp");
    esq.addColumn("NrbAccount.NrbTIN", "AccountTin");
    esq.addColumn("NrbAccount.NrbState.Name", "AccountState");
 
    esq.filters.addItem(Terrasoft.createColumnIsNotNullFilter("NrbAccount"));
    esq.filters.addItem(Terrasoft.createColumnFilterWithParameter(Terrasoft.ComparisonType.START_WITH, "NrbNumber", contractNumber));
 
    esq.getEntityCollection(function (response) {
        Ext.callback(callback, scope, [response, "ContractNumberSearchList"]);
    }, scope || this);
},
 
loadSearchList: function (response, listName) {
    var list = this.get(listName);
    list.clear();
    list.loadAll(response.collection);
},
 
onContractNumberSearchListViewItemRender: function (item) {
    if (Ext.isEmpty(item)) {
        return;
    } 
    item.displayValue = item.values.NrbNumber;
    var itemValue = item.value = item.values.Id;
 
    var values = [
        item.values.NrbNumber,
        item.values.AccountName,
        item.values.AccountTin,
        item.values.AccountKpp,
        item.values.AccountState
    ].filter(function (item) {
        return !Ext.isEmpty(item);
    });
 
    var tpl = "<div	class=\"listview-item-info\" data-value=\"{0}\"> {1} </div>";
    item.customHtml = item.values.customHtml = this.Ext.String.format(tpl, itemValue, values.join(' | '));
},
 
onContractSearchItemSelected: function (contract) {
    if (Ext.isEmpty(contract)) {
        return;
    }
 
    this.loadLookupDisplayValue("Account", contract.values.AccountId);
    this.loadLookupDisplayValue("NrbContract", contract.values.Id);
    this.set("NrbName", contract.values.AccountName);
    this.set("NrbInn", contract.values.AccountTin);
    this.set("NrbKpp", contract.values.AccountKpp);
},

 

Нравится

Поделиться

2 комментария

а как это выглядит? :)

Присоединяюсь к вопросу выше)

Показать все комментарии