<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 class="search">
                <mySearch :searchList="searchList" @searchInfo="searchInfo"></mySearch>
                <el-button class="btn-check" size="medium" type="primary" @click="dialogCheck(1)">添加
                </el-button>
            </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="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="opNo" label="操作工号">
                    </el-table-column>
                    <el-table-column prop="opName" 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>
                            <el-button size="mini" type="primary" @click="dialogCheck(3,scope.row)">修改</el-button>
                            <el-button size="mini" 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="titname+'终端'" :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="info-line">
                            <el-form-item prop="terminalTypeName">
                                <span>终端类别</span>
                                <el-input v-model="infolist.terminalTypeName" placeholder="终端类别" :disabled="disableStatus"></el-input>
                            </el-form-item>
                            <el-form-item prop="terminalType">
                                <span>类别编码</span>
                                <el-input v-model="infolist.terminalType" placeholder="类型编码" :disabled="disableStatus"></el-input>
                            </el-form-item>
                        </div>
                        <div class="info-line">
                            <el-form-item prop="brandName">
                                <span>终端品牌</span>
                                <el-input v-model="infolist.brandName" placeholder="终端品牌" :disabled="disableStatus"></el-input>
                            </el-form-item>
                            <el-form-item prop="brandCode">
                                <span>品牌编码</span>
                                <el-input v-model="infolist.brandCode" placeholder="品牌编码" :disabled="disableStatus"></el-input>
                            </el-form-item>
                        </div>
                        <div class="info-line">
                            <el-form-item prop="modelType">
                                <span>终端型号</span>
                                <el-input v-model="infolist.modelType" placeholder="终端型号" :disabled="disableStatus"></el-input>
                            </el-form-item>
                            <el-form-item prop="opNo">
                                <span>操作姓名</span>
                                <el-input v-model="infolist.opName" placeholder="操作姓名" disabled></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 toolList from "../../../components/toolList.vue";
    import myMessage from "../../../components/myMessage.vue"

    export default {
        components: {
            mySearch,
            toolList,
            myMessage
        },
        data() {
            const terminalTypeName = (rule, value, callback) => {
                if (!this.infolist.terminalTypeName) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const brandName = (rule, value, callback) => {
                if (!this.infolist.brandName) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const modelType = (rule, value, callback) => {
                if (!this.infolist.modelType) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const brandCode = (rule, value, callback) => {
                if (!this.infolist.brandCode) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const terminalType = (rule, value, callback) => {
                if (!this.infolist.terminalType) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                rules: {
                    terminalTypeName: [{
                        required: true,
                        trigger: 'blur',
                        validator: terminalTypeName
                    }],
                    terminalType: [{
                        required: true,
                        trigger: 'blur',
                        validator: terminalType
                    }],
                    brandName: [{
                        required: true,
                        trigger: 'blur',
                        validator: brandName
                    }],
                    brandCode: [{
                        required: true,
                        trigger: 'blur',
                        validator: brandCode
                    }],
                    modelType: [{
                        required: true,
                        trigger: 'blur',
                        validator: modelType
                    }],
                },
                tooltit: '终端类型管理',
                searchList: [{
                        type: 'input',
                        tit: '类别',
                        value: '',
                        width: '32%',
                    },
                    {
                        type: 'input',
                        tit: '品牌',
                        value: '',
                        width: '32%',
                    },
                    {
                        type: 'input',
                        tit: '型号',
                        value: '',
                        width: '32%',
                    },
                ],
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [{}],
                dialogStatus: false,
                disableStatus: false,
                titname: '终端',
                infolist: {},
                typeOptions: [{
                    dataCode: 1,
                    dataName: 111,
                }],
                userInfo: {},
                params: {},
                centerDialogVisible: false,
                messTit: '',
                delid: '',
                loading:false
            }
        },
        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.loading = true;
                this.tableData = [];
                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;
                    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');
                if (this.titname === '新建') {
                    this.submitInfo("/market/terminal/terminaltypes/add", v);
                } else if (this.titname === '修改') {
                    this.submitInfo("/market/terminal/terminaltype/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'
                                });
                                _this.infolist = {};
                                _this.dialogStatus = false;
                                _this.getList({}, _this.pageSize);
                            }

                        });
                    }
                })
            },
            closeMessage(v) {
                this.centerDialogVisible = false;
                let _this = this;
                if (v === 1) {
                    this.$http({
                        url: "/market/terminal/terminaltype/del",
                        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);
                        }
                    });
                }
            },
            //删除
            delLine(v) {
                this.centerDialogVisible = true;
                this.messTit = '即将删除此条数据, 是否删除?';
                this.delid = v.id;
            },
            //获取字典
            getDepot() {
                this.$http({
                    url: "/market/cfgDataDict/queryList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    console.log(res.data)
                    this.typeOptions = res.data;
                });
            },
            //功能栏
            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;
                console.log(this.infolist);
            }
        },
        mounted() {
            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>
