<template>
    <div>
        <div class="communal-list">
            <div class="communal-title">
                <div>签证费用标准</div>
                <div class="communal-box">
                    <el-select style="width: 150px;margin-right: 10px;" @change="visaFeeTypechange" v-model="visaFeeType" placeholder="签证费用类型">
                        <el-option v-for="(item,index) in visaFeeTypearr" :key="index" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                    <el-input placeholder="国家" v-model="input" clearable style="width: 350px;">
                    </el-input>
                    <el-button @click="Inquireclick()" type="primary" style="margin-left: 10px;">搜 索</el-button>
                    <router-link to="/home/CountryFeeCostOperation">
                        <el-button type="primary" style="margin-left: 10px;">新增</el-button>
                    </router-link>
                </div>
            </div>
            <template>
                <el-table :data="tableData" 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="continent" label="洲">
                    </el-table-column>
                    <el-table-column prop="country" label="国家">
                    </el-table-column>
                    <!-- <el-table-column prop="isVisaExemption" label="是否免签" width="80">
                        <template slot-scope="is">
                            <span v-if="is.row.isVisaExemption == 1">否</span>
                            <span v-else>是</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="isVisaOnArrival" label="是否落地签" width="80">
                        <template slot-scope="is">
                            <span v-if="is.row.isVisaOnArrival == 1">否</span>
                            <span v-else>是</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="isElectronicSignature" label="是否电子签" width="80">
                        <template slot-scope="is">
                            <span v-if="is.row.isElectronicSignature == 1">否</span>
                            <span v-else>是</span>
                        </template>
                    </el-table-column> -->
                    <el-table-column prop="lastUpdateUserName" label="数据更新人"  width="150">
                    </el-table-column>
                    <el-table-column prop="lastUpdateTime" label="数据更新时间"  width="150">
                    </el-table-column>
                    <!-- <el-table-column prop="visaTime" label="一般签证时间(天)" width="100">
                    </el-table-column>
                    <el-table-column prop="visaPrice" label="费用(元)" :formatter="rounding">
                    </el-table-column>
                    <el-table-column prop="grandBusinessAgencyFee" label="大公务代办费(元)" :formatter="rounding">
                    </el-table-column>
                    <el-table-column prop="pettyBusinessAgencyFee" label="小公务代办费(元)" :formatter="rounding">
                    </el-table-column>
                    <el-table-column prop="urgentTime" label="加急签证时间(天)">
                    </el-table-column>
                    <el-table-column prop="urgentPrice" label="加急签证费用(元)" :formatter="rounding">
                    </el-table-column> -->
                    <el-table-column prop="provinceVisaFeeLabel" label="费用描述" width="110">
                        <template slot-scope="provinceVisaFeeLabel">
                            <el-popover title="费用描述" trigger="hover" placement="left" width="400">
                                <div style="white-space: pre-line;overflow-y: auto;height: 400px;" v-html="provinceVisaFeeLabel.row.provinceVisaFeeLabel"></div>
                                <el-button slot="reference" size="mini">移上查看</el-button>
                            </el-popover>
                        </template>
                    </el-table-column>
                    <!-- <el-table-column prop="urgentTime" label="加急签证时间" width="50">
                    </el-table-column>
                    <el-table-column prop="urgentPrice" label="加急费用" width="80">
                    </el-table-column>
                    <el-table-column prop="urgentPriceDesc" label="加急费用描述" width="180">
                        <template slot-scope="urgentPriceDesc">
                            <el-popover placement="top-start" title="加急费用描述" width="200" trigger="hover"
                                :content="urgentPriceDesc.row.urgentPriceDesc">
                                <el-button slot="reference">移上查看</el-button>
                            </el-popover>
                        </template>
                    </el-table-column>
                    <el-table-column prop="remark" label="签证描述" width="180">
                        <template slot-scope="remark">
                            <el-popover placement="top-start" title="加急费用描述" width="200" trigger="hover"
                                :content="remark.row.remark">
                                <el-button slot="reference">移上查看</el-button>
                            </el-popover>
                        </template>
                    </el-table-column> -->
                    <el-table-column label="操作" width="160">
                        <template slot-scope="scope">
                            <el-button size="mini" @click="upDate(scope.$index, scope.row)">编辑</el-button>
                            <el-button size="mini" type="danger" @click="del(scope.$index, scope.row)">删除</el-button>
                        </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="total">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    beforeRouteLeave(to, from, next) {
        if(to.name!='CountryFeeCostOperation'){
            localStorage.removeItem('qzfyval');
        }
        next()
    },
    data() {
        return {
            loading: false,
            tableDatas: [],
            tableData: [],
            currentPage: 1, // 当前页码
            pageSize: 12,// 每页的数据条数
            input: '',
            token: '',
            userId: 0,
            total: 0, // 总数据条数
            visaFeeType:0,
            visaFeeTypearr:[{
                label: '因公',
                value: 0
            }, {
                label: '因私',
                value: 1
            }],
        }
    },
    methods: {
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.currentPage = 1;
            this.pageSize = val;
            this.QueryVisaCountryFeeCosts();
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val;
            this.QueryVisaCountryFeeCosts();
        },
        QueryVisaCountryFeeCosts(){
            var url = "/api/Resource/VisaFeeStandardList"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    portType: 1,
                    pageIndex: that.currentPage,
                    pageSize: that.pageSize,
                    visaFeeType: that.visaFeeType,
                    countryName: that.input,
                }
            }).then(function (res) {
                that.tableData=[];
                if (res.data.code == 200) {            
                    that.total=res.data.count;
                    that.tableData = res.data.data;
                    console.log(that.tableData);
                    
                }
            }).catch(function (error) {
                that.$message.error("数据加载失败，请稍联系信息部！");
            });
        },
        visaFeeTypechange(){
            this.currentPage = 1;
            this.QueryVisaCountryFeeCosts();
        },
        HotelData() {
            this.QueryVisaCountryFeeCosts();
        },
        //搜索框处理
        Inquireclick() {
            this.currentPage = 1;
            this.QueryVisaCountryFeeCosts();
        },
        rounding(row, column) {
            return parseFloat(row[column.property]).toFixed(2)
        },

        upDate(index, row) {
            var qzfyval={
                currentPage:this.currentPage,
                input:this.input,
            }
            localStorage.setItem('qzfyval', JSON.stringify(qzfyval));
            this.$router.push({
                path: "/home/CountryFeeCostOperation",
                query: { id: row.id }
            })
        },

        del(index, row) {
            this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                var url = "/api/Resource/VisaFeeStandardSoftDel"
                var that = this
                this.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer ' + this.token
                    },
                    data: {
                        id: row.id,
                        currUserId: this.userId
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        that.HotelData();
                    } else {
                        that.$message.error('删除失败！');
                    }
                    that.loading = false
                }).catch(function (error) {
                    that.loading = false
                    that.$message.error("网络错误，请稍后重试");
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '操作已取消！'
                });
            });
        }
    },
    mounted() {
        this.token = JSON.parse(localStorage.getItem('userinif')).token;
        this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
        this.HotelData();
    }
}
</script>
<style>
.communal-list {
    background-color: #fff;
    padding: 10px;
    box-shadow: 0 0 5px #0005;
    border-radius: 10px;
}

.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>