<template>
    <div class="pd10" v-loading="isLoading" element-loading-text="数据加载中">
        <el-form :inline="true" :model="formData" class="demo-form-inline">
            <!-- <el-form-item>
            <Area @click="handleNodeClick" ref="area" @send="takeover"></Area>
          </el-form-item> -->
            <el-form-item>
                <Timeinterval ref="Timeinterval" :interval="3"></Timeinterval>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
                <!-- <el-button size="small" type="primary" icon="el-icon-circle-plus" @click="addFn">新增</el-button> -->
                <el-button size="small" type="primary" icon="el-icon-delete" @click="deleteFn">删除</el-button>
                <el-button size="small" type="primary" v-if="biaoCode === 'tjrbpush'" @click="push">上送网公司</el-button>
                <el-button size="small" type="primary" icon="el-icon-download" @click="exportEvent">导出</el-button>
            </el-form-item>
        </el-form>
        <vxe-table stripe :data="tableData" size="mini" ref="prealarmData"
            :row-config="{ isCurrent: true, isHover: true }" :height="vh" border style="width: 100%"
            header-cell-class-name="table_header" :header-cell-style="{
                height: '25px',
                padding: '0px'
            }" :row-style="{ height: '28px' }" :cell-style="{ padding: '0px' }" @checkbox-all="selectAllChangeEvent"
            @checkbox-change="handleSelectionChange">
            <vxe-table-column type="checkbox" align="center" width="55"></vxe-table-column>
            <vxe-table-column field="billNo" show-overflow align="center" title="单据编号"
                min-width="120px"></vxe-table-column>
            <vxe-table-column field="billName" show-overflow align="center" title="单据名称"
                min-width="120px"></vxe-table-column>
            <vxe-table-column field="executeOrgName" show-overflow align="center" title="项目执行单位名称"
                min-width="120px"></vxe-table-column>
            <vxe-table-column field="treatmentMeasures" show-overflow align="center" title="采取措施"
                min-width="120px"></vxe-table-column>
            <vxe-table-column field="fillUserName" show-overflow align="center" title="填报人名称"
                min-width="120px"></vxe-table-column>
            <vxe-table-column field="completeTime" show-overflow align="center" title="完成时间"
                min-width="120px"></vxe-table-column>
            <!-- <vxe-table-column field="workAlarmId" show-overflow align="center" title="告预警单id" min-width="120px"></vxe-table-column> -->
            <vxe-table-column field="feedbackOrgName" show-overflow align="center" title="反馈单位名称"
                min-width="120px"></vxe-table-column>
            <vxe-table-column field="provinceName" show-overflow align="center" title="省名称"
                min-width="120px"></vxe-table-column>
            <vxe-table-column field="province" show-overflow align="center" title="操作" min-width="120px">
                <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="modifyFn(scope.row)">修改</el-button>
                </template>
            </vxe-table-column>
        </vxe-table>
        <el-pagination background align="right" @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="formData.pageNum" :page-sizes="[20, 30, 50, 100]" :page-size="formData.pageSize"
            layout="total, sizes, prev, pager, next, jumper" :total="total" class="mt10"></el-pagination>
        <!-- 新增/修改 -->
        <el-dialog :close-on-click-modal="false" title="修改反馈数据" :visible.sync="modifyInformation" width="40%"
            height="80%">
            <el-form :inline="true" :model="form1" class="form" ref="form" label-width="130px" :rules="rules">
                <el-form-item label="项目执行单位名称:" class="mt10" prop="executeOrgName">
                    <Organization2 @click="handleNodeClick6" ref="Organization2" :valueTitle="valueTitle5"
                        @clear="clear('executeOrgId', 'executeOrgName')" :editCheckCode="editCheckCode5">
                    </Organization2>
                </el-form-item>

                <el-form-item label="填报人名称:" prop="fillUserId" class="mt10">
                    <el-select v-model="form1.fillUserId" clearable placeholder="请选择接收人名称" @change="changeFn">
                        <el-option v-for="item in ImplementationPeople" :key="item.id" :label="item.name"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="完成时间:" prop="completeTime" class="mt10">
                    <el-date-picker v-model="form1.completeTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
                        placeholder="选择日期"></el-date-picker>
                </el-form-item>
                <!-- <el-form-item label="告预警单id:" prop="workAlarmId" class="mt10">
                    <el-input v-model="form1.workAlarmId" ></el-input>
                </el-form-item> -->
                <el-form-item label="反馈单位名称:" class="mt10" prop="feedbackOrgName">
                    <Organization1 @click="handleNodeClick7" ref="Organization1" :valueTitle="valueTitle6"
                        @clear="clear('feedbackOrgId', 'feedbackOrgName')" :editCheckCode="editCheckCode6">
                    </Organization1>
                </el-form-item>
                <el-form-item label="采取措施:" prop="treatmentMeasures" class="mt10">
                    <el-input v-model="form1.treatmentMeasures" autosize type="textarea"></el-input>
                </el-form-item>
                <!-- <el-form-item label="省名称:" class="mt10" prop="provinceName" >
                  <Organization1
                    @click="handleNodeClick8" ref="Organization1" :valueTitle="valueTitle7" 
                    :editCheckCode="editCheckCode7"></Organization1>
                </el-form-item> -->
            </el-form>

            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="modifyInformation = false">取 消</el-button>
                <el-button type="primary" @click="modifyinformationFn">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import Area from '@/views/components/Area/Area.vue'
