<template>
  <div>
    <el-row>
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
        <el-form-item label="名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="监听类型" prop="type">
          <el-select v-model="queryParams.type" placeholder="请选择监听类型" clearable>
            <el-option
              v-for="dict in flowable_listener_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :icon="Search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button :icon="Refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-row>

    <el-table v-loading="loading" :data="listenerList.value" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="名称" align="center" prop="name"/>
      <el-table-column label="监听类型" align="center" prop="type">
        <template #default="scope">
          <dict-tag :options="flowable_listener_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="事件类型" align="center" prop="eventType"/>
      <el-table-column label="值类型" align="center" prop="valueType">
        <template #default="scope">
          <dict-tag :options="flowable_listener_value_type" :value="scope.row.valueType"/>
        </template>
      </el-table-column>
      <el-table-column label="执行内容" align="center" prop="value"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page-sizes="[5,10]"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script lang="ts" name="FlowListener" setup>
import { listListener } from '@/api/flowable/listener'
import {
	ref,
	reactive,
	watchEffect,
	getCurrentInstance,
} from "vue";
import { Search, Refresh, Plus, Edit, Delete, Download } from '@element-plus/icons-vue'
import type { FormInstance, FormRules, ElForm } from "element-plus";

// 引入全局方法
const { proxy } = getCurrentInstance() as any;
const { flowable_listener_value_type } = proxy.useDict("flowable_listener_value_type");
const { flowable_listener_type } = proxy.useDict("flowable_listener_type");

const queryForm = ref<InstanceType<typeof ElForm>>();
const formRef = ref<FormInstance>()

const props = defineProps<{
  selectValues: {
    type: Number | String | Array,
    default: null,
    required: false
  }
}>()

// const emit = defineEmits<{(
//   e: 'handleSelect',
//   selection: any
// ): void}>()

const emit = defineEmits(["handleSelect"]);

// 遮罩层
const loading = ref<boolean>(true);

/** 流程监听表格数据 */
const listenerList = reactive<any>({
  value: []
})
/** 总条数 */
const total = ref<number>(0);
/** 查询参数 */
const queryParams = reactive({
  pageNum: 1,
  pageSize: 5,
  name: null,
  type: null,
  eventType: null,
  valueType: null,
  value: null,
  status: null
})

/** 查询流程监听列表 */
const getList = () => {
  loading.value = true
  listListener(queryParams).then((response: any) => {
    listenerList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}
getList()

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

/** 重置按钮操作 */
const resetQuery = () => {
  proxy.resetForm(queryForm)
  handleQuery()
}

/** 多选框选中数据 */
const handleSelectionChange = (selection: any) => {
  emit('handleSelect', selection)
}
</script>

<style scoped>

</style>
