/**
 * Created by Zhong on 2017/9/28.
 */
let optionsOprObj = {
    options: null,
    optionsTypes: {GENERALOPTS: 'GENERALOPTS', COLOROPTS: 'COLOROPTS'},
    rationQuanACToBillsQuan: $('#generalOpts1'),
    rationQuanACToRationUnit: $('#generalOpts2'),
    getOptions: function () {
        let me = this;
        me.options = projectOptins;
        let gOpts = me.options[me.optionsTypes.GENERALOPTS];
        if(gljUtil.isDef(gOpts)){
            for(let attr in gOpts){
                me[attr].prop('checked', gOpts[attr]);
            }
        }
    },
    saveOptions: function (type, opts) {
        let optSettingType = 'options.' + type;
        let postData = Object.create(null);
        postData[optSettingType] = opts;
        CommonAjax.post('/options/saveOptions', {optSetting: postData});
    },
    //更新optionsOprObj对象options数据
    updateOptions: function (options, updateObj) {
        if(gljUtil.isDef(options[updateObj.type])){
            options[updateObj.type][updateObj.opt] = updateObj.value;
        }
    },
    getOptsByType: function (options, type) {
        return gljUtil.isDef(options[type]) ? options[type] : null;
    },
    getOption: function (type, optionName) {
        if(!gljUtil.isDef(optionName)){
            return this.options&&gljUtil.isDef(this.options[type]) ? this.options[type] : null;
        }
        else {
            return this.options&&gljUtil.isDef(this.options[type][optionName])
                ? this.options[type][optionName]
                    : optionName === this.optionsTypes.GENERALOPTS
                    ? true
                : null;
        }
    },
    needToSaveGeneralOpts: function () {
        let v1 = this.rationQuanACToBillsQuan.prop('checked');
        let v2 = this.rationQuanACToRationUnit.prop('checked');
        let orgV1 = this.getOption(this.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan');
        let orgV2 = this.getOption(this.optionsTypes.GENERALOPTS, 'rationQuanACToRationUnit');
        return v1 !== orgV1 || v2 !== orgV2;
    }
};


$('#poj-set').on('shown.bs.modal', function () {
    let orgV1 = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan');
    let orgV2 = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToRationUnit');
    optionsOprObj.rationQuanACToBillsQuan.prop('checked', orgV1);
    optionsOprObj.rationQuanACToRationUnit.prop('checked', orgV2);

});
//选项移到了项目属性的系统选项中
/*optionsOprObj.rationQuanACToBillsQuan.click(function () {
    let value = optionsOprObj.rationQuanACToBillsQuan.checked;
    optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToBillsQuan', value: value});
    optionsOprObj.saveOptions(optionsOprObj.optionsTypes.GENERALOPTS, optionsOprObj.getOptsByType(optionsOprObj.options, optionsOprObj.optionsTypes.GENERALOPTS));
});
optionsOprObj.rationQuanACToRationUnit.click(function () {
    let value = optionsOprObj.rationQuanACToRationUnit.checked;
    optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToRationUnit', value: value});
    optionsOprObj.saveOptions(optionsOprObj.optionsTypes.GENERALOPTS, optionsOprObj.getOptsByType(optionsOprObj.options, optionsOprObj.optionsTypes.GENERALOPTS));
});*/
