
import {
  isLogin
} from '@/api/login'

const user = {
  state: {
    tab_index: 1,
    role_type: 1, // 1.医生 2.护士
    requestScheduals: {},
    requestDialysisScheduals: {},
    waitscheduals: {},
    scheduals: {},
    adminUserArr: [],
    user: {
      id: 0,
      mobile: '',
      avatar: '',
      user_name: '',
      intro: '',
      user_type: 0,
      user_title: 0
    },
    admin: null,
    org: {
      id: 0,
      creator: 0,
      org_short_name: '',
      org_name: '',
      org_intro: '',
      org_logo: '',
      address: '',
      province: 0,
      city: 0,
      district: 0
    },
    serve: {
      state: 0,
      status: 1,
      start: 0,
      end: 0
    },
    subscibe: {
      id: 0,
      period_start: 0,
      period_end: 0,
      state: 3
    },
    template_info: {
      id: 0,
      org_id: 0,
      template_id: 0
    },
    fileds: [],
    globalConfig: {},

    websocket: null,
    waitScrollTop: 0,
    dialysisScrollTop: 0,
    monitorScrollTop: 0,
    adviceScrollTop: 0

  },

  mutations: {
    SET_ADMIN: (state, payload) => {
      state.admin = payload.admin
    },
    SET_FILEDS: (state, payload) => {
      state.fileds = payload.fileds
    },
    SET_USER: (state, user) => {
      if (user == null) {
        state.user.id = 0
        state.user.mobile = ''
        state.user.avatar = ''
        state.user.user_name = ''
        state.user.intro = ''
        state.user.user_type = 0
        state.user.user_title = ''
      } else {
        state.user.id = user.id
        state.user.mobile = user.mobile
        state.user.avatar = user.avatar
        state.user.user_name = user.user_name
        state.user.intro = user.intro
        state.user.user_type = user.user_type
        state.user.user_title = user.user_title
      }
    },
    SET_ORG: (state, org) => {
      if (org == null) {
        state.org.id = 0
        state.org.org_short_name = ''
        state.org.org_name = ''
        state.org.org_intro = ''
        state.org.org_logo = ''
        state.org.address = ''
        state.org.province = 0
        state.org.city = 0
        state.org.district = 0
        state.org.creator = 0
      } else {
        state.org.id = org.id
        state.org.org_short_name = org.org_short_name
        state.org.org_name = org.org_name
        state.org.org_intro = org.org_intro
        state.org.org_logo = org.org_logo
        state.org.address = org.address
        state.org.province = org.province
        state.org.city = org.city
        state.org.district = org.district
        state.org.creator = org.creator
      }
    },
    SET_SUBSCIBE: (state, subscibe) => {
      // state.subscibe.id = subscibe.id
      // state.subscibe.period_start = subscibe.period_start
      // state.subscibe.period_end = subscibe.period_end
      // state.subscibe.state = subscibe.state
    },
    SET_ROLE_TYPE: (state, type) => {
      state.role_type = type
    },
    SET_ORG_SERVE: (state, serve) => {
      state.serve.state = serve.state
      state.serve.status = serve.status
      state.serve.start = serve.start
      state.serve.end = serve.end
    },
    // eslint-disable-next-line camelcase
    SET_TEMPLATE: (state, template_info) => {
      if (template_info == null) {
        state.template_info.id = 0
        state.template_info.org_id = 0
        state.template_info.template_id = 0
      } else {
        state.template_info.id = template_info.id
        state.template_info.org_id = template_info.org_id
        state.template_info.template_id = template_info.template_id
      }
    },
    SET_REQUESTSCHEDUALS: (state, requestScheduals) => {
      state.requestScheduals = requestScheduals
    },
    SET_REQUESTDIALYSISSCHEDUALS: (state, requestDialysisScheduals) => {
      state.requestDialysisScheduals = requestDialysisScheduals
    },
    SET_SCHEDUALS: (state, scheduals) => {
      state.scheduals = scheduals
    },
    SET_WAITSCHEDUALS: (state, waitscheduals) => {
      state.waitscheduals = waitscheduals
    },
    SET_ADMINUSERARR: (state, adminUserArr) => {
      state.adminUserArr = adminUserArr
    },
    SET_GLOBALCONFIG: (state, globalConfig) => {
      state.globalConfig = globalConfig
    },
    SET_WAITSCROLLTOP: (state, waitScrollTop) => {
      state.waitScrollTop = waitScrollTop
    },
    SET_DIALYSISSCROLLTOP: (state, dialysisScrollTop) => {
      state.dialysisScrollTop = dialysisScrollTop
    },
    SET_MONITORSCROLLTOP: (state, monitorScrollTop) => {
      state.monitorScrollTop = monitorScrollTop
    },
    SET_ADVICESCROLLTOP: (state, adviceScrollTop) => {
      state.adviceScrollTop = adviceScrollTop
    }
  },

  actions: {
    InitUserInfo ({commit}, userInfo) {
      var user = userInfo.user
      var org = userInfo.org
      var subscibe = userInfo.subscibe
      var template_info = userInfo.template_info
      var admin = userInfo.admin

      var fileds = userInfo.filed_list

      commit('SET_USER', user)
      commit('SET_ORG', org)
      commit('SET_SUBSCIBE', subscibe)
      commit('SET_TEMPLATE', template_info)
      commit('SET_FILEDS', {
        fileds
      })
      commit('SET_ADMIN', {
        admin
      })
    },
    SwitchRoleTypeToDoctor ({commit}) {
      commit('SET_ROLE_TYPE', 1)
    },
    SetRequestScheduals ({commit}, requestScheduals) {
      commit('SET_REQUESTSCHEDUALS', requestScheduals)
    },
    SetRequestDialysisScheduals ({commit}, requestDialysisScheduals) {
      commit('SET_REQUESTDIALYSISSCHEDUALS', requestDialysisScheduals)
    },
    SetScheduals ({commit}, scheduals) {
      commit('SET_SCHEDUALS', scheduals)
    },
    SetWaitScheduals ({commit}, waitscheduals) {
      commit('SET_WAITSCHEDUALS', waitscheduals)
    },

    SetAdminUserArr ({commit}, adminUserArr) {
      commit('SET_ADMINUSERARR', adminUserArr)
    },
    SetGlobalConfig ({commit}, globalConfig) {
      commit('SET_GLOBALCONFIG', globalConfig)
    },
    SetWaitScrollTop ({commit}, waitScrollTop) {
      commit('SET_WAITSCROLLTOP', waitScrollTop)
    },
    SetDialysisScrollTop ({commit}, dialysisScrollTop) {
      commit('SET_DIALYSISSCROLLTOP', dialysisScrollTop)
    },
    SetMonitorScrollTop ({commit}, monitorScrollTop) {
      commit('SET_MONITORSCROLLTOP', monitorScrollTop)
    },
    SetAdviceScrollTop ({commit}, adviceScrollTop) {
      commit('SET_ADVICESCROLLTOP', adviceScrollTop)
    }
  }
}

export default user
