<template>
    <hc-new-card>
        <template #header>
            <hc-new-switch :datas="tabTab" :keys="tabKey" :round="false" size="default" @change="tabChange" />
            <div v-if="tabKey === 'key2'" class="ml-3 w-40">
                <el-select v-model="searchForm.key1" filterable block placeholder="选择工区">
                    <el-option label="工区1" value="1" />
                    <el-option label="工区2" value="2" />
                    <el-option label="工区3" value="3" />
                </el-select>
            </div>
        </template>
        <template #extra>
            <el-button hc-btn type="primary" @click="addModalClick">
                <HcIcon name="add" />
                <span>新增</span>
            </el-button>
            <el-button hc-btn type="warning" @click="reportClick">
                <HcIcon name="send-plane-2" />
                <span>上报</span>
            </el-button>
        </template>
        <div class="relative h-full flex">
            <div :id="`hc_table_card_${uuid}`" class="flex-1">
                <hc-card-item>
                    <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" is-new :index-style="{ width: 60 }">
                        <template #action="{ row }">
                            <el-link type="success" @click="rowEditClick(row)">修改</el-link>
                            <el-link type="danger">删除</el-link>
                        </template>
                    </hc-table>
                    <template #action>
                        <hc-pages :pages="searchForm" @change="pageChange" />
                    </template>
                </hc-card-item>
            </div>
            <div :id="`hc_info_card_${uuid}`">
                <el-scrollbar>
                    <hc-card-item title="详情信息">
                        <hc-info-table>
                            <tr>
                                <hc-info-table-td center is-title>变更方案编号：</hc-info-table-td>
                                <hc-info-table-td width="120px">33</hc-info-table-td>
                                <hc-info-table-td center is-title>变更方案名称：</hc-info-table-td>
                                <hc-info-table-td width="120px">测试的</hc-info-table-td>
                                <hc-info-table-td center is-title>变更发起单位：</hc-info-table-td>
                                <hc-info-table-td width="120px">-</hc-info-table-td>
                            </tr>
                            <tr>
                                <hc-info-table-td center is-title>业务日期：</hc-info-table-td>
                                <hc-info-table-td width="160px">2022-02-15</hc-info-table-td>
                                <hc-info-table-td center is-title>变更类型：</hc-info-table-td>
                                <hc-info-table-td width="120px">一般变更</hc-info-table-td>
                                <hc-info-table-td center is-title>延长工期：</hc-info-table-td>
                                <hc-info-table-td width="120px">-</hc-info-table-td>
                            </tr>
                            <tr>
                                <hc-info-table-td center is-title>变更申请金额：</hc-info-table-td>
                                <hc-info-table-td width="120px">116</hc-info-table-td>
                                <hc-info-table-td center is-title>现场确认时间：</hc-info-table-td>
                                <hc-info-table-td width="120px">2022-02-15</hc-info-table-td>
                                <hc-info-table-td center is-title>实际变更桩号：</hc-info-table-td>
                                <hc-info-table-td width="120px">-</hc-info-table-td>
                            </tr>
                            <tr>
                                <hc-info-table-td center is-title>引用预变更：</hc-info-table-td>
                                <hc-info-table-td width="auto" colspan="5">-</hc-info-table-td>
                            </tr>
                            <tr>
                                <hc-info-table-td center is-title>变更原因：</hc-info-table-td>
                                <hc-info-table-td width="auto" colspan="5">-</hc-info-table-td>
                            </tr>
                        </hc-info-table>
                    </hc-card-item>
                    <hc-card-item class="mt-3" title="变更申请部位">
                        <hc-table :column="tableColumn1" :datas="tableData1" is-new :index-style="{ width: 60 }" />
                    </hc-card-item>
                    <hc-card-item class="mt-3" title="变更申请清单">
                        <div class="hc-table-ref-box no-border">
                            <el-table class="w-full" :data="tableData" row-key="id" height="100%" highlight-current-row border>
                                <el-table-column type="index" label="序号" />
                                <el-table-column prop="key1" label="清单编号" />
                                <el-table-column prop="key2" label="清单名称" />
                                <el-table-column prop="key3" label="单价" />
                                <el-table-column label="数量" align="center">
                                    <el-table-column prop="key5" label="变更前" />
                                    <el-table-column prop="key6" label="变更增减" />
                                    <el-table-column prop="key7" label="变更后" />
                                </el-table-column>
                                <el-table-column label="金额" align="center">
                                    <el-table-column prop="key8" label="变更前" />
                                    <el-table-column prop="key9" label="变更增减" />
                                    <el-table-column prop="key10" label="变更后" />
                                </el-table-column>
                            </el-table>
                        </div>
                    </hc-card-item>
                    <hc-card-item class="mt-3" title="附件列表">
                        <hc-table :column="tableColumn2" :datas="tableData2" is-new :index-style="{ width: 60 }" />
                    </hc-card-item>
                </el-scrollbar>
            </div>
        </div>

        <!-- 上报弹窗 -->
        <hc-report-dialog v-model="isReport" />

        <!-- 新增修改的弹窗 -->
        <addModal v-model="isAddShow" />
    </hc-new-card>
