<template>
    <div class='tableZh'>
        <div class='tab-top' style='display:flex;'>
            <div class='picker-box'>
                <span class='picker-span'>日期：</span>
                <el-date-picker
                    style='width:190px'
                    v-model='dateVal'
                    value-format='yyyyMMdd'
                    type='daterange'
                    @change='getZhjl'
                    size='mini'
                    range-separator='-'
                    start-placeholder
                    end-placeholder
                ></el-date-picker>
            </div>
            <Select
                @change='getZhjl'
                width='200'
                tipPlace='top'
                caption='政府部门：'
                size='small'
                v-model='searVal'
                style='margin-right:12px'
                v-if='department.length>0'
                :selectdata='department'
                :placeholder='"请选择"'
            ></Select>
            <el-input
                clearable
                placeholder='搜索记录事项'
                @keyup.enter.native='getZhjl'
                @blur='getZhjl'
                @change='getZhjl'
                size='small'
                prefix-icon='el-icon-search'
                v-model='ssjlsx'
                style='width:200px'
            ></el-input>
        </div>
        <el-table
            border
            @row-click='handdle'
            v-loading='loading'
            :header-cell-style='{background:"rgba(245,246,247,1)",fontFamily:"MicrosoftYaHei",color:"rgba(100,108,115,1)",lineHeight:"16px",fontSize:"12px"}'
            :data='zhjlTable'
            style='width: 100%;margin-top:12px'
        >
            <el-table-column label='序号' type='index' width='60' :index='indexMethod'></el-table-column>
            <el-table-column prop sortable label='日期' width='100' resizable>
                <template slot-scope='{row}'>{{formatter(row.createdate)||'--'}}</template>
            </el-table-column>
            <el-table-column prop label='政府部门' :show-overflow-tooltip='true' width='200'>
                <template slot-scope='{row}'>
                    {{row.department?row.department == '其他部门'?`${row.department} - ${row.otherdescription}`:row.department:'--'}}
                </template>
            </el-table-column>
            <el-table-column prop label='记录事项' :show-overflow-tooltip='true' min-width='660'>
                <template slot-scope='{row}'>{{row.recordsx||'--'}}</template>
            </el-table-column>
            <el-table-column prop label='工作要求' :show-overflow-tooltip='true' width='160'>
                <template slot-scope='{row}'>{{row.workyq||'--'}}</template>
            </el-table-column>
            <el-table-column prop label='整改事项' :show-overflow-tooltip='true' width='160'>
                <template slot-scope='{row}'>{{row.zgyq||'--'}}</template>
            </el-table-column>
            <el-table-column prop label='附件' width='80'>
                <template slot-scope='{row}'>
                    <div
                        v-if='row.glsmsZhsxfj'
                        style='cursor:pointer;color: #0091ff;'
                        @click='clickPic(row.glsmsZhsxfj)'
                    >{{row.glsmsZhsxfj.length+'张'}}</div>
                    <!-- <div style='cursor:pointer;color: #0091ff;' @click='clickPic'>{{5+'张'}}</div> -->
                    <div v-else>{{'--'}}</div>
                </template>
            </el-table-column>
        </el-table>
        <div class='foot'>
            <el-pagination
                background
                layout='prev, pager, next'
                :total='total'
                :page-size='size'
                @prev-click='pageChanged'
                @next-click='pageChanged'
                @current-change='pageChanged'
            ></el-pagination>
            <pic-large ref='picLargeOpen'></pic-large>
            <!-- <pic-large v-if='imgUrl.length>0' :imgUrl='imgUrl' ref='picLargeOpen'></pic-large> -->
        </div>
    </div>
</template>
<script>
import moment from 'moment'
import { Select } from 'meri-design'
// import Select from '@/components/Select/Select.vue'
import { queryGlams } from '@/api/other.js'
import { querySelect } from '@/api/public.js'

