
const user = {
  state: {
    role_type: 1, // 1.医生 2.护士
    user: {
      id: 0,
      mobile: "",
      avatar: "",
      user_name: "",
      intro: "",
      user_type: 0,
      user_title: 0,
    },
    org: {
      id: 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:[],

  },

  mutations: {
    SET_FILEDS: (state, payload) => {
      state.fileds = payload.fileds
      console.log(payload.fileds)
      console.log(state.fileds)

    },
    SET_USER: (state, user) => {
      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) => {
      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
    },
    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
    },SET_TEMPLATE:(state, template_info) =>{
      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
    }
  },

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

      var fileds = userInfo.filed_list
      console.log(userInfo.filed_list)
      console.log(fileds)

      commit("SET_USER", user)
      commit("SET_ORG", org)
      commit("SET_SUBSCIBE", subscibe)
      commit("SET_TEMPLATE", template_info)
      commit('SET_FILEDS', {
        fileds
      })




    },
    SwitchRoleTypeToDoctor({commit}) {
      commit("SET_ROLE_TYPE", 1)
    }
  }
}

export default user
