<template>
    <div>
        <el-form :inline="true" class="demo-form-inline form">
            <el-form-item>
                <Area @click="handleNodeClick" ref="area"></Area>
            </el-form-item>

            <el-form-item label="干扰源类型:" class="box1">
                <el-select v-model="formData.loadType" clearable placeholder="请选择">
                    <el-option
                        v-for="item in interferenceType"
                        :key="item.id"
                        :label="item.label"
                        :value="item.id"
                    ></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="干扰源用户名称:">
                <el-input v-model="formData.userName" clearable placeholder="请输入关键字"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" class="ml10" icon="el-icon-search" @click="onsubmit">查询</el-button>
                <el-button type="primary" icon="el-icon-refresh" @click="Reset">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row>
            <el-col :span="24">
                <div class="button mb10">
                    <el-button type="primary" icon="el-icon-s-claim" @click="planReviewFn('')">审核</el-button>
                </div>
                <el-table
                    stripe
                    :data="reportreviewData"
                    :height="height"
                    border
                    style="width: 100%"
                    v-loading="isLoading"
                    header-cell-class-name="table_header"
                    @selection-change="handleSelectionChange"
                >
                    <el-table-column type="selection" width="55"></el-table-column>
                  <el-table-column type="selection" width="65"></el-table-column>
                  <el-table-column prop="orgName" label="所属单位" :show-overflow-tooltip="true"></el-table-column>
                  <el-table-column prop="loadType" label="干扰源类型" :show-overflow-tooltip="true"></el-table-column>
                  <el-table-column
                      prop="userName"
                      label="干扰源用户名称"
                      :show-overflow-tooltip="true"
                  ></el-table-column>
                  <el-table-column prop="recordTime" label="建档时间" :show-overflow-tooltip="true"></el-table-column>
                  <el-table-column prop="iisFileUpload" label="是否上传报告" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                      <span v-if="scope.row.iisFileUpload == 0" type="primary" size="small">否</span>
                      <span v-if="scope.row.iisFileUpload == 1" type="primary" size="small">是</span>
                    </template>
                  </el-table-column>


                  <el-table-column prop="createByName" label="创建人" :show-overflow-tooltip="true"></el-table-column>
                  <el-table-column prop="icheckPersonName" label="审核人" :show-overflow-tooltip="true"></el-table-column>


                  <el-table-column prop="istatus" label="状态" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                            <span
                                v-if="scope.row.istatus == 0"
                                type="primary"
                                size="small"
                                style="color: #da70d6"
                            >
                                新建
                            </span>
                      <span
                          v-else-if="scope.row.istatus == 1"
                          type="primary"
                          size="small"
                          style="color: #48d1cc"
                      >
                                待审核
                            </span>
                      <span
                          v-else-if="scope.row.istatus == 3"
                          type="primary"
                          size="small"
                          style="color: #dc143c; text-decoration: underline"
                          @click="failed = true"
                      >
                                未通过
                            </span>
                      <span
                          v-else-if="scope.row.istatus == 2"
                          type="primary"
                          size="small"
                          style="color: #9acd32"
                      >
                                通过
                            </span>
                      <span v-else type="primary" size="small">{{ scope.row.istatus }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column prop="plandetails" label="详情">
                    <template slot-scope="scope">
                      <!-- <span  type="primary" size="small" style="color:blue;text-decoration:underline" @click="userDetails=true">查看</span> -->
                      <el-button
                          v-if="scope.row.istatus != null"
                          @click="ck(scope.row)"
                          size="mini"
                          type="primary"
                      >
                        查看
                      </el-button>

                      <!--                          <el-button
                                                    v-if="scope.row.istatus != null"
                                                    @click="ck(scope.row)"
                                                    size="mini"
                                                    type="primary"
                                                >
                                                  编辑
                                                </el-button>-->

                      <el-button
                          v-if="scope.row.istatus != null"
                          @click="deleteData(scope.row)"
                          size="mini"
                          type="primary"
                      >
                        删除
                      </el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <el-pagination
                    class="mt10"
                    align="right"
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="formData.pageNum"
                    :page-sizes="[20, 30, 40, 50, 100]"
                    :page-size="formData.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                ></el-pagination>
            </el-col>
        </el-row>

        <!-- 审核弹窗 -->
        <el-dialog :close-on-click-modal="false" title="入网评估报告审核" :visible.sync="reportreview" width="1400px">

            <el-form :inline="true" :model="formdata">
              <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">基本信息</el-divider>
                <el-form-item label="所属单位">
                    <el-input v-model="formdata.orgName" disabled></el-input>
                </el-form-item>

                <el-form-item label="干扰源类型:" class="box1">
                    <el-select v-model="formdata.loadType" placeholder="请选择" disabled>
                        <el-option
                            v-for="item in interferenceType"
                            :key="item.id"
                            :label="item.label"
                            :value="{
                                label: item.name,
                                value: item.id,
                                code: item.code,
                                name: item.name,
                                id: item.id,
                                sort: item.sort
                            }"
                        ></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="干扰源用户名称:">
                    <el-input v-model="formdata.userName" clearable placeholder="请输入关键字" disabled></el-input>
                </el-form-item>

                <el-form-item label="建档时间">
                    <el-date-picker
                        v-model.trim="formdata.recordTime"
                        type="date"
                        placeholder="选择日期"
                        disabled
                    ></el-date-picker>
                </el-form-item>

                <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">
                    报告在线查看
                </el-divider>

              <el-form-item class="item" label="文件名称:">
                <el-input v-model="documentName1" clearable placeholder="请输入填报名称" disabled></el-input>
              </el-form-item>

              <el-form-item>
                <el-button size="small" type="primary" icon="el-icon-download" @click="xz">下载</el-button>
              </el-form-item>
              <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">
                入网评估结论填报
              </el-divider>

              <el-row>
                <el-form-item label="是否超标:">
                  <el-radio v-model="radio" label="0" disabled>是</el-radio>
                  <el-radio v-model="radio" label="1" disabled>否</el-radio>
                </el-form-item>
              </el-row>

              <el-row>
                <el-form-item label="超标指标:">
                  <el-checkbox-group v-model="checkedCities"  disabled>
                    <el-checkbox disabled v-for="(city, ind) in cities" :label="city.id" :key="ind">
                      {{ city.name }}
                    </el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
              </el-row>

              <el-row>
              <el-form-item label="计划采取措施:" style="margin-top: 20px">
                <el-select v-model="measures" placeholder="请选择" disabled>
                  <el-option
                      v-for="item in takeMeasures"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
              </el-row>
              <el-row>
              <el-form-item label="入网详情:" style="margin-top: 20px">
                <el-input
                    v-model="rwxq"
                    placeholder="请输入入网详情"
                    type="textarea"
                    style="width: 500px"
                    disabled
                ></el-input>
              </el-form-item>
              </el-row>

              <el-row style="margin-top: 10px">
              <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">审核意见</el-divider>
              <!-- <div style="width: 100%; display: flex; justify-content: center">
                  <div class="shyj">{{ textContent }}</div>
              </div> -->
              <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="textarea"></el-input>
              <div style="display: flex; justify-content: center; margin-top: 10px">
                <el-button type="primary" class="ml20" @click="passFn">通过</el-button>
                <el-button type="primary" class="ml20" @click="failFn">不通过</el-button>
              </div>
              </el-row>
            </el-form>

        </el-dialog>
    </div>
