<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container">
        <div class="container-box">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div class="search">
                <mySearch :searchList="searchList" @searchInfo="searchInfo"></mySearch>
            </div>
            <div class="tabbox">
                <el-table class="com-table" ref="multipleTable" :data="tableData" tooltip-effect="dark" size="small" border
                    style="width: 100%;height:calc(100% - 60px);overflow: scroll;">
                    <el-table-column prop="noticeTitle" label="公告标题">
                    </el-table-column>
                    <el-table-column label="公告内容">
                        <template slot-scope="scope">
                            <el-tooltip class="item" effect="light" :content="scope.row.noticeContent" placement="bottom">
                                <span class="tab-long">{{scope.row.noticeContent}}</span>
                            </el-tooltip>
                        </template>
                    </el-table-column >

                    <el-table-column prop="pubOpName" label="发布姓名">
                        <template slot-scope="scope">
                            <span>{{$desensitization(scope.row.pubOpName,1)}}</span>
                        </template>
                    </el-table-column>
                   <!-- <el-table-column prop="contactPhone" label="联系电话">
                    </el-table-column> -->
                    <el-table-column prop="deptName" label="查看部门">
                    </el-table-column>
                    <el-table-column prop="opTime" label="查看时间">
                    </el-table-column>
                    <!-- <el-table-column label="操作" width="160px" align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(2,scope.row)">查看</el-button>
                        </template>
                    </el-table-column> -->
                </el-table>
                <el-pagination class="pageBox" @current-change="currchange" layout="prev, pager, next" background :total="total">
                </el-pagination>
            </div>
            <el-dialog :title="titname" :visible.sync="dialogStatus" width="50%" :destroy-on-close="true"
                :modal-append-to-body="false" :close-on-click-modal="false">
                <div>
                    <div style="padding-left: 80px" v-if="!disableStatus">
                        <myUpload @uploadBack="uploadBack" :fileInfo="fileInfo" :fileList="fileInfo.fileList"></myUpload>
                    </div>
                    <div style="padding-left: 80px" v-if="disableStatus">
                        <uploadDown :datalist="datalist" :dialogStatus="uploadstatus"></uploadDown>
                    </div>
                </div>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogCli(1)">取 消</el-button>
                    <el-button type="primary" @click="dialogCli(2)">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </fullscreen>
