<template>
    <div class="groupApproval">
        <div class="query-box">
            <ul>
                <li>
                    <span>
                        <em>团类型</em>
                        <el-select class="w200" v-model="msg.PriceTeamType" filterable :placeholder="$t('pub.pleaseImport')"
                            @change="getControlList()">
                            <el-option label="不限" value="0">
                            </el-option>
                            <el-option v-for="item in TeamListArr" :label="item.Name" :value="item.Id"
                                :key="item.Id"></el-option>
                        </el-select>
                    </span>
                </li>
                <li>
                    <span>
                        <em>团号</em>
                        <el-input maxlength="50" v-model="msg.TCNUM" class="permiss-input w200"
                            @keyup.native.enter="getControlList" :placeholder="$t('pub.pleaseImport')"></el-input>
                    </span>
                </li>
                <li>
                    <span>
                        <em>编号</em>
                        <el-input maxlength="6" v-model="msg.TCID" class="permiss-input 200"
                            @keyup.native.enter="getControlList" :placeholder="$t('pub.pleaseImport')"
                            @keyup.native="checkInteger(msg,'TCID')"></el-input>
                    </span>
                </li>
                <li></li>
            </ul>
        </div>
        <ul class="_nav clearfix">
            <li :class="active==1?'_active':''" @click="active=1, msg.OutGroupAuditState=1, getControlList()">待审批</li>
            <li :class="active==2?'_active':''" @click="active=2, msg.OutGroupAuditState=2, getControlList()">已审批</li>
        </ul>

        <ul style="overflow: initial!important">
            <li style="margin-bottom:10px;width: 100%;">

            </li>
        </ul>
        <table class="singeRowTable" border="0" cellspacing="0" cellpadding="0" v-loading="loading">
            <thead>
                <tr>
                    <th width="160">团队编号</th>
                    <th>系列</th>
                    <th width="400">团名</th>
                    <th>OP</th>
                    <th>团队类型</th>
                    <th>应收</th>
                    <th>实收</th>
                    <th>待收</th>
                    <th>应付</th>
                    <th>实付</th>
                    <th>待付</th>
                    <th>团队利润</th>
                    <th v-if="active==1">审批人</th>
                    <th v-if="active==2">审批结果</th>
                    <th v-if="active==2">审批信息</th>
                    <th width="200">操作</th>
                </tr>
            </thead>
            <tbody>

                <tr v-for="(item,index) in dataList" :key="index">
                    <td style="cursor: pointer;text-decoration: underline;" @click="goTravel(item.TCID)">{{item.TCNUM}}({{item.TCID}})</td>
                    <td>{{item.LtName}}</td>
                    <td style="padding: 5px;">{{item.Title}}</td>
                    <td>{{item.OPName}}</td>
                    <td>{{item.PriceTeamTypeName}}</td>
                    <td>{{item.ShouldReceive}}</td>
                    <td>{{item.ActualReceive}}</td>
                    <td>{{item.WaitRecive}}</td>
                    <td>{{item.ShouldPay}}</td>
                    <td>{{item.ActualPay}}</td>
                    <td>{{item.WaitPay}}</td>
                    <td>{{item.ActualProfit}}</td>
                    <td v-if="active==1">{{item.AuditEmpName}}</td>
                    <td v-if="active==2">
                        <span v-if="item.OutGroupAuditState == 2" style="color: green;">通过</span>
                        <span v-if="item.OutGroupAuditState == 3" style="color: red;">拒绝</span>
                    </td>
                    <td v-if="active==2">
                        <div>{{item.AuditEmpName}}</div>
                        <div>{{item.OutGroupAuditDate}}</div>
                    </td>
                    <td class="_icon_btn">
                        <el-tooltip class="item" effect="dark" content="审核" placement="top" v-if="active==1 && EmployeeId==item.OutGroupAuditEmpId">
                            <i class="iconfont icon-ico_commodity_defaul" @click="shenhei(item)" v-if="active==1 && EmployeeId==item.OutGroupAuditEmpId"></i>
                        </el-tooltip>
                        <el-tooltip class="item" effect="dark" content="驳回" placement="top" v-if="active==1 && EmployeeId==item.OutGroupAuditEmpId">
                            <i class="iconfont icon-shenhebohui" @click="bohui(item)" v-if="active==1 && EmployeeId==item.OutGroupAuditEmpId"></i>
                        </el-tooltip>
                        <el-tooltip class="item" effect="dark" content="收支明细" placement="top">
                            <i class="iconfont icon-mingxi" @click="goTeamBalance(item.TCID)"></i>
                        </el-tooltip>


                    </td>
                </tr>
                
            </tbody>
            <tr v-if="dataList.length==0">
                <td :colspan="active==1?14:15" style="text-align:center">暂无数据</td>
            </tr>
           
            
        </table>
        <div style="width: 100%;">
            <el-pagination  background @current-change="handleCurrentChange" :current-page.sync="msg.pageIndex"
                layout="total,prev, pager, next, jumper" :page-size="msg.pageSize" :total="total">
            </el-pagination>
        </div>

    </div>
