<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container" style="margin: 0;width: 100%;">
        <div class="container-box" style="padding: 0 20px 0 0;">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div style="overflow: hidden;">
                <div class="search" style="float: left;">
                    <mySearch :searchList="searchList" @searchInfo="searchInfo"></mySearch>
                </div>
                <div style="margin-top: 20px;float: right;" class="bigbtns">
                    <el-button style="margin-left: 20px;" class="btn-check" size="medium" type="primary" v-if="advInfo.isAdmin" @click="dialogCheck(1)">新建
                    </el-button>
                </div>
            </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%" v-loading="loading">
                    <el-table-column prop="name" label="模板名称">
                    </el-table-column>
                    <el-table-column prop="opTime" label="创建时间">
                    </el-table-column>
                    <el-table-column label="操作" width="180px" align="center" fixed="right">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="jumpinfop('/onlineExcelInfo',1,'在线表格查看',scope.row)">查看</el-button>
                            <el-button size="mini" v-if="scope.row.finishStatus == 0" type="primary" @click="jumpinfop('/onlineExcelInfo',2,'在线表格处理',scope.row)">处理</el-button>
                            <el-button size="mini" v-if="scope.row.finishStatus == 0 && advInfo.isAdmin" type="danger" @click="delLine(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="'新增表格模板'" :visible.sync="dialogStatus" width="50%" :destroy-on-close="true"
                       :modal-append-to-body="false" :close-on-click-modal="false">
                <div v-loading="loading">
                    <el-form :model="infolist" ref="infolist" :rules="rules">
                        <div class="online">
                            <el-form-item prop="name">
                                <span>模板名称</span>
                                <el-input v-model="infolist.name" placeholder="模板名称" :disabled="disableStatus"></el-input>
                            </el-form-item>
                        </div>
                    </el-form>
                    <div slot="footer" class="dialog-footer myfooter">
                        <el-button type="primary" @click="dialogCli(2)" v-if="titname !== '查看'">确 定</el-button>
                        <el-button @click="dialogCli(1)" v-if="titname === '查看'">确 定</el-button>
                        <el-button @click="dialogCli(1)">取 消</el-button>
                    </div>
                </div>
            </el-dialog>
        </div>
        <myMessage :messTit='messTit' @closeMessage="closeMessage" :centerDialogVisible="centerDialogVisible" v-if="centerDialogVisible"></myMessage>
    </fullscreen>
</template>
<script>
import mySearch from "../../../components/search.vue";
import myUpload from "../../../components/upload";
import toolList from "../../../components/toolList";
import myMessage from "../../../components/myMessage.vue"

export default {
    components: {
        myUpload,
        mySearch,
        toolList,
        myMessage
    },
    data() {
        const name = (rule, value, callback) => {
            if (!this.infolist.name) {
                callback(new Error('不能为空'))
            } else {
                callback()
            }
        }
        return {
            rules: {
                name: [{
                    required: true,
                    trigger: 'change',
                    validator: name
                }],
            },
            tooltit: '重点攻坚渠道合作率-在线表格',
            searchList: [{
                type: 'input',
                tit: '名称',
                value: '',
                width: '100%',
            },],
            fullscreen: false,
            total: 0,
            pageSize: 1,
            tableData: [{}],
            dialogStatus: false,
            disableStatus: false,
            titname: '终端',
            infolist: {},
            typeOptions: [{
                dataCode: 1,
                dataName: 111,
            }],
            userInfo: {},
            params: {},
            termOption: [],
            centerDialogVisible: false,
            messTit: '',
            delid: '',
            loading: false,
            advInfo: {},
        }
    },
    methods: {
        //搜索数据
        searchInfo(v) {
            this.params = {};
            v[0] ? this.params.name = v[0] : '';
            this.getList(this.params, this.pageSize);
        },
        //获取列表
        getList(v, n) {
            this.pageSize = n;
            this.loading = true;
            this.tableData = [];
            let _this = this;
            this.$http({
                url: "/market/cKeyChannelCoopExcel/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;
                this.loading = false;
            });
        },
        // 分页
        currchange(v) {
            this.pageSize = v;
            this.getList(this.params, this.pageSize);
        },
        //查看
        dialogCheck(v, n) {
            this.dialogStatus = true;
            this.disableStatus = false;
            if (v === 1) {
                this.titname = '新建';
                this.getUser();
                return
            } else if (v === 2) {
                this.titname = '查看';
                this.disableStatus = true;
            } else if (v === 3) {
                this.titname = '修改';
                this.loading = true;
            }
            this.infolist = Object.assign({}, n); //拷贝
            this.infolist.opNo = this.userInfo.loginNo;
            this.infolist.opName = this.userInfo.loginName;
            this.loading = false;
        },
        //修改  添加
        dialogCli(v) {
            if (v === 1) {
                this.infolist = {};
                this.dialogStatus = false;
                return
            }
            this.infolist.opTime = this.$formatDate(new Date(), 'YYYY-MM-DD HH:mm:ss');
            this.infolist.finishStatus = 0;
            if (this.titname === '新建') {
                this.submitInfo("/market/cKeyChannelCoopExcel/add", v);
            } else if (this.titname === '修改') {
                this.submitInfo("/market/keyChannelCoopExcel/update", v);
            }
        },
        submitInfo(u, v) {
            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'
                            });
                            var id = res.data.desc;
                            var row = {
                                id:id
                            };
                            _this.infolist = {};
                            console.log(_this.infolist);
                            _this.dialogStatus = false;
                            _this.getList({}, _this.pageSize);
                            //跳转到编辑
                            _this.jumpinfop('/onlineExcelInfo',2,'在线表格处理',row)
                        }

                    });
                }
            })
        },
        //删除
        delLine(v) {
            this.centerDialogVisible = true;
            this.messTit = '是否确认办结?';
            this.delid = v.id;
        },
        closeMessage(v) {
            this.centerDialogVisible = false;
            let _this = this;
            if (v === 1) {
                this.$http({
                    url: "/market/cKeyChannelCoopExcel/finishExcel",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        id: this.delid
                    },
                }).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);
                    }
                });
            }
        },
        //功能栏
        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;
        },
        jumpinfop(p,v,n,row){
            this.$router.push({
                path: p,
                query:{
                    type:v,
                    id:row.id
                }
            });
            this.setabList(n, p + '?type='+ v + '&id=' + row.id);
        },
        setabList(n, p) {
            let params = {
                children: "",
                name: n,
                rountPath: p,
                target: "_self",
            };
            for (let i = 0; i < this.$store.state.tabList.length; i++) {
                if (this.$store.state.tabList[i].name === params.name) {
                    this.$store.state.tabList[i] = params;
                }
            }
            let set = new Set([...this.$store.state.tabList, params]);
            set.add(params);
            this.$store.commit("setDefaultActive", params.rountPath);
            this.$store.commit("setTabList", Array.from(set));
        },
        getAdvUserInfo() {
            console.log("getAdvUserInfo");
            this.$http({
                url: "/market/cKeyChannelCoopExcel/getUserInfo",
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                },
            }).then((res) => {
                if (res.data.result !== 1) {
                    console.log(res);
                    this.advInfo = res.data.body;
                    console.log(this.advInfo);
                }
            });
        }
    },
    mounted() {
        this.getAdvUserInfo();
        this.getList({}, 1);
        this.getUser();
    },
    created() {

    }
}
</script>
<style scoped lang="scss">
.titbox {
    div {
        float: right;

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

.tabbox {
    margin-top: 16px;
}

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