<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container" style="margin: 0;width: 100%;">
        <div class="container-box">
            <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"
                               @click="addNew()">新建
                    </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="viewName" label="模板名称" align="center">
                    </el-table-column>
                    <el-table-column prop="opTime" label="发起时间" align="center">
                    </el-table-column>
                    <el-table-column prop="deptName" label="发起部门" align="center">
                    </el-table-column>
                    <el-table-column prop="userName" label="发起人" align="center">
                    </el-table-column>
                    <el-table-column prop="typeName" label="模板类型" align="center">
                    </el-table-column>
                    <el-table-column label="操作" width="220px" align="center" fixed="right">
                        <template slot-scope="scope">
                            <el-button size="mini" @click="toView(scope.row)" v-if="scope.row.type == '1'">查看
                            </el-button>
                            <el-button size="mini" @click="toViewer(scope.row)" v-if="scope.row.type == '2'">查看
                            </el-button>
                            <el-button size="mini" @click="toEdit(scope.row)" v-if="scope.row.type == '1'">修改
                            </el-button>
                            <el-button size="mini" @click="delDialog(scope.row)" v-if="scope.row.type == '1'">删除
                            </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>
        </div>
        <myMessageNew :messTit='deleteTag' @closeMessage="processDel" :centerDialogVisible="centerDialogVisible"
                      v-if="centerDialogVisible" yes-btn-name="是" no-btn-name="否"></myMessageNew>
    </fullscreen>
</template>
<script>
import mySearch from "../../../components/search.vue";
import myUpload from "../../../components/upload";
import toolList from "../../../components/toolList";
import myMessageNew from "../../../components/myMessageNew.vue"

export default {
    components: {
        myUpload,
        mySearch,
        toolList,
        myMessageNew
    },
    data() {
        return {
            tableData: [{}],
            total: 0,
            params: {},
            deleteTag: '',
            centerDialogVisible: false,
            loading: false,
            issuedAddStatus: false,
            issuedParam: {},
            tooltit: '收入信息发布',
            searchList: [{
                type: 'input',
                tit: '模板名称',
                value: '',
                width: '100%',
            },],
            fullscreen: false,
            delViewId: ''
        }
    },
    methods: {
        delDialog(row) {
            this.delViewId = row.viewId;
            this.deleteTag = '确认删除吗？';
            this.centerDialogVisible = true;
        },
        processDel(v) {
            this.centerDialogVisible = false;
            var _this = this;
            if (v === 1) {
                this.$http({
                    url: "/market/cIncomeExcelView/delView",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {excelId: this.delViewId},
                }).then((res) => {
                    if (res.data.result === 1) {
                        _this.$message({
                            message: '删除失败',
                            type: 'error'
                        });
                    } else {
                        _this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        _this.getList({}, _this.pageSize);
                    }
                });
            }
        },
        //搜索数据
        searchInfo(v) {
            this.params = {};
            v[0] ? this.params.name = v[0] : '';
            this.getList(this.params, this.pageSize);
        },
        //功能栏
        iconCli(v) {
            if (v === 1) {
                this.getList(this.params, this.pageSize);
            }
            if (v === 2) {
                this.fullscreen = !this.fullscreen
            }
        },
        // 分页
        currchange(v) {
            this.pageSize = v;
            this.getList(this.params, this.pageSize);
        },
        getList(v, n) {
            this.pageSize = n;
            this.loading = true;
            this.tableData = [];
            let _this = this;
            this.$http({
                url: "/market/cIncomeExcelView/getViewList",
                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;
            });
        },
        processDelete(v) {
            this.centerDialogVisible = false;
            if (v === 1) {
                console.log("删除")
            }
        },
        addNew() {
            var _this = this;
            _this.jumpinfop('/incomeExcelViewInfo', 1, '新增收入信息', "")
        },
        toEdit(row) {
            var _this = this;
            _this.jumpinfop('/incomeExcelViewInfo', 2, '修改收入信息', row.viewId);
        },
        toView(row) {
            var _this = this;
            _this.jumpinfop('/incomeExcelViewInfo', 3, '查看收入信息', row.viewId);
        },
        toViewer(row) {
            var _this = this;
            _this.jumpinfop('/incomeExcelViewInfo', 4, '查看收入信息', row.id);
        },
        addNewIssued(row) {
            this.issuedParam = {
                templateId: row.id,
            };
            this.issuedAddStatus = true;
        },
        //跳转页面
        jumpinfop(p, v, n, id) {
            this.$router.push({
                path: p,
                query: {
                    type: v,
                    id: id
                }
            });
            this.setabList(n, p + '?type=' + v + '&id=' + 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));
        },
    },
    mounted() {
        this.getList({}, 1);
    },
    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: 90%;
        display: inline-block;
    }

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

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

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

.online {
    width: 100%;

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

    span {
        vertical-align: top;
    }

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

