/**
 * Created by Mai on 2017/6/21.
 */

var projectInfoObj = {
    projectInfo: null,
    getFullPathHtml: function (proj) {
        let fullPath = [], i, pm = '<span class="text-truncate"><a href="/pm">项目管理</a></span>', angleRight = '<span class="text-truncate"><i class="fa fa-angle-right fa-fw"></i></span>';
        if (proj) {
            let pathArr = proj.fullPath;
            let engName = pathArr[pathArr.length -2] || '',
                projectName = pathArr[pathArr.length -3] || '',
                folderName = pathArr[pathArr.length -4] || '';
            let newHtml = `   <span data-toggle="tooltip" data-placement="bottom" data-original-title="${folderName}"><i class="fa fa-folder-open-o"></i>...</span>
                <span class="text-muted px-1">\</span>
                <span data-toggle="tooltip" data-placement="bottom" data-original-title="${projectName}"><i class="fa fa-cubes"></i>...</span>
                <span class="text-muted px-1">\</span>
                <span data-toggle="tooltip" data-placement="bottom" data-original-title="${engName}"><i class="fa fa-cube"></i>...</span>
                <span class="text-muted px-1">\</span>
                 <span><i class="fa fa-sticky-note-o"></i></span>
                <span class="text-truncate"  data-toggle="tooltip" data-placement="bottom" data-original-title="${proj.name}">&nbsp;${proj.name}</span>
                ${projectReadOnly ?
                '<span data-toggle="tooltip" data-placement="bottom" data-original-title="当前的工程状态为“只读”，如果要进行编辑，请在项目管理-分享界面，使用“拷贝工程”功能。">(只读)</span>' 
                : ''}
                ${projectCooperate ? 
                '<span data-toggle="tooltip" data-placement="bottom" data-original-title="当前的工程状态为“协作”，可直接编辑分享人的原始数据。">(协作)</span>'
                : ''}`;
            fullPath.push(newHtml);

        }
        return fullPath.join('');
    },
    showProjectInfo: function (proj) {
        var that = this;
        CommonAjax.post('/pm/api/getProject', {"user_id": userID, "proj_id": scUrlUtil.GetQueryString('project')}, function (data) {
            if (data) {
                that.projectInfo = data;
                if(!data.engineeringInfo.billsGuidance_lib || data.engineeringInfo.billsGuidance_lib.length === 0){
                    $('#stdBillsGuidanceTab').addClass('disabled');
                }
              /*  else {
                    $('#stdBillsGuidanceTab').text(data.engineeringInfo.billsGuidance_lib[0].type === 1 ? '清单指引' : '清单精灵');
                }*/

                //init decimal
                setDecimal(decimalObj, data.property.decimal);
                billsQuanDecimal.datas = data.property.billsQuantityDecimal || [billsDecimalView.angleDecimal];
                basicInfoView.orgDatas = data.property.basicInformation ? basicInfoView.toViewDatas(data.property.basicInformation) : [];
                projFeatureView.orgDatas = data.property.projectFeature ? projFeatureView.toViewDatas(data.property.projectFeature) : [];
                $('#fullpath').html(that.getFullPathHtml(that.projectInfo));
                $("[data-toggle='tooltip']").tooltip();
            }
        });
    }
};
