// packageE/healthy/healthyDetails/healthyDetails.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    tabIndex: 0,
    resultData: {},
    question: {},
    basic_info: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let record_id = options.record_id;

    let scene = decodeURIComponent(options.scene);
    if (scene) {
      var info_arr = [];
      info_arr = scene.split(",");
      for (let i = 0; i < info_arr.length; i++) {
        let chil_arr = [];
        chil_arr = info_arr[i].split("=");
        console.log(chil_arr);
        if (chil_arr[0] == "record_id") {
          record_id = chil_arr[1];
        }
      }
    }

    this.getDetailsData(record_id);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  getDetailsData(record_id) {
    let urlStr = app.getNetAddresss(
      "plugin.health-assessment.api.index.getData"
    );
    app._postNetWork({
      url: urlStr,
      data: {
        art: "getDetail",
        record_id,
      },
      success: (resdata) => {
        let res = resdata.data;

        if (res.result != 1) return;
        let resultData = res.data.getDetail.result;
        let question = res.data.getDetail.question;
        console.log("成功", question);

        // let sex = "";
        let basic_info = [];
        for (let i = 0; i < question.basic.length; i++) {
          let obj = {};
          if (question.basic[i].type == "1") {
            obj.name = "性别";
            obj.company_name = "";
            obj.answer = question.basic[i].answer;
          } else if (question.basic[i].type == "2") {
            obj.name = "年龄";
            obj.company_name = "";
            obj.answer = resultData.age;
            continue;
          } else if (
            question.basic[i].type == "5" ||
            question.basic[i].type == "6"
          ) {
            continue;
          } else {
            obj.name = question.basic[i].name;
            obj.company_name = question.basic[i].company_name;
            obj.answer = question.basic[i].answer;
          }
          basic_info.push(obj);
        }
        this.setData({ resultData, question, basic_info });
      },
      fail: function (res) {
        console.log(res.msg);
      },
    });
  },
  setTabs(e) {
    let index = e.target.dataset.index;
    if (index == this.data.tabIndex) return;
    this.setData({
      tabIndex: index,
    });
    console.log(e.target.dataset.index);
  },
});