</template>

<script>
    export default {
        data() {
            return {
                loading: false,
                dataList: [],
                active: '1',
                msg: {
                    pageIndex: 1,
                    pageSize: 5,
                    PriceTeamType: "0",
                    TCNUM: '',//团号
                    TCID: '',
                    OutGroupAuditState: 1,
                    OutGroupAuditEmpId: 0,//当前登录用户id , 如果有查询所有的权限 则=0	
                },
                TeamListArr:[],
                total:0,
                EmployeeId:0,
            }
        },
        created() { 
            this.getTeamList()
            let userinfo = this.getLocalStorage();
            this.EmployeeId = userinfo.EmployeeId
            let ActionMenuCode=userinfo.ActionMenuCode;
            if(ActionMenuCode.indexOf('Finance_clumpSeeAll')!=-1){//如果有权限 可以查看所有 如果没有只能看自己审核的
                this.msg.OutGroupAuditEmpId = 0
            }else{
                this.msg.OutGroupAuditEmpId = userinfo.EmployeeId
            }
            if(this.$route.query && this.$route.query.TCID){
                this.msg.TCID = this.$route.query.TCID
            }
        },
        mounted() {
            this.getList()
            
        },
        methods: {
            getControlList() {
                this.msg.pageIndex = 1;
                this.getList()
            },
            handleCurrentChange(e){
                this.msg.pageIndex = e;
                this.getList()
            },
            getList() {
                this.loading = true
                let msg = JSON.parse(JSON.stringify(this.msg))
                if(msg.TCID==''){
                    msg.TCID = 0
                }
                this.apipost(
                    "travel_get_GetOutGroupAuditPageList",
                    msg,
                    res => {
                        this.loading = false
                        if (res.data.resultCode == 1) {
                            this.dataList = res.data.data.pageData;
                            this.total = res.data.data.count;

                        }else{
                            this.Error(res.data.message);
                        }
                    },
                    err => { 

                    }
                );
            },
            shenhei(item) {
                let that = this;
                that.$confirm('是否审核通过该团?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.groupAudit(2,item.TCID)
                }).catch(() => {

                });
            },
            bohui(item) {
                let that = this;
                that.$confirm('是否驳回该团?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //掉接口
                    this.groupAudit(3,item.TCID)
                }).catch(() => {

                });
            },
            groupAudit(type,TCID){
                this.apipost("travel_post_SetOutGroupAuditInfo", {TCID:TCID,OutGroupAuditState:type}, res => {
                    if (res.data.resultCode == 1) {
                        this.Success(res.data.message);
                        this.getList()
                    } else {
                        this.Error(res.data.message);
                    }   
                },
                    err => { }
                );
            },
            goTeamBalance(id, OutBranchId) {//团队收支明细
                this.$router.push({
                    name: "TeamBalancePayment",
                    query: {
                        id: id,
                        IsHaveAuth: true,
                        blank: "y",
                        tab: "团队收支明细"
                    }
                });
            },
            getTeamList() {
                this.apipost("travel_get_GetTravelPriceTeamTypeList", {}, res => {
                    if (res.data.resultCode == 1) {
                        this.TeamListArr = res.data.data;
                    } else {
                        this.Error(res.data.message);
                    }
                },
                    err => { }
                );
            },
            goTravel(TCID){//跳转到团队列表
                this.$router.push({
                    path: 'TravelControlList',
                    query: {
                        TCID: TCID,
                        blank: 'y',
                        tab: '团控列表'
                    }
                });
            }
        }
    }

</script>
<style scoped>
    .groupApproval .singeRowTable {
        margin-top: 20px;
    }

    ._nav {
        margin: 20px 0 0 0;
        background-color: #f5f5f5;
    }

    ._nav li {
        float: left;
        font-size: 14px;
        color: #666666;
        padding: 15px 20px;
        cursor: pointer;
        position: relative;
        background-color: #f1f1f1;
        margin-right: 5px
    }

    ._nav li._active {
        background-color: #FFFFFF;
        color: #333333
    }

    ._nav li._active::after {
        content: "";
        width: 20px;
        height: 3px;
        background-color: #E95252;
        display: inline-block;
        position: absolute;
        bottom: 0;
        left: 38%;
    }

    ._icon_btn i {
        width: 30px;
        height: 30px;
        display: inline-block;
        color: white !important;
        border-radius: 50%;
        text-align: center;
        line-height: 30px;
        margin-right: 10px;
        cursor: pointer;
        outline: none;
    }

    ._icon_btn i.icon-ico_commodity_defaul {
        background-color: #F16C3C;
    }

    ._icon_btn i.icon-ico_commodity_defaul:hover {
        background-color: #e87c54
    }

    ._icon_btn i.icon-ico_commodity_defaul:active {
        background-color: #f76630
    }

    ._icon_btn i.icon-shenhebohui {
        background-color: #E95252
    }

    ._icon_btn i.icon-mingxi {
        background-color: rgb(71, 191, 140)
    }
</style>