// 组件引用
import { defineStore } from "pinia";
// 接口引用
import { updatePlan } from "@/api/business/zhaf/xunJian/plan.js";
// 公共方法引用
import modal from "@/plugins/modal.plugins.js";
import common from "@/plugins/common.plugins.js";
import keyListen from "@/plugins/keyListen.plugins.js";

const xunJianStores = defineStore(`storage-xunJian`, {
  state: () => ({
    planTabs: 0, //巡检计划页 tabs切换值
    siteId: null, //巡检计划页 站点id
    planSonId: null, //巡检计划页 子计划id
    planSonId1: null, //巡检计划页 子计划id
    siteNubmber: null, //巡检计划页 站点号码
    siteStatus: null, //巡检详情页 定位状态
    inspectionStatus: null,//巡检页 是否已巡检状态 1.未巡检 2.已巡检
    contentArray: {},

    collectDataList: [], //巡检点位采集数据存储
    planDataList: [],//巡检计划采集数据存储

    modal: {
      show: false,
      exitPassword: "",
      newExitPassword: "Usky-1707",//系统退出密码
    }
  }),
  unistorage: true,
  actions: {
    //巡检计划循环提交
    planForSubmit() {
      var _this = this

      if (!common.isNetwork()) {
        return false;
      }

      if (_this.planDataList.length > 0) {
        _this.planDataList.forEach((e) => {
          setTimeout(() => {
            updatePlan(e).then((res) => {
              if (res.status == "SUCCESS") {
                _this.planDataList.splice(_this.planDataList.indexOf(e), 1);
              } else {
                throw new Error('提交终止！')
              }
            });
          }, 1000);
        });
      }
    },
    modalConfirm() {
      //#ifdef APP-PLUS
      if (!this.modal.exitPassword) {
        modal.showToast("密码不能为空");
        return;
      }

      if (this.modal.exitPassword != this.modal.newExitPassword) {
        modal.showToast("密码错误");
        this.modal.show = true;
        return;
      }

      this.modal.exitPassword = ""
      this.modal.show = false;
      keyListen.quitApp(); //退出APP
      //#endif
    }
  },
});

export default xunJianStores;
