/**
 * 选择绩效考核指标弹框
 *
 * Created by likui on 2019/8/22.
 */
'use strict';
var page = {
    el: {
        tb: '#tb',
        dimensionId: '#dimensionId',
        dimensionCode: '#dimensionCode'
    }, initQuotaDataGrid: function () {
        $(page.el.tb).datagrid({
            queryParams: {
                status: 1
            },
            loadMsg: '数据远程载入中,请等待...',
            singleSelect: false,
            checkbox: true,
            height: 450,
            columns: [[
                {
                    field: 'ck',
                    checkbox: true
                },
                {
                    field: 'quotaCode',
                    title: '指标编码',
                    width: 100
                },
                {
                    field: 'quotaDesc',
                    title: '指标描述',
                    width: 200
                },
                {
                    field: 'dimensionName',
                    title: '考核维度',
                    width: 100
                }
            ]],
            onLoadSuccess: function (data) {
                var idAry = quotaIds.split(",");
                $.each(data.rows, function (index, item) {
                    if (idAry.indexOf(item.id + '') != -1) {
                        $(page.el.tb).datagrid("checkRow", index);
                    }
                });
            },
        });
    },
    searchData: function () {
        var dimensionCode = $(page.el.dimensionCode).combobox('getValue');
        if (dimensionCode) {
            var queryParams = $(page.el.tb).datagrid('options').queryParams;
            queryParams.dimensionCode = dimensionCode;
            $(page.el.tb).datagrid('options').url = g.ctx + 'pc/spe/supAppraiseQuota/rest/list?page=1&rows=10000';
            $(page.el.tb).datagrid('load');
        } else {
            $(page.el.tb).datagrid("loadData", {total: 0, rows: []});
        }
    }, confirmChose: function () {
        var rows = $(page.el.tb).datagrid('getChecked');
        var dimensionId = $(page.el.dimensionId).val();
        var dimensionCode = $(page.el.dimensionCode).combobox('getValue');
        var dimensionName = $(page.el.dimensionCode).combobox('getText');

        return {
            rows: rows,
            dimension: {id: dimensionId, dimensionCode: dimensionCode, dimensionName: dimensionName}
        };
    }
}
$(function () {
    $(page.el.dimensionCode).combobox({
        valueField: 'dimensionCode',
        textField: 'dimensionName',
        url: g.ctx + 'pc/spe/supAppraiseDimension/rest/listAll',
        queryParams: {choseDimIds: choseDimIds},
        editable: false,
        prompt: '--- 请选择 ---',
        panelHeight: 'auto',
        panelWidth: 300,
        loadFilter: function (row) {
            console.log(row)
            let result = []
            $.each(row, function (idx, itm) {
                if (choseDimIds.indexOf(itm.dimensionCode) !== -1) {
                    result.push(itm)
                }
            })
            console.log(result)
            return result;
        },
        onSelect: function (data) {
            $(page.el.dimensionId).val(data.id);
        }
    });

    page.initQuotaDataGrid();
});
