<template>
  <div class="layout-pd">
    <el-row>
      <!--操作-->
      <el-col :xs="24">
        <el-card class="mt8" shadow="hover">
          <el-form :model="Data.Filter" @submit.stop.prevent>
            <el-form-item prop="name" style="width: 100%">
              <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
                <el-form-item label="用户名">
                  <el-input v-model="Data.Filter.name" placeholder="用户名" clearable></el-input>
                </el-form-item>
              </el-col>
            </el-form-item>
          </el-form>

          <hr>

          <!-- 按钮 -->
          <el-row justify="space-between" class="submit-button" style="margin-bottom:-7px">
            <el-row>
              <el-button type="primary" icon="ele-Search" @click="onQuery"> 查询 </el-button>
              <el-button type="primary" icon="ele-RefreshRight" @click="onReset"> 重置 </el-button>
            </el-row>
          </el-row>
        </el-card>
      </el-col>
      <!--表格-->
      <el-col :xs="24">
        <el-card style="height: 55vh" class="my-fill mt8" shadow="hover">
          <el-table ref="multipleTableRef" v-loading="Data.loading" stripe :data="Data.tableModel" row-key="id"
            style="width: 100%">
            <el-table-column v-for="column in Data.dynamicColumns" :key="column.prop" :prop="column.prop"
              :label="column.label" />
          </el-table>
          <div class="my-flex my-flex-end" style="margin-top: 20px">
            <el-pagination v-model:currentPage="Data.pageInput.currentPage" v-model:page-size="Data.pageInput.pageSize"
              :total="Data.total" :page-sizes="[10, 20, 50, 100]" small background @size-change="onSizeChange"
              @current-change="onCurrentChange" layout="total, sizes, prev, pager, next, jumper" />
          </div>
        </el-card>
      </el-col>
    </el-row>
    <EditDialog ref="editDialogRef" />
    <AuditDialog ref="auditDialogRef" />
  </div>

</template>

<script setup lang="ts" name="authorize/fuelingsdk">
import { onMounted, reactive } from "vue";
import { ElTable } from 'element-plus'
import { associationFilterModel_SearchFilter, associationFilterModel, PageInputAssociationFilterModel } from "/@/api/admin/reportManagement/association/associationDto";
import { AssociationApi } from "/@/api/admin/reportManagement/association/associationApi";

/**页面对象 */
const Data = reactive({
  time: '',
  /**加载显示 */
  loading: false,
  /**条件查询模块 */
  Filter: {
    name: "",
  } as associationFilterModel_SearchFilter,
  /**表格信息 */
  tableModel: [] as Array<associationFilterModel>,
  /**动态表头 */
  dynamicColumns: [
    { prop: 'name', label: '用户名' },
    { prop: 'email', label: '邮箱' },
    { prop: 'mobile', label: '手机号码' },
    { prop: 'createdDate', label: '创建时间' },
    { prop: 'modifiedDate', label: '修改时间' },
    { prop: 'disable', label: '是否启用用户' },
    { prop: 'isLock', label: '账户是否锁定' },
  ],
  /**分页标识 */
  pageInput: {
    currentPage: 1,
    pageSize: 10,
  } as PageInputAssociationFilterModel,
  /**分页总数 */
  total: 0,
})

/**初始化 */
const init = async () => {
  Data.loading = true
  const res: any = await new AssociationApi().getPage({ ...Data.pageInput, filter: Data.Filter })
  console.log(Data.Filter)
  Data.tableModel = res?.data ?? []
  Data.total = res?.length ?? 0
  Data.loading = false
}

onMounted(() => {
  init()
})

/**条件查询 */
const onQuery = () => {
  init()
}

/**重置查询条件 */
const resetQuery = () => {
  Data.Filter.name = ''
  Data.pageInput.currentPage = 1
  Data.pageInput.pageSize = 10
}

/**重置 */
const onReset = () => {
  resetQuery()
  init()
}

/**
* 页条变化
* @param val
*/
const onSizeChange = (val: number) => {
  Data.pageInput.pageSize = val
  init()
}

/**
 * 页数 变化
 * @param val
 */
const onCurrentChange = (val: number) => {
  Data.pageInput.currentPage = val
  init()
}

</script>

<style scoped lang="scss">
.el-input,
.el-select {
  width: 240px;
}

/* 输入框标签固定四个字符宽度 */
::v-deep .el-form-item__label {
  // 字体大小14，4个字符，12px右间距
  width: 14*4px+12px;
  justify-content: start;
}

/* 数据表头 设置灰色样式 */
::v-deep .el-table th.el-table__cell {
  background-color: #F6F6F6;
}
</style>