<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: 50%;display: flex;">
                        <div style="width: 25%;">
                            <el-select v-model="DiId" placeholder="团组选择" clearable filterable @change="deleSelect"
                                style="width: 100%;">
                                <el-option v-for="item in delegationInfoList" :key="item.id" :label="item.teamName"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                    <div style="width: 50%;display: flex;align-items: flex-start;justify-content: end;">
                        <el-button size="small" type="primary" style="" @click="exportPriceDetail">导出费用明细</el-button>
                        <el-button style="margin-right: 10px;" size="small" type="primary" @click="addIf">新增</el-button>
                        <!-- <el-upload
                        class="upload-demo"
                        action="http://132.232.92.186:8888/api/Groups/CommonSaveFile"
                        :on-preview="handlePreview"
                        :on-remove="handleRemove"
                        :before-remove="beforeRemove"
                        multiple
                        :limit="3"
                        :data="datas"
                        :on-exceed="handleExceed"
                        :file-list="fileList"
                        name="files">
                        <el-button size="small" type="primary">点击上传</el-button>
                        <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
                        </el-upload> -->
                    </div>
                </div>
            </div>
            <div
                :style="delegationInfo.teamLevSId == 'VIP' || delegationInfo.teamLevSId == 'VVIP' ? 'margin:10px 0;color:red;' : 'margin:10px 0;color:#606266;'">
                <span style="font-weight: bold;font-size:14px;">团队名称：</span>
                <span style="font-size:14px;">{{ delegationInfo.teamName }}&nbsp;&nbsp;&nbsp;</span>
                <span style="font-weight: bold;font-size:14px;">客户级别：</span>
                <span style="font-size:14px;">{{ delegationInfo.teamLevSId }}&nbsp;&nbsp;&nbsp;</span>
                <span style="font-weight: bold;font-size:14px;">客户：</span>
                <span style="font-size:14px;">{{ delegationInfo.clientName }}&nbsp;&nbsp;&nbsp; {{
}}&nbsp;&nbsp;&nbsp;</span>
                <span style="font-weight: bold;font-size:14px;">出访国家：</span>
                <span style="font-size:14px;">{{ delegationInfo.visitCountry }}&nbsp;&nbsp;&nbsp;</span>
                <span style="font-weight: bold;font-size:14px;">起止日期：</span>
                <span style="font-size:14px;">{{ delegationInfo.visitStartDate }}—{{ delegationInfo.visitEndDate
                }}&nbsp;&nbsp;&nbsp;</span>
                <span style="font-weight: bold;font-size:14px;">天数/人数：</span>
                <span style="font-size:14px;">{{ delegationInfo.visitDays }}天/{{ delegationInfo.visitPNumber }}人</span>
            </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="area" label="地区">
                    </el-table-column>
                    <el-table-column prop="priceName" label="费用名称">
                    </el-table-column>
                    <el-table-column prop="priceTypeStr" label="款项类型">
                    </el-table-column>
                    <el-table-column prop="serviceGuide" label="服务导游">
                    </el-table-column>
                    <el-table-column prop="serviceTel" label="导游联系电话">
                    </el-table-column>
                    <el-table-column prop="busName" label="Bus名称">
                    </el-table-column>
                    <el-table-column prop="busTel" label="Bus联系电话">
                    </el-table-column>
                    <el-table-column prop="serviceStartTime" label="服务时间起止">
                        <template slot-scope="scope">
                            {{ scope.row.serviceStartTime }}至{{ scope.row.serviceEndTime }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="serviceQuotedPrice" label="服务报价">
                        <template slot-scope="scope">
                            {{ scope.row.serviceQuotedPrice }} {{ scope.row.currencyStr }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="payPercentage" label="付款百分比">
                        <template slot-scope="scope">
                            {{ scope.row.payPercentage }}%
                        </template>
                    </el-table-column>
                    <el-table-column prop="payThenMoney" label="此次付款金额">
                        <template slot-scope="scope">
                            {{ scope.row.payThenMoney }} {{ scope.row.currencyStr }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="remainingBalance" label="尾款金额">
                        <template slot-scope="scope">
                            {{ scope.row.remainingBalance }} {{ scope.row.currencyStr }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="isAuditGM" label="是否审核" width="80">
                        <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 prop="isPay" label="是否支付" width="80">
                        <template slot-scope="isPay">
                            <span v-if="isPay.row.isPay == 1">已支付</span>
                            <span v-else-if="isPay.row.isPay == 0">未支付</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="id" label="详细费用" width="110">
                        <template slot-scope="scope">
                            <el-button @click="AddDetails(scope.row.id)" size="small">点击填写</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" width="120">
                        <template slot-scope="scope">
                            <!-- <el-button-group> -->
                            <el-button type="primary" size="mini" icon="el-icon-edit"
                                @click="upDate(scope.$index, scope.row)"></el-button>
                            <el-button style="margin-left: 0px;" type="danger" size="mini" icon="el-icon-delete"
                                @click="del(scope.$index, scope.row)"></el-button>
                            <!-- </el-button-group> -->
                        </template>
                    </el-table-column>
                </el-table>
            </template>
            <div 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';
export default {
    data() {
        return {
            loading: false,
            tableDatas: [],
            tableData: [],
            currentPage: 1, // 当前页码
            pageSize: 12,// 每页的数据条数
            input: '',
            token: '',
            userId: 0,
            DiId: '',
            VisaSelectList: [],
            VisaClient: '',
            delegationInfoList: [],
            delegationInfo: {},
            datas: {},
            fileList: [
                // {name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, 
                // {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}
            ]
        }
    },
    methods: {
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.currentPage = 1;
            this.pageSize = val;
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val;
        },
        //团组下拉框
        deleSelect() {
            var url = "/api/Groups/DecreasePaymentsSelect"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    UserId: that.userId,
                    CTId: 79
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.delegationInfoList = res.data.data.groupName;

                    if (that.DiId == undefined) {
                        that.delegationInfo = that.delegationInfoList[0]
                        that.DiId = that.delegationInfoList[0].id;
                    } else {
                        for (let index = 0; index < that.delegationInfoList.length; index++) {
                            if (that.delegationInfoList[index].id == that.DiId) {
                                that.delegationInfo = that.delegationInfoList[index];
                                that.DiId = that.delegationInfoList[index].id;
                            }
                        }
                    }

                    that.QueryCarTouristGuideGroundByDiId();
                    that.handledatas();
                }
            }).catch(function (error) {
                that.$message.error("网络错误，请稍后重试");
            });
        },
        deleSelectChange() {
            if (this.DiId != "") {
                this.QueryCarTouristGuideGroundByDiId();
            } else {
                this.tableDatas = [];
                this.tableData = [];
            }
        },
        //团组信息绑定
        QueryCarTouristGuideGroundByDiId() {

            if (!this.DiId) {
                return;
            }

            var url = "/api/Groups/QueryCarTouristGuideGroundByDiId"
            var that = this;
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    pageIndex: 0,
                    pageSize: 0,
                    portType: 1,
                    diID: that.DiId,
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.tableDatas = res.data.data;
                    that.tableData = that.tableDatas
                    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;
                            }
                        }
                    }

                }

            }).catch(function (error) {

                that.$message.error("网络错误，请稍后重试");
            });
        },
        //填写详细费用
        AddDetails(id) {
            this.$router.push({
                path: "/home/CarTouristGuideGrounContent",
                query: {
                    id: id,
                    diId: this.DiId,
                }
            })

        },
        upDate(index, row) {
            this.$router.push({
                path: "/home/OpCarTouristGuideGroundId",
                query: {
                    DiId: this.DiId,
                    id: row.id
                }
            })

        },
        addIf() {
            if (this.DiId != 0 && this.DiId != '' && this.DiId != undefined) {
                this.$router.push({
                    path: "/home/OpCarTouristGuideGroundId",
                    query: {
                        DiId: this.DiId,
                    }
                })

            } else {
                this.$message('请选择团组在进行添加');
            }
        },
        del(index, row) {
            this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                var url = "/api/Groups/DelCarTouristGuideGround"
                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.tableDatas.splice(index, 1);
                    } else {
                        that.$message.error('删除失败！');
                    }
                    that.loading = false
                }).catch(function (error) {
                    that.loading = false
                    that.$message.error("网络错误，请稍后重试");
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '操作已取消！'
                });
            });
        },
        exportPriceDetail() {
            var url = "/api/Groups/ExportLocalGuidePriceDetail"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    "diid": this.DiId,
                }
            }).then(function (res) {
                console.log(res)
                if (res.data.code == 200) {
                    window.open(res.data.data.url);
                } else {
                    that.$message.error('导出失败！' + res.data.msg);
                }
            }).catch(function (error) {
                that.$message.error("网络错误，请稍后重试");
            });
        },
        //票据上传
        handleRemove(file, fileList) {
            console.log(file, fileList);
        },
        handlePreview(file) {
            console.log(file);
        },
        handleExceed(files, fileList) {
            this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
        },
        beforeRemove(file, fileList) {
            return this.$confirm(`确定移除 ${file.name}？`);
        },
        //处理datas
        handledatas() {
            this.datas = {
                Ctable: 79,
                Diid: this.DiId,
                Cid: 0,
                Userid: this.userId
            }
        }
    },
    mounted() {
        this.DiId = this.$route.query.diId
        this.token = JSON.parse(localStorage.getItem('userinif')).token;
        this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId

        this.deleSelect();
        //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-box {
    display: flex;
}

.communal-box>button {
    margin-left: 10px;
    padding: 8px 20px;
}
</style>