/*
 * @Descripttion: zx
 * @Company: 思宏科技
 * @version: v1.0
 * @Author: zx
 * @Date: 2021-11-11 14:06:25
 * @LastEditors: HJ
 * @LastEditTime: 2021-12-03 11:44:39
 */
const app = getApp()
import { fhGetPatientRecord, fhGetPatientInfo } from '../../../api/remote/index'
const pageOptions = {
  // 页面数据
  data: {
    isFirstOnShow: true, // 是否为首次执行onShow
    basicForm: null,
    hospitalForm: null
  },
  async fhGetPatientInfo() {
    const form = []
    const memberId = app.globalData.baseInfo.memberId
    try {
      const { results } = await fhGetPatientInfo(form, memberId)
      this.setData({
        basicForm: results
      })
    } catch (e) {
      console.log('debug axios', e)
    }
  },
  // 获取患者住院信息
  async fhGetPatientRecord() {
    const form = []
    const memberId = app.globalData.baseInfo.memberId
    const hospitalId = app.globalData.hospitalInfo.hospitalId

    try {
      const { results } = await fhGetPatientRecord(form, memberId, hospitalId)
      this.setData({
        hospitalForm: results
      })
    } catch (e) {
      console.log('debug axios', e)
    }
  },
  login() {
    var that = this
    wx.showModal({
      title: '认证提醒',
      content:
        '为了保证患者就医安全，维护医院正常医疗秩序，按国家网络安全要求，所有患者及家属必须进行实名认证。',
      success(res) {
        if (res.confirm) {
          if (that.data.basicForm !== null) {
            if (that.data.hospitalForm !== null) {
              wx.reLaunch({
                url: '/remote/patient/home/index'
              })
            } else {
              wx.reLaunch({
                url: '/remote/patient/hospitalInformation/index'
              })
            }
          } else {
            wx.reLaunch({
              url: '/remote/patient/basicInformation/index'
            })
          }
        }
      }
    })
  },
  // 页面载入时
  onLoad(e) {
    this.init(e)
    this.fhGetPatientInfo()
    this.fhGetPatientRecord()
    this.login()
  },
  // 页面初始化
  init(e) {},
  // 页面准备好时
  onReady() {},
  // 页面显示时
  onShow() {
    const { isFirstOnShow } = this.data

    if (isFirstOnShow) {
      // 首次执行时
      this.setData({
        isFirstOnShow: false
      })
      return
    }
  },
  // 页面隐藏时
  onHide() {},
  // 页面卸载时
  onUnload() {},
  // 下拉页面时
  onPullDownRefresh() {},
  // 到达页面底部时
  onReachBottom() {},
  // 页面滚动时
  onPageScroll() {},
  // 分享时，注：onShareAppMessage不能为async异步函数，会导致不能及时取得返回值，使得分享设置无效
  onShareAppMessage() {
    /* const title = ''
    const path = ''
    const imageUrl = ``

    return {
      title,
      path,
      imageUrl,
    } */
  }
}

Page(pageOptions)
