<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="auto">
            <el-form-item label="逆变器SN" prop="sn">
              <el-input v-model="queryParams.sn" placeholder="请输入逆变器SN" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <!--            <el-form-item label="项目id" prop="projectId">-->
            <!--              <el-input v-model="queryParams.projectId" placeholder="请输入项目id" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="电站id" prop="stationid">-->
            <!--              <el-input v-model="queryParams.stationid" placeholder="请输入电站id" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="电站名称" prop="stationname">-->
            <!--              <el-input v-model="queryParams.stationname" placeholder="请输入电站名称" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="业主id" prop="userid">-->
            <!--              <el-input v-model="queryParams.userid" placeholder="请输入业主id" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <el-form-item label="装机容量" prop="power">
              <el-input v-model="queryParams.power" placeholder="请输入装机容量" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="装机容量单位" prop="powerstr">
              <el-input v-model="queryParams.powerstr" placeholder="请输入装机容量单位" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="当日能量" prop="etoday">
              <el-input v-model="queryParams.etoday" placeholder="请输入当日能量" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <!--            <el-form-item label="当日发电量原始值" prop="etoday1">-->
            <!--              <el-input v-model="queryParams.etoday1" placeholder="请输入当日发电量原始值" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <el-form-item label="当日能量单位" prop="etodaystr">
              <el-input v-model="queryParams.etodaystr" placeholder="请输入当日能量单位" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="总电量" prop="etotal">
              <el-input v-model="queryParams.etotal" placeholder="请输入总电量" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <!--            <el-form-item label="累计发电量原始值" prop="etotal1">-->
            <!--              <el-input v-model="queryParams.etotal1" placeholder="请输入累计发电量原始值" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <el-form-item label="总能量单位" prop="etotalstr">
              <el-input v-model="queryParams.etotalstr" placeholder="请输入总能量单位" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <!--            <el-form-item label="满发小时数" prop="fullhour">-->
            <!--              <el-input v-model="queryParams.fullhour" placeholder="请输入满发小时数" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="功率" prop="pac">-->
            <!--              <el-input v-model="queryParams.pac" placeholder="请输入功率" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="功率单位" prop="pacstr">-->
            <!--              <el-input v-model="queryParams.pacstr" placeholder="请输入功率单位" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item-->
            <!--              label="逆变器状态：-->
            <!--1 = 在线-->
            <!--2 = 离线-->
            <!--3 = 报警"-->
            <!--              prop="state"-->
            <!--            >-->
            <!--              <el-input-->
            <!--                v-model="queryParams.state"-->
            <!--                placeholder="请输入逆变器状态：-->
            <!--1 = 在线-->
            <!--2 = 离线-->
            <!--3 = 报警"-->
            <!--                clearable-->
            <!--                @keyup.enter="handleQuery"-->
            <!--              />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="更新时间" prop="datatimestamp">-->
            <!--              <el-input v-model="queryParams.datatimestamp" placeholder="请输入更新时间" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="采集器SN" prop="collectorsn">-->
            <!--              <el-input v-model="queryParams.collectorsn" placeholder="请输入采集器SN" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="逆变器类型" prop="productmodel">-->
            <!--              <el-input v-model="queryParams.productmodel" placeholder="请输入逆变器类型" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="逆变器系列" prop="series">-->
            <!--              <el-input v-model="queryParams.series" placeholder="请输入逆变器系列" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="逆变器名称" prop="name">-->
            <!--              <el-input v-model="queryParams.name" placeholder="请输入逆变器名称" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="电站地址" prop="addr">-->
            <!--              <el-input v-model="queryParams.addr" placeholder="请输入电站地址" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="采集器状态" prop="collectorstate">-->
            <!--              <el-input v-model="queryParams.collectorstate" placeholder="请输入采集器状态" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item-->
            <!--              label="逆变器离线状态：-->
            <!--0 = 正常离线-->
            <!--1 = 异常离线"-->
            <!--              prop="stateexceptionflag"-->
            <!--            >-->
            <!--              <el-input-->
            <!--                v-model="queryParams.stateexceptionflag"-->
            <!--                placeholder="请输入逆变器离线状态：-->
            <!--0 = 正常离线-->
            <!--1 = 异常离线"-->
            <!--                clearable-->
            <!--                @keyup.enter="handleQuery"-->
            <!--              />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="累计满发小时数" prop="totalfullhour">-->
            <!--              <el-input v-model="queryParams.totalfullhour" placeholder="请输入累计满发小时数" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="逆变器电表类型，详见附录3" prop="invertermetermodel">-->
            <!--              <el-input v-model="queryParams.invertermetermodel" placeholder="请输入逆变器电表类型，详见附录3" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="创建时间" prop="createdate">-->
            <!--              <el-input v-model="queryParams.createdate" placeholder="请输入创建时间" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="质保结束时间" prop="updateshelfendtime">-->
            <!--              <el-input v-model="queryParams.updateshelfendtime" placeholder="请输入质保结束时间" clearable @keyup.enter="handleQuery" />-->
            <!--            </el-form-item>-->
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <!--          <el-col :span="1.5">-->
          <!--            <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['business:inverter:add']">新增</el-button>-->
          <!--          </el-col>-->
          <!--          <el-col :span="1.5">-->
          <!--            <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['business:inverter:edit']"-->
          <!--              >修改</el-button-->
          <!--            >-->
          <!--          </el-col>-->
          <!--          <el-col :span="1.5">-->
          <!--            <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['business:inverter:remove']"-->
          <!--              >删除</el-button-->
          <!--            >-->
          <!--          </el-col>-->
          <el-col :span="1.5">
            <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['business:inverter:export']">导出</el-button>
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" border :data="inverterList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <!--        <el-table-column label="逆变器id" align="center" prop="id" v-if="true" />-->
        <el-table-column label="逆变器SN" align="center" prop="sn" />
        <!--        <el-table-column label="项目id" align="center" prop="projectId" />-->
        <!--        <el-table-column label="电站id" align="center" prop="stationid" />-->
        <!--        <el-table-column label="电站名称" align="center" prop="stationname" />-->
        <!--        <el-table-column label="业主id" align="center" prop="userid" />-->
        <el-table-column label="装机容量" align="center" prop="power" />
        <el-table-column label="装机容量单位" align="center" prop="powerstr" />
        <el-table-column label="当日能量" align="center" prop="etoday" />
        <!--        <el-table-column label="当日发电量原始值" align="center" prop="etoday1" />-->
        <el-table-column label="当日能量单位" align="center" prop="etodaystr" />
        <el-table-column label="总电量" align="center" prop="etotal" />
        <!--        <el-table-column label="累计发电量原始值" align="center" prop="etotal1" />-->
        <el-table-column label="总能量单位" align="center" prop="etotalstr" />
        <el-table-column label="满发小时数" align="center" prop="fullhour" />
        <!--        <el-table-column label="功率" align="center" prop="pac" />-->
        <!--        <el-table-column label="功率单位" align="center" prop="pacstr" />-->
        <!--        <el-table-column-->
        <!--          label="逆变器状态：-->
        <!--1 = 在线-->
        <!--2 = 离线-->
        <!--3 = 报警"-->
        <!--          align="center"-->
        <!--          prop="state"-->
        <!--        />-->
        <!--        <el-table-column label="更新时间" align="center" prop="datatimestamp" />-->
        <!--        <el-table-column label="采集器SN" align="center" prop="collectorsn" />-->
        <!--        <el-table-column label="逆变器类型" align="center" prop="productmodel" />-->
        <!--        <el-table-column-->
        <!--          label="直流输入路数：值+1 = 实际路数-->
        <!--如：值0 = 1路，值1 = 2路，值2 = 3路…"-->
        <!--          align="center"-->
        <!--          prop="dcinputtype"-->
        <!--        />-->
        <!--        <el-table-column label="交流输出类：0 = 单相，其他 = 三相" align="center" prop="acoutputtype" />-->
        <!--        <el-table-column label="逆变器系列" align="center" prop="series" />-->
        <!--        <el-table-column label="逆变器名称" align="center" prop="name" />-->
        <!--        <el-table-column label="电站地址" align="center" prop="addr" />-->
        <!--        <el-table-column label="采集器状态" align="center" prop="collectorstate" />-->
        <!--        <el-table-column-->
        <!--          label="逆变器离线状态：-->
        <!--0 = 正常离线-->
        <!--1 = 异常离线"-->
        <!--          align="center"-->
        <!--          prop="stateexceptionflag"-->
        <!--        />-->
        <!--        <el-table-column label="累计满发小时数" align="center" prop="totalfullhour" />-->
        <!--        <el-table-column label="逆变器电表类型，详见附录3" align="center" prop="invertermetermodel" />-->
        <!--        <el-table-column label="创建时间" align="center" prop="createdate" />-->
        <!--        <el-table-column label="质保结束时间" align="center" prop="updateshelfendtime" />-->
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-tooltip content="修改" placement="top">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['business:inverter:edit']"></el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['business:inverter:remove']"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
    <!-- 添加或修改逆变器列对话框 -->
    <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
      <el-form ref="inverterFormRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="逆变器SN" prop="sn">
          <el-input v-model="form.sn" placeholder="请输入逆变器SN" />
        </el-form-item>
        <el-form-item label="项目id" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入项目id" />
        </el-form-item>
        <el-form-item label="电站id" prop="stationid">
          <el-input v-model="form.stationid" placeholder="请输入电站id" />
        </el-form-item>
        <el-form-item label="电站名称" prop="stationname">
          <el-input v-model="form.stationname" placeholder="请输入电站名称" />
        </el-form-item>
        <el-form-item label="业主id" prop="userid">
          <el-input v-model="form.userid" placeholder="请输入业主id" />
        </el-form-item>
        <el-form-item label="装机容量" prop="power">
          <el-input v-model="form.power" placeholder="请输入装机容量" />
        </el-form-item>
        <el-form-item label="装机容量单位" prop="powerstr">
          <el-input v-model="form.powerstr" placeholder="请输入装机容量单位" />
        </el-form-item>
        <el-form-item label="当日能量" prop="etoday">
          <el-input v-model="form.etoday" placeholder="请输入当日能量" />
        </el-form-item>
        <!--        <el-form-item label="当日发电量原始值" prop="etoday1">-->
        <!--          <el-input v-model="form.etoday1" placeholder="请输入当日发电量原始值" />-->
        <!--        </el-form-item>-->
        <el-form-item label="当日能量单位" prop="etodaystr">
          <el-input v-model="form.etodaystr" placeholder="请输入当日能量单位" />
        </el-form-item>
        <el-form-item label="总电量" prop="etotal">
          <el-input v-model="form.etotal" placeholder="请输入总电量" />
        </el-form-item>
        <!--        <el-form-item label="累计发电量原始值" prop="etotal1">-->
        <!--          <el-input v-model="form.etotal1" placeholder="请输入累计发电量原始值" />-->
        <!--        </el-form-item>-->
        <el-form-item label="总能量单位" prop="etotalstr">
          <el-input v-model="form.etotalstr" placeholder="请输入总能量单位" />
        </el-form-item>
        <el-form-item label="满发小时数" prop="fullhour">
          <el-input v-model="form.fullhour" placeholder="请输入满发小时数" />
        </el-form-item>
        <el-form-item label="功率" prop="pac">
          <el-input v-model="form.pac" placeholder="请输入功率" />
        </el-form-item>
        <el-form-item label="功率单位" prop="pacstr">
          <el-input v-model="form.pacstr" placeholder="请输入功率单位" />
        </el-form-item>
        <el-form-item
          label="逆变器状态：
