import api from '../api/api'
import tool from './tool'
import store from '../store/index'

var areaData = [];
/* 企业列表数据 */
var enterpriseList = []

function arealist () {
  api.requested({
    "classname": "system.tools",
    "method": "query_arealist",
    "content": {
    }
  }).then(res=>{
    areaData =  tool.createMenu(res.data)
  })
}

function getEnterpriseList () {
  api.requested({
    "id": 20221021095802,
    "content": {
        "pageNumber": 1,
        "pageSize": 99999,
        "where": {
            "condition": ""
        }
    },
  }).then(res=>{
    enterpriseList = res.data
  })
}
 // 查询应用授权
 function query_userauth () {
  return new Promise((reslove, reject)=>{
    api.requested({
      "classname": "sysmanage.develop.userauthforweb.userauth",
      "method": "query_userauth",
      "content": {
        "place":1
      }
    }).then((res)=>{
      let active_modules = res.data[0].modules[0]
      sessionStorage.setItem('module_info', JSON.stringify(res.data))
      sessionStorage.setItem('active_modules', JSON.stringify(active_modules))
      store.dispatch('setActiveApp',{name:active_modules.apps[0].systemappname,app:active_modules.apps[0],val:''})
      reslove()
    })
  })
}
// 查询文件夹ID信息
function querySite_Parameter () {
  api.requested({
    "classname": "webmanage.site.site",
    "method": "querySite_Parameter",
    "content": {
    }
  }).then((res)=>{
    let obj = {
      appfolderid: res.data.appfolderid, // 应用附件文件夹ID
      salematerialfolderid: res.data.salematerialfolderid // 营销物文件夹ID
    }
    sessionStorage.setItem('folderid',JSON.stringify(obj))
  })
}
arealist ()
getEnterpriseList()

export default{
  query_userauth,
  querySite_Parameter,
  data () {
    return {
      areaData,
      'enterpriseList':enterpriseList
    }
  }
}