<template>
    <!-- 方案列表 -->
    <div class="bg-[#fff]">
        <a-page-header style="border: 1px solid rgb(235, 237, 240)" @back="router.go(-1)">
            <template #backIcon>
                <div class="flex">
                    <div><a-button type="primary">返回</a-button></div>
                </div>
            </template>
            <template #title>
                <div>
                    <!-- 需要判断id状态展示不同按钮组 -->
                    <a-space wrap>
                        <a-button type="primary" @click="view">查看基本信息</a-button>
                        <a-button type="primary" @click="add">新增方案</a-button>
                        <a-button type="primary" @click="edit">补充信息</a-button>
                        <a-button type="primary" @click="sumbit(1)">返回无需评审</a-button>
                        <a-button type="primary" @click="sumbit(2)">退回重新评审</a-button>
                    </a-space>
                </div>
            </template>
        </a-page-header>
        <a-table :row-selection="{ selectedRowKeys: selectedRowKeys, selectedRows: selectedRows, type: 'radio' }"
            :columns="columns" :data-source="data">
            <template #bodyCell="{ column, index }">
                <template v-if="column.key === 'key'">
                    <span>
                        {{ index + 1 }}
                    </span>
                </template>
            </template>
        </a-table>
        <!-- 退回重审 -->
        <BackReviewModal @register="registerModal" @success="init" />
        <NoReviewMoadal @register="registerNOModal" @success="init" />
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { useMessage } from '/@/hooks/web/useMessage';
import { useModal } from '/@/components/Modal';
import { repairPlan } from '/@/api/common/api'
import BackReviewModal from './BackReviewModal.vue'
import NoReviewMoadal from './NoReviewMoadal.vue'

const { createMessage } = useMessage();
let router = useRouter();
const param = ref(router.currentRoute.value.query)
const data = ref<any>([])
const columns = ref([
    {
        title: '序号',
        dataIndex: 'key',
    },
    {
        title: '修复方案标题',
        dataIndex: 'title',
    },
    {
        title: '编制单位',
        dataIndex: 'bzdw',
    },
    {
        title: '填报状态',
        dataIndex: 'tbzt',
        width: 180,
    },
    {
        title: '更新时间',
        dataIndex: 'tsamp',
        width: 180,
    },
])
const selectedRowKeys = ref<any>([])
const selectedRows = ref<any>([])

async function init() {
    data.value = await repairPlan({
        wrdkid: param.value.wrdkid,
        scjdbm: param.value.scjdbm
    })
}
init()

// 点击查看基本信息
function view() {
    if (selectedRowKeys.value.length == 0) {
        createMessage.info('请选择需要处理的内容，每次只能选中一条');
        return
    }
    router.push(`/directory/mlzk/land/modules/Detail?wrdkid=${param.value.wrdkid}&scjdbm=S2`)
}
// 点击新增方案
function add() {
    // 点击新增后重新调接口
    // init()
}
// 补充方案
function edit() {

}
// 退回评审无需评审

const [registerModal, { openModal }] = useModal();
const [registerNOModal, { openModal: openNoModal }] = useModal();
function sumbit(v) {
    if (selectedRowKeys.value.length == 0) {
        createMessage.info('请选择需要处理的内容，每次只能选中一条');
        return
    }
    if (v == 1) {
        openModal(true, {
            record: selectedRows.value[0],
            isUpdate: true,
            showFooter: true,
        });
    } else {
        openNoModal(true, {
            record: selectedRows.value[0],
            isUpdate: true,
            showFooter: true,
        });
    }

}

</script>