import { toRaw } from 'vue'

const state = {
  orgIdArr:[],
  orgId:'',
  orgName:'',
  orgCode:'',
  salePubInfo:{},
  purPubInfo:{},
}

const getters = {}

const mutations = {
    SET_ORGID: (state, orgId) => {
      state.orgId = orgId
    },
    SET_ORGID_ARR: (state, orgIdArr) =>{
      state.orgIdArr = orgIdArr
    },
    SET_ORG_NAME: (state, orgName) => {
      state.orgName = orgName
    },
    SET_ORG_CODE: (state, orgCode) => {
      state.orgCode = orgCode
    },
    SET_SALE_INFO: (state,salePubInfo) =>{
      state.salePubInfo = salePubInfo
    },
    SET_PURCHASE_INFO: (state,purPubInfo) =>{
      state.purPubInfo = purPubInfo
    },
}

const actions = {
  // 设置销售订单信息
  setSalInfo(context, name){
    context.commit('SET_SALE_INFO', name)
  },
   // 设置采购订单信息 
  setPurInfo(context, name){
    context.commit('SET_PURCHASE_INFO', name)
  },
  // 设置组织名称
  setorgName (context, name) {
    context.commit('SET_ORG_NAME', name)
  },
  // 设置组织id
  setorgId (context, orgId) {
    context.commit('SET_ORGID', orgId)
  },

  // 设置组织List
  setorgIdArr (context, orgIdArr){
    context.commit('SET_ORGID_ARR', orgIdArr)
  },

  // 设置组织code
  setproductDeptList (context, productDeptList){
      context.commit('SET_ORG_PRODUCTDEPTLIST',productDeptList)
  },
  
  // 获取组织信息
  getOrdInfo (context) {
    return new Promise((resolve, reject) => {
      resolve(toRaw(context.state.orgIdArr))
    })
  },
  // 获取组织id
  getOrdId (context) {
    return new Promise((resolve, reject) => {
      resolve(toRaw(context.state.orgId))
    })
  },
  // 获取组织名称
  getOrdName (context) {
    return new Promise((resolve, reject) => {
      resolve(toRaw(context.state.orgName))
    })
  },
  // 获取组织Code
  getOrgCode (context){
    return new Promise((resolve, reject) => {
        resolve(toRaw(context.state.orgCode))
    })
  },
  // 获取销售公共信息
  getSalInfo(context){
    return new Promise((resolve, reject) => {
      resolve(toRaw(context.state.salePubInfo))
    })
  },
  // 获取采购公共信息
  getPurInfo(context){
    return new Promise((resolve, reject) => {
      resolve(toRaw(context.state.purPubInfo))
    })
  }
}

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}
