import Vue from 'vue'
import Vuex from 'vuex'
import cloneDeep from 'lodash/cloneDeep'
import common from './modules/common'
import user from './modules/user'
import http from '../utils/httpRequest'

Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    common,
    user
  },
  state: {
    manList: [],
    illnesList: [],
    causeList: [],
    symptomList: [],
    tmentplanList: []
  },
  mutations: {
    // 重置vuex本地储存状态
    resetStore (state) {
      Object.keys(state).forEach((key) => {
        state[key] = cloneDeep(window.SITE_CONFIG['storeState'][key])
      })
    },
    // 人员列表
    setManList (state, data) {
      state.manList = data
    },
    setIllnes (state, data) {
      state.illnesList = data
    },
    setCause (state, data) {
      state.causeList = data
    },
    setSymptom (state, data) {
      state.symptomList = data
    },
    setTmentplan (state, data) {
      state.tmentplanList = data
    }
  },
  actions: {
    getManList (content) {
      http({
        url: http.adornUrl('/management/employee/findAll'),
        method: 'get',
        params: http.adornParams({})
      }).then(res => {
        if (res.data.code === 0) {
          content.commit('setManList', res.data.all)
          // content.state.manList = res.data.all
        }
      })
    },
    // 疾病表
    getIllnes (content) {
      http({
        url: http.adornUrl('/management/healthdisease/findAll'),
        method: 'get',
        params: http.adornParams({})
        // `${url}/management/healthdisease/findAll`
      }).then(res => {
        if (res.data.code === 0) {
          content.commit('setIllnes', res.data.all)
            // content.state.illnesList = res.all
        }
      })
    },
    // 病因表
    getCause (content) {
      http({
        url: http.adornUrl('/management/healthdiseasecause/findAll'),
        method: 'get',
        params: http.adornParams({})
      }).then(res => {
        if (res.data.code === 0) {
          content.commit('setCause', res.data.all)
        }
      })
    },
    // 症状表
    getSymptom (content) {
      http({
        url: http.adornUrl('/management/healthsymptom/findAll'),
        method: 'get',
        params: http.adornParams({})
      }).then(res => {
        if (res.data.code === 0) {
          content.commit('setSymptom', res.data.all)
        }
      })
    },
    // 治疗方案表
    getTmentplan (content) {
      http({
        url: http.adornUrl('/management/healthtreatmentplan/findAll'),
        method: 'get',
        params: http.adornParams({})
      }).then(res => {
        if (res.data.code === 0) {
          content.commit('setTmentplan', res.data.all)
        }
      })
    }
  },
  strict: process.env.NODE_ENV !== 'production'
})
