import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios'
import api from '../api/api'

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    loading:false,
    siteinfo:{
      attinfos:[]
    },
    deplist:[],
    sys_options:[]
  },
  getters: {
    siteinfo:state => state.siteinfo,
    loading:state => state.loading,
    deplist:state =>  state.deplist,
    sys_options:state => state.sys_options
  },
  mutations: {
    setSiteInfo(state,res) {
      state.siteinfo = res.data
    },
    setDeplist (state,res) {
      state.deplist = res
    },
    setSelectList (state,res) {
      state.sys_options = res.data
    },
  },
  actions: {
    // 系统选项分类查询
    optiontypeselect ({commit}, param) {
      return new Promise(async (reslove,reject)=>{
        let obj = {
          "classname": "sysmanage.develop.optiontype.optiontype",
          "method": "optiontypeselect",
          "content": {
              "pageNumber": 1,
              "pageSize": 1000,
              "typename": param,
              "parameter": {
              }
          }
        }
        const res = await api.requested(obj)

        commit('setSelectList',res)
        
        reslove(res)
      })
      
    },
    // 查询站点信息
    async querySiteInfo ({commit}, param) {
      const res = await api.requested(param)
      commit('setSiteInfo',res)
    },
    // 创建下载记录
    async createdownlog ({commit}, param) {
      let obj = {
        "classname": "system.attachment.Attachment",
        "method": "createdownlog",
        "content": {
            "linksid": param.linksid,
            "attachmentid":param.attachmentid
        }
      }
      const res = await api.requested(obj)
    },

    // 存储部门列表数据
    setDeplistData ({commit}, param) {
      commit('setDeplist',param)
    }
  },
  modules: {
  },
});
