<template>
  <CollapseContainer title="风险监测指标配置" :canExpan="false">
    <!--定义表格-->
    <BasicTable @register="registerTable">
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>

    <List>
      <template v-for="item in list" :key="item.key">
        <ListItem>
          <ListItemMeta>
            <template #title>
              {{ item.title }}
              <div class="extra" v-if="item.extra" @click="extraClick(item.key)">
                {{ item.extra }}
              </div>
            </template>
            <template #description>
              <div>{{ item.description }} </div>
            </template>
          </ListItemMeta>
        </ListItem>
      </template>
    </List>
  </CollapseContainer>
  <UpdatePassword ref="updatePasswordRef" />
</template>
<script lang="ts">
  import { List } from 'ant-design-vue';
  import { defineComponent, ref } from 'vue';
  import { CollapseContainer } from '/@/components/Container/index';

  import { secureSettingList } from './data';
  import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
  import { useUserStore } from '/@/store/modules/user';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { ActionItem, BasicColumn, BasicTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { defHttp } from '/@/utils/http/axios';

  export default defineComponent({
    components: {
      CollapseContainer,
      List,
      ListItem: List.Item,
      ListItemMeta: List.Item.Meta,
      UpdatePassword: createAsyncComponent(() => import('/@/layouts/default/header/components/user-dropdown/UpdatePassword.vue')),
    },
    setup() {
      const { createMessage } = useMessage();
      const userStore = useUserStore();
      const updatePasswordRef = ref();
      function extraClick(key) {
        if (key == '1') {
          updatePasswordRef.value.show(userStore.getUserInfo.username);
        } else {
          createMessage.warning('暂不支持');
        }
      }

      //定义表格列
      const columns: BasicColumn[] = [
        {
          title: '姓名',
          dataIndex: 'name',
          width: 170,
          align: 'left',
          resizable: true,
          sorter: {
            multiple: 1,
          },
        },
        {
          title: '关键词',
          dataIndex: 'keyWord',
          width: 130,
          resizable: true,
        },
        {
          title: '打卡时间',
          dataIndex: 'punchTime',
          width: 140,
          resizable: true,
        },
        {
          title: '工资',
          dataIndex: 'salaryMoney',
          width: 140,
          resizable: true,
          sorter: {
            multiple: 2,
          },
        },
        {
          title: '奖金',
          dataIndex: 'bonusMoney',
          width: 140,
          resizable: true,
        },
        {
          title: '性别',
          dataIndex: 'sex',
          sorter: {
            multiple: 3,
          },
          customRender: ({ record }) => {
            return record.sex ? (record.sex == '1' ? '男' : '女') : '';
          },
          width: 120,
          resizable: true,
        },
        {
          title: '生日',
          dataIndex: 'birthday',
          width: 120,
          resizable: true,
        },
        {
          title: '邮箱',
          dataIndex: 'email',
          width: 120,
          resizable: true,
        },
      ];
      //ajax请求api接口
      const demoListApi = (params) => {
        return defHttp.get({ url: '/test/jeecgDemo/list', params });
      };
      // 列表页面公共参数、方法
      const { tableContext } = useListPage({
        designScope: 'basic-table-demo-ajax',
        tableProps: {
          title: '用户列表',
          api: demoListApi,
          columns: columns,
          actionColumn: {
            width: 120,
          },
        },
      });
      //BasicTable绑定注册
      const [registerTable] = tableContext;
      /**
       * 操作栏
       */
      function getTableAction(record): ActionItem[] {
        return [
          {
            label: '编辑',
            onClick: handleEdit.bind(null, record),
          },
        ];
      }

      function handleEdit(record) {}

      return {
        updatePasswordRef,
        extraClick,
        list: secureSettingList,
      };
    },
  });
</script>
<style lang="less" scoped>
  .extra {
    float: right;
    margin-top: 10px;
    margin-right: 30px;
    font-weight: normal;
    color: #1890ff;
    cursor: pointer;
  }
</style>
