/**
 * Standard Ration Lib
 * Created by Mai on 2017/5/16.
 */
/*var rationChapterSpread, sectionRationsSpread;*/
var rationLibObj = {
    searchLimit: 50,
    searchMode: 0,
    libType: {complementary: 0, std: 1},
    compleRationLibId: 'compleRationLib',
    doAfterGetRationTree: null, //获取章节树回调
    doAfterLoadGetRations: null, //获取章节树下定额后回调
    rationChapterSpread: null,
    sectionRationsSpread: null,
    resultSpread: null,
    rationChapterTreeController: null,
    refreshSettingForHint: function () {
        TREE_SHEET_HELPER.initSetting($('#stdSectionRations')[0], rationLibObj.sectionRationsSetting);
    },
    checkSpread: function () {
        if (!this.rationChapterSpread) {
            this.rationChapterSpread = SheetDataHelper.createNewSpread($('#stdRationChapter')[0]);
            this.rationChapterSpread.getSheet(0).options.rowHeaderVisible = false;
            sheetCommonObj.spreadDefaultStyle(this.rationChapterSpread);
            this.rationChapterSpread.getSheet(0).name('stdRationLib_chapter');
            this.rationChapterSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onChapterSpreadCellDoubleClick);
        }
        if (!this.sectionRationsSpread) {
            this.sectionRationsSpread = SheetDataHelper.createNewSpread($('#stdSectionRations')[0]);
            this.sectionRationsSpread.getSheet(0).setColumnWidth(0, 1, GC.Spread.Sheets.SheetArea.rowHeader);
            sheetCommonObj.spreadDefaultStyle(this.sectionRationsSpread);
            if (!projectReadOnly) {
                this.sectionRationsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onRationSpreadCellDoubleClick);
            }
            this.refreshSettingForHint();
        }
    },
    refreshSpread: function () {
        if (this.rationChapterSpread) {
            this.rationChapterSpread.refresh();
        }
        if (this.sectionRationsSpread) {
            this.sectionRationsSpread.refresh();
        }
        if(this.resultSpread){
            this.resultSpread.refresh();
        }
    },
    loadStdRationLibs: async function () {
        let select = $('#stdRationLibSelect');
        select.empty();
        let ration_lib = projectObj.project.projectInfo.engineeringInfo.ration_lib;
        ration_lib.push({
            isDefault: false,
            id: rationLibObj.compleRationLibId,
            name: '我的补充定额'
        });
        const receiveList = await ajaxPost('/pm/api/getReceiveLibList', { user_id: userID, libType: commonConstants.ShareLibType.RATION_LIB });
        const otherCompleLibs = receiveList.map(user => ({ name: `${user.real_name}的补充定额库`, isDefault: false, id: `${rationLibObj.compleRationLibId}*${user._id}`}));
        ration_lib.push(...otherCompleLibs);
        let selectedRationLib = sessionStorage.getItem('stdRationLib');
        ration_lib.forEach(function (data) {
            let option = $('