<template>
  <PageWrapper dense contentFullHeight fixedHeight>
    <div class="table-box">
      <BasicTable @register="registerTable">
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'action'">
            <TableAction
              :actions="[
                {
                  label: '修改类型',
                  onClick: () => {
                    changeCaseType(record)
                  },
                },
                {
                  label: '查看任务',
                  onClick: () => {
                    getTaskList(record)
                  },
                },
                {
                  label: '查看任务日志',
                  onClick: () => {
                    getTaskLogList(record)
                  },
                },
              ]"
            />
          </template>
        </template>
      </BasicTable>
    </div>
    <a-modal
      width="80%"
      style="top: 20px;"
      v-model:open="taskModal" 
      title="任务"
      :destroyOnClose="true"
      @ok="closeTaskModal" 
      @cancel="closeTaskModal">
        <TaskModal :processId="taskModalProcessId"/>
    </a-modal>
    <a-modal
      width="80%"
      style="top: 20px;"
      v-model:open="taskLogModal" 
      title="任务日志"
      :destroyOnClose="true"
      @ok="closeTaskLogModal" 
      @cancel="closeTaskLogModal">
        <TaskLogModal :processId="taskModalProcessId"/>
    </a-modal>
  </PageWrapper>
</template>
<script lang="ts" setup>
import { PageWrapper } from '@/components/Page';
import { ref } from 'vue';
import { loadCaseInfoTuBanList } from '@/api/demo/system';
import { BasicTable,useTable,TableAction } from '@/components/Table';
import { columns, searchFormSchema } from './casetypemodification.data';
import TaskModal from './TaskModal/index.vue'
import TaskLogModal from './TaskLogModal/index.vue'
import { message, Modal } from 'ant-design-vue'
import { UpdateCaseinfoTypeKC } from '@/api/demo/casetypemodification'

const taskModal = ref(false)
const taskLogModal = ref(false)
const taskModalProcessId = ref()
const [registerTable, { reload }] =
  useTable({
    title: '可修改线索类型列表',
    api: loadCaseInfoTuBanList,
    beforeFetch(params) {
      params.typename = '农用地'
      params.nowStatus = '待接收,待填报,待整改,市级审核,县级审核'
      return params
    },
    columns,
    rowKey: 'id',
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    // 使用搜索表单
    useSearchForm: true,
    showTableSetting: true,
    bordered: true,
    actionColumn: {
      width: 275,
      title: '操作',
      dataIndex: 'action',
      fixed: 'right',
    },
  });
const changeCaseType = (record) => {
  Modal.confirm({
    title: '是否确认修改线索类型为建设用地(20属性)',
    onOk: async () => {
      try {
        let caseno = record.caseno
        let res = await UpdateCaseinfoTypeKC(caseno)
        reload()
        message.success('修改线索类型成功')
      } catch(error) {
        console.log(error)
        message.error('修改线索类型失败')
      }
    },
    onCancel() {
      
    },
  })
}
const getTaskList = (record) => {
    taskModalProcessId.value = record.Id
    taskModal.value = true
}
const getTaskLogList = (record) => {
    taskModalProcessId.value = record.Id
    taskLogModal.value = true
}
const closeTaskModal = () => {
  taskModal.value = false
}
const closeTaskLogModal = () => {
  taskLogModal.value = false
}
</script>
<style lang="less" scoped>
</style>
