import Taro from "@tarojs/taro";
import { createSlice } from "@reduxjs/toolkit";

// 当前设备：设备介绍页使用
const instrumentReducer = createSlice({
  name: "instrument", // store的名字
  initialState: {
    bindingStatus: 0, // 0已绑定，1未绑定，2已解绑
    createBy: null,
    createTime: "",
    exportFields: [],
    id: 0,
    instrumentId: 0,
    instrumentIdArray: null,
    instrumentName: "",
    instrumentSerialIdList: [],
    queryInstrumentIds: null,
    remark: null,
    serial: "", // 设备序列号
    source: "",
    status: 0, // 0正常 1停用
    updateBy: null,
    updateTime: null,
    validStatus: 1, // 1有效，0无效

    // scanData: {
    //   name: "", // 扫码名字
    //   code: "", // 扫码序列号
    //   isChange: false, // 是否换绑
    // },
  },

  reducers: {
    setInstrument(state, { payload }) {
      state.bindingStatus = payload.bindingStatus;
      state.id = payload.id;
      state.instrumentId = payload.instrumentId;
      state.instrumentIdArray = payload.instrumentIdArray;
      state.instrumentName = payload.instrumentName;
      state.instrumentSerialIdList = payload.instrumentSerialIdList;
      state.queryInstrumentIds = payload.queryInstrumentIds;
      state.remark = payload.remark;
      state.serial = payload.serial;
      state.source = payload.source;
      state.status = payload.status;
      state.validStatus = payload.validStatus;
    },
    setSerial(state, { payload }) {
      state.serial = payload;
    },
    setInstrumentName(state, { payload }) {
      state.instrumentName = payload;
    },
  },
});

export const { setInstrument, setSerial, setInstrumentName } =
  instrumentReducer.actions;
export default instrumentReducer.reducer;
