import db from "../../plugins/db";

const state = {
  scanNo: 0, // 已采集数量（从当前设置的计数时间算起）
  unuploadNo: 0, // 未上传数量（从当前设置的计数时间算起）,
  startCountTime: null, // 计数时间，默认：当前登录时间
  showToLoginModel: false
};

const mutations = {
  setStartCountTime(state, startCountTime) {
    state.startCountTime = startCountTime;
  },
  setShowToLoginModel(state, showToLoginModel) {
    state.showToLoginModel = showToLoginModel;
  },
  setScanNo(state, scanNo) {
    state.scanNo = scanNo;
  },
  setUnuploadNo(state, unuploadNo) {
    state.unuploadNo = unuploadNo;
  }
};

const actions = {
  async updateStartCountTime({ commit }, data) {
    const startCountTime = Object.assign({}, state.startCountTime, data);
    commit("setStartCountTime", startCountTime);
    await db.setDict("startCountTime", JSON.stringify(startCountTime));
  }
};

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