<template>
    <div class="visa-box">
        <div class="search-ul">
            <div class="search-li">
                <el-select @change="changeOption()" v-model="gnamevalue" filterable placeholder="请输入团组名称">
                    <el-option v-for="item in gnameoption" :key="item.id" :label="item.groupName" :value="item.id">
                    </el-option>
                </el-select>
            </div>
            <div class="search-li">
                <div class="country-box">
                    <label>签证表国别: </label>
                    <el-select v-model="groupvalues" filterable placeholder="请选择">
                        <el-option v-for="item in optionsgroup" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                </div>
                <div class="interpret-box">
                    <label>翻译语种: </label>
                    <el-select v-model="value" filterable placeholder="请选择">
                        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                        </el-option>
                    </el-select>
                </div>

                <router-link :to="{ path: '/home/visaEdit', query: { DiId: gnamevalue } }">
                    <el-button type="primary">新增数据</el-button>
                </router-link>
                <el-button type="primary" style="margin-left: 5px;">新增简单数据</el-button>
            </div>
        </div>
        <el-row>
            <el-button type="primary">一键导出签证</el-button>
            <el-button type="primary">一键导省外办</el-button>
            <el-button type="primary">一键导市外办</el-button>
            <el-button type="primary">签证事项表</el-button>
            <el-button type="primary">照 会</el-button>
            <el-button type="primary">印度名单表</el-button>
            <el-button type="primary">马来西亚名单表</el-button>
        </el-row>
        <div class="form-box">
            <template>
                <el-table :data="tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)" border
                    style="width: 100%">
                    <el-table-column label="序 号" width="55">
                        <template slot-scope="scope">
                            {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="clientName" width="200" label="姓 名">
                    </el-table-column>
                    <el-table-column prop="tel" label="手 机" width="220">
                    </el-table-column>
                    <el-table-column prop="cerdNo" label="身份证" width="200">
                    </el-table-column>
                    <el-table-column prop="ext" label="签证表" width="100">
                        <el-link type="primary">导 出</el-link>
                    </el-table-column>
                    <el-table-column prop="phone" label="派遣函" width="200">
                        <el-link type="primary">市外办</el-link>
                        <el-link type="primary">省外办</el-link>
                    </el-table-column>
                    <el-table-column prop="urgentPhone" label="操 作">
                        <el-link type="primary">检索资料</el-link>
                        <el-link type="primary">美加表</el-link>
                        <el-link type="primary">非美加表</el-link>
                        <el-link type="danger">删除</el-link>
                    </el-table-column>
                </el-table>
            </template>
            <div class="block">
                <el-pagination align='center' @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page="currentPage" :page-sizes="[5, 10, 15, 20]" :page-size="pageSize"
                    layout="total, sizes, prev, pager, next" :total="tableData.length">
                </el-pagination>
            </div>
        </div>
        <div class="form-box">
            <div class="visas-title">
                <div>历史用户信息处</div>
                <div class="visas-box">
                    <el-input @input="clickUsers()" placeholder="请输入内容" v-model="input" clearable>
                    </el-input>
                    <el-button @click="Inquireclick()" type="primary">勾选项入团</el-button>
                </div>
            </div>
            <template>
                <el-table :data="externalDatas.slice((currentPageUser - 1) * pageSizeUser, currentPageUser * pageSizeUser)"
                    border tooltip-effect="dark" ref="multipleTable" :row-key="getRowKeys"
                    @selection-change="handleSelectionChange" style="width: 100%">
                    <el-table-column :reserve-selection="true" type="selection" width="55">
                    </el-table-column>
                    <el-table-column label="序 号" width="55">
                        <template slot-scope="scope">
                            {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
                        </template>
                    </el-table-column>
                    <el-table-column width="100" prop="clientName" label="姓 名">
                    </el-table-column>
                    <el-table-column prop="landlinePhone" label="手 机" width="180">
                    </el-table-column>
                    <!-- <el-table-column
                        prop="companyName"
                        label="地 址"
                        width="180">
                    </el-table-column> -->
                    <el-table-column prop="idNo" label="身份证" width="250">
                    </el-table-column>
                    <el-table-column label="操 作">
                        <template slot-scope="scope">
                            <el-link type="primary">增加入此团</el-link>
                            <el-link type="primary" @click="upDate(scope.$index, scope.row)">编辑</el-link>
                            <el-link type="danger">删除</el-link>
                        </template>

                    </el-table-column>
                </el-table>
            </template>
            <div class="block">
                <el-pagination align='center' @size-change="handleSizeChanges" @current-change="handleCurrentChanges"
                    :current-page="currentPageUser" :page-sizes="[5, 10, 15, 20]" :page-size="pageSizeUser"
                    layout="total, sizes, prev, pager, next" :total="externalDatas.length">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            input: '',
            gnameoption: [],
            gnamevalue: '',
            externalData: [],
            externalDatas: [],
            optionsgroup: [],
            options: [
                {
                    value: '0',
                    label: '中文'
                },
                {
                    value: '1',
                    label: '英语'
                }
            ],
            groupvalues: '',
            value: '0',
            tableData: [],
            currentPage: 1, // 当前页码
            pageSize: 5,// 每页的数据条数
            currentPageUser: 1, // 当前页码
            pageSizeUser: 5,// 每页的数据条数
            multipleTable: [],
            token: ''
        }
    },
    methods: {
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.currentPage = 1;
            this.pageSize = val;
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val;
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChanges(val) {
            this.currentPageUser = 1;
            this.pageSizeUser = val;
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChanges(val) {
            this.currentPageUser = val;
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
            console.log(this.multipleSelection)
        },
        getRowKeys(row) {
            return row.num
        },
        getgroupsname() {
            var url = "/api/Groups/GetGroupNameAndVisaNationality"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    portType: 1,
                }
            }).then(function (res) {
                console.log(res)
                if (res.data.code == 200) {
                    that.gnameoption = res.data.data.groupNameData;
                    that.gnamevalue = that.gnameoption[0].id;
                    that.optionsgroup = res.data.data.visaNationalityData;
                    that.groupvalues = that.optionsgroup[0].id;
                }
                that.getCrm()
            })
        },
        getCrm() {
            this.tableData = [];
            var url = "/api/Groups/GetCrmByGroupId"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    portType: 1,
                    groupId: that.gnamevalue
                }
            }).then(function (res) {
                console.log(res)
                if (res.data.code == 200) {
                    that.tableData = res.data.data;
                }
            })
        },
        changeOption() {
            console.log(this.gnamevalue)
            this.getCrm()
        },
        getExternalusers() {
            var url = "/api/CRM/GetClientList"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    portType: 1,
                }
            }).then(function (res) {
                console.log(res)
                if (res.data.code == 200) {
                    that.externalData = res.data.data;
                    that.externalDatas = that.externalData;
                }
            })
        },
        clickUsers() {
            var newarr = [];
            if (this.input == "") {
                newarr = this.externalData;
            } else {
                for (var i = 0; i < this.externalData.length; i++) {
                    if (this.externalData[i].clientName.indexOf(this.input) != -1) {
                        newarr.push(this.externalData[i]);
                    }
                    else if (this.externalData[i].idNo.indexOf(this.input) != -1) {
                        newarr.push(this.externalData[i]);
                    }
                    else if (this.externalData[i].landlinePhone.indexOf(this.input) != -1) {
                        newarr.push(this.externalData[i]);
                    }
                    // else if (this.externalData[i].companyName.indexOf(this.input) != -1) {
                    //     newarr.push(this.externalData[i]);
                    // }
                }
            }
            this.externalDatas = newarr;
            this.currentPageUser = 1;
        },
        upDate(index, row) {

            this.$router.push({
                path: "/home/visaEdit",
                query: {
                    DiId: this.gnamevalue,
                    id: row.id
                }
            })
        }
    },
    mounted() {
        this.token = JSON.parse(localStorage.getItem('userinif')).token;
        this.getgroupsname();
        this.getExternalusers();
    }
}
</script>
<style>
.visa-box {
    background-color: #fff;
    padding: 10px;
    box-shadow: 0 0 5px #0005;
    border-radius: 10px;
}

.search-li:nth-child(1) {
    width: 20%;
}

.search-li:nth-child(1) .el-select {
    width: 100%;
    margin: 0;
}

.search-li:nth-child(2) {
    width: 80%;
    justify-content: end;
}

.search-ul {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.search-li label {
    color: #606266;
}

.search-li {
    display: flex;
}

.search-li>div {
    margin-right: 10px;
}

.form-box .el-table th.el-table__cell>.cell {
    text-align: center;
}

.form-box .el-table td.el-table__cell div {
    text-align: center;
}

.form-box .block {
    margin-top: 10px;
}

.visa-box .el-row {
    text-align: right;
    margin-bottom: 5px;
}

.visas-list {
    background-color: #fff;
    padding: 10px;
    box-shadow: 0 0 5px #0005;
    border-radius: 10px;
}

.visas-title {
    display: flex;
    font-size: 17px;
    font-weight: 600;
    color: #555;
    margin-top: 8px;
    margin-bottom: 2px;
    justify-content: space-between;
    align-items: center;
}

.visas-box {
    display: flex;
}

.visas-box>button {
    margin-left: 10px;
    padding: 8px 20px;
}

.country-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.interpret-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
</style>