<template>
  <table-pro-max
      ref="tableRef"
      :request-api="reqApi"
      :columns="columns"
  >

  </table-pro-max>
</template>

<script setup lang="tsx">
import TableProMax from "@/components/table/TableProMax.vue";
import {ref} from "vue";
import {ComponentExposed} from "vue-component-type-helpers";
import {TableProMaxProps} from "@/types/components/table";
import api from "@/axios";
import {Modal} from "ant-design-vue";
import {
  AssessmentRecordPagerQueryParams,
  AssessmentRecordPagerVo
} from "@/types/views/unitManage/police/assessmentRecord.ts";
import {deductedDetail} from "@/views/unitManage/police/assessmentRecord/index.tsx";

type TableProps = TableProMaxProps<AssessmentRecordPagerVo, AssessmentRecordPagerQueryParams>
const tableRef = ref<ComponentExposed<typeof TableProMax>>(null)
const reqApi: TableProps["requestApi"] = (params) => {
  return api.post('/assessmentRecord/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>
