'use strict'

/**
 * Created by Tony on 2021/11/3.
 */

let adHocTaskObj = {
    currentRationRepId: '',
    currentRationLibId: '',
    iniPage: function() {
        this._getCompilationList();
    },
    _getCompilationList: function(){
        let me = adHocTaskObj, params = {};
        CommonAjax.postEx("report_tpl_api/getCompilationList", params, 20000, true, function(result){
                for (let item of result) {
                    $("#compilations").append("<option value='" + item._id + "'>" + item.name + "</option>");
                }
                me.changeCompilation($("#compilations").get(0));
                me.currentRationRepId = $("#compilations").get(0).value;
            }, null, null
        );
    },
    changeCompilation: function(dom) {
        $("#rations").empty();
        ///rationRepository/api
        let compilationId = dom.value;
        CommonAjax.post('/rationRepository/api/getRationLibsByCompilation', {compilationId: compilationId}, function (rstData) {
            $('#rations').empty();
            for(let rationLib of rstData){
                let opt = `<option value="${rationLib.ID}">${rationLib.dispName}</option>`;
                $('#rations').append(opt);
            }
            adHocTaskObj.currentRationLibId = $("#rations").get(0).value;
        });
    },
    changeRationRepository: function(dom) {
        adHocTaskObj.currentRationLibId = dom.value;
    },
    createDesktopMdb: function() {
        let params = {};
        params.compilationId = adHocTaskObj.currentRationRepId;
        params.rationLibId = adHocTaskObj.currentRationLibId;
        params.hasRationTree = $("#eleRationTree").get(0).checked;
        params.hasRation = $("#eleRationItems").get(0).checked;
        params.hasAssistRation = $("#eleAssistRationItems").get(0).checked;
        params.hasGLJ = $("#eleAllGLJ").get(0).checked;
        params.hasCOE = $("#eleCOE").get(0).checked;
        CommonAjax.postEx('/adHoc_report_api/createDesktopMdb', params, 10000, false, function (result) {
            console.log(`result: `);
            console.log(result);
        });
    }
};