<template>
  <div>
    <el-card class="!border-none" v-loading="pager.loading" shadow="never">
      <!-- <el-button v-perms="['flow/add']" type="primary" @click="handleAdd">
        <template #icon>
          <icon name="el-icon-Plus" />
        </template>
        新增
      </el-button> -->
      <!-- <el-button
                  v-perms="['flow/delete']"
                  :disabled="!selectData.length"
                  @click="handleDelete(selectData)"
              >
                  删除
              </el-button> -->
      <div class="mt-4">
        <el-table :data="pager.lists" @selection-change="handleSelectionChange">
          <el-table-column label="ID" prop="id" />
          <el-table-column label="任务名称" prop="name" show-overflow-tooltip />
          <el-table-column label="任务描述" prop="remark" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="任务金额" prop="remark" show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            label="任务完成时间"
            prop="remark"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column label="所属公司" prop="remark" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="片区经理" prop="remark" show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            label="当前审核人"
            prop="department"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column label="审核状态" prop="status" show-overflow-tooltip>
            <template #default="{ row }">
              <span v-if="row.status == 2" style="color: #f56c6c">未通过</span>
              <span v-if="row.status == 1" style="color: #67c23a">已通过</span>
              <span v-if="row.status == 0" style="color: #e6a23c">未审核</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="状态" prop="status" show-overflow-tooltip>
            <template #default="{ row }">
              <span v-if="row.status == 1">启用</span>
              <span v-if="row.status == 0">禁用</span>
            </template>
          </el-table-column> -->
          <!-- <el-table-column
            label="账号状态"
            min-width="100"
            v-perms="['auth.admin/edit']"
          >
            <template #default="{ row }">
              <el-switch
                v-if="row.root != 1"
                v-model="row.status"
                :active-value="1"
                :inactive-value="0"
                @change="changeStatus(row)"
              />
            </template>
          </el-table-column> -->
          <el-table-column label="操作" width="120" fixed="right">
            <template #default="{ row }">
              <el-button
                v-perms="['flow/edit']"
                type="primary"
                link
                @click="handleEdit(row)"
              >
                审核
              </el-button>
              <!-- <el-button
                v-perms="['flow/delete']"
                type="danger"
                link
                @click="handleDelete(row.id)"
              >
                删除
              </el-button> -->
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="flex mt-4 justify-end">
        <pagination v-model="pager" @change="getLists" />
      </div>
    </el-card>
    <edit-popup
      v-if="showEdit"
      ref="editRef"
      :dict-data="dictData"
      @success="getLists"
      @close="showEdit = false"
    />
  </div>
</template>
  
  <script lang="ts" setup name="flowLists">
import { usePaging } from "@/hooks/usePaging";
import { useDictData } from "@/hooks/useDictOptions";
import { apiFlowLists, apiFlowDetil, apiFlowStatus } from "@/api/examined";
import { timeFormat } from "@/utils/util";
import feedback from "@/utils/feedback";
import EditPopup from "./examined_popup.vue";

const editRef = shallowRef<InstanceType<typeof EditPopup>>();
// 是否显示编辑框
const showEdit = ref(false);

// 查询条件
const queryParams = reactive({
  name: "",
  check_type: "",
  type: "",
  flow_cate: "",
  department_ids: "",
  copy_uids: "",
  remark: "",
  flow_list: "",
  admin_id: "",
  status: "",
  delete_user_id: "",
});

// 选中数据
const selectData = ref<any[]>([]);

// 表格选择后回调事件
const handleSelectionChange = (val: any[]) => {
  selectData.value = val.map(({ id }) => id);
};

// 获取字典数据
const { dictData } = useDictData("");

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
  fetchFun: apiFlowLists,
  params: queryParams,
});

// 添加
const handleAdd = async () => {
  showEdit.value = true;
  await nextTick();
  editRef.value?.open("add");
};

// 编辑
const handleEdit = async (data: any) => {
  showEdit.value = true;
  await nextTick();
  editRef.value?.open("edit");
  editRef.value?.setFormData(data);
};
// 状态
const changeStatus = (row: any) => {
  console.log(row.status);
  apiFlowStatus({ id: row.id, status: row.status });
};

// 删除
// const handleDelete = async (id: number | any[]) => {
//   await feedback.confirm("确定要删除？");
//   await apiFlowDelete({ id });
//   getLists();
// };

getLists();
</script>
  