import apiTools from '@/api'
export default {
  namespaced: true,
  state: {
    firstOpen: true, //第一次打開控件，處理echart Canvas初始化寬度問題，延時生成
    schoolAclassOneInfoNum: undefined
  },
  getters: {
    getSchoolAclassOneInfoNum(state) {
      return state.schoolAclassOneInfoNum
    },
    getIsFirstOpenAuth(state) {
      return state.firstOpen
    }
  },
  mutations: {
    setSchoolAclassOne(state, data) {
      state.schoolAclassOneInfoNum = data
      //console.log(state.schoolAclassOneInfoNum);
    },
    setFirstOpenAuth(state, status) {
      state.firstOpen = status
      //console.log(state.firstOpen)
    }
  },
  actions: {
    getSchoolAclassOne(context, schoolCode) {
      return new Promise((resolve, reject) => {
        apiTools.stuAccount.getSchoolAclassOne(schoolCode).then(
          res => {
            context.commit('setSchoolAclassOne', res)
            resolve({
              code: 1,
              message: 'Get AclassOne數量 API  successful'
            })
          },
          err => {
            reject({
              code: 0,
              data: [],
              message: 'Get AclassOne數量 API error!'
            })
          }
        )
      })
    },
    setSchoolAclassOneState(context, params) {
      //console.log(params)
      let schoolCode = params.schoolCode
      let studentIds = params.studentIds
      apiTools.stuAccount.setSchoolAclassOneState(schoolCode, studentIds).then(res => {
        //console.log(res)
        //資料回來刷新
        context.commit('setSchoolAclassOne', res)
      })
    },
    recallSchoolAclassOne(context, schoolCode) {
      apiTools.stuAccount.recallSchoolAclassOne(schoolCode).then(res => {
        console.log(res)
        //資料回來刷新
        context.commit('setSchoolAclassOne', res)
      })
    }
  }
}
