/**
 * Created by zhang on 2018/9/3.
 */

$(document).ready(function () {
    const locked = lockUtil.getLocked();
    lockUtil.lockTools($(document.body), locked);
    try {
        let tem = sortJson(JSON.parse($("#originalFeature").val()));
        $("#featureList").val(JSON.stringify(tem,null,4));
    }catch (err){
        console.log(err);
    }

   $("#format").click( function() {
       try {
           let jsonText =  $("#featureList").val();
           $("#featureList").val(JSON.stringify(JSON.parse(jsonText),null,4));
       }catch (err){
           console.log(err);
           alert("输入的JSON格式有误，请重新输入！");
       }
   });
    $("#save").click(async function() {
        try {
            let libID = $("#libID").val();
            let jsonText =  $("#featureList").val();
            if(jsonText.indexOf("'")!=-1){
                alert("输入的格式不能包含 ' 位于："+jsonText.substr(jsonText.indexOf("'")-15,18));
                return;
            }
            let newFeature = await ajaxPost("/projectFeature/saveLib",{query:{ID:libID},data:{feature:JSON.parse(jsonText)}});
        }catch (err){
            console.log(err);
            alert("保存失败，请查看输入数据");
        }
    });
    $("#createNormal").click(async function() {
        let projectFeature = [
            {dispName: '工程专业', key: 'engineering', value: ''},//只读，用户新建单位工程时选择的值
            {dispName: '工程类型', key: 'projType', value: '',cellType:'comboBox',options:"住宅@公共建筑@厂房@办公"},
            {dispName: '结构类型', key: 'structureType', value: '',cellType:'comboBox',options:"排架结构@框架结构@现浇、框架结构@预制、砖混结构@外砖内模@内浇外挂@钢结构"},
            {dispName: '基础类型', key: 'baseType', value: '',cellType:'comboBox',options:"带基@框排架柱距6m以内@框排架柱距6m以外@满基筏式@满基板式@满基箱式@独立基础"},
            {dispName: '建筑特征', key: 'buildingFeature', value: '',cellType:'comboBox',options:"点式@凹式@凸式@Y式@其他"},
            {dispName: '建筑面积(m2)', key: 'buildingArea', value: '',cellType:'number'},
            {dispName: '其中地下室建筑面积(m2)', key: 'basementBuildingArea', value: '',cellType:'number'},
            {dispName: '总层数', key: 'totalFloors', value: '',cellType:'number'},
            {dispName: '地下室层数(+/-0.00以下)', key: 'basementFloors', value: '',cellType:'number'},
            {dispName: '建筑层数(+/-0.00以下)', key: 'buildingFloors', value: '',cellType:'number'},
            {dispName: '建筑物总高度(m)', key: 'buildingHeight', value: '',cellType:'number'},
            {dispName: '地下室总高度(m)', key: 'basementHeight', value: '',cellType:'number'},
            {dispName: '首层高度(m)', key: 'firstFloorHeight', value: '',cellType:'number'},
            {dispName: '裙楼高度(m)', key: 'podiumBuildingHeight', value: '',cellType:'number'},
            {dispName: '标准层高度(m)', key: 'standardFloorHeight', value: '',cellType:'number'},
            {dispName: '基础材料及装饰', key: 'baseMaterial', value: ''},
            {dispName: '楼地面材料及装饰', key: 'flooringMaterial', value: ''},
            {dispName: '外墙材料及装饰', key: 'exteriorWallMaterial', value: ''},
            {dispName: '屋面材料及装饰', key: 'roofingMaterial', value: ''},
            {dispName: '门窗材料及装饰', key: 'doorsWindowsMaterial', value: ''}
        ];
        try {
            let jsonText =  JSON.stringify(projectFeature);
            $("#featureList").val(JSON.stringify(JSON.parse(jsonText),null,4));
        }catch (err){
            console.log(err);
        }

    })


});
