<template>
    <div class="container">
        <fullscreen :fullscreen.sync="fullscreen" class="container-box">
            <div class="titbox">
                <h2>待办任务</h2>
                <div>
                    <i class="el-icon-refresh" @click="iconCli(1)"></i>
                    <i class="el-icon-full-screen" @click="iconCli(2)"></i>
                    <!--                    <i class="el-icon-folder-opened"></i>-->
                    <!--                    <i class="el-icon-view"></i>-->
                    <!--                    <i class="el-icon-more"></i>-->
                </div>
            </div>
            <div class="search">
                <mySearch :searchList="searchList" @searchInfo="searchInfo"></mySearch>
            </div>
            <div class="tabbox">
                <el-table height="calc(100% - 40px)" class="com-table" ref="multipleTable" :data="tableData" tooltip-effect="dark" size="small"
                    border style="width: 100%">
                    <el-table-column prop="terminalTypeName" label="任务标题">
                    </el-table-column>
                    <el-table-column prop="brandName" label="派发人">
                    </el-table-column>
                    <el-table-column prop="modelType" label="派发姓名">
                    </el-table-column>
                    <el-table-column prop="num" label="派发时间">
                    </el-table-column>
                    <el-table-column label="操作" width="180px" align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(1,scope.row)">查看</el-button>
                            <el-button size="mini" type="primary" @click="dialogCheck(2,scope.row)">回复</el-button>
                            <el-button size="mini" type="primary" @click="dialogCheck(3,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>
        </fullscreen>
        <el-dialog :title="titname" :visible.sync="dialogStatus" width="50%" :destroy-on-close="true" :modal-append-to-body="false"
            :close-on-click-modal="false">

            <el-form :model="infolist" ref="infolist" :rules="rules">
                <div class="info-line">
                    <el-form-item >
                        <span>任务标题</span>
                        <el-input v-model="infolist.noticeTitle" placeholder="标题" disabled></el-input>
                    </el-form-item>
                    <el-form-item >
                        <span>反馈时间</span>
                        <el-date-picker v-model="infolist.BackTime" type="date" placeholder="要求反馈时间" disabled>
                        </el-date-picker>
                    </el-form-item>
                </div>
                <el-form-item class="info-line online">
                    <span>接收部门</span>
                    <el-select v-model="visiblec" placeholder="接收部门" multiple clearable disabled>
                        <el-option v-for="item in typeOptions" :key="item.id" :label="item.ou" :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item class="info-line online" >
                    <span>任务描述</span>
                    <el-input v-model="infolist.noticeContent" placeholder="任务描述" type="textarea" :rows="3" disabled></el-input>
                </el-form-item>
                <div style="padding:0 20px 0 100px;margin-bottom: 20px;">
                    <uploadDown :datalist="datalist" :dialogStatus="uploadstatus"></uploadDown>
                </div>
                <el-form-item class="info-line online" >
                    <span>回复内容</span>
                    <el-input v-model="infolist.noticeContent" placeholder="回复内容" type="textarea" :rows="3" :disabled='disableStatus'></el-input>
                </el-form-item>
                <div style="padding-left: 80px" v-if="!disableStatus">
                    <myUpload @uploadBack="uploadBack" :fileInfo="fileInfo" :fileList="fileInfo.fileList"></myUpload>
                </div>
                <div style="padding:0 20px 0 100px;margin-bottom: 20px;" v-if="disableStatus">
                    <uploadDown :datalist="datalistback" :dialogStatus="uploadstatus"></uploadDown>
                </div>
            </el-form>

            <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>
