import db from "../plugins/db";
import { getLocalDate } from "../plugins/utils";

export default {
  methods: {
    async initScanArea(subjects) {
      const storeScanArea = await db.getDict("scanArea", {});
      let newScanArea = {};
      subjects.map(subject => {
        let info = { ...subject };
        if (
          storeScanArea[subject.id] &&
          storeScanArea[subject.id].collectConfig
        )
          info.collectConfig = storeScanArea[subject.id].collectConfig;

        newScanArea[subject.id] = info;
      });
      this.$store.commit("client/setScanArea", newScanArea);
    },
    async initStore() {
      // 今日事今日毕的前提下，采集数和上传数只取当天的记录数。
      const curDate = getLocalDate();
      const scanNo = await db.countUploadList({
        createdTime: curDate
      });
      const uploadNo = await db.countUploadList({
        fininshTime: curDate,
        isUpload: 1
      });

      this.$store.commit("client/setScanNo", scanNo);
      this.$store.commit("client/setUploadNo", uploadNo);
    }
  }
};
