/*
 * @FilePath: \wwwd:\code\screenFront\src\store\module\MicrofactoryDev.ts
 * @Author: 王路平
 * @文件版本: V1.0.0
 * @Date: 2023-02-06 15:58:13
 * @Description:
 *
 * 版权信息         : 2023 by ${再登软件}, All Rights Reserved.
 */
import { defineStore } from "pinia";
import { Names } from "@/store/storeName";
import { development, production } from "@/utils/devSever";
export const useMicrofactoryDevStore = defineStore(Names.MicrofactoryDev, {
  // 使用方式
  // const Index= useIndexStore()
  // 1、Index.{数据}++
  // 2、Index.$patch({数据:??})
  // 3、Index.$patch((state)=>{ state.数据=??})
  // 4、通过action修改
  state: () => {
    return {
      devlist: [],
      gateway: {
        id: null,
        Status: null,
        on: 0,
        off: 0,
      },
      SewingTime:null,
      PresserFoot:null,
      CuttingLine:null,
      Activation:null
    };
  },
  //computed 修改一些值
  //需要使用return将数据抛出
  //getters内可相互使用计算结果
  //使用时可直接放入标签内<div>Index.方法()</div>
  getters: {},
  //methods 可同步/异步，提交state
  //actions内获取state数据使用this
  // 使用方式
  // 1、Index.方法()
  //异步方法需要添加async和await
  actions: {
    setDevList(val: any) {
      val.forEach((res) => {
        if (res.image) {
          if (process.env.NODE_ENV === "development") {
            res.image = development.imgxhr + res.image;
          } else if (process.env.NODE_ENV === "production") {
            res.image = production.imgxhr + res.image; //正式环境+
          }
        }
      });
      this.devlist = val;
    },
    setGateway(val: any) {
      val.forEach((res) => {
        if (JSON.parse(res.name)) {
          this.gateway.on = res.counts;
        }
        if (!JSON.parse(res.name)) {
          this.gateway.off = res.counts;
        }
      });
      this.gateway.id = val[0].deptId;
      this.gateway.Status = JSON.parse(val[0].gatewayStatus);
    },
    setSewingTime(val:any){
        this.SewingTime=val
    },
    setPresserFoot(val:any){
        this.PresserFoot=val
    },
    setCuttingLine(val:any){
        this.CuttingLine=val
    },
    setActivation(val:any){
        this.Activation=val
    },
    changedata(val:any,type:string){
      this[type]=val
    },
    resetData(){
      this.devlist=[],
      this.gateway= {
        id: null,
        Status: null,
        on: 0,
        off: 0,
      },
      this.SewingTime=null,
      this.PresserFoot=null,
      this.CuttingLine=null,
      this.Activation=null
    }
  },
});
