<template>
    <div class="container">
        <header>
            <el-form :label-width="120">
                <el-row>
                    <el-col :span="6">
                        <el-form-item label="问题发现时间">
                            <date-time-range-picker-ext
                                v-model="query.discoveryTime"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="问题发生时间">
                            <date-time-range-picker-ext
                                v-model="query.happenTime"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="问题录入时间">
                            <date-time-range-picker-ext
                                v-model="query.crtTime"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <div class="form-row flex">
                    <label class="text-center">问题信息</label>
                    <div class="flex wrap query-box">
                        <el-input
                            placeholder="问题编号 / 样本源头编号"
                            v-model="query.originId"
                            clearable
                            style="width: 200px"
                        />
                        <el-input
                            placeholder="涉及案件 / 警情编号"
                            v-model="query.caseNumber"
                            clearable
                            style="width: 200px"
                        />
                        <el-input
                            placeholder="事情简要描述"
                            v-model="query.thingDesc"
                            clearable
                            style="width: 260px"
                        />
                        <el-select
                            style="width: 146px"
                            placeholder="业务类别"
                            clearable
                            v-model="query.businessTypeCode"
                        >
                            <el-option
                                v-for="item in dict.businessType"
                                :key="item.id"
                                :label="item.dictLabel"
                                :value="item.dictValue"
                            />
                        </el-select>
                        <el-tree-select
                            :data="dictProblemSources"
                            :props="{ value: 'id' }"
                            node-key="id"
                            v-model="query.problemSourcesCode"
                            clearable
                            filterable
                            multiple
                            collapse-tags
                            style="width: 180px"
                            placeholder="问题来源"
                        />
                        <el-select
                            style="width: 146px"
                            placeholder="专项督察"
                            clearable
                            v-model="query.specialSupervision"
                        >
                            <el-option
                                v-for="item in dict.specialSupervision"
                                :key="item.id"
                                :label="item.dictLabel"
                                :value="item.dictValue"
                            />
                        </el-select>
                        <el-input
                            placeholder="通报期数"
                            style="width: 146px"
                            v-model="query.reportNumber"
                            clearable
                        />
                        
                    </div>
                </div>
                <div class="form-row flex">
                    <label class="text-center">核查情况</label>
                    <div class="flex wrap query-box">
                        <div style="width: 200px">
                            <depart-tree-select
                                v-model="query.involveDepartId"
                                placeholder="涉及单位"
                            />
                        </div>
                        <div style="width: 200px">
                            <depart-tree-select
                                v-model="query.handleDepartId"
                                placeholder="办理单位"
                            />
                        </div>
                        <el-select
                            style="width: 120px"
                            placeholder="是否属实"
                            clearable
                            v-model="query.checkStatus"
                        >
                            <el-option
                                v-for="item in dict.inspectCase"
                                :key="item.id"
                                :label="item.dictLabel"
                                :value="item.dictValue"
                            />
                        </el-select>
                        <el-select
                            style="width: 120px"
                            placeholder="是否整改"
                            clearable
                            v-model="query.isRectifyCode"
                        >
                            <el-option
                                v-for="item in dict.isRectify"
                                :key="item.id"
                                :label="item.dictLabel"
                                :value="item.dictValue"
                            />
                        </el-select>
                        <div class="flex gap-4">
                            <el-select
                                v-model="query.blameKey"
                                style="width: 90px"
                                @change="delete query.blameValue"
                            >
                                <el-option value="name" label="姓名" />
                                <el-option value="empNo" label="警号" />
                                <el-option value="idCode" label="身份证" />
                            </el-select>
                            <el-input
                                placeholder="涉及人员"
                                v-model="query.blameValue"
                                clearable
                                style="width: 190px"
                            />
                        </div>
                        <el-select placeholder="处置结果"
                                v-model="query.handleResultCode"
                                clearable
                                style="width: 280px" multiple>
                            <el-option
                                v-for="item in dict.handleResult"
                                :key="item.id"
                                :label="item.dictLabel"
                                :value="item.dictValue"
                            />
                        </el-select>
                    </div>
                </div>
                <div class="form-row flex">
                    <label class="text-center">其他选项</label>
                    <div class="flex wrap query-box">
                        <el-select
                            style="width: 200px"
                            placeholder="流程阶段"
                            clearable
                            v-model="query.flowKey"
                        >
                            <el-option
                                v-for="item in flowNodes"
                                :key="item.flowKey"
                                :label="item.flowName"
                                :value="item.flowKey"
                            />
                        </el-select>
                        <el-select
                            style="width: 120px"
                            placeholder="办理状态"
                            clearable
                            v-model="query.processingStatus"
                            multiple
                        >
                            <el-option
                                v-for="item in dict.processingStatus"
                                :key="item.id"
                                :label="item.dictLabel"
                                :value="item.dictValue"
                            />
                        </el-select>
                        
                        <el-select
                            style="width: 120px"
                            placeholder="是否超时"
                            clearable
                            v-model="query.timeoutFlag"
                        >
                            <el-option label="未超时" :value="false" />
                            <el-option label="已超时" :value="true" />
                        </el-select>
                        <div class="flex gap-4">
                            <el-select
                                v-model="query.responderKey"
                                style="width: 90px"
                                @change="delete query.responderValue"
                            >
                                <el-option value="name" label="姓名" />
                                <el-option value="phone" label="电话" />
                            </el-select>
                            <el-input
                                placeholder="投诉反映人"
                                v-model="query.responderValue"
                                clearable
                                style="width: 190px"
                            />
                        </div>
                        <el-select
                            style="width: 120px"
                            placeholder="申请延期"
                            clearable
                            v-model="query.extensionFlag"
                        >
                            <el-option label="已申请" :value="true" />
                            <el-option label="未申请" :value="false" />
                        </el-select>
                        <el-select
                            style="width: 140px"
                            placeholder="下发单位层级"
                            clearable
                            v-model="query.crtDepartLevel"
                        >
                            <el-option label="市局下发" :value="0" />
                            <el-option label="二级机构下发" :value="2" />
                        </el-select>
                    </div>
                </div>
            </el-form>
            <div class="flex end mt-20 mb-26">
                <div>
                    <el-button type="primary" @click="getList">
                        <template #icon
                            ><icon name="el-icon-Search"
                        /></template>
                        查询</el-button
                    >
                    <el-button @click="reset">重置</el-button>
                </div>
            </div>
        </header>
        <div class="table-container" v-loading="loading">
            <el-table :data="dones">
                <el-table-column type="expand">
                    <template #default="{ row }">
                            <div class="row mt-10">
                                <div class="col col-6">
                                    <label>样本源头编号</label>
                                    <span>{{ row.originId }}</span>
                                </div>
                                <div class="col col-6">
                                    <label>问题发现时间</label>
                                    <span>{{ row.discoveryTime }}</span>
                                </div>
                                <div class="col col-6">
                                    <label>问题发生时间</label>
                                    <span>{{ row.happenTime || "/" }}</span>
                                </div>
                                <div class="col col-6">
                                    <label>问题录入时间</label>
                                    <span>{{ row.crtTime }}</span>
                                </div>
                            </div>
                            <div class="row mt-10">
                                <div class="col col-6">
                                    <label>问题来源</label>
                                    <span>{{ row.problemSources }}</span>
                                </div>
                                <div class="col col-6">
                                    <label>业务类别</label>
                                    <span>{{ row.businessTypeName }}</span>
                                </div>
                                <div class="col col-12">
                                    <label>涉嫌问题</label>
                                    <span>{{
                                        getInvolveProblem(row.involveProblem, dict.suspectProblem)
                                    }}</span>
                                </div>
                            </div>
                            <div class="row mt-10">
                                <div class="col col-6" v-if="row.responderName">
                                    <label>投诉反映人</label>
                                    <span>{{ row.responderName }}</span>
                                </div>
                                <div class="col col-6" v-if="row.contactPhone">
                                    <label>联系电话</label>
                                    <span>{{ row.contactPhone }}</span>
                                </div>
                            </div>

                            <div class="row mt-10">
                                <div class="col col-6">
                                    <label>涉及警种</label>
                                    <span>{{ row.policeTypeName }}</span>
                                </div>
                                <div class="col col-6">
                                    <label>涉及单位</label>
                                    <span>{{
                                        row.involveDepartName || "/"
                                    }}</span>
                                </div>
                            </div>
                            <div class="row mt-10">
                                <div class="col col-24">
                                    <label>事情简要描述</label>
                                    <span>{{ row.thingDesc }}</span>
                                </div>
                            </div>
                        </template>
                </el-table-column>
                <el-table-column label="问题发现时间" prop="discoveryTime" width="150" />
                <el-table-column label="问题来源" prop="problemSources" width="90" />
                <el-table-column label="业务类别" prop="businessTypeName" width="100" />
                <el-table-column label="涉嫌问题">
                    <template #default="{ row }">
                        <span>{{ getInvolveProblem(row.involveProblem, dict.suspectProblem) }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="问题内容" prop="thingDesc" show-overflow-tooltip />
                <el-table-column label="涉及单位" show-overflow-tooltip>
                        <template #default="{ row }">
                            <span>{{ row.involveDepartName }}</span>
                        </template>
                    </el-table-column>
                <el-table-column label="办理单位" show-overflow-tooltip>
                        <template #default="{ row }">
                            <span>{{row.handleSecondDepartName}}{{row.handleThreeDepartName}}</span>
                        </template>
                    </el-table-column>
                <el-table-column label="办理状态" width="100" align="center">
                    <template #default="{ row }">
                        <el-tag>{{
                            getDictLable(
                                dict.processingStatus,
                                row.processingStatus
                            )
                        }}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="流程节点" width="120" align="center">
                    <template #default="{ row }">
                        <el-tag v-if="row.flowKey">{{
                            flowNodes.filter(
                                (item) => item.flowKey === row.flowKey
                            )[0]?.flowName
                        }}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="当前处理对象" prop="currentProcessingObject" show-overflow-tooltip />
                <el-table-column label="操作" width="120">
                    <template #default="{ row }">
                        <el-button type="primary" link @click="handleAction(row)"
                            >详情</el-button
                        >
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="flex end mt-8">
            <el-pagination
                @size-change="getList"
                @current-change="getList"
                :page-sizes="[10, 20, 50]"
                v-model:page-size="query.size"
                v-model:current-page="query.current"
                layout="total, sizes, prev, pager, next"
                :total="total"
            >
            </el-pagination>
        </div>
    </div>

    <negative-dialog v-model="show" :id="activeNegativeId"/>
</template>
<script lang="ts" setup>
import { listDones } from '@/api/work'
import { getDictLable, getInvolveProblem } from '@/utils/util'
import useCatchStore from '@/stores/modules/catch'

const catchStore = useCatchStore();
const dict = catchStore.getDicts(['businessType', 'suspectProblem', 'processingStatus'])
const dictProblemSources = catchStore.getDictProblemSources();
const flowNodes = catchStore.getFlowNodes();

const dones = ref([])
const query = ref({
    current: 1,
    size: 10
});
const total = ref(0);
const loading = ref(true)

function getList() {
    loading.value = true
    listDones(query.value).then(data => {
        dones.value = data.records
        total.value = data.total
        loading.value = false
    })
}

onMounted(() => {
    getList()

})

function reset() {
    query.value = {
        current: 1,
        size: 10
    }
    getList()
}

const show = ref(false)
const activeNegativeId = ref('')

function handleAction(row) {
    show.value = true
    activeNegativeId.value = row.negativeId
}
</script>