<template>
    <div>
        <div class="standards-all">
            <div class="standards-head">
                <div class="standards-head-li">
                    <div>
                        <label>搜索:</label>
                        <el-input style="width: 220px;margin-left: 10px;" v-model="input" placeholder="请输入内容"></el-input>
                        <el-button @click="OverseaVehicleList" type="primary">搜 索</el-button>
                    </div>
                </div>
                <div class="standards-head-li">
                    <!-- <el-button type="primary">查 询</el-button> -->
                    <el-button @click="addclick('新增')" type="primary">新 增</el-button>
                </div>
            </div>
            <div class="standards-table">
                <el-table
                :data="tableData"
                border
                style="width: 100%">
                    <el-table-column
                    type="index"
                    label="序号"
                    width="55">
                    </el-table-column>
                    <el-table-column
                    prop="continentName"
                    label="洲"
                    width="80">
                    </el-table-column>
                    <el-table-column
                    prop="countryName"
                    label="国家/地区"
                    width="100">
                    </el-table-column>
                    <el-table-column
                    prop="cityName"
                    label="城市"
                    width="180">
                    </el-table-column>
                    <el-table-column
                    prop="currency"
                    label="币种"
                    width="80">
                    </el-table-column>
                    <el-table-column
                    prop="guidePrice"
                    label="导游费用"
                    width="120">
                    </el-table-column>
                    <el-table-column
                    prop="otherPrice1"
                    label="举牌接机"
                    width="120">
                    </el-table-column>
                    <el-table-column
                    prop="otherPrice2"
                    label="送机协助值机"
                    width="120">
                    </el-table-column>
                    <el-table-column
                    prop="otherPrice3"
                    label="其他费用"
                    width="120">
                    </el-table-column>
                    <el-table-column
                    prop="lastUpdateUserName"
                    label="最后操作人"
                    width="100">
                    </el-table-column>
                    <el-table-column
                    prop="lastUpdateTime"
                    label="最后操作时间"
                    width="180">
                    </el-table-column> 
                    <el-table-column
                    prop="remark"
                    label="备注"
                    >
                    </el-table-column>
                    <el-table-column
                    prop="address"
                    label="操作"
                    width="125">
                        <template slot-scope="scope">
                            <el-button
                            @click.native.prevent="addclick('修改', scope.row)"
                            size="mini">
                            修 改
                            </el-button>
                            <el-button
                            style="margin-left: 0px;margin-top: 4px;"
                            @click.native.prevent="deleteRow(scope.$index, tableData,scope.row)"
                            type="danger"
                            size="mini">
                            移 除
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="block">
                    <el-pagination
                      @size-change="handleSizeChange"
                      @current-change="handleCurrentChange"
                      :current-page="currentPage4"
                      :page-sizes="[14, 10, 18, 22]"
                      :page-size="100"
                      layout="total, sizes, prev, pager, next, jumper"
                      :total="count">
                    </el-pagination>
                  </div>
            </div>
            <el-dialog :close-on-click-modal="false" width="1315px" title="编辑三公费用标准" :visible.sync="AdditionalFees">
                <el-form :model="addfees" ref="addfees" :rules="addfeesrules">
                    <div class="standards-inif">
                        <el-form-item label="洲" prop="continent" :label-width="formLabelWidth">
                            <el-input size="medium" :controls="false" v-model="addfees.continent"></el-input>
                        </el-form-item>
                        <el-form-item label="国家" prop="country" :label-width="formLabelWidth">
                            <el-input size="medium" :controls="false" v-model="addfees.country"></el-input>
                        </el-form-item>
                        <el-form-item label="城市" prop="city" :label-width="formLabelWidth">
                            <el-input size="medium" :controls="false" v-model="addfees.city"></el-input>
                        </el-form-item>
                        <el-form-item label="币种" prop="currency" :label-width="formLabelWidth">
                            <el-select size="medium" style="height:36px"
                                v-model="addfees.currency" filterable placeholder="请选择">
                                <el-option v-for="item in currencyDatas" :key="item.id" :label="item.name" :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="导游费用" prop="roomCost" :label-width="formLabelWidth">
                            <el-input-number :precision="2" size="medium" :controls="false" v-model="addfees.guidePrice"></el-input-number>
                        </el-form-item>
                        <el-form-item label="举牌接机" prop="foodCost" :label-width="formLabelWidth">
                            <el-input-number :precision="2" size="medium" :controls="false" v-model="addfees.otherPrice1"></el-input-number>
                        </el-form-item>
                        <el-form-item label="送机协助值机" prop="publicCost" :label-width="formLabelWidth">
                            <el-input-number :precision="2" size="medium" :controls="false" v-model="addfees.otherPrice2"></el-input-number>
                        </el-form-item>
                        <el-form-item label="其他费用" prop="trainCost" :label-width="formLabelWidth">
                            <el-input-number :precision="2" size="medium" :controls="false" v-model="addfees.otherPrice3"></el-input-number>
                        </el-form-item>
                    </div>
                    <div class="remark-box">
                        <el-form-item label="备注" :label-width="formLabelWidth">
                            <el-input :rows="2" type="textarea" v-model="addfees.remark"></el-input>
                        </el-form-item>
                    </div>
                    <div>
                        <div style="display: flex;align-items: center;justify-content: space-between;margin-bottom: 5px;">
                            <label style="font-weight: 600;">具体车型</label>
                            <el-button @click="caraddYH" size="mini" type="primary">添 加</el-button>
                        </div>
                        <el-table border :data="addfees.carInfos">
                            <el-table-column label="车型名称" width="200">
                                <template slot-scope="scope">
                                    <el-input size="mini" :controls="false" v-model="scope.row.carTypeName"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="服务类型" width="180">
                                <template slot-scope="scope ">
                                    <el-select size="mini" v-model="scope.row.serviceType" filterable
                                        placeholder="请选择">
                                        <el-option v-for="item in serviceTypeDatas" :key="item.value" :label="item.text"
                                            :value="item.value">
                                        </el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column label="价格" width="180">
                                <template slot-scope="scope ">
                                    <el-input-number style="width:100%" size="mini" :precision="2" :controls="false" v-model="scope.row.price"></el-input-number>
                                </template>
                            </el-table-column>
                            <el-table-column label="备注">
                                <template slot-scope="scope">
                                    <el-input size="mini" :rows="1" type="textarea" v-model="scope.row.remark"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作" width="100">
                                <template slot-scope="scope">
                                    <el-button size="mini"
                                        @click.native.prevent="carRemove(scope.$index, addfees.carInfos, scope.row)"
                                        type="danger">移除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="addsbtn('addfees')">保 存</el-button>
                    <el-button @click="AdditionalFees = false">取 消</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</template>