</template>

<script setup>
import { nextTick, onMounted, ref } from 'vue'
import addModal from './components/plan/addModal.vue'
import { getRandom } from 'js-fast-way'

defineOptions({
    name: 'AlterAdminPlan',
})

const uuid = getRandom(4)

//渲染完成
onMounted(() => {
    setSplitRef()
})

//初始化设置拖动分割线
const setSplitRef = () => {
    //配置参考： https://split.js.org/#/?direction=vertical&snapOffset=0
    nextTick(() => {
        window.$split(['#hc_table_card_' + uuid, '#hc_info_card_' + uuid], {
            sizes: [60, 40],
            snapOffset: 0,
            minSize: [100, 400],
        })
    })
}

//类型tab数据和相关处理
const tabKey = ref('key1')
const tabTab = ref([
    { key: 'key1', name: '普通变更' },
    { key: 'key2', name: '工区变更' },
])

const tabChange = (item) => {
    tabKey.value = item?.key
    console.log(item)
}

//搜索表单
const searchForm = ref({
    key1: null, current: 1, size: 10, total: 0,
})

//分页
const pageChange = ({ current, size }) => {
    searchForm.value.current = current
    searchForm.value.size = size
}

//表格数据
const tableLoading = ref(false)
const tableColumn = ref([
    { key: 'key1', name: '变更编号' },
    { key: 'key2', name: '变更名称' },
    { key: 'key3', name: '变更金额' },
    { key: 'key4', name: '变更类型' },
    { key: 'key5', name: '业务日期' },
    { key: 'key6', name: '审批状态' },
    { key: 'action', name: '操作', width: 94 },
])
const tableData = ref([
    { key1: '1111' },
])

const rowEditClick = () => {

}

//新增修改的弹窗
const isAddShow = ref(false)
const addModalClick = () => {
    isAddShow.value = true
}

//申请部位
const tableColumn1 = ref([
    { key: 'key1', name: '工程名称' },
    { key: 'key2', name: '节点路径' },
    { key: 'key3', name: '合同图号' },
    { key: 'key4', name: '变更金额(元)' },
    { key: 'key5', name: '是否增补' },
])
const tableData1 = ref([
    { key1: '1111' },
])

//附件列表
const tableColumn2 = ref([
    { key: 'key1', name: '文件名称' },
    { key: 'key2', name: '必须上传' },
    { key: 'key3', name: '附件列表' },
])
const tableData2 = ref([
    { key1: '工程设计变更申请单', key2: '是', key3: '文件名称' },
])

//是否上报
const isReport = ref(false)
const reportClick = () => {
    isReport.value = true
}
</script>