</template>
<script>
    import myUpload from "../../../components/upload";
    import uploadDown from "../../../components/uploadDown";
    import mySearch from '../../../components/search'
    import toolList from '../../../components/toolList'

    export default {
        components: {
            myUpload,
            uploadDown,
            mySearch,
            toolList
        },
        data() {
            const knowledgeTitle = (rule, value, callback) => {
                if (!this.infolist.knowledgeTitle) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const opName = (rule, value, callback) => {
                if (!this.infolist.opName) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const contactPhone = (rule, value, callback) => {
                if (!this.infolist.contactPhone) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const pubDeptId = (rule, value, callback) => {
                if (!this.infolist.pubDeptId) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                rules: {
                    pubDeptId: [{
                        required: true,
                        trigger: 'change',
                        validator: pubDeptId
                    }],
                    contactPhone: [{
                        required: true,
                        trigger: 'blur',
                        validator: contactPhone
                    }],
                    opName: [{
                        required: true,
                        trigger: 'blur',
                        validator: opName
                    }],
                    knowledgeTitle: [{
                        required: true,
                        trigger: 'blur',
                        validator: knowledgeTitle
                    }],
                },
                tooltit: '浏览日志',
                fullscreen: false,
                total: 0,
                pageSize: 1,
                notice: {
                    input: '',
                    startime: null,
                    endtime: null,
                },
                tableData: [],
                dialogStatus: false,
                fileInfo: {
                    limit: 5,
                    url: 'satisfy/cknowledgeatt/upload',
                    fileList: []
                },
                datalist: {
                    url: '/sysmgr/noticeatt/downfile',
                    type: 2
                },
                uploadstatus: false,
                infolist: {},
                typeOptions: [],
                titname: '查看日志',
                disableStatus: false,
                visibleList: [],
                visiblec: [],
                attList: [],
                userInfo: {},
                searchList: [{
                        type: 'input',
                        tit: '请输入标题',
                        value: '',
                        width: '32%'
                    },
                    {
                        type: 'date',
                        tit: '开始时间',
                        value: '',
                        width: '32%',
                    },
                    {
                        type: 'date',
                        tit: '结束时间',
                        value: '',
                        width: '32%',
                    },
                ],
                params: {}
            }
        },
        methods: {
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.noticeTitle = v[0] : '';
                v[1] ? this.params.opTimeFrom = this.$formatDate(v[1], "YYYY-MM-DD") : '';
                v[2] ? this.params.opTimeTo = this.$formatDate(v[2], "YYYY-MM-DD") : '';
                this.getList(this.params, this.pageSize);
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.$http({
                    url: "/sysmgr/cnoticelog/queryLogPage",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                    },
                    data: v,
                }).then((res) => {
                    this.tableData = res.data.data;
                    this.total = res.data.totalRecord;
                    // for (let i = 0; i < this.tableData.length; i++) {
                    //     _this.tableData[i].pubTime = _this.timeChange(_this.tableData[i].pubTime);
                    // }
                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            //查看
            dialogCheck(v, n) {
                this.dialogStatus = true;
                this.disableStatus = false;
                this.visiblec = [];
                if (v === 1) {
                    this.titname = '新建';
                    this.infolist = {};
                    return
                } else if (v === 2) {
                    this.titname = '查看';
                    this.disableStatus = true;
                } else if (v === 3) {
                    this.titname = '修改';
                }
                this.infolist = Object.assign({}, n); //拷贝
                this.$http({
                    url: "",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    console.log(res.data);
                    this.datalist.attList = res.data.attList;
                    this.uploadstatus = true;
                    this.infolist = res.data;
                    this.fileInfo.fileList = [];
                    this.attList = [];
                    res.data.attList.forEach(item => {
                        this.fileInfo.fileList.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            fileName: item.fileName
                        });
                        this.attList.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            fileName: item.fileName
                        });
                    })
                    res.data.deptList.forEach(item => {
                        this.visiblec.push(item.deptCode);
                    })
                });
            },
            //修改  添加
            dialogCli(v) {
                this.datalist.attList = [];
                this.uploadstatus = false;
                if (v === 2) {
                    this.fileInfo.fileList = [];
                    this.infolist = {};
                    this.dialogStatus = false;
                    return
                }
                this.infolist.time = new Date().getTime();
                if (this.titname === '新建') {
                    this.submitInfo("///save", v);
                } else if (this.titname === '修改') {
                    this.submitInfo("///update", v);
                }
            },
            submitInfo(u, v) {
                let _this = this;
                this.$refs.infolist.validate(valid => {
                    if (valid) {
                        this.infolist.visibleList = this.visibleList;
                        let attList = [];
                        for (let i = 0; i < this.attList.length; i++) {
                            attList.push({
								id: this.attList[i].id,
								fileCode: this.attList[i].fileCode,
								fileName: this.attList[i].fileName,
								opName: this.attList[i].opName,
								opNo: this.attList[i].opNo,
								opTime: this.attList[i].opTime,
                                noticeId: this.infolist.noticeId
                            });
                        }
                        this.$http({
                            url: u,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: {
                                noticeInfo: this.infolist,
                                attList: attList,
                                deptList: this.visibleList
                            },
                        }).then((res) => {
                            if (res.data.result === 1) {
                                _this.$message({
                                    message: res.data.desc,
                                    type: 'error'
                                });
                            } else {
                                _this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                                _this.fileInfo.fileList = [];
                                _this.infolist = {};
                                _this.dialogStatus = false;
                                _this.getList({}, _this.pageSize);
                            }

                        });
                    }
                })
            },
            //获取部门
            getDepot() {
                this.$http({
                    url: "/sysmgr/sysdept/queryList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.typeOptions = res.data;
                });
            },
            //时间转换
            timeChange(v) {
                var time = new Date(v * 1);
                var y = time.getFullYear();
                var m = time.getMonth() + 1;
                m < 10 ? '0' + m : m;
                var d = time.getDate();
                d < 10 ? '0' + d : d;
                var h = time.getHours();
                h < 10 ? '0' + h : h;
                var mm = time.getMinutes();
                mm < 10 ? '0' + mm : mm;
                var s = time.getSeconds();
                s < 10 ? '0' + s : s;
                return y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
            },
            //功能栏
            iconCli(v) {
                if (v === 1) {
                    this.getList(this.params, this.pageSize);
                }
                if (v === 2) {
                    this.fullscreen = !this.fullscreen
                }
            },
            //文件返回值
            uploadBack(v) {
                this.attList = v;
            },
            getUser() {
                this.userInfo = JSON.parse(window.sessionStorage.userInfo);
                // this.infolist.regionName = '';
                // this.infolist.regionCode = '';
                this.infolist.opNo = this.userInfo.loginNo;
                // this.infolist.deptName = '';
                // this.infolist.deptCode = '';
                this.infolist.opName = this.userInfo.loginName;
                this.infolist.phoneNo = this.userInfo.phoneNo;
            }
        },
        mounted() {
            this.getList({}, 1);
            // this.getDepot();
            // this.getUser();
        },
        created() {

        }
    }
</script>
<style scoped lang="scss">
    @import "../../../assets/style";
    .tab-long {
        height: 22px;
        float: left;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        /* 将对象作为弹性伸缩盒子模型显示 */
        -webkit-line-clamp: 1;
        /* 控制最多显示几行 */
        -webkit-box-orient: vertical;
        /* 设置或检索伸缩盒对象的子元素的排列方式 */
    }

    .titbox {
        div {
            float: right;

            i {
                font-size: 22px;
                margin-left: 20px;
                cursor: pointer;
            }
        }
    }

    .search-box {
        margin-top: 20px;

        .sel {
            width: 20%;
            margin-right: 10px;
        }

        .dtime {
            width: 20%;
            margin-right: 10px;
        }

        .s-name {
            width: 20%;
            margin-right: 10px;
        }

        .btn-check {
            float: right;
        }
    }

    .tabbox {
        margin-top: 15px;
    }

    .pageBox {
        text-align: right;
        margin-top: 10px;
    }

    .info-line {
        width: 100%;
        display: block;
        padding-left: 20px;

        div {
            width: 50%;
            display: inline-block;
        }

        span {
            width: 80px;
            display: inline-block;
            text-align: left;

            i {
                color: red;
                display: inline-block;
                padding-right: 5px;
            }
        }

        .el-select,
        .el-input {
            width: calc(100% - 100px);
        }
    }

    .online {
        width: 100%;

        .el-select {
            width: calc(100% - 100px);
        }

        span {
            vertical-align: top;
        }

        .el-textarea {
            width: calc(100% - 100px);
        }
    }
</style>
