// pages/sickInfo/sickInfo.js
const app = getApp();
import {sickInfo} from "../../../api/consultOrder"
import {formatDateText} from "../../../utils/util"
Page({
  /**
   * 页面的初始数据
   */
    data: {
      sick:{
      },
      otherList:[]
    },
    previewImage(event) {
      let id = event.currentTarget.dataset.id;
      let urls = this.data.sick.diagnose_images;
      wx.previewImage({
        current: urls[id], // 当前显示图片的http链接
        urls: urls // 需要预览的图片http链接列表
      })
    },
   getsickInfo(id){
    sickInfo({
      order_inquiry_id:id
    }).then(data=>{
     this.setData({
      sick:data,
     });
     //infoType 1 只有是否  2 饮酒，吸烟 3 化合物 4 只有文字叙述
     let filter1=[];
     let filter2=[];
     let arr=[
       {
       type:"taboo",
       name:'是否服用过您想购买的药品且无相关禁忌：',
       nameTip:'',
       status:data.is_taboo,
       desc:"",
       infoType:1
     },
     {
      type:"allergy_history",
      name:'是否有过敏史：',
      nameTip:'过敏史：',
      infoType:1,
      status:data.is_allergy_history,
      desc:data.allergy_history
    },
    {
      type:"family_history",
      name:'是否有家族史：',
      nameTip:'家族史：',
      infoType:1,
      status:data.is_family_history,
      desc:data.family_history
    },
    {
      infoType:1,
      type:"pregnant",
      name:'是否处于备孕、妊娠、哺乳期：',
      nameTip:'',
      status:data.is_pregnant,
      desc:data.pregnant
    },
    {  infoType:1,
      type:"operation",
      name:'是否做过手术：',
      nameTip:'手术史',
      status:data.is_operation,
      desc:data.operation
    },
    {
      infoType:2,
      type:"drink_wine",
      name:'是否有饮酒史：',
      nameTip:'',
      status:data.drink_wine_status,
      desc:''
    },
    {
      infoType:2,
      type:"smoke",
      name:'是否有吸烟史：',
      nameTip:'',
      status:data.smoke_status,
      desc:''
    },
    {
      infoType:3,
      type:"chemical",
      name:'是否有接触过化学物：',
      nameTip:'接触过的化学物：',
      status:data.chemical_compound_status,
      desc:data.chemical_compound_describe
    },
    {
      infoType:4,
      type:'hospital',
      name:'确诊医院：',
      status:'',
      nameTip:'',
      desc:data.diagnosis_hospital
    },
    {
      type:"takeMedince",
      name:'是否服药：',
      nameTip:'正在服药：',
      status:data.is_take_medicine,
      desc:data.drugs_name,
      infoType:1
    }
    ]
    if(data.sex==1){
      filter1=arr.filter((item)=>{
          return  item.type!="pregnant"
      });
   }else{
      filter1=arr;
   }
   if(!data.diagnosis_hospital){
      filter2=filter1.filter((item)=>{
          return  item.type!="hospital"
      });
   }else{
      filter2=filter1
   }
   let newarr=filter2.filter((item)=>{
     return  item.status!=null 
   });
    let date=formatDateText(this.data.sick.diagnosis_date);
      this.setData({
        otherList:newarr,
        "sick.diagnosis_date":date
      })

    })
   },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getsickInfo(options.order_inquiry_id)
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  
})