/***********************************************************************
 * 目的: 项目特有的store用法示例
 * 作者: heyf@steerinfo.com
 * 创建日期: 2020-05-08
 *
 * 更新历史:
 * 日期                    人员                变更目的
 * 2020-05-08        修改人员名     修改的原因和目的*
**********************************************************************/

import Vue from 'vue'
import Vuex from 'vuex'
import {
  setCookie,
  getCookie,
  formatDate,
  dgTree
} from '@/utils/util.js';
import {
  stDev,
  stProd,
  proPath
} from '@/config/config.js';
import axios from '@/config/axios.js';

import ioms from './ioms/index.js';

// import { ctx } from '@/config/config.js';
Vue.use(Vuex);
const state = {
  matList: [], // 物资名称
  unitList: [], // 供应商数据
  sdrUnitList: [], // 发货单位数据
  rcvUnitList: [], // 收货单位数据
  loadList: [], // 卸货地点数据
  wgtTypeList: [], // 业务类型数据
  carrierUnitList: [] // 承运单位
};

const getters = {
};

const mutations = {
  setMatList (state, matList) {
    state.matList = [...matList]
  },
  setUnitList (state, unitList) {
    state.unitList = [...unitList]
  },
  setSdrUnitList (state, unitList) {
    state.sdrUnitList = [...unitList]
  },
  setRcvUnitList (state, unitList) {
    state.rcvUnitList = [...unitList]
  },
  setLoadList (state, loadList) {
    state.loadList = [...loadList]
  },
  setTypeList (state, wgtTypeList) {
    state.wgtTypeList = [...wgtTypeList]
  },
  setCarrierList (state, carrierUnitList) {
    state.carrierUnitList = [...carrierUnitList]
  }
}

const actions = {
  async setMatList ({ commit }) {
    const res = await axios.get('pass/systemBase/v1/meterbasematterinfos/noPage' + '?validFlag=1')
    commit('setMatList', res.data);
  },
  async setUnitList ({ commit }) {
    const { data: res } = await axios.get('pass/systemBase/v1/meterbasecustomersuppliers/like/?pageNum=1&pageSize=100000')
    commit('setUnitList', res.list);
  },
  async setSdrUnitList ({ commit }) {
    const { data: res } = await axios.get('pass/systemBase/v1/meterbasecustomersuppliers/selectOut')
    commit('setSdrUnitList', res.list);
  },
  async setRcvUnitList ({ commit }) {
    const { data: res } = await axios.get('pass/systemBase/v1/meterbasecustomersuppliers/selectIn')
    commit('setRcvUnitList', res.list);
  },
  async setLoadList ({ commit }) {
    const res = await axios.get('pass/systemBase/v1/meterbaseloadpoints/noPage' + '?validFlag=1')
    commit('setLoadList', res.data);
  },
  async setTypeList ({ commit }) {
    const res = await axios.get('pass/systemBase/v1/combaseinfos/noPage' + '?pBaseCode=001006' + '&validFlag=1')
    commit('setTypeList', res.data);
  },
  async setCarrierList ({ commit }) {
    const res = await axios.get('pass/systemBase/v1/meterbasecarrierunits/noPage' + '?validFlag=1')
    commit('setCarrierList', res.data);
  }
}

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