<template>
    <div>
        <div class="standards-all">
            <div class="standards-head">
                <div class="standards-head-li">
                    <div>
                        <label>国家:</label>
                        <!-- <el-input style="width:200px" v-model="input" placeholder="请输入内容"></el-input> -->
                        <el-select style="width: 220px;margin-left: 10px;" v-model="input" @change="countrychange($event)" filterable placeholder="请选择国家">
                            <el-option
                                v-for="item in countrylist"
                                :key="item.countryName"
                                :label="item.countryName"
                                :value="item.countryName">
                            </el-option>
                        </el-select>
                    </div>
                    <div>
                        <label>城市:</label>
                        <el-select style="width: 220px;margin-left: 10px;" v-model="input2" @change="citychange" filterable placeholder="请选择公司">
                            <el-option
                                v-for="item in citylist"
                                :key="item"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                        <!-- <el-input style="width:200px" v-model="input2" placeholder="请输入内容"></el-input> -->
                    </div>
                    <div>
                        <label>归属城市:</label>
                        <el-select style="width: 220px;margin-left: 10px;" v-model="provinceId" @change="provinceIdchange" filterable placeholder="请选择归属城市">
                            <el-option
                                v-for="item in provinceIdarr"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                            </el-option>
                        </el-select>
                    </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
                    prop="rowNumber"
                    label="序号"
                    width="55">
                    </el-table-column>
                    <el-table-column
                    prop="continent"
                    label="洲"
                    width="80">
                    </el-table-column>
                    <el-table-column
                    prop="country"
                    label="国家/地区"
                    width="100">
                    </el-table-column>
                    <el-table-column
                    prop="city"
                    label="城市"
                    width="180">
                    </el-table-column>
                    <el-table-column
                    prop="currencyName"
                    label="币种"
                    width="80">
                    </el-table-column>
                    <el-table-column
                    prop="roomCost"
                    label="住宿费"
                    width="120">
                    </el-table-column>
                    <el-table-column
                    prop="foodCost"
                    label="伙食费"
                    width="120">
                    </el-table-column>
                    <el-table-column
                    prop="publicCost"
                    label="公杂费"
                    width="120">
                    </el-table-column>
                    <el-table-column
                    prop="trainCost"
                    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="720px" 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="provinceId" :label-width="formLabelWidth">
                            <el-select size="medium"  v-model="addfees.provinceId" filterable placeholder="请选择归属城市">
                                <el-option
                                    v-for="item in provinceIdarr"
                                    :key="item.id"
                                    :label="item.name"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="币种" prop="currency" :label-width="formLabelWidth">
                            <el-select size="medium" @change="currencychange" style="height:36px" v-model="addfees.currency" filterable placeholder="请选择">
                                <el-option
                                  v-for="item in options"
                                  :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.roomCost"></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.foodCost"></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.publicCost"></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.trainCost"></el-input-number>
                        </el-form-item>
                    </div>
                    <div class="remark-box">
                        <el-form-item label="备注" :label-width="formLabelWidth">
                            <el-input :rows="8" type="textarea" v-model="addfees.remark"></el-input>
                        </el-form-item>
                    </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>
