<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container">
        <div class="container-box">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div style="text-align: right;margin-top: 10px;">
                <el-button class="btn-check" size="medium" type="primary" @click="dialogCheck(3)">添加
                </el-button>
            </div>
            <div class="tabbox">
                <el-table height="calc(100% - 40px)" class="com-table" :data="tableData" tooltip-effect="dark"
                    size="small" border style="width: 100%" v-loading="loading">
                    <el-table-column prop="tempName" label="模板名称">
                    </el-table-column>
                    <el-table-column prop="tempVersion" label="版本号">
                    </el-table-column>
                    <el-table-column label="最后一次修改时间">
                        <template slot-scope="scope">
                            {{scope.row.updateTime||scope.row.opTime}}
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" width="160px" align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(1,scope.row)">查看</el-button>
                            <el-button size="mini" type="danger" @click="delLine(scope.row)" v-if="scope.row.sts">删除</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>

        <el-dialog :title="titname + '模板'" :visible.sync="dialogStatus" width="80%" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false" :before-close="closedia">
            <div v-loading="loadinged">
                <el-form :model="infolist" ref="infolist" :rules="rules">
                    <div class="info-line">
                        <el-form-item prop="tempName">
                            <span>模板名称</span>
                            <el-input v-model="infolist.tempName" placeholder="模板名称">
                            </el-input>
                        </el-form-item>
                        <el-form-item prop="tempVersion">
                            <span>版本号</span>
                            <el-input v-model="infolist.tempVersion" placeholder="版本号">
                            </el-input>
                        </el-form-item>
                    </div>
                </el-form>
                <myUpload style="float: left;" @uploadBack="uploadBack" :fileInfo="fileInfot"
                    :fileList="fileInfot.fileList" v-if="titname != '查看'"></myUpload>
               <div style="padding: 20px;clear: both;">
                    <el-table class="com-table" ref="multipleTable" tooltip-effect="dark"
                        size="mini" border style="width: 100%">
                        <el-table-column :prop="item.name" :label="item.name" v-for="item in tableDatacs">
                            <el-table-column :prop="items.name" :label="items.name" v-for="items in item.value"
                                v-if="item.sts">
                                <el-table-column :prop="itemss.name" :label="itemss.name" v-for="itemss in items.value"
                                    v-if="items.sts">

                                </el-table-column>
                            </el-table-column>
                        </el-table-column>
                    </el-table>
                </div>
                <div slot="footer" class="dialog-footer myfooter">
                    <el-button type="primary" @click="dialogCli(2)">确 定</el-button>
                    <el-button @click="dialogCli(1)">取 消</el-button>
                </div>
            </div>
        </el-dialog>
        <myMessage :messTit='messTit' @closeMessage="closeMessage" :centerDialogVisible="centerDialogVisible"
            v-if="centerDialogVisible"></myMessage>
    </fullscreen>

</template>
<script>
    import mySearch from "../../../components/search.vue";
    import myMessage from "../../../components/myMessage.vue"
    import toolList from '../../../components/toolList'
    import myUpload from '../../../components/upload.vue'

    export default {
        components: {
            mySearch,
            myMessage,
            toolList,
            myUpload
        },
        data() {
            const tempName = (rule, value, callback) => {
                if (!this.infolist.tempName) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const tempVersion = (rule, value, callback) => {
                if (!this.infolist.tempVersion) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                tableDatacs:[],

                rules: {
                    tempName: [{
                        required: true,
                        trigger: 'blur',
                        validator: tempName
                    }],
                    tempVersion: [{
                        required: true,
                        trigger: 'blur',
                        validator: tempVersion
                    }],
                },
                tooltit: '模板管理',
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [],
                dialogStatus: false,
                disableStatus: false,
                titname: '',
                infolist: {},
                userInfo: {},
                params: {},
                centerDialogVisible: false,
                messTit: '',
                delid: '',
                loading: false,
                loadinged: false,
                fileInfot: {
                    type: 'btn',
                    typename: '导入模板',
                    btntype: 'primary',
                    limit: 1,
                    url: '/market/cIllegalCallTemp/importTemp',
                    fileList: []
                },
                tempRows:''
            }
        },
        methods: {
            closedia() {
                this.infolist = {};
                this.dialogStatus = false;
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.loading = true;
                this.tableData = [];
                this.$http({
                    url: "/market/cIllegalCallTemp/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.infolist = Object.assign({}, n);
                if (v === 1) {
                    this.titname = '查看';
                    this.disableStatus = true;
                    this.tableDatacs = JSON.parse(n.tempHead)
                    return
                } else if (v === 3) {
                    this.titname = '添加';
                    this.disableStatus = false;
                }
                this.infolist.opNo = this.userInfo.loginNo;
                this.infolist.opName = this.userInfo.loginName;
            },
            //添加
            dialogCli(v) {
                if (v === 1) {
                    this.infolist = {};
                    this.dialogStatus = false;
                    this.tableDatacs = [];
                    return
                } else {
                    this.infolist.opTime = this.$formatDate(new Date(), "YYYY-MM-DD");
                    this.infolist.callTempList = this.tableDatacs;
                    this.infolist.tempRows = this.tempRows;
                    if (this.titname === '添加') {
                        this.submitInfo("/market/cIllegalCallTemp/add");
                    } else if (this.titname === '查看') {
                        this.submitInfo("/market/cIllegalCallTemp/update", v);
                    }
                }
            },
            submitInfo(u) {
                let _this = this;
                this.$refs.infolist.validate(valid => {
                    if (valid) {
                        this.loadinged = true;
                        this.$http({
                            url: u,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: this.infolist,
                        }).then((res) => {
                            this.loadinged = false;
                            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);
                                _this.tableDatacs = [];
                            }

                        });
                    }
                })
            },
            closeMessage(v) {
                this.centerDialogVisible = false;
                let _this = this;
                if (v === 1) {
                    _this.$http({
                        url: "/market/cIllegalCallTemp/del",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: {
                            tempId: 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);
                        }
                    });
                }
            },
            //删除
            delLine(v) {
                this.centerDialogVisible = true;
                this.messTit = '即将删除此条数据, 是否删除?';
                this.delid = v.tempId;
            },
            //文件返回值
            uploadBack(v) {
                this.tableDatacs = v.data.body.callTempList;
                this.tempRows = v.data.body.tempRows;
            },
            //功能栏
            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);
            },
        },
        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>