1 = 在线
2 = 离线
3 = 报警"
          prop="state"
        >
          <el-input
            v-model="form.state"
            placeholder="请输入逆变器状态：
1 = 在线
2 = 离线
3 = 报警"
          />
        </el-form-item>
        <el-form-item label="更新时间" prop="datatimestamp">
          <el-input v-model="form.datatimestamp" placeholder="请输入更新时间" />
        </el-form-item>
        <el-form-item label="采集器SN" prop="collectorsn">
          <el-input v-model="form.collectorsn" placeholder="请输入采集器SN" />
        </el-form-item>
        <el-form-item label="逆变器类型" prop="productmodel">
          <el-input v-model="form.productmodel" placeholder="请输入逆变器类型" />
        </el-form-item>
        <el-form-item label="逆变器系列" prop="series">
          <el-input v-model="form.series" placeholder="请输入逆变器系列" />
        </el-form-item>
        <el-form-item label="逆变器名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入逆变器名称" />
        </el-form-item>
        <el-form-item label="电站地址" prop="addr">
          <el-input v-model="form.addr" placeholder="请输入电站地址" />
        </el-form-item>
        <el-form-item label="采集器状态" prop="collectorstate">
          <el-input v-model="form.collectorstate" placeholder="请输入采集器状态" />
        </el-form-item>
        <el-form-item
          label="逆变器离线状态：
