<template>
    <!-- 上传 -->
    <el-dialog draggable :title="title" v-model="uploadConclusions" width="800px" :before-close="cancel">
        <el-divider content-position="left">基本信息</el-divider>
        <el-form
            :inline="true"
            ref="formRef"
            :model="addForm"
            label-width="120px"
            :rules="rules"
            :disabled="title == '未建档干扰源用户详情'"
        >
            <el-form-item label="所属单位:">
                <Area v-model="addForm.orgNo" disabled />
            </el-form-item>
            <el-form-item label="干扰源用户名称:" prop="userName">
                <el-input v-model="addForm.userName" clearable placeholder="请输入关键字" disabled></el-input>
            </el-form-item>
            <el-form-item label="干扰源类型:">
                <el-select v-model="addForm.loadType" clearable collapse-tags placeholder="请选择" disabled filterable>
                    <el-option
                        v-for="item in interferenceType"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="建档时间:">
                <el-input v-model="addForm.recordTime" clearable placeholder="请输入关键字" disabled></el-input>
            </el-form-item>

            <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">报告在线查看</el-divider>
            <el-form-item class="item" label="报告:">
                <el-button type="primary" link @click="download">
                    {{ addForm.ifilePathName }}
                </el-button>
            </el-form-item>
            <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">
                入网评估结论填报
            </el-divider>
            <el-form-item label="是否超标:" style="margin-top: 10px" prop="iIsOverLimit">
                <el-radio v-model="addForm.iIsOverLimit" :label="1" disabled>是</el-radio>
                <el-radio v-model="addForm.iIsOverLimit" :label="0" disabled>否</el-radio>
            </el-form-item>
            <br />
            <el-form-item label="超标指标:" style="margin-top: 10px" prop="IOverLimitTarget">
                <el-checkbox-group v-model="addForm.IOverLimitTarget" disabled>
                    <el-checkbox v-for="(item, ind) in exceeded" :label="item.id">
                        {{ item.name }}
                    </el-checkbox>
                </el-checkbox-group>
            </el-form-item>
            <br />
            <el-form-item label="计划采取措施:" style="margin-top: 10px" prop="IPlanStep">
                <el-select v-model="addForm.IPlanStep" placeholder="请选择" disabled filterable>
                    <el-option
                        v-for="item in takeMeasures"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                    ></el-option>
                </el-select>
            </el-form-item>
            <br />
            <el-form-item label="入网详情:" style="margin-top: 10px" prop="IDescription">
                <el-input
                    disabled
                    v-model="addForm.IDescription"
                    :autosize="{ minRows: 2, maxRows: 4 }"
                    placeholder="请输入入网详情"
                    type="textarea"
                    style="width: 500px"
                ></el-input>
            </el-form-item>
            <el-divider content-position="left" style="font-size: 18px; font-weight: bolder">审核意见</el-divider>
            <el-form-item prop="checkComment">
                <el-input
                    type="textarea"
                    style="width: 400px"
                    placeholder="请输入审核意见"
                    :autosize="{ minRows: 2, maxRows: 4 }"
                    v-model="addForm.checkComment"
                ></el-input>
            </el-form-item>
        </el-form>
        <div style="display: flex; justify-content: center; margin-top: 30px" v-if="title != '未建档干扰源用户详情'">
            <el-button type="primary" class="ml20" @click="submit(1)">通过</el-button>
            <el-button type="primary" class="ml20" @click="submit(0)">不通过</el-button>
            <el-button type="primary" class="ml20" @click="cancel">取消</el-button>
        </div>
    </el-dialog>
</template>
<script setup lang="ts">
import { ref, reactive } from 'vue'
import { useDictData } from '@/stores/dictData'
import Area from '@/components/form/area/index.vue'
import { UploadInstance, UploadProps, UploadRawFile, ElMessage, ElMessageBox } from 'element-plus'
import { genFileId } from 'element-plus'
import { checkLoadTypeUserI, getLoadTypeUserById } from '@/api/process-boot/interference'
const dictData = useDictData()

const exceeded = dictData.getBasicData('Steady_Statis')
const takeMeasures = dictData.getBasicData('Plan_Take')
const interferenceType = dictData.getBasicData('Interference_Source')

const emit = defineEmits(['onSubmit'])
const uploadConclusions = ref(false)

const addForm: any = ref({})

const title = ref('')
const rules = {
    checkComment: [{ required: true, message: '请输入入网详情', trigger: 'blur' }]
}
const formRef = ref()

const submit = (flag: any) => {
    formRef.value?.validate((valid: any) => {
        if (valid) {
            checkLoadTypeUserI({
                checkComment: addForm.value.checkComment,
                checkPerson: dictData.state.area[0].id,
                checkResult: flag,
                id: addForm.value.id
            }).then((res: any) => {
                ElMessage.success('操作成功')
                cancel()
                emit('onSubmit')
            })
        }
    })
}
// 下载
const download = async () => {
    // window.open(addForm.value.ifile)
    let response = await fetch(addForm.value.ifile)
    let blob = await response.blob()
    let a = document.createElement('a')
    a.href = window.URL.createObjectURL(blob)
    a.download = addForm.value.ifilePathName
    a.click()
    a.remove()
}

// 重置
const cancel = () => {
    addForm.value.checkComment = ''
    uploadConclusions.value = false
}

const open = (text: string, row: any) => {
    title.value = text
    addForm.value = {}
    getLoadTypeUserById({ id: row.id }).then((res: any) => {
        addForm.value = {
            id: res.data.id,
            orgNo: res.data.orgNo,
            loadType: res.data.loadType,
            userName: res.data.userName,
            recordTime: res.data.recordTime,
            iIsOverLimit: res.data.iisOverLimit ? res.data.iisOverLimit : 0,
            IDescription: res.data.idescription ? res.data.idescription : '',
            IPlanStep: res.data.iplanStep ? res.data.iplanStep : '',
            IOverLimitTarget: res.data.ioverLimitTarget ? res.data.ioverLimitTarget.split(',') : [],
            ifilePathName: res.data.ifilePathName ? res.data.ifilePathName : '',
            ifile: res.data.ifile
        }
    })

    uploadConclusions.value = true
}

defineExpose({ open })
</script>
<style lang="scss" scoped>
:deep(.el-upload-list__item) {
    width: 400px;
}
</style>
