import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { getPosGroupList } from '@/api/demo/system';

import { updateShape,updateTif } from '@/api/task';
import { useMessage } from '@/hooks/web/useMessage';
const { createMessage } = useMessage();

function handleUpdateShape(){
  updateShape().then(res=>{
    if(res){
      createMessage.success("更新成功！");
    }else{
      createMessage.error("更新失败！");
    }
  })
}

function handleUpdateTif(){
  updateTif().then(res=>{
    if(res){
      createMessage.success("更新成功！");
    }else{
      createMessage.error("更新失败！");
    }
  })
}


window.handleUpdateShape  = handleUpdateShape;
window.handleUpdateTif = handleUpdateTif;

export const columns: BasicColumn[] = [
  {
    title: '任务名称',
    dataIndex: 'taskName',
  },
  {
    title: '备注/说明',
    dataIndex: 'remark',
  },
  {
    title: '图斑数量',
    dataIndex: 'shpCount',
  }, 
  
  {
    title: '已领取数量',
    dataIndex: 'receiveShpCount',
  }, 
  {
    title: '未领取数量',
    dataIndex: 'noReceiveShpCount',
  },{
    title: '领取状态',
    dataIndex: 'state',
  },
  {
    title: '任务状态',
    dataIndex: 'status',
    width: 80,
    customRender: ({ record }) => {
      const enable = record.isCompleted;
      const color = enable ? 'green' : 'red';
      const text = enable ? '已完成' : '未完成';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },{
    title:"操作",
    dataIndex:"action",
    width: 150,
    fixed: 'right',
  }
  
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'taskName',
    label: '任务名称',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formGroupSchema: FormSchema[] = [
  {
    field: 'posGroupId',
    component: 'ApiSelect',
    label: '职级组',
    required: true,
    componentProps: ({ formActionType, formModel }) => {
      return {
        api: getPosGroupList, // 接口
        // 接口参数
        resultField: 'result',
        labelField: 'name',
        valueField: 'id',
      };
    },
  },
];


export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    required: true,
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'shpId',
    label: '选择AI解译成果',
    component: 'Select',
    componentProps: {
      fieldNames: {
        label: 'shpName',
        key: 'id',
        value: 'id',
      },
      onChange:(value)=>{

      },
      getPopupContainer: () => document.body,
    },
    required: true,
    suffix: () => h('span', {style:"background:#0960BD;padding:8px 10px;border-radius:4px;color:#fff;cursor:pointer;", class: 'update-button',onclick:"handleUpdateShape()"}, '更新数据'),
  },
  {
    field: 'previousPhase',
    label: '选择前时项',
    component: 'TreeSelect',
    componentProps: {
      multiple:true,
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
      onChange:(value)=>{

      },
      getPopupContainer: () => document.body,
    },
    required: true,
    suffix: () => h('span', {style:"background:#0960BD;padding:8px 10px;border-radius:4px;color:#fff;cursor:pointer;", class: 'update-button',onclick:"handleUpdateTif()"}, '更新数据'),
  },
  {
    field: 'laterPhase',
    label: '选择后时项',
    component: 'TreeSelect',
    componentProps: {
      multiple:true,
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
      onChange:(value)=>{

      },
      getPopupContainer: () => document.body,
    },
    required: true,
    suffix: () => h('span', {style:"background:#0960BD;padding:8px 10px;border-radius:4px;color:#fff;cursor:pointer;", class: 'update-button',onclick:"handleUpdateTif()"}, '更新数据'),
  },
  {
    field: 'taskName',
    label: '任务名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'remark',
    label: '备注/说明',
    component: 'InputTextArea',
    required: false,
  }
];