import Organization2 from './Area/Organization2.vue'
import Organization1 from './Area/Organization1.vue'
import Company from './Area/Company.vue'
import Timeinterval from '@/views/components/TimePicker/index4'
// import { dicData } from "@/assets/commjs/dictypeData";
import {
    getUserListByDeptId,
    pageAlarmBack,
    updateAlarmBack,
    delAlarmBack,
    pushAlarmHis,
    downAlarmBack
} from '@/api/Supervisionmanage2/feedbackdata'
import { listRoleMenu, updateRoleMenu } from '@/api/admin/role'
export default {
    components: { Area, Timeinterval, Organization2, Organization1 },
    props: {},
    data() {
        return {
            biaoCode: '',
            id: JSON.parse(window.sessionStorage.getItem('Info')).roleList[0],
            isLoading: false,
            modifyInformation: false,
            zoom: '', //图表焦点校验
            vh: undefined,
            editCheckCode6: '',
            valueTitle6: '',
            editCheckCode5: '',
            valueTitle5: '',
            formData: {
                searchBeginTime: '',
                searchEndTime: '',
                pageNum: 1,
                pageSize: 20
            },
            form1: {
                completeTime: '',
                executeOrgId: '',
                executeOrgName: '',
                feedbackOrgId: '',
                feedbackOrgName: '',
                fillUserId: '',
                fillUserName: '',
                treatmentMeasures: '',
                workAlarmId: ''
            },
            rules: {
                treatmentMeasures: [{ required: true, message: '请输入采取措施', trigger: 'blur' }],
                fillUserId: [{ required: true, message: '请选择接收人名称', trigger: 'change' }],
                completeTime: [{ required: true, message: '选择日期', trigger: 'change' }]
            },
            total: 0,
            tableData: [],
            multipleSelection: [],
            ImplementationPeople: []
        }
    },
    created() {
        this.getUserId()
    },
    mounted() {
        this.setHeight()
        window.addEventListener('resize', this.setHeight)
        this.listmenuRoleList()

        this.onSubmit()
        this.getUserId()
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.vh = window.sessionStorage.getItem('appheight') - 95
        },
        clear(key, key1) {
            this.form1[key] = ''
            this.form1[key1] = ''
        },
        //获取权限
        listmenuRoleList() {
            let p = { id: this.id }
            listRoleMenu(p).then(response => {
                let ids = []
                //console.log("权限资源",response.data)
                response.data.forEach(item => {
                    if (item.code === 'tjrbpush') {
                        this.biaoCode = item.code
                    }
                })
            })
        },
        // //获取类型
        // getclassificationData() {
        //     //计划状态
        //     this.planStatus = dicData("plan_status", []);
        // },
        // takeover(val){
        //   this.formData.searchValue = val[0].id
        //   this.onSubmit();
        // },
        getUserId() {
            let form = {
                deptId: JSON.parse(window.sessionStorage.getItem('Info')).deptId
            }
            getUserListByDeptId(form).then(res => {
                this.ImplementationPeople = res.data
            })
        },
        handleSelectionChange(val) {
            // console.log(val);
            this.multipleSelection = val.records
        },
        selectAllChangeEvent(val) {
            // console.log(val);
            this.multipleSelection = val.records
        },
        //查询
        onSubmit() {
            this.isLoading = true
            // this.$refs.Timeinterval.timeOptions = [
            //   // { label: "年份", value: 1 },
            //   // { label: "季度", value: 2 },
            //   { label: "月份", value: 3 },
            //   // { label: "周", value: 4 },
            //   // // { label: "自定义", value: 5 },
            // ]
            this.item = this.$refs.Timeinterval.timeValue
            this.formData.searchBeginTime = this.item[0]
            this.formData.searchEndTime = this.item[1]
            pageAlarmBack(this.formData).then(res => {
                this.tableData = res.data.records
                this.total = res.data.total
                this.isLoading = false
            })
        },
        //数据过滤
        // formFilter(row,column){
        //  if(row.column.property == "planStatus"){
        //       let title = ''
        //       this.planStatus.forEach(item=>{
        //           if( item.id == row.row.planStatus ){
        //               title =item.name
        //           }
        //       })
        //       return title
        //   }else {
        //     return row.row[row.column.property];
        //     }
        // },
        //新增
        // addFn(){
        //   this.modifyInformation = true
        //   this.valueTitle = ''
        //   this.editCheckCode = ''
        //   this.form = {
        //         billNo:'',
        //         billName:'',
        //         billType:'',
        //         createrOrgName:'',
        //         specialityType:'',
        //         orgName:'',
        //         receiveUserName:'',
        //         createrTime:'',
        //         managerDeptName:'',
        //         mainSenderName:'',
        //         copySenderName:'',
        //         techSupvBasis:'',
        //         problemDesc:'',
        //         dealAdvise:'',
        //     }
        // },
        //修改
        modifyFn(val) {
            this.modifyInformation = true
            this.valueTitle5 = val.executeOrgName
            this.editCheckCode5 = val.executeOrgId
            this.valueTitle6 = val.feedbackOrgName
            this.editCheckCode6 = val.feedbackOrgId
            this.form1 = JSON.parse(JSON.stringify(val))
        },
        //修改确定
        modifyinformationFn() {
            this.$confirm('是否确认修改?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    updateAlarmBack(this.form1).then(res => {
                        if (res.code == 'A0000') {
                            this.$message({
                                type: 'success',
                                message: res.message
                            })
                        }
                        this.onSubmit()
                        this.modifyInformation = false
                    })
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消修改'
                    })
                })
        },
        //导出
        exportEvent() {
            // pageAlarmBack({
            //   searchBeginTime:this.formData.searchBeginTime,
            //   searchEndTime:this.formData.searchEndTime,
            //   orgId:this.formData.orgId ,
            //   pageNum: 1,
            //   pageSize: this.total,
            // }).then((res) => {
            //   res.data.records.forEach(item=>{
            //     if(item.isUploadHead == 0){
            //       item.isUploadHead = '未上送'
            //     }else if(item.isUploadHead == 1){
            //       item.isUploadHead = '已上送'
            //     }else if(item.isUploadHead == 2){
            //       item.isUploadHead = '取消上送'
            //     }
            //   })
            //   this.$refs.prealarmData.exportData({
            //     filename: '技术监督预告警单反馈数据', // 文件名字
            //     sheetName: "Sheet1",
            //     type: "xlsx", //导出文件类型 xlsx 和 csv
            //     useStyle: true,
            //     data: res.data.records, // 数据源 // 过滤那个字段导出
            //     columnFilterMethod: function (column, $columnIndex) {
            //       return !(column.$columnIndex === 0);
            //     },
            //   });
            // });
            downAlarmBack().then(res => {
                let blob = new Blob([res], {
                    type: 'application/vnd.ms-excel'
                })
                const url = window.URL.createObjectURL(blob)
                const link = document.createElement('a') // 创建a标签
                link.href = url // link.download = "电压暂降事件分析报告"; // 设置下载的文件名
                link.download = '技术监督预告警单反馈数据.xls' // 设置下载的文件名
                document.body.appendChild(link)
                link.click() //执行下载
                document.body.removeChild(link)
            })
        },
        //计划上送网公司
        push() {
            if (this.multipleSelection.length == 0) {
                this.$message({
                    showClose: true,
                    message: '请选择一条数据上送网公司!!!',
                    type: 'warning'
                })
                return
            }
            // let isUpload = []
            // this.multipleSelection.forEach(item=>{
            //   isUpload.push(item.isUploadHead)
            // })
            // if(isUpload.includes(1) == true){
            //       this.$message({
            //               type: "warning",
            //               message: '已上送,无需重复上送',
            //               });
            //               return
            // }else{
            this.$confirm('是否确认上送网公司?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    let ids = []
                    this.multipleSelection.forEach(item => {
                        ids.push(item.alarmBackId)
                    })

                    pushAlarmHis(ids).then(res => {
                        if ((res.code == 'A0000')) {
                            this.$message({
                                type: 'success',
                                message: res.message
                            })
                        }
                        this.onSubmit()
                    })
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消上送'
                    })
                })
            // }
        },
        // 删除
        deleteFn() {
            if (this.multipleSelection.length == 0) {
                this.$message({
                    showClose: true,
                    message: '请选择一条数据删除!!!',
                    type: 'warning'
                })
                return
            }
            this.$confirm('是否确认删除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    let planIds = []
                    this.multipleSelection.forEach(item => {
                        planIds.push(item.alarmBackId)
                    })

                    delAlarmBack(planIds).then(res => {
                        if ((res.code == 'A0000')) {
                            this.$message({
                                type: 'success',
                                message: res.message
                            })
                        }
                        this.onSubmit()
                    })
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
        },
        changeFn(val) {
            this.ImplementationPeople.forEach(item => {
                if (val == item.id) {
                    this.form1.fillUserName = item.name
                }
            })
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.formData.pageSize = val
            this.onSubmit()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.formData.pageNum = val
            this.onSubmit()
        },
        handleNodeClick(data) {
            // this.formData.searchValue = data.id
        },
        handleNodeClick6(data) {
            this.form1.executeOrgId = data.code
            this.form1.executeOrgName = data.name
        },
        handleNodeClick7(data) {
            this.form1.feedbackOrgId = data.code
            this.form1.feedbackOrgName = data.name
        }
    },

    computed: {},

    watch: {}
}
</script>
<style lang="less" scoped>
@import url('../../../styles/comStyle.less');

::v-deep .el-form-item--small .el-form-item__content,
.el-form-item--small .el-form-item__label {
    height: 32px;
}

::v-deep .form {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;

    .el-form-item {
        display: flex;
        width: 48%;

        .el-form-item__content {
            flex: 1 !important;

            .el-select {
                width: 100%;
            }

            .el-input__inner {
                width: 100% !important;
            }

            .el-date-editor {
                width: 100%;
            }
        }
    }
}

::v-deep .el-form-item--small .el-form-item__error {
    padding-top: 8px;
}

::v-deep .vxe-table .cell {
    text-align: center;
}
</style>