</template>

<script>
import Area from '@/views/components/Area/Area.vue'
//   import Timeinterval from "../../../components/Timeinterval.vue";
import { dicData } from '@/assets/commjs/dictypeData'
import {
    getLoadTypeUserList,
    checkLoadTypeUserI,
  getLoadTypeUserById
} from '@/api/Process-supervision/interferencemanagement/interferencemanagement'

export default {
    components: { Area },
    data() {
        return {
            vh: '',
            height: null,
            isLoading: false,
            reportreview: false,
            formData: {
                loadType: '',
                userName: '',
                orgNo: '',
                pageNum: 1,
                pageSize: 20
                // checkType: 1
            },
            formdata: {
                id:'',
                orgName: '',
                recordTime: '',
                loadType: '',
                userName: ''
            },
            radio:'',
            checkedCities: [],
            cities: [],
          takeMeasures: [],
          documentName1: '',
          measures: '',
          rwxq:'',
            //干扰源类型
            interferenceType: [],
            textarea: '',
            total: null,

            tableHeaderReportreview: [
                { prop: 'orgName', label: '所属单位' },
                { prop: 'loadType', label: '干扰源类型' },
                { prop: 'userName', label: '干扰源用户名称' },
                { prop: 'recordTime', label: '建档时间' },
                { prop: 'iuploadTime', label: '报告提交评估时间' }
            ],
            reportreviewData: [],
            multipleSelection: [],
            fileList: [],
            device: '',
            documentName: ''
        }
    },
    created() {
        this.getclassificationData()
        this.formData.orgNo = JSON.parse(window.sessionStorage.getItem('Info')).deptId

        this.cities = dicData('Steady_Statis', [])

        this.takeMeasures = dicData('Plan_Take', [], 1)
    },
    mounted() {
        this.onsubmit()
        this.setHeight()
        window.addEventListener('resize', this.setHeight)
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.device = window.devicePixelRatio
            this.height = window.sessionStorage.getItem('appheight') - 215
        },
        //获取类型
        getclassificationData() {
            //电压等级
            this.interferenceType = dicData('Interference_Source', [])
        },
        //预览
        handleRemove(file, fileList) {
            // console.log(file, fileList,'111111');
        },
        xz() {
            window.open(this.multipleSelection[0].ifile)
        },
        handleChange(file, fileList) {
            // console.log(file.name.split(".").splice(0, 1).toString());
            this.documentName = file.name.split('.').splice(0, 1).toString()
        },
        handleExceed(files, fileList) {
            this.$message.warning(
                `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
                    files.length + fileList.length
                } 个文件`
            )
        },
        beforeRemove(file, fileList) {
            return this.$confirm(`确定移除 ${file.name}?`)
        },
        //查询
        onsubmit() {
            this.isLoading = true
            this.formData.checkType = 1
            getLoadTypeUserList(this.formData).then(res => {
                this.isLoading = false
                this.reportreviewData = res.data.records
                this.total = res.data.total
            })
        },
        // 数据过滤
        formFilter(row, column) {
            if (column.property == 'loadType') {
                let title = ''
                this.interferenceType.forEach(item => {
                    if (item.id == row.loadType) {
                        title = item.name
                    }
                })
                return title
            } else {
                return row[column.property]
            }
        },
        //审核
        planReviewFn(planId) {
          if(planId && planId!==''){
            //说明是从代办页面点击过来的
            this.queryPlanOneDetail(planId)
          }else {
            if (this.multipleSelection.length == 1) {
              this.queryPlanOneDetail(this.multipleSelection[0].id)
            } else {
              this.$message({
                message: this.multipleSelection.length == 0 ? '请选择1条数据!' : '只能选择1条数据!',
                type: 'warning'
              })
            }
          }
        },

      //查询详情
      queryPlanOneDetail(planId){

        let data = {id:planId}
        getLoadTypeUserById(data).then(res => {
          if(res.code === 'A0000'){
            this.formdata = res.data
            this.documentName1 = res.data.ifilePath == null ? '' : res.data.ifilePath
            this.radio = res.data.iisOverLimit == null ? '' : res.data.iisOverLimit.toString()
            this.checkedCities = res.data.ioverLimitTarget == null ? '' : res.data.ioverLimitTarget.split(',')
            this.measures = res.data.iplanStep == null ? '' : res.data.iplanStep
            this.rwxq = res.data.idescription == null ? '' : res.data.idescription
            this.reportreview = true
          }

        })
      },

        //分页
        handleSizeChange(val) {
            this.formData.pageSize = val
            this.onsubmit()
        },
        handleCurrentChange(val) {
            this.formData.pageNum = val
            this.onsubmit()
        },
        //普测计划审核通过
        passFn() {
            checkLoadTypeUserI({
                checkComment: this.textarea,
                checkResult: 1,
                id: this.formdata.id
            }).then(res => {
                if (res.code === 'A0000') {
                    this.$message({
                        message: '审核完成',
                        type: 'success'
                    })
                    this.reportreview = false
                    this.onsubmit()
                } else {
                    this.$message({
                        message: res.message,
                        type: 'warning'
                    })
                }
            })
        },
        //普测计划不通过
        failFn() {
            checkLoadTypeUserI({
                checkComment: this.textarea,
                checkResult: 0,
                id:  this.formdata.id
            }).then(res => {
                if (res.code === 'A0000') {
                    this.$message({
                        message: '审核完成',
                        type: 'success'
                    })
                    this.reportreview = false
                } else {
                    this.$message({
                        message: res.message,
                        type: 'warning'
                    })
                }
            })
        },
        //普测计划取消
        cancelFn() {
            this.reportreview = false
        },
        // 切换选项
        handleNodeClick(data) {
            // console.log(data);
            this.formData.orgNo = data.id
        },
        //勾选
        handleSelectionChange(val) {
            this.multipleSelection = val
        },
        //重置
        Reset() {
            this.$refs.area.form.valueTitle = JSON.parse(window.sessionStorage.getItem('Info')).deptName
            this.formData = {
                orgNo: JSON.parse(window.sessionStorage.getItem('Info')).deptId,
                loadType: '',
                userName: '',

                pageNum: 1,
                pageSize: 20
            }
        },
        //序号
        rowClassName({ row, rowIndex }) {
            row.number = rowIndex + 1
        }
    }
}
</script>
<style lang="less" scoped>
@import url('../../../../styles/comStyle.less');
::v-deep .el-table .cell {
    text-align: center;
}
::v-deep .el-tabs--border-card > .el-tabs__content {
    padding: 10px;
}
::v-deep .form {
    .el-form-item {
        margin-bottom: 0;
    }
}
.button {
    float: right;
    margin-right: 5px;
}
::v-deep .el-dialog {
    display: flex;
    flex-direction: column;
    margin: 0 !important;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /*height:600px;*/
    max-height: calc(100% - 200px);
    max-width: calc(100% - 30px);
}
::v-deep .el-dialog .el-dialog__body {
    flex: 1;
    overflow: auto;
}
</style>
