/*
 * @Descripttion: 远程探视卡片组件
 * @Company: 思宏科技
 * @version: v1.0
 * @Author: HJ
 * @Date: 2021-11-25 10:00:23
 * @LastEditors: OBKoro1
 * @LastEditTime: 2021-12-29 15:12:21
 */
const { visitStateEnumeration } = require('../../../utils/enumMap.js')
const dayjs = require('../../../src/js/dayjs/index')
const componentOptions = {
  // 组件选项
  options: {
    multipleSlots: true,
    addGlobalClass: true
  },
  behaviors: [],
  properties: {
    value: {
      type: Object,
      value: () => {
        return {}
      },
      observer(value) {
        const { visitStartTime, visitEndTime, visitDate ,actualStartTime} = value
        value.visitStartTime = this.formatTime(visitStartTime)
        value.visitEndTime = this.formatTime(visitEndTime)
        value.visitDate = this.formatTime(visitDate, 'YYYY/MM/DD')
        value.actualStartTime = this.formatTime(actualStartTime, 'HH:mm')

        this.setData({ curr: value })
        console.log("我是",value)
      }
    }
  },
  // 组件数据
  data: {
    isPageHidden: false, // 页面是否处于隐藏状态
    visitStateEnumeration,
    curr: {}
  },
  // 数据监听器
  observers: {},
  // 组件方法
  methods: {
    init() {},
    // 时间格式化
    formatTime(time, format = 'HH:mm') {
      return time ? dayjs(time).format(format) : null
    },
    tap(e) {
      const { visittype } = e.currentTarget.dataset
      if(visittype === 'ILLNESS') {
        wx.navigateTo({
          url: `/remote/patient/visitApplication/index?visitState=${this.data.curr.visitState}&id=${this.data.curr.id}`
        })
      }else if(visittype === 'newborn'){
        wx.navigateTo({
          url: `/pages/babyVisit/applyBorn/applyBorn?id=${this.data.curr.id}`
        })
      }
      
    },
    // 快捷操作
    shortcutActions() {
      switch (this.data.value.visitState) {
        case 'TO_BE_CONFIRM':
          this.triggerEvent('action', this.data.value)
          break
        default:
          this.tap()
          break
      }
    }
  },
  // 组件生命周期
  lifetimes: {
    created() {},
    attached() {
      this.init()
    },
    ready() {},
    moved() {},
    detached() {}
  },
  definitionFilter() {},
  // 页面生命周期
  pageLifetimes: {
    // 页面被展示
    show() {
      const { isPageHidden } = this.data

      // show事件发生前，页面不是处于隐藏状态时
      if (!isPageHidden) {
        return
      }

      // 重新执行定时器等操作
    },
    // 页面被隐藏
    hide() {
      this.setData({
        isPageHidden: true
      })

      // 清除定时器等操作
    },
    // 页面尺寸变化时
    resize() {}
  }
}

Component(componentOptions)
