<!-- 
    TODO 系统工具 / 定时任务
 -->
<template>
  <el-main class="schedule-setting">
    <el-form
      class="el-search-form"
      :model="listParm"
      label-width="80px"
      :inline="true"
    >
      <el-form-item class="item-search">
        <el-input
          v-model="listParm.beanName"
          placeholder="实例名称"
          clearable
        />
      </el-form-item>
      <el-form-item class="item-search">
        <el-input
          v-model="listParm.methodName"
          placeholder="方法名称"
          clearable
        />
      </el-form-item>
      <el-form-item class="item-search">
        <el-input
          v-model="listParm.methodParams"
          placeholder="方法参数"
          clearable
        />
      </el-form-item>
      <el-form-item class="item-search">
        <el-select
          v-model="listParm.jobStatus"
          clearable
          placeholder="状态"
        >
          <el-option
            v-for="item in scheduleSettingList.stateList"
            :key="item.label"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item class="item-search">
        <el-select
          v-model="listParm.rateRatioState"
          clearable
          placeholder="周期类型"
        >
          <el-option
            v-for="item in scheduleSettingList.cycleTypeList"
            :key="item.label"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          :loading="scheduleSettingList.loading"
          :icon="Search"
          @click="searchBtn"
        >
          搜索
        </el-button>
        <el-button
          :loading="scheduleSettingList.loading"
          class="reset-btn"
          :icon="RefreshRight"
          @click="resetBtn"
        >
          重置
        </el-button>
        <el-button
          v-permission="['sys:schedulesetting:add']"
          type="primary"
          :icon="Plus"
          @click="addEditBtn(EditType.ADD)"
        >
          新增
        </el-button>
      </el-form-item>
    </el-form>
    <!-- 表格数据 -->
    <el-table
      :height="tableHeight"
      :data="scheduleSettingList.mainList"
      border
      stripe
    >
      <el-table-column
        prop="beanName"
        label="实例名称"
        :show-overflow-tooltip="true"
        width="220"
      />
      <el-table-column
        prop="methodName"
        label="方法名称"
        :show-overflow-tooltip="true"
        width="220"
      />
      <el-table-column
        prop="methodParams"
        label="参数"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        prop="jobStatus"
        label="状态"
        width="100"
      >
        <template #default="scope">
          <el-tag :type="scope.row.jobStatus === 1 ? 'success' : 'info'">
            {{ scope.row.jobStatus === 1 ? '运行' : '停止' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="cycleType"
        label="周期类型"
        width="100"
      >
        <template #default="scope">
          <div v-if="scope.$index >= 0">
            {{ dealcycleType(scope.row.cycleType) }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        width="165"
      />
      <el-table-column
        prop="createUserName"
        label="创建人"
        width="130"
      />
      <el-table-column
        label="操作"
        width="150"
      >
        <template #default="scope">
          <el-select
            v-model="scope.row.types"
            class="type-actions"
            popper-class="type-actions"
          >
            <el-option
              v-for="item in actionOptions"
              :key="item.value"
              v-permission="item.permissions"
              :label="item.label"
              :value="item.value"
              @click="hanleChangeAction(scope.row)"
            >
              <template v-if="item.value === BaseFeesetAction.FEESET_ACTIVE">
                <el-button
                  :type="item.type"
                  :icon="item.icon"
                  class="block"
                >
                  {{ scope.row.jobStatus === 0 ? item.label : item.labelStop }}
                </el-button>
              </template>
              <template v-else>
                <el-button
                  :type="item.type"
                  :icon="item.icon"
                  class="block"
                >
                  {{ item.label }}
                </el-button>
              </template>
            </el-option>
          </el-select>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      v-model:current-page="listParm.pageNum"
      :page-sizes="[10, 20, 40, 80, 100]"
      :page-size="listParm.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="listParm.total"
      background
      @size-change="sizeChange"
      @current-change="currentChange"
    />
  </el-main>
  <!-- 新增/编辑 -->
  <AddEditScheduleSetting
    ref="addEditScheduleSettingRef"
    :cycle-typecist="scheduleSettingList.cycleTypeList"
    @save-schedule-setting="hanleSaveScheduleSetting"
  />
</template>
<script lang="ts" setup name="scheduleSetting">
import {
    Search,
    Plus,
    RefreshRight
} from "@element-plus/icons-vue";
import useResizeHeight from "@/hooks/useResizeHeight";
import timeFiltering from "@/utils/timeFiltering";
import AddEditScheduleSetting from './AddEditScheduleSetting.vue';
import { useScheduleSetting } from "@/composables/scheduleSetting/useScheduleSetting";
import { EditType } from "@/type/BaseEnum";
import { BaseFeesetAction } from "@/type/BaseFeesetAction";

const {
    listParm,
    scheduleSettingList,
    addEditScheduleSettingRef,
    actionOptions,
    sizeChange,
    currentChange,
    searchBtn,
    resetBtn,
    addEditBtn,
    hanleChangeAction,
    hanleSaveScheduleSetting,
    dealcycleType
} = useScheduleSetting()

// 表格自适应屏幕高度 
const { tableHeight } = useResizeHeight()
</script>
<style lang="scss" scoped>
.schedule-setting {}
</style>