/*
 * @FilePath: \wwwd:\code\screenFront\src\store\module\offsite.ts
 * @Author: 王路平
 * @文件版本: V1.0.0
 * @Date: 2023-02-21 08:24:55
 * @Description:
 *
 * 版权信息         : 2023 by ${再登软件}, All Rights Reserved.
 */
import { defineStore } from "pinia";
import { Names } from "@/store/storeName";
export const Offsite = defineStore(Names.offsite, {
  // 使用方式
  // const Index= useIndexStore()
  // 1、Index.{数据}++
  // 2、Index.$patch({数据:??})
  // 3、Index.$patch((state)=>{ state.数据=??})
  // 4、通过action修改
  state: () => {
    return {
      city: [],
      itemDevNum: [
        // {
        //   title: "设备总量",
        //   type: "交付产品",
        //   num: 0,
        // },
        // {
        //   title: "东莞分公司",
        //   type: "广东省",
        //   num: 0,
        //   status:null
        // },
        // {
        //   title: "浙江分公司",
        //   type: "浙江省",
        //   num: 0,
        //   status:null
        // },
        {
          title: "在线产品",
          type: "在线产品",
          num: 0,
          status:null
        },
        {
          title: "离线产品",
          type: "离线产品",
          num: 13,
          status:null
        },
      ],
      offsitegatewayStatus:[],
      devtype: [],
      devlist: [],
      EquipmentStatusDiagram:[]
    };
  },
  //computed 修改一些值
  //需要使用return将数据抛出
  //getters内可相互使用计算结果
  //使用时可直接放入标签内<div>Index.方法()</div>
  getters: {},
  //methods 可同步/异步，提交state
  //actions内获取state数据使用this
  // 使用方式
  // 1、Index.方法()
  //异步方法需要添加async和await
  actions: {
    setcity(val: string[]) {
      this.city = val;
    },
    setdevitem(val: any) {
      this.itemDevNum.forEach((ele) => {
        val.forEach((res) => {
          if (res.name == ele.type) {
            //网关是否在线
            ele.status=res.gatewayStatus
            ele.num = res.counts;
          }
        });
      });
    },
    setdevtype(val: any) {
      this.devtype.push(val);
    },
    setdevlist(val: any) {
      val.forEach((res, index) => {
        res["index"] = index + 1;
      });
      this.devlist = val;
    },
    changeDevList(val: any) {
      // this.devlist=val
      if (!this.devlist) return;
      val.forEach((res) => {
        this.devlist.forEach((ele) => {
          if (res.id == ele.id) {
            ele.deviceStatus = res.deviceStatus;
          }
        });
      });
    },
    setoffsitegatewayStatus(val:any){
      this.offsitegatewayStatus=val
    },
    changeoffsitegatewayStatus(val:any){

    },
    changeEquipmentStatusDiagram(val:any){
      this.EquipmentStatusDiagram=val
    },
    //重置store数据
    resetAllData() {
      (this.city = []),
        (this.itemDevNum = [
          {
            title: "在线产品",
            type: "在线产品",
            num: 0,
          },
          {
            title: "离线产品",
            type: "离线产品",
            num: 13,
          },
        ]),
        (this.devtype = []),
        (this.devlist = []);
    },
  },
});
