<template>
  <div>
    <TableProMax ref="tableRef" :request-api="reqApi" :columns="columns"> </TableProMax>
  </div>
</template>

<script setup lang="tsx">
import TableProMax from '@/components/table/TableProMax.vue'
import api from '@/axios'
import { TableProMaxProps } from '@/types/components/table'
import { AssessmentRecordPagerQueryParams, AssessmentRecordPagerVo } from '@/types/views/assessmentRecord.ts'
import { ComponentExposed } from 'vue-component-type-helpers'
import { ref } from 'vue'
import { Modal } from 'ant-design-vue'
import { deductedDetail } from '@/views/query/assessmentIndex.tsx'
const tableRef = ref<ComponentExposed<typeof TableProMax>>(null!)
type TableProps = TableProMaxProps<AssessmentRecordPagerVo, AssessmentRecordPagerQueryParams>
const reqApi: TableProps['requestApi'] = (params) => api.post('/m1/ar/pager', params) //分页
const columns: TableProps['columns'] = [
  {
    dataIndex: 'enterprisesUnitName',
    title: '单位名称',
  },
  {
    dataIndex: 'type',
    title: '类型',
    customRender: ({ text }) => text?.label,
  },
  {
    dataIndex: 'ckProjectName',
    title: '考核项目',
  },
  {
    dataIndex: 'totalScore',
    title: '总分',
  },
  {
    dataIndex: 'deductionPointsTotal',
    title: '扣分',
    customRender: ({ record }) => {
      if (!record.deductionPointsTotal) {
        return <a-tag color='green'>0</a-tag>
      }
      return (
        <a-tag class='pointer' color='red' onClick={() => deductedDetail(record)}>
          {record.deductionPointsTotal}
        </a-tag>
      )
    },
  },
  {
    dataIndex: 'result',
    title: '得分',
    customRender: ({ record }) => record.totalScore - record.deductionPointsTotal,
  },
  {
    dataIndex: 'policeUnitName',
    title: '考核单位',
  },
  {
    dataIndex: 'createUserName',
    title: '考核人',
  },
  {
    dataIndex: 'createTime',
    title: '考核时间',
  },
  {
    dataIndex: 'remark',
    title: '考核备注',
  },
  {
    dataIndex: 'signature',
    title: '签字',
    customRender: ({ record }) => {
      return (
        <a-button
          onClick={() => {
            Modal.info({
              title: `${record.enterprisesUnitName}${record.ckProjectName} 签字结果`,
              content: () => (
                <>
                  <div>
                    审核人签字: <a-image src={record.assessmentUserSignature} />
                  </div>
                  <div>
                    被审核单位人员签字: <a-image src={record.byAssessmentEnterprisesUnitUserSignature} />
                  </div>
                </>
              ),
            })
          }}
        >
          查看
        </a-button>
      )
    },
  },
]
</script>

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