<template>
  <section class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      v-show="showSearch"
      :inline="true"
      label-width="auto"
    >
      <el-form-item label="任务标题" prop="roleName">
        <el-input
          v-model="queryParams.roleName"
          placeholder="请输入角色名称"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="权限字符" prop="roleKey">
        <el-input
          v-model="queryParams.roleKey"
          placeholder="请输入权限字符"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务类型" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="角色状态"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" style="width: 308px">
        <el-date-picker
          v-model="dateRange"
          value-format="YYYY-MM-DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </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-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="create()"
          >新增</el-button
        >
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="warning"-->
      <!--          plain-->
      <!--          icon="Download"-->
      <!--          @click="handleExport"-->
      <!--          v-hasPermi="['system:role:export']"-->
      <!--          >导出</el-button-->
      <!--        >-->
      <!--      </el-col>-->
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="任务标题" prop="roleId" align="center" />
      <el-table-column
        label="执行周期"
        prop="roleName"
        :show-overflow-tooltip="true"
        align="center"
      />
	    <el-table-column
			    label="任务类型"
			    prop="roleKey"
			    :show-overflow-tooltip="true"
			    align="center"
	    />
      <el-table-column
        label="进度"
        prop="roleKey"
        :show-overflow-tooltip="true"
        align="center"
      />
      <el-table-column label="执行范围" prop="roleSort" align="center">
        <template #default>
          <el-link type="primary" @click="selectCompany">共200家</el-link>
        </template>
      </el-table-column>
	    <el-table-column label="任务状态" align="center" />
      <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="Document"></el-button>
          </el-tooltip>
          <el-tooltip content="修改" placement="top">
            <el-button link type="primary" icon="Edit"></el-button>
          </el-tooltip>
          <el-tooltip content="删除" placement="top">
            <el-button link type="primary" icon="Delete"></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"
    />

    <TaskForm ref="taskFormRef" />

	  <ChooseCompany  ref="chooseCompanyRef"/>
  </section>
</template>

<script setup>
import TaskForm from "./form.vue";
import ChooseCompany from '@/BusinessCom/ChooseCompany/index.vue'

const { proxy } = getCurrentInstance();
const { task_period_type } = proxy.useDict("task_period_type");
const chooseCompanyRef=ref()
const loading = ref(false);
const showSearch = ref(true);
const taskFormRef = ref();
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    roleName: undefined,
    roleKey: undefined,
    status: undefined,
  },
  rules: {
    roleName: [
      { required: true, message: "角色名称不能为空", trigger: "blur" },
    ],
    roleKey: [{ required: true, message: "权限字符不能为空", trigger: "blur" }],
    roleSort: [
      { required: true, message: "角色顺序不能为空", trigger: "blur" },
    ],
  },
});
const total = ref(0);
const { queryParams, form, rules } = toRefs(data);
const dateRange = ref([]);
const list = ref([
  {
    roleId: 1,
    roleName: "超级管理员",
    roleKey: "admin",
    roleSort: 1,
    roleStatus: "0",
    roleRemark: "超级管理员拥有所有权限",
  },
]);
/**
 * 获取列表
 */
function getList() {}

/** 重置按钮操作 */
function resetQuery() {
  dateRange.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

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

/**
 * 新增任务
 */
function create() {
  unref(taskFormRef).open({ title: "新增任务" });
}

/**
 * 选择公司
 */
function  selectCompany(){
	unref(chooseCompanyRef).open({ title: "选择执行范围" });
}
</script>

<style scoped lang="scss"></style>
