<template>
    <!-- 招标解析 -->
    <el-card class="analysis-container">
        <div class="table-container">
            <TableModel :formLabel="formLabel" :showOperation="true" :showRightTools="false" ref="analysisTableRef"
                :columnsList="columnsList" :request-api="listAPI" :sendParams="sendParams" :handleColWidth="250">
                <template slot="tableTitle">
                    <h3>数据列表</h3>
                </template>
                <template slot="tableActions">
                    <el-button @click="handleAdd" v-hasPermi="['analysis:analysis:add']" class="add-btn"><i
                            class="el-icon-plus"></i> 新建项目</el-button>
                </template>
                <template slot="analysisStatus" slot-scope="{ data }">
                    <el-tag v-if="!data.analysisStatus" type="info">待解析</el-tag>
                    <el-tag v-else-if="data.analysisStatus === '0'" type="warn">解析中</el-tag>
                    <el-tag v-else-if="data.analysisStatus === '1'" type="success">解析成功</el-tag>
                    <el-tag v-else-if="data.analysisStatus === '2'" type="danger">解析失败</el-tag>
                </template>
                <template slot="handle" slot-scope="{ data }">
                    <el-button type="text" v-hasPermi="['enterpriseLibrary:analysis:detail']" class="action-btn"
                        @click="handleDetail(data)">
                        查看
                    </el-button>
                    <el-button type="text" v-hasPermi="['enterpriseLibrary:analysis:detail']" class="action-btn"
                        @click="handleBidDetail(data)">
                        标段解析
                    </el-button>
                    <el-button type="text" v-hasPermi="['enterpriseLibrary:analysis:detail']" class="action-btn"
                        @click="handleBidListDetail(data)">
                        查看标段
                    </el-button>
                    <el-button type="text" v-hasPermi="['enterpriseLibrary:tool:del']" class="action-btn"
                        style="color: #db3e29" @click="handleDelete(data)">
                        删除
                    </el-button>
                </template>
            </TableModel>
        </div>
        <!-- 新建项目 -->
        <AnalysisForm v-if="showAnalysisForm" :title="title" :row="row" @closeDialog="showAnalysisForm = false"
            :width="600" @handleQuery="handleQuery" />
    </el-card>
</template>

<script>
import TableModel from '@/components/TableModel2'
import { columnsList, formLabel } from './config'
import { encryptWithSM4 } from '@/utils/sm'
import { listAPI, delProDataAPI, testMQAPI } from '@/api/analysis/analysis'
import OnlyOfficeViewer from '@/views/common/OnlyOfficeViewer.vue'
import AnalysisForm from './components/AnalysisForm.vue'
export default {
    name: 'Analysis',
    components: {
        TableModel,
        OnlyOfficeViewer,
        AnalysisForm,
    },
    data() {
        return {
            formLabel,
            columnsList,
            listAPI,
            sendParams: {
                enterpriseId: 2,
            },
            showAnalysisForm: false,
            title: '',
            row: {},
        }
    },

    created() { },

    methods: {

        /** 新增按钮操作 */
        handleAdd() {
            this.title = '新建项目'
            this.showAnalysisForm = true
        },

        /** 修改操作 */
        handleUpdate(row) {
            this.title = '修改项目'
            this.isAdd = 'edit'
            this.row = row
            this.isflag = true
        },

        /* 查看操作 */
        handleDetail(row) {
            this.$router.push({
                name: 'AnalysisDetail',
                query: {
                    proId: encryptWithSM4(row.proId + '' || '0'),
                },
            })
        },
        /** 标段解析操作 */
        handleBidDetail(row) {
            this.$router.push({
                name: 'AnalysisBidDetail',
                query: {
                    proId: encryptWithSM4(row.proId + '' || '0'),
                },
            })
        },
        /** 查看标段操作 */
        handleBidListDetail(row) {
            this.$router.push({
                name: 'AnalysisBidIndex',
                query: {
                    proId: encryptWithSM4(row.proId + '' || '0'),
                },
            })
        },

        /* 搜索操作 */
        handleQuery() {
            this.$refs.analysisTableRef.getTableList()
        },

        /** 删除操作 */
        handleDelete(row) {
            this.$confirm(
                `确定要删除"${row.proName}"吗？删除后将无法恢复！`,
                '操作提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    dangerouslyUseHTMLString: true,
                    customClass: 'delete-confirm-dialog',
                },
            ).then(() => {
                delProDataAPI({
                    proId: row.proId,
                })
                    .then((res) => {
                        if (res.code === 200) {
                            this.$message.success('删除成功')
                            this.handleQuery()
                        } else {
                            this.$message.error(res.msg || '删除失败')
                        }
                    })
                    .catch((error) => {
                        console.error('删除失败:', error)
                    })
            })
        },
    },
}
</script>
<style scoped lang="scss">
.analysis-container {
    height: calc(100vh - 84px);
    overflow: hidden;
    background: linear-gradient(180deg, #f1f6ff 20%, #e5efff 100%);
}

::v-deep .table-card {
    height: calc(100vh - 230px) !important;
}

.add-btn {
    width: 121px;
    height: 36px;
    background: #1f72ea;
    box-shadow: 0px 4px 8px 0px rgba(51, 135, 255, 0.5);
    border-radius: 4px 4px 4px 4px;
    color: #fff;
    border: none;
    font-size: 14px;
    transition: all 0.3s;

    &:hover {
        background: #4a8bff;
        box-shadow: 0px 6px 12px 0px rgba(51, 135, 255, 0.6);
    }
}

.action-btn {
    margin-right: 8px;

    &:last-child {
        margin-right: 0;
    }
}
</style>