</template>
<script>
    import mySearch from "../../../components/search.vue";
    import myUpload from '../../../components/upload'
    import uploadDown from '../../../components/uploadDown'

    export default {
        components: {
            mySearch,
            myUpload,
            uploadDown
        },
        data() {
            const terminalTypeName = (rule, value, callback) => {
                if (!this.infolist.tit) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const brandName = (rule, value, callback) => {
                if (!this.infolist.num) {
                    callback(new Error('不能为空'))
                } else {
                    if (this.infolist.num > 10) {
                        this.infolist.num = 10;
                    }
                    callback()
                }
            }
            const modelType = (rule, value, callback) => {
                if (!this.infolist.time) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                rules: {
                    terminalTypeName: [{
                        required: true,
                        trigger: 'blur',
                        validator: terminalTypeName
                    }],
                    brandName: [{
                        required: true,
                        trigger: 'blur',
                        validator: brandName
                    }],
                    modelType: [{
                        required: true,
                        trigger: 'blur',
                        validator: modelType
                    }],
                },
                searchList: [{
                        type: 'input',
                        tit: '公告标题',
                        value: '',
                        width: '24%',
                    },
                    {
                        type: 'date',
                        tit: '开始时间',
                        value: '',
                        width: '24%',
                    },
                    {
                        type: 'date',
                        tit: '结束时间',
                        value: '',
                        width: '24%',
                    },
                    {
                        type: 'sel',
                        tit: '任务状态',
                        value: '',
                        width: '24%',
                        options: [{
                                dataCode: 1,
                                dataName: '待回复',
                            },
                            {
                                dataCode: 2,
                                dataName: '已回复',
                            }
                        ],
                    },
                ],
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [{}],
                dialogStatus: false,
                disableStatus: false,
                titname: '终端',
                infolist: {},
                typeOptions: [{
                    dataCode: 1,
                    dataName: 111,
                }],
                userInfo: {},
                params: {},
                infoApply: [],
                fileInfo: {
                    limit: 1,
                    url: '/sysmgr/noticeatt/upload',
                    fileList: []
                },
                datalist: {
                    url: '/sysmgr/noticeatt/downfile',
                    type: 2
                },
                 datalistback: {
                    url: '/sysmgr/noticeatt/downfile',
                    type: 2
                },
                uploadstatus: false,
                visiblec:[]
            }
        },
        methods: {
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.terminalTypeName = v[0] : '';
                v[1] ? this.params.brandName = v[1] : '';
                v[2] ? this.params.modelType = v[2] : '';
                this.getList(this.params, this.pageSize);
            },
            //获取列表
            getList(v, n) {
                // this.pageSize = n;
                // let _this = this;
                // this.$http({
                //     url: "/market/terminal/terminaltype/queryPage",
                //     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].opTime = _this.timeChange(_this.tableData[i].opTime);
                //     }
                // });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            //申请
            dialogCheck(v,n) {
                this.dialogStatus = true;
                this.infolist = Object.assign({}, n);
                this.infolist.opNo = this.userInfo.loginNo;
                this.infolist.opName = this.userInfo.loginName;
                if (v === 1) {
                    this.titname = '查看';
                    this.disableStatus = true;
                    return
                } else if (v === 2) {
                    this.titname = '回复';
                    this.disableStatus = false;
                }
            },
            //添加
            dialogCli(v) {
                if (v === 1) {
                    this.infolist = {};
                    this.dialogStatus = false;
                    return
                }
                this.infolist.opTime = new Date().getTime();
                this.submitInfo("/market/terminal/terminaltypes/add");
            },
            submitInfo(u) {
                let _this = this;
                this.$refs.infolist.validate(valid => {
                    if (valid) {
                        this.$http({
                            url: u,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: this.infolist,
                        }).then((res) => {
                            if (res.data.result === 1) {
                                _this.$message({
                                    message: res.data.desc,
                                    type: 'error'
                                });
                            } else {
                                _this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                                _this.infolist = {};
                                _this.dialogStatus = false;
                                _this.getList({}, _this.pageSize);
                            }

                        });
                    }
                })
            },
            //删除
            delLine(v) {
                let _this = this;
                this.$confirm('即将删除此条数据, 是否删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$http({
                        url: "/market/terminal/terminaltype/del",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: {
                            id: v.id
                        },
                    }).then((res) => {
                        if (res.data.result === 1) {
                            _this.$message({
                                message: res.data.desc,
                                type: 'error'
                            });
                        } else {
                            _this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            _this.getList(this.params, this.pageSize);
                        }
                    });
                })
            },
            //文件返回值
            uploadBack(v) {
                console.log(v)
            },
            //时间转换
            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
                }
            },
            getUser() {
                this.userInfo = JSON.parse(window.sessionStorage.userInfo);
                this.infolist = {
                    opNo: '',
                    opName: '',
                };
                this.infolist.opNo = this.userInfo.loginNo;
                this.infolist.opName = this.userInfo.loginName;

            }
        },
        mounted() {
            this.getList({}, 1);
            this.getUser();
        },
        created() {

        }
    }
</script>
<style scoped lang="scss">
    .onetab {
        margin-bottom: 20px;
        padding: 0 20px;
    }

    .titbox {
        div {
            float: right;

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

    .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>
