<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <!--操作栏-->
      <template #action="{ record }">
        <!-- <TableAction :actions="getTableAction(record)" /> -->
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
      </template>
    </BasicTable>
  </div>
  <BasicModal @register="registeViewPlanDetail" title="项目信息详情" width="1200px" :showOkBtn="false">
      <viewPlanDetail :projectId="projectId"/>
  </BasicModal>
  <BasicModal @register="registerProjectPlan" title="发起项目计划审批" width="1200px" :showOkBtn="false" :showCancelBtn="false">
    <addPlan :projectType="projectType" :projectId="projectId" @close="closeProjectPlanModal()" />
  </BasicModal>
</template>

<script lang="ts" name="system-user" setup>
//ts语法
import { ref } from 'vue';
import { ActionItem, BasicTable, TableAction } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';

import { useModal } from '/@/components/Modal';
import { BasicModal } from '/@/components/Modal';
import addPlan from './addPlan.vue'
import viewPlanDetail from "./viewPlanDetail.vue";
import { columns, searchFormSchema } from '../projectInfo/projectInfo.data';

import { queryProjectApprovedPage } from './projectPlan.api';

let projectId = ref();
let projectType = ref();
const [registeViewPlanDetail, { openModal:openViewPlanDetail }] = useModal();//查看计划审批的
const [registerProjectPlan, { openModal: openProjectPlan, closeModal: closeProjectPlan }] = useModal();//发起计划审批的

const { tableContext } = useListPage({
  designScope: 'basic-table-demo-ajax',
  tableProps: {
    title: '项目信息',
    api: queryProjectApprovedPage,
    columns: columns,
    actionColumn: {
      width: 120,
      fixed: "right",
    },
    //表单查询项设置
    formConfig: {
      schemas: searchFormSchema,
    }
  },
});
//BasicTable绑定注册
const [registerTable, { reload }] = tableContext;
function getTableAction(record): ActionItem[] {
  return [
    {
      label: '详情',
      onClick: handleDetailpage.bind(null, record),
    },

  ];
}
/**
 * 下拉操作栏
 */
function getDropDownAction(record): ActionItem[] {
  return [
    {
      label: '设计项目计划',
      ifShow: () => {
        return record.status == 4
      },
      onClick: handlePlan.bind(null, record)
    },
    {
      label: '查看项目计划',
      ifShow: () => {
        return record.status == 5
      },
      onClick: handleViewPlan.bind(null, record)
    },
  ];
}

function handleDetailpage(record) {
  projectId.value = record.id
  openViewPlanDetail()


  // console.log(selectedRows.value);
  // console.log(selectedRowKeys.value);
}
function handlePlan(record) {
  projectType.value = record.projectType
  projectId.value = record.id
  openProjectPlan()

  // console.log(selectedRows.value);
  // console.log(selectedRowKeys.value);
}
function handleViewPlan(record) {
  projectId.value = record.id
  projectType.value =undefined
  openViewPlanDetail()
}
function closeProjectPlanModal() {
  closeProjectPlan()
  reload()
}
</script>

<style scoped></style>