<template>
    <div>
        <div class="communal-list">
            <div>
                <div class="communal-title">
                    <div>机票费用录入</div>
                </div>
                <div style="display: flex;justify-content: space-between;">
                    <div style="width: 60%;">
                        <el-select style="width: 300px;" v-model="DiId" placeholder="团组选择" clearable filterable
                            @change="AirTicketResSelectChange">
                            <el-option v-for="item in AirTicketResSelectData" :key="item.id" :label="item.groupName"
                                :value="item.id">
                            </el-option>
                        </el-select>
                    </div>
                    <div>
                        <el-button type="primary" @click="download" style="margin-left: 10px;">导出报表</el-button>
                        <el-button type="primary" @click="downloadCN" style="margin-left: 10px;">中文行程单</el-button>
                        <el-button type="primary" @click="downloadEN" style="margin-left: 10px;">英文行程单</el-button>
                        <el-button type="primary" style="margin-left: 10px;" @click="addIf">新增</el-button>
                    </div>
                </div>
                <div style="margin:10px 0;color:#606266;">
                    <span style="font-weight: bold;font-size:15px;">团队名称：</span>
                    <span style="color:#606266;">{{ delegationInfo.teamName }}&nbsp;&nbsp;&nbsp;</span>
                    <span style="font-weight: bold;font-size:15px;">客户：</span>
                    <span style="color:#606266;">{{ delegationInfo.clientName }}&nbsp;&nbsp;&nbsp;</span>
                    <span style="font-weight: bold;font-size:15px;">出访国家：</span>
                    <span style="color:#606266;">{{ delegationInfo.visitCountry }}&nbsp;&nbsp;&nbsp;</span>
                    <span style="font-weight: bold;font-size:15px;">起止日期：</span>
                    <span style="color:#606266;">{{ delegationInfo.visitStartDate }}—{{ delegationInfo.visitEndDate
                    }}&nbsp;&nbsp;&nbsp;</span>
                    <span style="font-weight: bold;font-size:15px;">天数/人数：</span>
                    <span style="color:#606266;">{{ delegationInfo.visitDays }}天/{{ delegationInfo.visitPNumber }}人</span>
                </div>
            </div>
            <div class="costbudgeting">
                <span>*团组成本预算-机票的预算：</span>
                <div v-if="budgeting.length>1">
                    <div class="costbudgeting-li" v-for="(item,index) in budgeting" :key="index">
                        <span>({{item.costType}}段)</span>
                        <span>时间:{{item.costTypeStartTime}} ~ {{item.costTypeEndTime}}</span>
                        <span v-for="(items,index) in item.data.airFeeData" :key="index">&nbsp;&nbsp;&nbsp;{{items.airType}}：{{townum(items.airDRCB)}}元/人&nbsp;&nbsp;&nbsp;{{items.airNum}}人&nbsp;&nbsp;&nbsp;共:{{townum(items.airZCB)}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                        <el-popover
                        placement="right"
                        width="552"
                        trigger="hover">
                        <el-table max-height="800" border :data="item.data.airInitData">
                            <el-table-column width="150" property="date" label="DATE"></el-table-column>
                            <!-- <el-table-column width="100" property="name" label="姓名"></el-table-column> -->
                            <el-table-column width="400" property="itinerary" label="ITIN"></el-table-column>
                        </el-table>
                        <span slot="reference" style="cursor: pointer;">"移上查看详细"</span>
                        </el-popover>
                        <!-- 客户名单 -->
                        <el-popover
                        placement="bottom"
                        width="662"
                        trigger="hover">
                        <el-table max-height="600" border :data="rollcallarr">
                            <el-table-column width="100" property="date" label="姓名">
                                <template slot-scope="scope">
                                    {{ scope.row.lastName}}{{scope.row.firstName}}
                                </template>
                            </el-table-column>
                            <el-table-column width="200" property="lastName" label="拼音">
                                <template slot-scope="scope">
                                    {{ pinyingxing(scope.row.lastName) }}/{{  pinyingxing(scope.row.firstName) }}
                                </template>
                            </el-table-column>
                            <el-table-column width="50" property="sex" label="性别">
                                <template slot-scope="scope">
                                    {{ scope.row.sex==0?'男':'女'}}
                                </template>
                            </el-table-column>
                            <el-table-column width="110" property="birthDay" label="生日">
                                <template slot-scope="scope">
                                    {{ fgarr(scope.row.birthDay) }}
                                </template>
                            </el-table-column>
                            <el-table-column width="200" property="idCardNo" label="身份证号码">
                                <template slot-scope="scope">
                                    {{ scope.row.idCardNo }}
                                </template>
                            </el-table-column>
                        </el-table>
                        <span slot="reference" style="cursor: pointer;margin-left: 20px;">"移上查看客户名单"</span>
                        </el-popover>
                    </div>
                </div>
                <div v-if="budgeting.length<=1">
                    <div class="costbudgeting-li" v-for="(item,index) in budgeting" :key="index">
                        <span v-for="(items,index) in item.data.airFeeData" :key="index">{{items.airType}}：{{townum(items.airDRCB)}}元/人&nbsp;&nbsp;&nbsp;{{items.airNum}}人&nbsp;&nbsp;&nbsp;共:{{townum(items.airZCB)}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                        <el-popover
                        placement="right"
                        width="552"
                        trigger="hover">
                        <el-table max-height="800" border :data="item.data.airInitData">
                            <el-table-column width="150" property="date" label="DATE"></el-table-column>
                            <!-- <el-table-column width="100" property="name" label="姓名"></el-table-column> -->
                            <el-table-column width="400" property="itinerary" label="ITIN"></el-table-column>
                        </el-table>
                        <!-- <el-button slot="reference">click 激活</el-button> -->
                        <span slot="reference" style="cursor: pointer;">"移上查看详细"</span>
                        </el-popover>
                        <!-- 客户名单 -->
                        <el-popover
                        placement="bottom"
                        width="662"
                        trigger="hover">
                        <el-table max-height="600" border :data="rollcallarr">
                            <el-table-column width="100" property="date" label="姓名">
                                <template slot-scope="scope">
                                    {{ scope.row.lastName}}{{scope.row.firstName}}
                                </template>
                            </el-table-column>
                            <el-table-column width="200" property="birthDay" label="拼音">
                                <template slot-scope="scope">
                                    {{ pinyingxing(scope.row.lastName) }}/{{  pinyingxing(scope.row.firstName) }}
                                </template>
                            </el-table-column>
                            <el-table-column width="50" property="sex" label="性别">
                                <template slot-scope="scope">
                                    {{ scope.row.sex==0?'男':'女'}}
                                </template>
                            </el-table-column>
                            <el-table-column width="110" property="birthDay" label="生日">
                                <template slot-scope="scope">
                                    {{ fgarr(scope.row.birthDay) }}
                                </template>
                            </el-table-column>
                            <el-table-column width="200"  label="身份证号码">
                                <template slot-scope="scope">
                                    {{ scope.row.idCardNo==""?'-':scope.row.idCardNo }}
                                </template>
                            </el-table-column>
                        </el-table>
                        <span slot="reference" style="cursor: pointer;margin-left: 20px;">"移上查看客户名单"</span>
                        </el-popover>
                    </div>
                </div>
                <div style="display: flex;align-items: center;" v-if="budgeting.length==0">
                    <div class="costbudgeting-li">
                        未设置团组成本或成本未通知
                    </div>
                    <el-popover
                        placement="bottom"
                        width="662"
                        trigger="hover">
                        <el-table max-height="600" border :data="rollcallarr">
                            <el-table-column width="100" property="date" label="姓名">
                                <template slot-scope="scope">
                                    {{ scope.row.lastName}}{{scope.row.firstName}}
                                </template>
                            </el-table-column>
                            <el-table-column width="200" property="birthDay" label="拼音">
                                <template slot-scope="scope">
                                    {{ pinyingxing(scope.row.lastName) }}/{{  pinyingxing(scope.row.firstName) }}
                                </template>
                            </el-table-column>
                            <el-table-column width="50" property="sex" label="性别">
                                <template slot-scope="scope">
                                    {{ scope.row.sex==0?'男':'女'}}
                                </template>
                            </el-table-column>
                            <el-table-column width="110" property="birthDay" label="生日">
                                <template slot-scope="scope">
                                    {{ fgarr(scope.row.birthDay) }}
                                </template>
                            </el-table-column>
                            <el-table-column width="200"  label="身份证号码">
                                <template slot-scope="scope">
                                    {{ scope.row.idCardNo==""?'-':scope.row.idCardNo }}
                                </template>
                            </el-table-column>
                        </el-table>
                        <span slot="reference" style="cursor: pointer;margin-left: 20px;">"移上查看客户名单"</span>
                    </el-popover>
                </div>
            </div>
            <template>
                <el-table :data="tableDatas.slice((currentPage - 1) * pageSize, currentPage * pageSize)" border
                    style="width: 100%" v-loading="loading" element-loading-text="拼命加载中...">
                    <el-table-column prop="num" label="序 号" width="55">
                        <template slot-scope="scope">
                            {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="cTypeName" label="舱位类型" width="100">
                    </el-table-column>
                    <el-table-column prop="flightDescription" label="航班简述" width="600">
                    </el-table-column>
                    <el-table-column prop="clientNameStr" label="客人名单" width="280">
                    </el-table-column>
                    <el-table-column prop="clientNum" label="客人人数">
                    </el-table-column>
                    <el-table-column prop="prePrice,preCurrencyStr" label="机票单价" width="120" sortable>
                        <template slot-scope="scope">
                            {{ townum(scope.row.prePrice) }}({{ scope.row.preCurrencyStr }})
                        </template>
                    </el-table-column>
                    <el-table-column prop="price,currencyStr" label="机票总价" width="120">
                        <template slot-scope="scope">
                            {{ townum(scope.row.price) }}({{ scope.row.currencyStr }})
                        </template>
                    </el-table-column>
                    <el-table-column prop="isAuditGM" label="是否审核" width="120">
                        <template slot-scope="isAuditGM">
                            <span v-if="isAuditGM.row.isAuditGM == 1">已通过</span>
                            <span v-else-if="isAuditGM.row.isAuditGM == 0">未审核</span>
                            <span v-else-if="isAuditGM.row.isAuditGM == 2">未通过</span>
                            <span v-else>自动审核通过</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" :width="'80px'">
                        <template slot-scope="scope">
                            <el-button size="mini" @click="upDate(scope.$index, scope.row)">编辑</el-button>
                            <div style="height: 8px;"></div>
                            <el-button size="mini" type="danger" @click="del(scope.$index, scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </template>
            <div v-if="fynone" class="block">
                <el-pagination align='center' @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page="currentPage" :page-sizes="[10, 12, 15, 20]" :page-size="pageSize"
                    layout="total, sizes, prev, pager, next" :total="tableDatas.length">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
import { el } from '@fullcalendar/core/internal-common';
import { pinyin } from 'pinyin-pro';
export default {
    data() {
        return {
            loading: false,
            tableDatas: [],
            tableData: [],
            currentPage: 1, // 当前页码
            pageSize: 12,// 每页的数据条数
            input: '',
            token: '',
            userId: 0,
            DiId: '',
            AirTicketResSelectData: [],
            delegationInfo: {},
            fynone:true,
            budgeting:[],
            gridData: [{
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄'
            }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄'
            }, {
            date: '2016-05-01',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄'
            }, {
            date: '2016-05-03',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄'
            }],
            rollcallarr:[]
        }
    },
    methods: {
        //拼音
        pinyingxing(val){
            return pinyin(val, { toneType: 'none' }).toUpperCase();
        },
        //fenge
        fgarr(val){
            val=val+""
            return val.split(' ')[0]
        },
        btn(){
            console.log(this.budgeting.length)
        },
        //保留两位小数
        townum(val){
            return val.toFixed(2)
        },
        //获取成本提示
        getcostbudgeting(){
            this.budgeting=[];
            var url = "/api/Groups/PostGroupCostModulePrompt"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    userId: that.userId,
                    diId: that.DiId,
                    cTable:85,
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    console.log(res)
                    that.budgeting=res.data.data.modulePromptInfos;
                } else {
                    // that.$message.error(res.data.msg);
                }
            })
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.currentPage = 1;
            this.pageSize = val;
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val;
        },
        //团组下拉框
        AirTicketResSelect() {
            var url = "/api/Groups/AirTicketResSelect"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    userId: that.userId
                }
            }).then(function (res) {
                console.log(res)
                if (res.data.code == 200) {
                    that.AirTicketResSelectData = res.data.data.groupName;
                 
                    if (that.AirTicketResSelectData.length != 0) {
                        var diid = that.$route.query.DiId;
                        if (diid) {
                            that.DiId = parseInt(diid);
                        } else {
                            that.DiId = that.AirTicketResSelectData[0].id;
                        }
                        that.AirTicketResList();
                        that.getcostbudgeting();
                        that.PostTourClientListByDiId();
                    }

                }
            }).catch(function (error) {
                that.$message.error("网络错误，请稍后重试");
            });
        },
        AirTicketResSelectChange() {
            this.AirTicketResList();
            this.getcostbudgeting();
            this.PostTourClientListByDiId();
        },
        //团组信息绑定
        AirTicketResList() {
            var url = "/api/Groups/AirTicketResList"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    portType: 1,
                    diId: that.DiId,
                    userId: that.userId,
                }
            }).then(function (res) {
                console.log(res)
                if (res.data.code == 200) {
                    that.tableDatas = res.data.data.airTicketReservations;
                    that.tableData = that.tableDatas
                    if(that.tableData<=0){
                        that.fynone=false;
                    }else{
                        that.fynone=true;
                    }
                    if (that.tableDatas.length != 0) {
                        if (that.tableDatas.slice((that.currentPage - 1) * that.pageSize, that.currentPage * that.pageSize).length == 0) {
                            if (that.currentPage > 1) {
                                that.currentPage = that.currentPage - 1;
                            }
                        }

                    }
                    that.delegationInfo = res.data.data.delegationInfo
                }else{
                    that.fynone=false;
                }

            }).catch(function (error) {
                that.fynone=false;
                that.$message.error("网络错误，请稍后重试");
            });
        },
        upDate(index, row) {
            this.$router.push({
                path: "/home/OpAirTicketRes",
                query: {
                    DiId: this.DiId,
                    id: row.id
                }
            })

        },
        //获取客户名单info
        PostTourClientListByDiId() {
            var that = this
            var url = "/api/Groups/PostTourClientListByDiId"
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + that.token
                },
                data: {
                    portType:1,
                    diid: that.DiId,
                    pageId:104,
                    userId:that.userId
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.rollcallarr=res.data.data;
                } else {
                    that.$message.error(res.data.msg);
                }
            })
        },
        addIf() {
            if (this.DiId != 0 && this.DiId != '' && this.DiId != undefined) {
                this.$router.push({
                    path: "/home/OpAirTicketRes",
                    query: {
                        DiId: this.DiId,
                    }
                })

            } else {
                this.$message('请选择团组在进行添加');
            }
        },
        del(index, row) {
            this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                var url = "/api/Groups/DelAirTicketRes"
                var that = this
                this.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer ' + this.token
                    },
                    data: {
                        Id: row.id,
                        DeleteUserId: this.userId
                    }
                }).then(function (res) {
                    console.log(res)

                    if (res.data.code == 200) {

                        that.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        that.AirTicketResList();
                    } else {
                        that.$message.error('删除失败！');
                    }
                    that.loading = false
                }).catch(function (error) {
                    that.loading = false
                    that.$message.error("网络错误，请稍后重试");
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '操作已取消！'
                });
            });
        },
        download() {
            var url = "/api/Groups/DeriveAirTicketRes"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    DiId: that.DiId,
                    UserId: that.userId
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    window.location.href = res.data.data
                } else {
                    that.$message.error(res.data.smg);
                }
            })
        },
        downloadCN() {
            var url = "/api/Groups/ItineraryAirTicketRes"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    DiId: that.DiId,
                    UserId: that.userId,
                    Language: "CN"
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    window.location.href = res.data.data
                } else {
                    that.$message.error("网络错误，请稍后重试");
                }
            })
        },
        downloadEN() {
            var url = "/api/Groups/ItineraryAirTicketRes"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    DiId: that.DiId,
                    UserId: that.userId,
                    Language: "EN"
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    window.location.href = res.data.data
                } else {
                    that.$message.error("网络错误，请稍后重试");
                }
            })
        }
    },
    mounted() {
        this.token = JSON.parse(localStorage.getItem('userinif')).token;
        this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
        this.AirTicketResSelect();
        //this.AirTicketResList()
    }
}
</script>
<style>
.communal-list {
    background-color: #fff;
    padding: 10px;
    box-shadow: 0 0 5px #0005;
    border-radius: 10px;
    min-height: 830px;
    
}

.communal-title {
    display: flex;
    font-size: 17px;
    font-weight: 600;
    color: #555;
    margin-top: 8px;
    margin-bottom: 10px;
    justify-content: space-between;
    align-items: center;
}
.communal-list .block{
    margin-top: 20px;
}
.communal-box {
    display: flex;
}

.communal-box>button {
    margin-left: 10px;
    padding: 8px 20px;
}
.costbudgeting{
    color: red;
    font-size: 14px;
}
.costbudgeting-li{
    margin: 5px 0;
    
}
</style>