import { ORDER_STATUS3 } from '@/utils/dictionary.js'
import TableTags from '@/components/DataTable/tools/Tags.vue'
import TableAction from '@/components/DataTable/tools/Action.vue'
import { h, ref, reactive } from 'vue'

/* 注册table */
const tableRef = ref()
const searchParams = ref()

function handleSearch(params) {
  searchParams.value = { ...params, handleFlag: 1 }
  if (params?.time?.length) {
    searchParams.value = {
      ...params,
      createStartTime: params.time[0],
      createEndTime: params.time[1]
    }
  }
  delete searchParams.value.time
  tableRef.value.reFetch({ searchParams })
}

/**
 * @description: 获取数据及操作
 * @param {*} row 单行数据
 * @param {*} type 操作类型 create:创建，preview:预览，edit:编辑
 * @return {*}
 */
function handleAssign(row) {
  data.rowData = row
  data.modalShow = true
}
function handleDetail(row) {
  data.rowData = row
  data.detailDrawer = true
}

const data = reactive({
  tableRef,
  searchParams,
  rowData: {},
  modalShow: false,
  detailDrawer: false,
  handleSearch,

  columns: [
    {
      title: '序号',
      key: 'key',
      render: (_, index) => {
        return `${index + 1}`
      },
      align: 'center'
    },
    {
      title: '工单编号',
      key: 'code',
      align: 'center',
      width: 250
    },
    {
      title: '问题总数',
      key: 'questionTotal',
      align: 'center'
    },
    {
      title: '未处理问题数',
      key: 'unhandledTotal',
      align: 'center'
    },
    {
      title: '工单状态',
      key: 'status',
      align: 'center',
      render(row) {
        return h(TableTags, {
          data: row.status,
          filters: ORDER_STATUS3
        })
      }
    },
    {
      title: '工单生成时间',
      key: 'createTime',
      align: 'center',
      width: 200
    },
    {
      title: '工单完成时间',
      key: 'finishTime',
      align: 'center',
      width: 200
    },
    {
      title: '处理人员',
      key: 'assignUserName',
      align: 'center',
      width: 200
    },
    {
      title: '操作',
      align: 'center',
      width: 150,
      fixed: 'right',
      render(row) {
        return h(TableAction, {
          actions: [
            {
              label: '工单问题',
              type: 'button',
              props: {
                type: 'primary',
                text: true,
                onClick: handleDetail.bind(null, row)
              },
              auth: 'basic_list'
            }
          ],
          align: 'center'
        })
      }
    }

  ]
})

export default data
