import { ElMessage } from 'element-plus'
import { printJSON } from '@/utils/printUtils'

/**
 * 列表页打印
 * @param list 列表数据【数组】
 * @param columns 表头信息
 * @param checkoutList 多选【数组】
 * @param printName 打印名称
 */
export function usePrintList(list: any, columns: { value: string; text: string }[], checkoutList: any, printName: string) {
  // 打印列
  const properties = columns.map((item: { value: string; text: string }) => {
    return {
      field: item.value,
      displayName: item.text,
    }
  })
  if (checkoutList.length <= 0 && list.length > 0) {
    printJSON(list, properties, printName)
  }
  else if (checkoutList.length > 0) {
    const printList = list.filter((item: any) => checkoutList.includes(item.id))
    printJSON(printList, properties, printName)
  }
  else {
    ElMessage.warning('无可打印内容')
  }
}