<script>
import { el } from '@fullcalendar/core/internal-common'
export default {
    data() {
        return {
            loginuserid:'',
            input:'',
            tableData: [],
            currentPage4: 1,
            count:0,
            pageSize:14,
            pageIndex:1,
            AdditionalFees:false,
            //新增
            addfees:{
                id:0,
                continent:'',//洲
                country:'', //国家
                city:'',//城市
                currency:807,//币种
                guidePrice:0,//导游费用
                otherPrice1:0,//举牌接机
                otherPrice2:0,//送机协助值机
                otherPrice3:0,//其他费用
                remark:'',//备注
                carInfos:[
                    {
                        carTypeName:'',
                        serviceType:'',
                        price:'',
                        id:0,
                        remark:''
                    }
                ]
            },
            formLabelWidth:'100px',
            addfeesrules:{
                continent: [
                    { required: true, trigger: 'change',message:'请填写洲' }
                ],
                country: [
                    {required: true, trigger: 'change',message:'请填写国家' }
                ],
                city: [
                    { required: true, trigger: 'change',message:'请填写城市' }
                ],
                currency: [
                    { required: true,  trigger: 'blur',message:'请选择币种' }
                ],
                guidePrice: [
                    { required: true, trigger: 'change' ,message:'请填写导游费用'},
                ],
                otherPrice1: [
                    { required: true, trigger: 'change',message:'请填写举牌接机' },
                ],
                otherPrice2: [
                    { required: true, trigger: 'change',message:'请填写送机协助值机' },
                ],
                otherPrice3: [
                    { required: true, trigger: 'change',message:'请填写其他费用' },
                ],
            },
            serviceTypeDatas:[],
            currencyDatas:[]
        }
    },
    methods:{
        //获取基础数据
        OverseaVehicleInit(){
            var url = "/api/Resource/OverseaVehicleInit"
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
            }).then(function (res) {
                that.serviceTypeDatas=[];
                that.currencyDatas=[];
                if(res.data.code==200){
                    that.serviceTypeDatas= res.data.data.serviceTypeDatas;
                    that.currencyDatas= res.data.data.currencyDatas;
                }
            })
        },
        //添加具体车型
        caraddYH(){
            this.addfees.carInfos.push({
                carTypeName:'',
                serviceType:'',
                price:'',
                id:0,
                remark:''
            })
        },
        //移除具体车型
        carRemove(index, rows,inif){
            rows.splice(index, 1)
        },
        //获取标准列表
        OverseaVehicleList(){
            var url = "/api/Resource/OverseaVehicleList"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data:{
                    portType: 1,
                    pageIndex:that.pageIndex,
                    pageSize:that.pageSize,
                    search:that.input,
                }
            }).then(function (res) {
                if(res.data.code==200){
                   that.tableData= res.data.data;
                   that.count= res.data.count;
                }
                
            }).catch(()=>{})
        },
        //获取详情
        OverseaVehicleInfo(val){
            var url = "/api/Resource/OverseaVehicleInfo/"+val
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                }
            }).then(function (res) {
                if(res.data.code==200){
                    return res.data.data;
                }else{
                    that.$message.error(res.data.msg);
                }
            })
        },
        //新增按钮
        addclick(text,val){
            if (this.$refs.addfees){
                this.$nextTick(() => {
                    this.$refs['addfees'].clearValidate();
                })
            }
            this.AdditionalFees=true;
            var that = this
            if(text=='修改'){
                new Promise(function (resolve, reject) {
                    var url = "/api/Resource/OverseaVehicleInfo/" + val.id
                    that.$axios({
                        method: 'get',
                        url: url,
                        headers: {
                            Authorization: 'Bearer ' + that.token
                        }
                    }).then(function (res) {
                        var vals=[];
                        if (res.data.code == 200) {
                            vals = res.data.data;
                            that.addfees.id = vals.id;
                            that.addfees.continent = vals.continentName;
                            that.addfees.country = vals.countryName;
                            that.addfees.city = vals.cityName;
                            that.addfees.currency = vals.currency;
                            that.addfees.guidePrice = vals.guidePrice;
                            that.addfees.otherPrice1 = vals.otherPrice1;
                            that.addfees.otherPrice2 = vals.otherPrice2;
                            that.addfees.otherPrice3 = vals.otherPrice3;
                            that.addfees.trainCost = vals.trainCost;
                            that.addfees.carInfos = vals.carInfos;
                            that.addfees.remark = vals.remark;
                            return resolve();
                        } else {
                            that.$message.error(res.data.msg);
                        }
                    })
                }).then(() => {
                    that.OverseaVehicleInit();
                });
            }else{
                this.OverseaVehicleInit();
                this.addfees = {
                    id: 0,
                    continent: '',//洲
                    country: '', //国家
                    city: '',//城市
                    currency: 807,//币种
                    guidePrice: 0,//导游费用
                    otherPrice1: 0,//举牌接机
                    otherPrice2: 0,//送机协助值机
                    otherPrice3: 0,//其他费用
                    carInfos: [
                        {
                            carTypeName: '',
                            serviceType: '',
                            price: '',
                            id: 0,
                            remark: ''
                        }
                    ],
                    trainCost: 0,//培训费
                    remark: '',//备注
                }
            
            }
        },
        handleSizeChange(val) {
            this.pageSize=val;
            this.OverseaVehicleList();
        },
        handleCurrentChange(val) {
            this.pageIndex=val;
            this.OverseaVehicleList()
        },
        //新增,修改api
        OverseaVehicleAddOrEdit(){
            var that = this
            new Promise(function (resolve, reject) {
                //验证具体车型
                if (that.addfees.carInfos.length==0){
                    that.$message.error('请添加具体车型信息');
                    return;
                }
                for(var i=0;i<that.addfees.carInfos.length;i++){
                    if(that.addfees.carInfos[i].carTypeName==''){
                        that.$message.error('请填写具体车型名称');
                        return;
                    }
                    if(that.addfees.carInfos[i].serviceType==''){
                        that.$message.error('请选择具体车型服务类型');
                        return;
                    }
                    if(that.addfees.carInfos[i].price==''||that.addfees.carInfos[i].price==null){
                        that.$message.error('请填写具体车型价格');
                        return;
                    }
                }
                var url = "/api/Resource/OverseaVehicleAddOrEdit"
                that.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer ' + that.token
                    },
                    data: {
                        id: that.addfees.id,
                        continentName: that.addfees.continent,
                        countryName: that.addfees.country,
                        cityName: that.addfees.city,
                        guidePrice: that.addfees.guidePrice,
                        otherPrice1: that.addfees.otherPrice1,
                        otherPrice2: that.addfees.otherPrice2,
                        otherPrice3: that.addfees.otherPrice3,
                        currency: that.addfees.currency,
                        carInfos: that.addfees.carInfos,
                        remark: that.addfees.remark,
                        currUserId: that.loginuserid,
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.$message({
                            type: 'success',
                            message: res.data.msg
                        });
                        that.AdditionalFees = false
                        return resolve();
                    } else {
                        that.$message.error(res.data.msg);
                    }
                })
            }).then(() => {
                that.OverseaVehicleList();
            });
        },
        //新增-修改
        addsbtn(formName){
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.OverseaVehicleAddOrEdit()
                } else {
                    this.$message.error('请将红框内容补全！');
                    return false;
                }
            });
        },
        //删除
        deleteRow(index, rows,inif){
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            center: true
            }).then(() => {
                var url = "/api/Resource/OverseaVehicleDel"
                var that = this
                new Promise(function (resolve, reject) {
                    that.$axios({
                        method: 'post',
                        url: url,
                        headers: {
                            Authorization: 'Bearer ' + that.token
                        },
                        data:{
                            id: inif.id,
                            currUserId:that.loginuserid,
                        }
                    }).then(function (res) {
                        if(res.data.code==200){
                            that.$message({
                                type: 'success',
                                message: res.data.msg
                            });
                            return resolve();
                        }else{
                            that.$message.error(res.data.msg);
                        }
                        
                    })
                }).then(() => {
                    that.OverseaVehicleList();
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
    },
    mounted(){
        this.loginuserid=JSON.parse(localStorage.getItem('userinif')).userInfo.userId;
        this.OverseaVehicleList();
    }
}
</script>
<style>
.standards-all{
    background-color: #fff;
    padding: 10px;
    box-shadow: 0 0 5px #0005;
    border-radius: 10px;
    min-height: 830px;
}
.standards-head-li{
    display: flex;
}
.standards-head-li div{
    margin-right: 10px;

}
.standards-head-li label{
    color: #606266;
    font-size: 15px;
    font-weight: 600;
}
.standards-head{
    display: flex;
    justify-content: space-between;
}
.standards-table{
    margin-top: 20px;
}
.standards-table .block{
    margin-top: 10px;
    text-align: center;
}
.standards-inif{
    display: flex;
    flex-wrap:wrap ;
}
.standards-inif .el-input--medium {
    width: 218px;
}
.standards-inif .el-input-number--medium{
    width: 218px;
}
.carinfo>div{
    display: flex;
}
.carinfo .el-input--medium {
    width: 218px;
}
.carinfo .standards-inif .el-input-number--medium{
    width: 218px;
}
.remark-box .el-textarea__inner{
    width: 100%;
}
</style>