/**
 * 配合比相关
 *
 * @author CaiAoLin
 * @date 2017/7/10
 * @version
 */
let mixRatioSpread = null;
let machineSpread = null;
let isDeleting = false;
$(document).ready(function() {

    // 切换tab触发refresh
    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
        currentTag = $(e.target).data('name');

        // 获取工料机当前选中的行号
        let projectGLJId = 0;
        if (currentTag === "mix-ratio") {
            if (mixRatioSpread === null) {
                mixRatioSpread = new CompositionSpread();
                mixRatioSpread.init(currentTag);
                mixRatioSpread.initRightClick(currentTag);
                mixRatioSpread.successCallback = compositionSuccess;
            }

            // 筛选数据显示(显示混凝土、砂浆、配合比)
            projectGLJSheet.filterData('unit_price.type', [GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR, GLJTypeConst.MIX_RATIO]);
            projectGLJSheet.selectRow(projectGLJSpread.firstMixRatioRow);
            projectGLJId = projectGLJSheet.getActiveDataByField('id');

            // 获取数据
            mixRatioSpread.getRatioData(projectGLJId);
        }

        if (currentTag === "machine") {
            if (machineSpread === null) {
                machineSpread = new CompositionSpread();
                machineSpread.init(currentTag);
                machineSpread.initRightClick(currentTag);
                machineSpread.successCallback = compositionSuccess;
            }

            // 筛选数据显示(显示普通机械)
            projectGLJSheet.filterData('unit_price.type', [GLJTypeConst.GENERAL_MACHINE]);
            projectGLJSheet.selectRow(projectGLJSpread.firstMachineRow);
            projectGLJId = projectGLJSheet.getActiveDataByField('id');

            // 获取数据
            machineSpread.getRatioData(projectGLJId);
        }

    });

});


/**
 * 成功事件
 *
 * @param {object} info
 * @return {void}
 */
function compositionSuccess(info) {
    // 成功则对相应的总消耗量进行设置
    projectGLJSheet.setCellByField('quantity', info.change, true);

    // 设置父级3个价格
    projectGLJSheet.setCellByField('unit_price.market_price', info.parentMarketPrice, false);
    projectGLJSheet.setCellByField('unit_price.base_price', info.parentBasePrice, false);
    projectGLJSheet.setCellByField('adjust_price', info.parentMarketPrice, false);
}
