/*
 *文件用途说明：用于评估报告打印
 *作者姓名：小严
 *制作日期：2017-09-21
 */
var ifDecoration = false;
var ifAttached = false;
var ifOther = false;
var annexNum = 1;
//var P_Money = "";
window.onload = function() {
  var ID = $("#InvestigateTable_Assessment\\.ID").val();
  GetInformationFromAssessment(ID);
  var P_Money = "";
  var IsLDF = "";
  var InLayer = "";
  var AllLayer = "";
  var Orientation = "";
  var StructureID_text = "";
  var Jzmj = "";
  var CompletedYear = "";
  var ProjectName = "";
  var LandTransferMoneyFormula = "";

  //读取评估表信息
  function GetInformationFromAssessment(id) {
    $.ajax({
      url: "/Platform/PgInvestigateTable/ReportFile/GetAssessmentByID.ashx?ID=" +
        id,
      dataType: "JSON",
      async: false,
      cache: false,
      success: function(data) {
        //加载评估表信息
        loadAssessment(data);
        //加载调查表信息
        loadInvestigateTable();
        //加载估价对象自定义概况
        loadSurvey();
        ////加载比准案例房地产状况
        //loadProperty()
        //加载装修
        if (ifDecoration) {
          loadDecoration1();
        } else {
          loadDecoration();
          $("#printdiv1").hide();
        }
        //加载附属物
        if (ifAttached) {
          loadAttached1();
        } else {
          loadAttached();
          $("#printdiv2").hide();
        }
        //加载其他
        loadOther();
        //加载房屋部位信息
        //loadHouseLocation();
      }
    });

    //加载评估表信息
    function loadAssessment(data) {
      //项目名称
      $("#Title").html(
        data.item[0]["ProjectName"] + "国有土地上住宅用房征收评估分户报告"
      );
      $("#ProjectName").html(data.item[0]["ProjectName"]);
      ProjectName = data.item[0]["ProjectName"];
      //编号
      $("#No").html(data.item[0]["AssessmentNo"]);
      //被征收人
      $("#Bzsr").html(data.item[0]["Bzsr"]);
      //房屋坐落
      $("#Fwzl").html(data.item[0]["Fwzl"]);
      //房屋部位
      // $("#Orientation").html(data.item[0]["Orientation"]);
      //所在层/总层数
      InLayer = data.item[0]["InLayer"] || "";
      AllLayer = data.item[0]["AllLayer"] || "";
      $("#Layer").html(InLayer + "/" + AllLayer);
      //落地房
      IsLDF = data.item[0]["IsLDF"];
      if (IsLDF == "是") {
        $("#Orientation").html("/");
        $("#StructureID_text").html("/");
        $("#CompletedYear").html("/");
      } else {
        //朝向
        $("#Orientation").html(data.item[0]["Orientation"]);
        //结构等级
        $("#StructureID_text").html(data.item[0]["StructureID_text"]);
        //建造年份
        $("#CompletedYear").html(data.item[0]["CompletedYear"]);
      }
      Orientation = data.item[0]["Orientation"];
      StructureID_text = data.item[0]["StructureID_text"];
      //建筑面积
      //$("#BuildingArea").html(parseFloat(data.item[0]["BuildingArea"]));
      $("#BuildingArea1").html(parseFloat(data.item[0]["BuildingArea"]));
      Jzmj = data.item[0]["Jzmj"];
      //建造年份
      //$("#CompletedYear").html(data.item[0]["CompletedYear"]);
      CompletedYear = data.item[0]["CompletedYear"];
      //地段
      $("#Section").html(data.item[0]["Section"]);
      //底层情况
      $("#Underlying").html(data.item[0]["Underlying"]);
      //土地性质
      $("#LandWay").html(data.item[0]["LandWay"]);
      //土地面积
      $("#LandArea").html(parseFloat(data.item[0]["LandArea"]));
      //独用天井使用面积
      $("#CourtyardArea").html(parseFloat(data.item[0]["CourtyardArea"]));
      //独用晒台使用面积
      $("#ShaitaiArea").html(parseFloat(data.item[0]["ShaitaiArea"]));
      //围墙类别
      $("#WallType").html(data.item[0]["WallType"]);
      //围墙面积
      $("#WallArea").html(parseFloat(data.item[0]["WallArea"]));
      //车房类别
      $("#GarageType").html(data.item[0]["GarageType"]);
      //车房房号
      $("#GarageNo").html(data.item[0]["GarageNo"]);
      //车房面积
      $("#GarageArea").html(parseFloat(data.item[0]["GarageArea"]));
      //价值时点
      var MoneyPoint = data.item[0]["MoneyPoint"].split("/");
      if (MoneyPoint.length > 1)
        $("#MoneyPoint").html(
          MoneyPoint[0] +
          "/" +
          MoneyPoint[1] +
          "/" +
          MoneyPoint[2].split(" ")[0].substring(0, 2)
        );
      else {
        MoneyPoint = data.item[0]["MoneyPoint"].split("-");
        if (MoneyPoint.length > 1)
          $("#MoneyPoint").html(
            MoneyPoint[0] +
            "/" +
            MoneyPoint[1] +
            "/" +
            MoneyPoint[2].split(" ")[0].substring(0, 2)
          );
        else $("#MoneyPoint").html(data.item[0]["MoneyPoint"].split(" ")[0]);
      }
      //结构修正系数
      $("#StructureRatio").html(parseFloat(data.item[0]["StructureRatio"]));
      //使用年限调整系数
      $("#YearRatio").html(parseFloat(data.item[0]["YearRatio"]));
      //朝向差价率
      $("#OrientationRatio").html(parseFloat(data.item[0]["OrientationRatio"]));
      //层次差价率
      $("#LayerRatio").html(parseFloat(data.item[0]["LayerRatio"]));
      //层高修正系数
      $("#LayerHighRatio").html(parseFloat(data.item[0]["LayerHighRatio"]));
      //容积率修正系数
      $("#VolumeRatio").html(parseFloat(data.item[0]["VolumeRatio"]));
      /*
       * 打印稿中显示其他因素修正系数
       */
      if (parseFloat(data.item[0]["OtherRatio"]) > 0) {
        OtherRatiohtml =
          "<tr><td colspan='3' class='tdc'>其他因素调整系数</td><td colspan='2' class='tdc'>" +
          parseFloat(data.item[0]["OtherRatio"]) +
          "</td></tr>";
        $("#PropertyTr").before(OtherRatiohtml);
        var rowspan = parseFloat($("#PropertyTd").attr("rowspan")).add(1);
        $("#PropertyTd").attr("rowspan", rowspan);
        $("#PropertyMo").attr("rowspan", rowspan);
      }
      //房屋评估价值
      $("#HousingAssessmentValue").html(
        parseFloat(data.item[0]["HousingAssessmentValue"])
      );
      //加载比准案例房地产状况
      loadProperty();
      //评估比准价格×结构修正系数×使用年限调整系数×（1±层次差价率）×（1±朝向差价率）×建筑面积
      if (parseFloat(data.item[0]["OtherRatio"]) > 0) {
        $("#Calculation_Process").html(
          P_Money +
          "×" +
          parseFloat(data.item[0]["StructureRatio"]) +
          "×" +
          data.item[0]["YearRatio"] +
          "×(1" +
          (parseFloat(data.item[0]["LayerRatio"]) < 0 ?
            parseFloat(data.item[0]["LayerRatio"]) :
            "+" + parseFloat(data.item[0]["LayerRatio"])) +
          "%)×(1" +
          (parseFloat(data.item[0]["OrientationRatio"]) < 0 ?
            parseFloat(data.item[0]["OrientationRatio"]) :
            "+" + parseFloat(data.item[0]["OrientationRatio"])) +
          "%)×" +
          parseFloat(data.item[0]["OtherRatio"]) +
          "×" +
          parseFloat(data.item[0]["Jzmj"]) +
          "=" +
          parseFloat(data.item[0]["HousingAssessmentValue"]) +
          "元"
        );
      } else {
        $("#Calculation_Process").html(
          "&nbsp;" +
          P_Money +
          "×" +
          parseFloat(data.item[0]["StructureRatio"]) +
          "×" +
          data.item[0]["YearRatio"] +
          "×(1" +
          (parseFloat(data.item[0]["LayerRatio"]) < 0 ?
            parseFloat(data.item[0]["LayerRatio"]) :
            "+" + parseFloat(data.item[0]["LayerRatio"])) +
          "%)×(1" +
          (parseFloat(data.item[0]["OrientationRatio"]) < 0 ?
            parseFloat(data.item[0]["OrientationRatio"]) :
            "+" + parseFloat(data.item[0]["OrientationRatio"])) +
          "%)×" +
          parseFloat(data.item[0]["Jzmj"]) +
          "=" +
          parseFloat(data.item[0]["HousingAssessmentValue"]) +
          "元"
        );
      }
      //装修面积
      $("#DecorateArea").html(parseFloat(data.item[0]["DecorateArea"] || 0));
      //装修评估价值
      $("#DecorateAssessedValue").html(
        parseFloat(data.item[0]["DecorateAssessedValue"] || 0)
      );
      //附属物评估价值
      $("#AttachedAssessedValue").html(
        parseFloat(data.item[0]["AttachedAssessedValue"] || 0)
      );
      LandTransferMoneyFormula = data.item[0]["LandTransferMoneyFormula"];
      //土地金额显示
      loadLandMoney();

      //加载市场价评估显示
      loadMarketPriceAssessed(data.item[0]);

      //评估总金额
      var countValue = parseFloat(data.item[0]["countValue"]);
      $("#countValue_DX").html(AmountLtoU(countValue));
      $("#countValue_XX").html(countValue + "元");
      //备注
      if (data.item[0]["Note"] != "") {
        var noteArray = data.item[0]["Note"].split("\r\n");
        var noteHtml = "";
        for (var i = 0; i < noteArray.length; i++) {
          noteHtml +=
            "<p style='margin:0;text-indent:24px;'>" + noteArray[i] + "</p>";
        }
        $("#Note").html(noteHtml);
      }
      //装修类别
      if (data.item[0]["DecorationType"] == "1") {
        ifDecoration = true;
        $("#DecorateArea").html("0");
        $("#DecorateAssessedValue").html(
          parseFloat(data.item[0]["DecorateAssessedValue"] || 0) +
          "<br>详见附件" +
          annexNum
        );
        annexNum++;
      }
      //附属物类别
      if (data.item[0]["AttachedType"] == "1") {
        ifAttached = true;
        $("#AttachedAssessedValue").html(
          parseFloat(data.item[0]["AttachedAssessedValue"] || 0) +
          "详见附件" +
          annexNum
        );
        annexNum++;
      }
    }

    function loadInvestigateTable() {
      $.ajax({
        url: "/Platform/PgInvestigateTable/ReportFile/GetInvestigateTable.ashx?id=" +
          id,
        async: false,
        success: function(data) {
          var tempData = JSON.parse(data);
          $("#BuildingArea").html(parseFloat(tempData[0]["Area"]));
        }
      });
    }
    //加载市场价评估显示
    function loadMarketPriceAssessed(data1) {
      $("#BuildingArea1")
        .parent()
        .html(
          '<table width="100% " cellpadding="0" cellspacing="0" style="table-layout: fixed; border-spacing: 0; border-collapse:collapse;">' +
          '<tr><td class="tdc BuildArea0">' +
          data1["Jzmj"] +
          "</td></tr></table>"
        );
      //
      $("#Parts")
        .parent()
        .html(
          '<table width="100% " cellpadding="0" cellspacing="0" style="table-layout: fixed; border-spacing: 0; border-collapse:collapse;">' +
          '<tr><td class="tdc Parts0" ></td></tr></table>'
        );

      $("#LayerRatio")
        .parent()
        .html(
          '<table width="100% " cellpadding="0" cellspacing="0" style="table-layout: fixed; border-spacing: 0; border-collapse:collapse;">' +
          '<tr><td class="tdc LayerRatio0" >' +
          data1["LayerRatio"] +
          "</td></tr></table>"
        );

      $("#OrientationRatio")
        .parent()
        .html(
          '<table width="100% " cellpadding="0" cellspacing="0" style="table-layout: fixed; border-spacing: 0; border-collapse:collapse;">' +
          '<tr><td class="tdc OrientationRatio0" >' +
          data1["OrientationRatio"] +
          "</td></tr></table>"
        );

      $("#StructureRatio")
        .parent()
        .html(
          '<table width="100% " cellpadding="0" cellspacing="0" style="table-layout: fixed; border-spacing: 0; border-collapse:collapse; ">' +
          '<tr><td class="tdc StructureRatio0" >' +
          data1["StructureRatio"] +
          "</td></tr></table>"
        );

      $("#YearRatio")
        .parent()
        .html(
          '<table width="100% " cellpadding="0" cellspacing="0" style="table-layout: fixed; border-spacing: 0; border-collapse:collapse;">' +
          '<tr><td class="tdc YearRatio0" >' +
          data1["YearRatio"] +
          "</td></tr></table>"
        );
      $("#HousingAssessmentValue")
        .parent()
        .html(
          '<table width="100% " cellpadding="0" cellspacing="0" style="table-layout: fixed; border-spacing: 0; border-collapse:collapse;">' +
          '<tr><td class="tdc HousingAssessmentValue0" >' +
          data1["HousingAssessmentValue"] +
          "</td></tr></table>"
        );

      $.ajax({
        url: "/Platform/PgInvestigateTable/ReportFile/GetAssessmentChildren.ashx?action=HouseLocaion&parentID=" +
          id,
        async: false,
        success: function(data) {
          if (data != null && data.length > 0) {
            //获取所有的属性值
            var keys = Object.keys(data[0]);
            //console.log(keys, "keys");
            var tempLocationName = "";
            var landhtml = "";
            var pgLandmtml =
              "<tr><td colspan='2' class='tdc'>所在层/总层数</td><td colspan='2' class='tdc'>朝向</td><td colspan='2' class='tdc'>结构</td><td colspan='2' class='tdc'>建筑面积（㎡）</td><td colspan='2' class='tdc'>建造年份</td></tr><tr><td colspan='2' class='tdc'>" +
              InLayer +
              "/" +
              AllLayer +
              "</td><td colspan='2' class='tdc'>" +
              Orientation +
              "</td > <td colspan='2' class='tdc'>" +
              StructureID_text +
              "</td><td colspan='2' class='tdc'>" +
              Jzmj +
              "</td><td colspan='2' class='tdc'>" +
              CompletedYear +
              "</td></tr> ";
            for (var item = 0; item < data.length; item++) {
              var tempItem = item;
              var nextTempItem = item + 1;
              keys.forEach(function(k) {
                var nextTempClass = "tdc " + k + nextTempItem;
                $("td." + k + tempItem)
                  .parent()
                  .append(
                    '<td style="border-left: 1px solid #000;" class="' +
                    nextTempClass +
                    '" >' +
                    data[item][k] +
                    "</td>"
                  );
              });
              landhtml +=
                "&nbsp;" +
                P_Money +
                "×" +
                parseFloat(data[item]["StructureRatio"]) +
                "×" +
                data[item]["YearRatio"] +
                "×(1" +
                (parseFloat(data[item]["LayerRatio"]) < 0 ?
                  parseFloat(data[item]["LayerRatio"]) :
                  "+" + parseFloat(data[item]["LayerRatio"])) +
                "%)×(1" +
                (parseFloat(data[item]["OrientationRatio"]) < 0 ?
                  parseFloat(data[item]["OrientationRatio"]) :
                  "+" + parseFloat(data[item]["OrientationRatio"])) +
                "%)×" +
                parseFloat(data[item]["BuildArea"]) +
                "=" +
                parseFloat(data[item]["HousingAssessmentValue"]) +
                "元<br/>";
              pgLandmtml +=
                "<tr><td colspan='2' class='tdc'>" +
                data[item]["InLayer"] +
                "/" +
                data[item]["AllLayer"] +
                "</td><td colspan='2' class='tdc'>" +
                data[item]["Orientation"] +
                "</td > <td colspan='2' class='tdc'>" +
                data[item]["StructureID_text"] +
                "</td><td colspan='2' class='tdc'>" +
                data[item]["BuildArea"] +
                "</td><td colspan='2' class='tdc'>" +
                data[item]["BuildYear"] +
                "</td></tr> ";
            }
            if (IsLDF == "是") {
              var rowspan = parseFloat($("#SurveyTd").attr("rowspan"))
                .add(2)
                .add(data.length);
              $("#SurveyTd").attr("rowspan", rowspan);
              $("#SurveyTr0").after(pgLandmtml);
            }
            $("#Calculation_Process").after(landhtml);
          } else {
            $("#house").attr("style", "display:none;");
            $("#house1").attr("style", "display:none;");
          }
        }
      });
    }

    //加载土地金额显示
    function loadLandMoney() {
      var moneyChoose = initData["InvestigateTable_Assessment_MoneyChoose"];

      if (moneyChoose.index != "") {
        var titleArray = new Array(4);
        var valueArray = new Array(4);

        var index = 0;
        if (moneyChoose.indexOf("1") > -1) {
          titleArray[index] = "土地出让<br>金";
          if (LandTransferMoneyFormula == null) {
            valueArray[index] =
              "楼面地价×实际容积率×土地面积×扣除比例<br>" +
              parseFloat(
                initData["InvestigateTable_Assessment_LandTransferMoney"]
              );
          } else {
            valueArray[index] =
              LandTransferMoneyFormula +
              "<br>" +
              parseFloat(
                initData["InvestigateTable_Assessment_LandTransferMoney"]
              );
          }
          index++;
        } else if (moneyChoose.indexOf("2") > -1) {
          titleArray[index] = "地价<br>调整";
          valueArray[index] =
            "按房屋用途计算的楼面地价-按土地用途计算的楼面地价）×房屋建筑面积<br>" +
            parseFloat(initData["InvestigateTable_Assessment_AdjustLandMoney"]);
          index++;
        }
        if (moneyChoose.indexOf("0") > -1) {
          titleArray[index] = "超容积率土地评估金额";
          valueArray[index] =
            "(证载土地面积-按标准容积率计算的土地面积)×楼面地价×容积率×综合费用修正系数<br>" +
            parseFloat(
              initData["InvestigateTable_Assessment_LandCompensationMoney"]
            );
          index++;
        }
        if (moneyChoose.indexOf("2") > -1 && moneyChoose.indexOf("1") > -1) {
          titleArray[index] = "地价<br>调整";
          valueArray[index] =
            "按房屋用途计算的楼面地价-按土地用途计算的楼面地价）×房屋建筑面积<br>" +
            parseFloat(initData["InvestigateTable_Assessment_AdjustLandMoney"]);
          index++;
        }
        if (moneyChoose.indexOf("4") > -1) {
          titleArray[index] = "补缴多余土地出让金";
          valueArray[index] =
            "土地性质为国有非出让土地的，出让金按土地评估价的20%扣除<br>" +
            parseFloat(
              initData["InvestigateTable_Assessment_PaymentLandTransferMoney"]
            );
          index++;
        }

        var html = "";
        for (var i = 0; i < index; i++) {
          if (i % 2 == 0) {
            html +=
              "<tr><td colspan='1' class='tdc1'>" +
              titleArray[i] +
              "</td><td colspan='5' class='tdc1'>" +
              valueArray[i] +
              "</td>";
          } else {
            html +=
              "<td colspan='1' class='tdc1'>" +
              titleArray[i] +
              "</td><td colspan='4' class='tdc1'>" +
              valueArray[i] +
              "</td></tr>";
          }
        }
        if (index % 2 != 0) {
          html += "<td colspan='5' class='tdc1'></td></tr>";
        }
        $("#LandMoneyTr").before(html);
      }
    }
    //加载估价对象自定义概况
    function loadSurvey() {
      $.ajax({
        url: "/Platform/PgInvestigateTable/ReportFile/GetAssessmentChildren.ashx?action=Survey&parentID=" +
          id,
        async: false,
        //cache: false,
        success: function(data) {
          var NameString = "";
          var ValueString = "";
          for (var i = 0, c = data.length; i < c; i++) {
            var elem = data[i];
            if (i <= 4) {
              $("#Name_Survey" + i + "").html(elem["S_Name"]);
              $("#Value_Survey" + i + "").html(elem["S_Value"]);
            }
            if (i == 5) {
              NameString += elem["S_Name"];
              ValueString += elem["S_Value"];
            }
            if (i > 5) {
              NameString += "," + elem["S_Name"];
              ValueString += "," + elem["S_Value"];
            }
          }
          if (NameString != "" && ValueString != "") {
            var SurveyHtml0 = "<tr>";
            var SurveyHtml1 = "<tr id='SurveyTr1'>";
            var NameArray = NameString.split(",");
            var ValueArray = ValueString.split(",");
            var MaxNum = 9;
            if (NameArray.length % 9 == 0)
              MaxNum = parseInt(NameArray.length / 9).mul(9);
            else
              MaxNum = parseInt(NameArray.length / 9)
              .add(1)
              .mul(9);
            for (var i = 0; i < MaxNum; i++) {
              if (i < NameArray.length) {
                if (i % 9 < 1) {
                  SurveyHtml0 +=
                    "<td colspan='2' class='tdc'>" + NameArray[i] + "</td>";
                  SurveyHtml1 +=
                    "<td colspan='2' class='tdc'>" + ValueArray[i] + "</td>";
                } else {
                  SurveyHtml0 +=
                    "<td colspan='1' class='tdc'>" + NameArray[i] + "</td>";
                  SurveyHtml1 +=
                    "<td colspan='1' class='tdc'>" + ValueArray[i] + "</td>";
                }
              } else {
                if (i % 9 < 1) {
                  SurveyHtml0 += "<td colspan='2' class='tdc'></td>";
                  SurveyHtml1 += "<td colspan='2' class='tdc'></td>";
                } else {
                  SurveyHtml0 += "<td colspan='1' class='tdc'></td>";
                  SurveyHtml1 += "<td colspan='1' class='tdc'></td>";
                }
              }

              if ((i + 1) % 9 == 0) {
                SurveyHtml0 += "</tr>";
                SurveyHtml1 += "</tr>";
                var Num = parseInt(i / 9);
                $("#SurveyTr" + Num + "").after(SurveyHtml0 + SurveyHtml1);
                var rowspan = parseFloat($("#SurveyTd").attr("rowspan")).add(2);
                $("#SurveyTd").attr("rowspan", rowspan);
                SurveyHtml0 = "<tr>";
                SurveyHtml1 = "<tr id='SurveyTr" + (Num + 1) + "'>";
              }
            }
          }
        }
      });
    }
    //加载比准案例房地产状况
    function loadProperty() {
      $.ajax({
        url: "/Platform/PgInvestigateTable/ReportFile/GetAssessmentChildren.ashx?action=Property&parentID=" +
          id,
        async: false,
        //cache: false,
        success: function(data) {
          var PropertyHtml =
            "<tr><td colspan='2' rowspan='" +
            (data.length + 1) +
            "' class='Mulitc'>比准案例房地产状况</td><td colspan='1' class='tdc'>建筑结构</td><td colspan='1' class='tdc'>建造年份</td><td colspan='1' class='tdc'>朝向</td><td colspan='1' class='tdc'>层次</td><td colspan='2' class='tdc'>土地性质/用途</td><td colspan='2' class='tdc'>比准价格（元/㎡）</td></tr>";
          for (var i = 0, c = data.length; i < c; i++) {
            var elem = data[i];
            PropertyHtml += "<tr>";
            PropertyHtml +=
              "<td colspan='1' class='tdc'>" + elem["P_Structure"] + "</td>";
            var Time = elem["P_BuildYear"];
            if (Time != null && Time != "") Time = Time.replace(/T.*/g, "");
            else Time = "";
            PropertyHtml += "<td colspan='1' class='tdc'>" + Time + "</td>";
            PropertyHtml +=
              "<td colspan='1' class='tdc'>" + elem["P_Orientation"] + "</td>";
            PropertyHtml +=
              "<td colspan='1' class='tdc'>" + elem["P_Layer"] + "</td>";
            PropertyHtml +=
              "<td colspan='2' class='tdc'>" + elem["P_LandType"] + "</td>";
            PropertyHtml +=
              "<td colspan='2' class='tdc'>" +
              parseFloat(elem["P_Money"]) +
              "</td>";
            PropertyHtml += "</tr>";

            P_Money = parseFloat(elem["P_Money"]);
          }
          if (data.length > 0) {
            $("#PropertyTr").after(PropertyHtml);
            var rowspan = parseFloat($("#PropertyTd").attr("rowspan"))
              .add(data.length)
              .add(1);
            $("#PropertyTd").attr("rowspan", rowspan);
          }
        }
      });
    }
    //加载装修
    function loadDecoration() {
      $.ajax({
        url: "/Platform/PgInvestigateTable/ReportFile/GetAssessmentChildren.ashx?action=Decorate&parentID=" +
          id,
        async: false,
        //cache: false,
        success: function(data) {
          if (data.length > 0) {
            var DecorateHtml = "";
            var RowNum = 0;
            for (var i = 0, c = data.length; i < c; i++) {
              var elem = data[i];
              RowNum++;
              DecorateHtml += "<tr>";
              DecorateHtml +=
                "<td colspan='2' class='tdc'>" + elem["D_HouseNo"] + "</td>";
              DecorateHtml +=
                "<td colspan='1' class='tdc'>" +
                parseFloat(elem["D_UsingArea"]) +
                "</td>";
              DecorateHtml +=
                "<td colspan='1' class='tdc'>" +
                parseFloat(elem["D_UnitPrice"]) +
                "</td>";
              if (i + 1 < data.length) {
                i++;
                elem = data[i];
                DecorateHtml +=
                  "<td colspan='2' class='tdc'>" + elem["D_HouseNo"] + "</td>";
                DecorateHtml +=
                  "<td colspan='2' class='tdc'>" +
                  parseFloat(elem["D_UsingArea"]) +
                  "</td>";
                DecorateHtml +=
                  "<td colspan='2' class='tdc'>" +
                  parseFloat(elem["D_UnitPrice"]) +
                  "</td>";
                DecorateHtml += "</tr>";
              } else {
                DecorateHtml += "<td colspan='2' class='tdc'></td>";
                DecorateHtml += "<td colspan='2' class='tdc'></td>";
                DecorateHtml += "<td colspan='2' class='tdc'></td>";
                DecorateHtml += "</tr>";
              }
            }
            if (data.length > 0) {
              $("#DecorateTr0").after(DecorateHtml);
              var rowspan = parseFloat($("#DecorateTd").attr("rowspan")).add(
                RowNum
              );
              $("#DecorateTd").attr("rowspan", rowspan);
            }
          } else {
            $("#DecorateTr0").remove();
            $("#DecorateTr1").remove();
          }
        }
      });
    }
    //加载分部分项装修评估表
    function loadDecoration1() {
      $.ajax({
        url: "/Platform/PgInvestigateTable/ReportFile/GetAssessmentChildren.ashx?action=Decorate1&parentID=" +
          id,
        async: false,
        success: function(data) {
          if (data.length > 0) {
            var decorateHtml =
              "<tr><td colspan='2' class='tdc'>阳台</td>" +
              "<td colspan='1' class='tdc'></td>" +
              "<td colspan='1' class='tdc'></td>" +
              "<td colspan='2' class='tdc'>客厅</td>" +
              "<td colspan='2' class='tdc'></td>" +
              "<td colspan='2' class='tdc'></td></tr>";
            //+ "<tr><td colspan='2' class='tdc'>卧室（阳）</td>"
            //+ "<td colspan='1' class='tdc'></td>"
            //+ "<td colspan='1' class='tdc'></td>"
            //+ "<td colspan='2' class='tdc'>餐厅</td>"
            //+ "<td colspan='2' class='tdc'></td>"
            //+ "<td colspan='2' class='tdc'></td></tr>"
            //+ "<tr><td colspan='2' class='tdc'>卧室（南）</td>"
            //+ "<td colspan='1' class='tdc'></td>"
            //+ "<td colspan='1' class='tdc'></td>"
            //+ "<td colspan='2' class='tdc'>厨房</td>"
            //+ "<td colspan='2' class='tdc'></td>"
            //+ "<td colspan='2' class='tdc'></td></tr>"
            //+ "<tr><td colspan='2' class='tdc'>卧室（北）</td>"
            //+ "<td colspan='1' class='tdc'></td>"
            //+ "<td colspan='1' class='tdc'></td>"
            //+ "<td colspan='2' class='tdc'>卫生间</td>"
            //+ "<td colspan='2' class='tdc'></td>"
            //+ "<td colspan='2' class='tdc'></td></tr>"
            $("#DecorateTr0").after(decorateHtml);
            var rowspan = parseFloat($("#DecorateTd").attr("rowspan")).add(1);
            $("#DecorateTd").attr("rowspan", rowspan);

            var decorateHtml1 = "";
            for (var i = 0, c = data.length; i < c; i++) {
              var elem = data[i];
              decorateHtml1 += "<tr>";
              decorateHtml1 += "<td colspan='1'>" + elem["D1_No"] + "</td>";
              decorateHtml1 += "<td colspan='1'>" + elem["D1_Name"] + "</td>";
              decorateHtml1 +=
                "<td colspan='1'>" + parseFloat(elem["D1_New"]) + "</td>";
              decorateHtml1 += "<td colspan='1'>" + elem["D1_Unit"] + "</td>";
              decorateHtml1 +=
                "<td colspan='1'>" + parseFloat(elem["D1_Number"]) + "</td>";
              decorateHtml1 +=
                "<td colspan='1'>" + parseFloat(elem["D1_UnitPrice"]) + "</td>";
              decorateHtml1 +=
                "<td colspan='1'>" + parseFloat(elem["D1_Money"]) + "</td>";
              decorateHtml1 += "<td colspan='1'>" + elem["D1_Remark"] + "</td>";
              decorateHtml1 += "</tr>";
            }
            $("#Decorate").after(decorateHtml1);
          }
        }
      });
    }
    //加载附属物
    function loadAttached() {
      $.ajax({
        url: "/Platform/PgInvestigateTable/ReportFile/GetAssessmentChildren.ashx?action=Attached&parentID=" +
          id,
        async: false,
        //cache: false,
        success: function(data) {
          if (data.length > 0) {
            var AttachedHtml = "";
            for (var i = 0, c = data.length; i < c; i++) {
              var elem = data[i];
              AttachedHtml += "<tr>";
              AttachedHtml +=
                "<td colspan='3' class='tdc'>" + elem["A_Name"] + "</td>";
              AttachedHtml +=
                "<td colspan='1' class='tdc'>" +
                parseFloat(elem["A_Area"]) +
                "</td>";
              AttachedHtml +=
                "<td colspan='1' class='tdc'>" +
                parseFloat(elem["A_UnitPrice"]) +
                "</td>";
              AttachedHtml +=
                "<td colspan='1' class='tdc'>" + elem["A_New"] + "</td>";
              AttachedHtml +=
                "<td colspan='2' class='tdc'>" +
                parseFloat(elem["A_PGMoney"]) +
                "</td>";
              AttachedHtml +=
                "<td colspan='2' class='tdc'>" + elem["A_Remark"] + "</td>";
              AttachedHtml += "</tr>";
            }
            if (data.length > 0) {
              $("#AttachedTr0").after(AttachedHtml);
              var rowspan = parseFloat($("#AttachedTd").attr("rowspan")).add(
                data.length
              );
              $("#AttachedTd").attr("rowspan", rowspan);
            }
          } else {
            $("#AttachedTr0").remove();
            $("#AttachedTr1").remove();
          }
        }
      });
    }
    //加载其他附属物
    function loadAttached1() {
      $.ajax({
        url: "/Platform/PgInvestigateTable/ReportFile/GetAssessmentChildren.ashx?action=Attached1&parentID=" +
          id,
        async: false,
        success: function(data) {
          if (data.length > 0) {
            var attachedHtml =
              "<tr>" +
              "<td colspan='2' class='tdc'></td>" +
              "<td colspan='1' class='tdc'></td>" +
              "<td colspan='1' class='tdc'></td>" +
              "<td colspan='1' class='tdc'></td>" +
              "<td colspan='3' class='tdc'></td>" +
              "<td colspan='2' class='tdc'></td>" +
              "</tr>";
            $("#AttachedTr0").after(attachedHtml);
            var rowspan = parseFloat($("#AttachedTd").attr("rowspan")).add(1);
            $("#AttachedTd").attr("rowspan", rowspan);

            var attachedHtml1 = "";
            for (var i = 0, c = data.length; i < c; i++) {
              var elem = data[i];
              attachedHtml1 += "<tr>";
              attachedHtml1 += "<td colspan='1'>" + elem["A1_No"] + "</td>";
              attachedHtml1 += "<td colspan='1'>" + elem["A1_Name"] + "</td>";
              attachedHtml1 +=
                "<td colspan='1'>" + parseFloat(elem["A1_New"]) + "</td>";
              attachedHtml1 += "<td colspan='1'>" + elem["A1_Unit"] + "</td>";
              attachedHtml1 +=
                "<td colspan='1'>" + parseFloat(elem["A1_Number"]) + "</td>";
              attachedHtml1 +=
                "<td colspan='1'>" + parseFloat(elem["A1_UnitPrice"]) + "</td>";
              attachedHtml1 +=
                "<td colspan='1'>" + parseFloat(elem["A1_Money"]) + "</td>";
              attachedHtml1 += "<td colspan='1'>" + elem["A1_Remark"] + "</td>";
              attachedHtml1 += "</tr>";
            }
            $("#Attached").after(attachedHtml1);
          }
        }
      });
    }
    //加载其他
    function loadOther() {
      $.ajax({
        url: "/Platform/PgInvestigateTable/ReportFile/GetAssessmentChildren.ashx?action=Other&parentID=" +
          id,
        async: false,
        success: function(data) {
          var sumA = 0;
          if (data.length > 0) {
            ifOther = true;
            var otherHtml = "";
            for (var i = 0, c = data.length; i < c; i++) {
              var elem = data[i];
              otherHtml += "<tr>";
              otherHtml += "<td colspan='1'>" + elem["O_No"] + "</td>";
              otherHtml += "<td colspan='1'>" + elem["O_Name"] + "</td>";
              otherHtml +=
                "<td colspan='1'>" + parseFloat(elem["O_New"]) + "</td>";
              otherHtml += "<td colspan='1'>" + elem["O_Unit"] + "</td>";
              otherHtml +=
                "<td colspan='1'>" + parseFloat(elem["O_Number"]) + "</td>";
              otherHtml +=
                "<td colspan='1'>" + parseFloat(elem["O_UnitPrice"]) + "</td>";
              otherHtml +=
                "<td colspan='1'>" + parseFloat(elem["O_Money"]) + "</td>";
              otherHtml += "<td colspan='1'>" + elem["O_Remark"] + "</td>";
              otherHtml += "</tr>";
              sumA += parseFloat(elem["O_Money"]);
            }
            otherHtml +=
              "<tr><td colspan='2' class='tdc'>合计</td><td colspan='6' class='tdc'>" +
              sumA +
              "元</td></tr>";
            $("#Other").after(otherHtml);
          } else {
            $("#printdiv3").hide();
          }
        }
      });
    }
  }
};