export default {
    data() {
        return {
            dateVal: '',
            loading: false,
            zhjlTable: [],
            searVal: '全部',
            total: 0,
            page: 1,
            size: 10,
            department: [],
            ssjlsx: '',
            isOpen: true,
            imgUrl: [],
            imgUrl2: [],
            imgUrls: [
                {
                    name: '供电系统原理图.png',
                    url:
                        'http://10.199.204.168:9080/doclinks/MANAGEINS/2020061921294136524467354%E4%BE%9B%E7%94%B5%E7%B3%BB%E7%BB%9F%E5%8E%9F%E7%90%86%E5%9B%BE.png',
                },
                {
                    name: '供电系统原理图.pdf',
                    url: 'http://10.199.204.168:9080/doclinks/MANAGEINS/2020061921260429024467352%E5%8C%BA%E4%BD%8D%E5%9B%BE.png',
                },
                {
                    name: '供电系统原理图.html',
                    url:
                        'http://10.199.204.168:9080/doclinks/MANAGEINS/2020061921294136524467354%E4%BE%9B%E7%94%B5%E7%B3%BB%E7%BB%9F%E5%8E%9F%E7%90%86%E5%9B%BE.png',
                },
                {
                    name: '供电系统原理图.png',
                    url:
                        'http://10.199.204.168:9080/doclinks/MANAGEINS/2020061921294136524467354%E4%BE%9B%E7%94%B5%E7%B3%BB%E7%BB%9F%E5%8E%9F%E7%90%86%E5%9B%BE.png',
                },
                {
                    name: '供电系统原理图.png',
                    url: 'http://gcgl.wanda.cn/%E7%BB%B4%E4%BF%AE%E5%B7%A5%E5%8D%95%E4%B8%80/WORKORDER_846049_2019-11-19T15-37-42-716.jpg',
                },
            ],
            allArr: [
                {
                    id: '全部',
                    name: '全部',
                },
            ],
        }
    },
    components: { Select },
    methods: {
        clickPic(row) {
            this.imgUrl = []
            if (row) {
                row.forEach((el) => {
                    let obj = {
                        name: el.description,
                        url: el.urlname,
                    }
                    this.imgUrl.push(obj)
                })
            }
            this.$refs.picLargeOpen.open(this.imgUrl)
            /* this.imgUrl = []
            this.imgUrl2 = []
            var patternFileExtension = /\.([0-9a-z]+)(?:[\?#]|$)/i
            if (this.imgUrls.length > 0) {
                this.imgUrls.forEach(el => {
                    let name = el.name.match(patternFileExtension)[1]
                    let obj = {
                        name: el.name,
                        url: el.url,
                        type: name
                    }
                    this.imgUrl.push(obj)
                })
            }
            console.log(this.imgUrl)
            // var fileExtension = '供电系统原理图.html'.match(patternFileExtension)
            // console.log(fileExtension[1])
            if (this.imgUrl.length > 0) {
                this.$refs.picLargeOpen.open(this.imgUrl)
            } */
        },
        formatter(date) {
            return moment.unix(date / 1000).format('YYYY.MM.DD')
        },
        rowClick() {},
        changeData(val) {
            //console.log(val)
        },
        indexMethod(index) {
            return (this.page - 1) * this.size + index + 1
        },
        // 综合记录
        getZhjl() {
            let getParams = {
                plazaId: this.$store.state.plazaId,
                page: this.page,
                size: this.size,
                orderBy: 'createdate,0',
            }
            if (this.searVal && this.searVal != '全部') {
                getParams.department = this.searVal
            }
            if (this.ssjlsx) {
                getParams.keyword = `${this.ssjlsx}:recordsx`
            }
            if (this.dateVal) {
                getParams.createdateStartDate = this.dateVal[0] + '000000'
                getParams.createdateEndDate = this.dateVal[1] + '000000'
            }
            queryGlams({ getParams }).then((res) => {
                if (res.result == 'success') {
                    this.loading = false
                    this.total = res.count
                    this.zhjlTable = res.data ? res.data : []
                }
                //console.log('综合记录', res)
            })
        },
        pageChanged(page) {
            this.page = page
            this.getZhjl()
        },
        changeSelect() {
            this.department = []
            let postParams = [
                {
                    columnName: { department: 'department' },
                    tableName: 'sms_zhsxjl',
                },
            ]
            let data = {
                plazaId: this.$store.state.plazaId,
            }
            querySelect({ data, postParams }).then((res) => {
                //console.log('政府部门', res)
                let department = [],
                    newArr = []
                department = res.data.data.sms_zhsxjl.department ? res.data.data.sms_zhsxjl.department : []
                if (department.length > 0) {
                    department.forEach((el) => {
                        let obj = {
                            id: el.key,
                            name: el.value,
                        }
                        newArr.push(obj)
                    })
                    //console.log(this.department)
                    this.department = this.allArr.concat(newArr)
                }
            })
        },
        handdle() {
            if (this.isOpen) {
                // window.open('http://bing.com', true)
            }
        },
    },
    mounted() {},
    created() {
        this.changeSelect()
    },
}
</script>
<style lang="less" scoped>
.tableZh {
    .picker-box {
        display: flex;
        align-items: center;
        background: #fff;
        padding: 0 6px;
        border: 1px solid #dcdfe6;
        border-radius: 4px;
        height: 32px;
        box-sizing: border-box;
        margin-right: 12px;
        .picker-span {
            margin-right: 6px;
            color: rgba(0, 0, 0, 0.65);
        }
    }
    .fileOpen {
        color: rgba(0, 145, 255, 1);
        cursor: pointer;
    }
}
</style>
<style lang="less">
.tableZh {
    .foot {
        height: 32px;
        display: flex;
        justify-content: flex-end;
        margin-top: 28px;
    }
    .picker-box {
        .el-input__inner {
            border: none;
        }
    }

    .el-range-editor.el-input__inner {
        padding: 3px 0px;
    }
    .el-icon-date {
        display: none;
    }
    .el-range__close-icon {
        position: absolute;
        right: 0px;
        top: 2px;
    }
    .el-range-editor--mini .el-range-input {
        font-size: 14px;
        color: rgb(31, 36, 41);
    }
}
</style>