0 = 正常离线
1 = 异常离线"
          prop="stateexceptionflag"
        >
          <el-input
            v-model="form.stateexceptionflag"
            placeholder="请输入逆变器离线状态：
0 = 正常离线
1 = 异常离线"
          />
        </el-form-item>
        <el-form-item label="累计满发小时数" prop="totalfullhour">
          <el-input v-model="form.totalfullhour" placeholder="请输入累计满发小时数" />
        </el-form-item>
        <el-form-item label="逆变器电表类型，详见附录3" prop="invertermetermodel">
          <el-input v-model="form.invertermetermodel" placeholder="请输入逆变器电表类型，详见附录3" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdate">
          <el-input v-model="form.createdate" placeholder="请输入创建时间" />
        </el-form-item>
        <el-form-item label="质保结束时间" prop="updateshelfendtime">
          <el-input v-model="form.updateshelfendtime" placeholder="请输入质保结束时间" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Inverter" lang="ts">
import { listInverter, getInverter, delInverter, addInverter, updateInverter } from '@/api/business/inverter';
import { InverterVO, InverterQuery, InverterForm } from '@/api/business/inverter/types';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const inverterList = ref<InverterVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();
const inverterFormRef = ref<ElFormInstance>();

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

const initFormData: InverterForm = {
  id: undefined,
  sn: undefined,
  projectId: undefined,
  stationid: undefined,
  stationname: undefined,
  userid: undefined,
  power: undefined,
  powerstr: undefined,
  etoday: undefined,
  etoday1: undefined,
  etodaystr: undefined,
  etotal: undefined,
  etotal1: undefined,
  etotalstr: undefined,
  fullhour: undefined,
  pac: undefined,
  pacstr: undefined,
  state: undefined,
  datatimestamp: undefined,
  collectorsn: undefined,
  productmodel: undefined,
  dcinputtype: undefined,
  acoutputtype: undefined,
  series: undefined,
  name: undefined,
  addr: undefined,
  collectorstate: undefined,
  stateexceptionflag: undefined,
  totalfullhour: undefined,
  invertermetermodel: undefined,
  createdate: undefined,
  updateshelfendtime: undefined
};
const data = reactive<PageData<InverterForm, InverterQuery>>({
  form: { ...initFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    sn: undefined,
    projectId: undefined,
    stationid: undefined,
    stationname: undefined,
    userid: undefined,
    power: undefined,
    powerstr: undefined,
    etoday: undefined,
    etoday1: undefined,
    etodaystr: undefined,
    etotal: undefined,
    etotal1: undefined,
    etotalstr: undefined,
    fullhour: undefined,
    pac: undefined,
    pacstr: undefined,
    state: undefined,
    datatimestamp: undefined,
    collectorsn: undefined,
    productmodel: undefined,
    dcinputtype: undefined,
    acoutputtype: undefined,
    series: undefined,
    name: undefined,
    addr: undefined,
    collectorstate: undefined,
    stateexceptionflag: undefined,
    totalfullhour: undefined,
    invertermetermodel: undefined,
    createdate: undefined,
    updateshelfendtime: undefined,
    params: {}
  },
  rules: {
    projectId: [{ required: true, message: '项目id不能为空', trigger: 'blur' }],
    powerstr: [{ required: true, message: '装机容量单位不能为空', trigger: 'blur' }],
    etoday: [{ required: true, message: '当日能量不能为空', trigger: 'blur' }],
    etoday1: [{ required: true, message: '当日发电量原始值不能为空', trigger: 'blur' }],
    etodaystr: [{ required: true, message: '当日能量单位不能为空', trigger: 'blur' }],
    etotal: [{ required: true, message: '总电量不能为空', trigger: 'blur' }],
    etotal1: [{ required: true, message: '累计发电量原始值不能为空', trigger: 'blur' }],
    etotalstr: [{ required: true, message: '总能量单位不能为空', trigger: 'blur' }],
    fullhour: [{ required: true, message: '满发小时数不能为空', trigger: 'blur' }],
    pac: [{ required: true, message: '功率不能为空', trigger: 'blur' }],
    pacstr: [{ required: true, message: '功率单位不能为空', trigger: 'blur' }],
    state: [{ required: true, message: '逆变器状态', trigger: 'blur' }],
    datatimestamp: [{ required: true, message: '更新时间不能为空', trigger: 'blur' }],
    collectorsn: [{ required: true, message: '采集器SN不能为空', trigger: 'blur' }],
    productmodel: [{ required: true, message: '逆变器类型不能为空', trigger: 'blur' }],
    dcinputtype: [{ required: true, message: '直流输入路数', trigger: 'change' }],
    acoutputtype: [{ required: true, message: '交流输出类：0 = 单相，其他 = 三相不能为空', trigger: 'change' }],
    series: [{ required: true, message: '逆变器系列不能为空', trigger: 'blur' }],
    name: [{ required: true, message: '逆变器名称不能为空', trigger: 'blur' }],
    addr: [{ required: true, message: '电站地址不能为空', trigger: 'blur' }],
    collectorstate: [{ required: true, message: '采集器状态不能为空', trigger: 'blur' }],
    stateexceptionflag: [{ required: true, message: '逆变器离线状态', trigger: 'blur' }],
    totalfullhour: [{ required: true, message: '累计满发小时数不能为空', trigger: 'blur' }],
    invertermetermodel: [{ required: true, message: '逆变器电表类型，详见附录3不能为空', trigger: 'blur' }],
    createdate: [{ required: true, message: '创建时间不能为空', trigger: 'blur' }],
    updateshelfendtime: [{ required: true, message: '质保结束时间不能为空', trigger: 'blur' }]
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询逆变器列列表 */
const getList = async () => {
  loading.value = true;
  const res = await listInverter(queryParams.value);
  inverterList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
};

/** 表单重置 */
const reset = () => {
  form.value = { ...initFormData };
  inverterFormRef.value?.resetFields();
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

/** 多选框选中数据 */
const handleSelectionChange = (selection: InverterVO[]) => {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
};

/** 新增按钮操作 */
const handleAdd = () => {
  reset();
  dialog.visible = true;
  dialog.title = '添加逆变器列';
};

/** 修改按钮操作 */
const handleUpdate = async (row?: InverterVO) => {
  reset();
  const _id = row?.id || ids.value[0];
  const res = await getInverter(_id);
  Object.assign(form.value, res.data);
  dialog.visible = true;
  dialog.title = '修改逆变器列';
};

/** 提交按钮 */
const submitForm = () => {
  inverterFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      if (form.value.id) {
        await updateInverter(form.value).finally(() => (buttonLoading.value = false));
      } else {
        await addInverter(form.value).finally(() => (buttonLoading.value = false));
      }
      proxy?.$modal.msgSuccess('操作成功');
      dialog.visible = false;
      await getList();
    }
  });
};

/** 删除按钮操作 */
const handleDelete = async (row?: InverterVO) => {
  const _ids = row?.id || ids.value;
  await proxy?.$modal.confirm('是否确认删除逆变器列编号为"' + _ids + '"的数据项？').finally(() => (loading.value = false));
  await delInverter(_ids);
  proxy?.$modal.msgSuccess('删除成功');
  await getList();
};

/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download(
    'business/inverter/export',
    {
      ...queryParams.value
    },
    `inverter_${new Date().getTime()}.xlsx`
  );
};

onMounted(() => {
  getList();
});
</script>