function prn_preview5() {
  var ID = $("#InvestigateTable_Assessment\\.ID").val();
  $.post("/Platform/OperateLog/List.aspx?action=getdata&type=setlog", {
    contents: "{0}一条评估记录",
    id: ID,
    instanceTable: "InvestigateTable_Assessment",
    title: "{0}在{1}{2}一条评估记录",
    type: "打印"
  });
  lod();

  function lod() {
    LODOP = getLodop();
    LODOP.PRINT_INIT("");
    LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
    LODOP.SET_PRINT_MODE("DOUBLE_SIDED_PRINT", 1);

    var showhtml = document.getElementById("printdiv").innerHTML;
    LODOP.ADD_PRINT_HTM("10mm", "14mm", "100%", "95%", showhtml);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 4);
    LODOP.SET_PRINT_STYLEA(0, "Horient", 3);
    LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
    if (ifDecoration) {
      LODOP.NewPage();
      showhtml = document.getElementById("printdiv1").innerHTML;
      LODOP.ADD_PRINT_HTM("10mm", "14mm", "100%", "87%", showhtml);
      LODOP.SET_PRINT_STYLEA(0, "ItemType", 4);
      LODOP.SET_PRINT_STYLEA(0, "Horient", 3);
      LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
    }
    if (ifAttached) {
      LODOP.NewPage();
      showhtml = document.getElementById("printdiv2").innerHTML;
      LODOP.ADD_PRINT_HTM("10mm", "14mm", "100%", "87%", showhtml);
      LODOP.SET_PRINT_STYLEA(0, "ItemType", 4);
      LODOP.SET_PRINT_STYLEA(0, "Horient", 3);
      LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
    }
    if (ifOther) {
      LODOP.NewPage();
      showhtml = document.getElementById("printdiv3").innerHTML;
      LODOP.ADD_PRINT_HTM("10mm", "14mm", "100%", "87%", showhtml);
      LODOP.SET_PRINT_STYLEA(0, "ItemType", 4);
      LODOP.SET_PRINT_STYLEA(0, "Horient", 3);
      LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
    }
    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "100%");
    LODOP.PREVIEW();
  }
}