export default {
    data() {
        return {
            loginuserid:'',
            input:'全部',
            input2:'全部',
            tableData: [],
            currentPage4: 1,
            count:0,
            pageSize:14,
            pageIndex:1,
            AdditionalFees:false,
            countrylist:[],
            citylist:[],
            provinceId:'',
            provinceIdarr:[],
            //新增
            addfees:{
                id:0,
                continent:'',//洲
                country:'', //国家
                city:'',//城市
                currency:807,//币种
                roomCost:0,//住宿费
                foodCost:0,//伙食费
                publicCost:0,//公杂费
                trainCost:0,//培训费
                provinceId:'',
                remark:'',//备注
            },
            options:[],
            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:'请选择币种' }
                ],
                provinceId: [
                    { required: true, trigger: 'change' ,message:'请选择归属城市'},
                ],
                roomCost: [
                    { required: true, trigger: 'change' ,message:'请填写住宿费'},
                ],
                foodCost: [
                    { required: true, trigger: 'change',message:'请填写伙食费' },
                ],
                publicCost: [
                    { required: true, trigger: 'change',message:'请填写公杂费' },
                ],
                trainCost: [
                    { required: true, trigger: 'change',message:'请填写培训费' },
                ],
            },
        }
    },
    methods:{
        //获取基础数据
        GetEnterExitCostDataSource(){
            var url = "/api/Groups/GetEnterExitCostDataSource"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data:{
                    portType: 1
                }
            }).then(function (res) {
                console.log(res)
                if(res.data.code==200){
                    that.options=res.data.data.currencyData;
                }
            })
        },
        //获取省份归属基础数据
        GetEnterExitProvBelongCostDataSource(){
            var url = "/api/Groups/GetEnterExitProvBelongCostDataSource"
            var that = this
            this.$axios({
                method: 'get',
                url: url,
            }).then(function (res) {
                if(res.data.code==200){
                    that.provinceIdarr=res.data.data;
                }
            })
        },
        provinceIdchange(){
            this.GatPostNationalTravel();
        },
        //获取标准列表
        GatPostNationalTravel(){
            var url = "/api/Groups/PostNationalTravelFeePage"
            var that = this
            var inputs=this.input
            var input2s=this.input2
            if(this.input=='全部'){
                inputs='';
            }
            if(this.input2=='全部'){
                input2s='';
            }
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data:{
                    portType: 1,
                    pageIndex:that.pageIndex,
                    pageSize:that.pageSize,
                    provinceId:that.provinceId==''?0:that.provinceId,
                    country:inputs,
                    city:input2s,
                }
            }).then(function (res) {
                console.log(res)
                if(res.data.code==200){
                   that.tableData= res.data.data;
                   that.count= res.data.count;
                }
                
            }).catch(()=>{})
        },
        //新增按钮
        addclick(text,val){
            if (this.$refs.salaryinif){
                this.$nextTick(() => {
                    this.$refs['salaryinif'].clearValidate();
                })
            }
            this.addfees={
                id:0,
                continent:'',//洲
                country:'', //国家
                city:'',//城市
                currency:807,//币种
                roomCost:0,//住宿费
                foodCost:0,//伙食费
                publicCost:0,//公杂费
                trainCost:0,//培训费
                provinceId:'',
                remark:'',//备注
            },
            this.AdditionalFees=true;
            if(text=='修改'){
                console.log(val)
                this.addfees.id=val.id;
                this.addfees.continent=val.continent;
                this.addfees.country=val.country;
                this.addfees.city=val.city;
                this.addfees.currency=val.currency;
                this.addfees.roomCost=val.roomCost;
                this.addfees.provinceId=val.provinceId;
                this.addfees.foodCost=val.foodCost;
                this.addfees.publicCost=val.publicCost;
                this.addfees.trainCost=val.trainCost;
                this.addfees.remark=val.remark;
                this.pageIndex=1
            }else if(text=='新增'){
                this.addfees.id=0;
            }
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pageSize=val;
            this.GatPostNationalTravel();
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.pageIndex=val;
            this.GatPostNationalTravel()
        },
        //currencyselect
        currencychange(val){
            console.log(val)
            this.addfees.currency=val
        },
        //新增,修改api
        PostNationalTravelFeeOperate(){
            var url = "/api/Groups/PostNationalTravelFeeOperate"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data:{
                    portType: 1,
                    id:that.addfees.id,
                    userId:that.loginuserid,
                    provinceId:that.addfees.provinceId,
                    continent:that.addfees.continent,
                    country:that.addfees.country,
                    city:that.addfees.city,
                    currency:that.addfees.currency,
                    roomCost:that.addfees.roomCost,
                    foodCost:that.addfees.foodCost,
                    publicCost:that.addfees.publicCost,
                    trainCost:that.addfees.trainCost,
                    remark:that.addfees.remark,
                }
            }).then(function (res) {
                console.log(res)
                if(res.data.code==200){
                    that.$message({
                        type: 'success',
                        message: res.data.msg
                    });
                    that.AdditionalFees=false
                    that.GatPostNationalTravel();
                }else{
                    that.$message.error(res.data.msg);
                }
                
            }).catch(()=>{})
        },
        //新增-修改
        addsbtn(formName){
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.PostNationalTravelFeeOperate()
                } else {
                    this.$message.error('请将红框内容补全！');
                    return false;
                }
            });
        },
        //删除
        deleteRow(index, rows,inif){
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            center: true
            }).then(() => {
                console.log(inif)
                var url = "/api/Groups/PostNationalTravelFeeDel"
                var that = this
                this.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer ' + this.token
                    },
                    data:{
                        id: inif.id,
                        deleteUserId:that.loginuserid,
                    }
                }).then(function (res) {
                    console.log(res)
                    if(res.data.code==200){
                        rows.splice(index, 1)
                        that.$message({
                            type: 'success',
                            message: res.data.msg
                        });
                        that.GatPostNationalTravel();
                    }
                    
                }).catch(()=>{})
                
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        //搜索数据源
        GetNationalTravelFeePageDataSource(){
            var url = "/api/Groups/GetNationalTravelFeePageDataSource"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                }
            }).then(function (res) {
                console.log(res)
                if(res.data.code==200){
                   that.countrylist=res.data.data
                   that.countrylist.unshift({cityData:[],countryName:'全部'})
                }
                
            }).catch(()=>{})
        },
        //国家change
        countrychange(item){
            this.input2="全部"
            this.citylist='';
            var obj={}
            obj= this.countrylist.find(function(i){
                return i.countryName ===item
            });
            //在change中获取到整条对象数据
            console.log(obj);

            this.citylist=obj.cityData
            this.citylist.unshift('全部')
            this.GatPostNationalTravel();
        },
        //城市change
        citychange(){
            this.GatPostNationalTravel();
        }
    },
    mounted(){
        this.loginuserid=JSON.parse(localStorage.getItem('userinif')).userInfo.userId;
        this.GatPostNationalTravel();
        this.GetEnterExitProvBelongCostDataSource();
        this.GetEnterExitCostDataSource();
        this.GetNationalTravelFeePageDataSource();
    }
}
</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;
}
.remark-box .el-textarea__inner{
    width: 93%;
}
</style>