<template>
    <div class="VisaFeeStandard-all">
        <div class="VisaFeeStandard-title">
            签证费用标准录入
        </div>
        <div class="VisaFeeStandard-General">
            <el-form ref="form" :rules="rules" :model="form" class="VisaFeeStandard-el-form" label-width="120px">
                <div class="clflex">
                    <el-form-item label="洲名" prop="continent">
                        <el-input v-model="form.continent"></el-input>
                    </el-form-item>
                    <el-form-item label="国家名" prop="country">
                        <el-input v-model="form.country"></el-input>
                    </el-form-item>
                    <el-form-item label="签证费用类型" prop="feeType">
                        <el-select @change="feeTypechange" v-model="form.feeType" placeholder="请选择签证费用类型">
                            <el-option v-for="(item,index) in visaFeeTypearr" :key="index" :label="item.label"
                                :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                </div>
                <div v-for="(item,index) in visaFeessb" :key="index">
                    <div class="region-box clflex">
                        <el-divider content-position="left">{{ item.provinceName }}</el-divider>
                        <el-form-item label="送签地址">
                            <el-input v-model="item.visaAddress"></el-input>
                        </el-form-item>
                        <el-form-item label="是否落地签">
                            <el-radio-group v-model="item.isVisaOnArrival">
                                <el-radio :label="false">否</el-radio>
                                <el-radio :label="true">是</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="是否电子签">
                            <el-radio-group v-model="item.isElectronicSign">
                                <el-radio :label="false">否</el-radio>
                                <el-radio :label="true">是</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="签证时间(工作日)">
                            <el-input v-model="item.visaTime"></el-input>
                        </el-form-item>
                        <el-form-item label="是否免签(大公务)">
                            <el-radio-group v-model="item.isVisaExemptionLarge">
                                <el-radio :label="false">否</el-radio>
                                <el-radio :label="true">是</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="签证费用(大公务)">
                            <el-input-number style="width: 100%" :precision="2" :controls="false"
                                v-model="item.largeVisaPrice"></el-input-number>
                        </el-form-item>
                        <el-form-item label="代办费(大公务)">
                            <el-input-number style="width: 100%" :precision="2" :controls="false"
                                v-model="item.largeAgencyFee"></el-input-number>
                        </el-form-item>
                        <el-form-item label="是否免签(小公务)">
                            <el-radio-group v-model="item.isVisaExemptionSmall">
                                <el-radio :label="false">否</el-radio>
                                <el-radio :label="true">是</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="签证费用(小公务)">
                            <el-input-number style="width: 100%" :precision="2" :controls="false"
                                v-model="item.smallVisaPrice"></el-input-number>
                        </el-form-item>
                        <el-form-item label="代办费(小公务)">
                            <el-input-number style="width: 100%" :precision="2" :controls="false"
                                v-model="item.smallAgencyFee"></el-input-number>
                        </el-form-item>
                        <el-form-item label="外办费用(普通)">
                            <el-input-number style="width: 100%" :precision="2" :controls="false"
                                v-model="item.normExtFee"></el-input-number>
                        </el-form-item>
                        <el-form-item label="外办费用(加急)">
                            <el-input-number style="width: 100%" :precision="2" :controls="false"
                                v-model="item.urgExtFee"></el-input-number>
                        </el-form-item>
                        <el-form-item label="签证是否加急">
                            <el-radio-group v-model="item.isUrgent">
                                <el-radio :label="false">否</el-radio>
                                <el-radio :label="true">是</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="加急时间">
                            <el-input v-model.number="item.urgentTime"></el-input>
                        </el-form-item>
                        <el-form-item label="加急费用">
                            <el-input-number style="width: 100%" :precision="2" :controls="false"
                                v-model="item.urgentPrice"></el-input-number>
                        </el-form-item>
                        <el-form-item label="加急费用描述">
                            <el-input v-model.number="item.urgentPriceDesc"></el-input>
                        </el-form-item>
                        <el-form-item style="width: 65.5%;" label="备注">
                            <el-input v-model.number="item.remark"></el-input>
                        </el-form-item>
                    </div>
                </div>
                <div style="width: 100%;text-align: right;">
                    <el-button type="primary" @click="submitForm('form')">立即创建</el-button>
                    <el-button @click="gohome">取消</el-button>
                </div>
            </el-form>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            form: {
                id:0,
                continent: '',
                country: '',
                feeType: '',
            },
            visaFeessb:[],
            visaFees:[
                {
                    id:0,
                    parentId:0,//签证费用表Id
                    provinceId:122,//签证费用归属省份Id
                    provinceName:'四川',//省份名称
                    visaAddress:'',//送签地址
                    isVisaOnArrival:false,//是否落地签
                    isElectronicSign:false,//是否电子签
                    visaTime:'',//签证时间(工作日)
                    isVisaExemptionLarge:false,//是否免签(大公务)
                    largeVisaPrice:0,//签证费用(大公务)
                    largeAgencyFee:0,//代办费(大公务)
                    isVisaExemptionSmall:false,//是否免签(小公务)
                    smallVisaPrice:0,//签证费用(小公务)
                    smallAgencyFee:0,//代办费(小公务)
                    normExtFee:0,//外办费用(普通)
                    urgExtFee:0,//外办费用(加急)
                    isUrgent:false,//签证是否加急
                    urgentTime:'',//加急时间(工作日)
                    urgentPrice:0,//加急费用
                    urgentPriceDesc:'',//加急费用描述
                    remark:'',//备注
                },
                {
                    id:0,
                    parentId:0,//签证费用表Id
                    provinceId:103,//签证费用归属省份Id
                    provinceName:'重庆',//省份名称
                    visaAddress:'',//送签地址
                    isVisaOnArrival:false,//是否落地签
                    isElectronicSign:false,//是否电子签
                    visaTime:'',//签证时间(工作日)
                    isVisaExemptionLarge:false,//是否免签(大公务)
                    largeVisaPrice:0,//签证费用(大公务)
                    largeAgencyFee:0,//代办费(大公务)
                    isVisaExemptionSmall:false,//是否免签(小公务)
                    smallVisaPrice:0,//签证费用(小公务)
                    smallAgencyFee:0,//代办费(小公务)
                    normExtFee:0,//外办费用(普通)
                    urgExtFee:0,//外办费用(加急)
                    isUrgent:false,//签证是否加急
                    urgentTime:'',//加急时间(工作日)
                    urgentPrice:0,//加急费用
                    urgentPriceDesc:'',//加急费用描述
                    remark:'',//备注
                },
                {
                    id:0,
                    parentId:0,//签证费用表Id
                    provinceId:108,//签证费用归属省份Id
                    provinceName:'贵州',//省份名称
                    visaAddress:'',//送签地址
                    isVisaOnArrival:false,//是否落地签
                    isElectronicSign:false,//是否电子签
                    visaTime:'',//签证时间(工作日)
                    isVisaExemptionLarge:false,//是否免签(大公务)
                    largeVisaPrice:0,//签证费用(大公务)
                    largeAgencyFee:0,//代办费(大公务)
                    isVisaExemptionSmall:false,//是否免签(小公务)
                    smallVisaPrice:0,//签证费用(小公务)
                    smallAgencyFee:0,//代办费(小公务)
                    normExtFee:0,//外办费用(普通)
                    urgExtFee:0,//外办费用(加急)
                    isUrgent:false,//签证是否加急
                    urgentTime:'',//加急时间(工作日)
                    urgentPrice:0,//加急费用
                    urgentPriceDesc:'',//加急费用描述
                    remark:'',//备注
                },
                {
                    id:0,
                    parentId:0,//签证费用表Id
                    provinceId:132,//签证费用归属省份Id
                    provinceName:'云南',//省份名称
                    visaAddress:'',//送签地址
                    isVisaOnArrival:false,//是否落地签
                    isElectronicSign:false,//是否电子签
                    visaTime:'',//签证时间(工作日)
                    isVisaExemptionLarge:false,//是否免签(大公务)
                    largeVisaPrice:0,//签证费用(大公务)
                    largeAgencyFee:0,//代办费(大公务)
                    isVisaExemptionSmall:false,//是否免签(小公务)
                    smallVisaPrice:0,//签证费用(小公务)
                    smallAgencyFee:0,//代办费(小公务)
                    normExtFee:0,//外办费用(普通)
                    urgExtFee:0,//外办费用(加急)
                    isUrgent:false,//签证是否加急
                    urgentTime:'',//加急时间(工作日)
                    urgentPrice:0,//加急费用
                    urgentPriceDesc:'',//加急费用描述
                    remark:'',//备注
                }
            ],
            visaFeeTypearr:[{
                label: '因公',
                value: 0
            }, {
                label: '因私',
                value: 1
            }],
            editid: 0, // 编辑的ID
            token: '', // 用户令牌
            userid: '', // 用户ID
            rules: {
                continent: [
                    { required: true, message: '请填写洲名', trigger: 'blur' }
                ],
                country: [
                    { required: true, message: '请填写国家名', trigger: 'blur' }
                ],
                feeType: [
                    { required: true, message: '请选择签证费用类型', trigger: 'change' }
                ]
            },
            Identification:true,
        }
    },
    methods: {
        //保存api
        VisaFeeStandardSave() {
            var that = this
            var url = "/api/Resource/VisaFeeStandardSave"
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + that.token
                },
                data: {
                    id:that.form.id,
                    continent: that.form.continent,
                    country: that.form.country,
                    feeType: that.form.feeType,
                    visaFees: that.visaFeessb,
                    currUserId:that.userid,
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.$message({
                        message: res.data.msg,
                        type: 'success',
                    });
                    that.gohome();
                } else {
                    that.$message.error(res.data.msg);
                }
            })
        },
        gohome() {
            // 返回上一页
            this.$router.go(-1);
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.VisaFeeStandardSave();
                } else {
                    this.$message.error('请检查是否填写完整！');
                    return false;
                }
            });
        },
        feeTypechange(){
            console.log(this.form.feeType);
            
            if(this.form.feeType != 0){
                this.visaFeessb=[{
                    id:0,
                    parentId:0,//签证费用表Id
                    provinceId:122,//签证费用归属省份Id
                    provinceName:'四川',//省份名称
                    visaAddress:'',//送签地址
                    isVisaOnArrival:false,//是否落地签
                    isElectronicSign:false,//是否电子签
                    visaTime:'',//签证时间(工作日)
                    isVisaExemptionLarge:false,//是否免签(大公务)
                    largeVisaPrice:0,//签证费用(大公务)
                    largeAgencyFee:0,//代办费(大公务)
                    isVisaExemptionSmall:false,//是否免签(小公务)
                    smallVisaPrice:0,//签证费用(小公务)
                    smallAgencyFee:0,//代办费(小公务)
                    normExtFee:0,//外办费用(普通)
                    urgExtFee:0,//外办费用(加急)
                    isUrgent:false,//签证是否加急
                    urgentTime:'',//加急时间(工作日)
                    urgentPrice:0,//加急费用
                    urgentPriceDesc:'',//加急费用描述
                    remark:'',//备注
                }]
                
            }else{
                this.visaFeessb=this.visaFees;
            }
        },
        //获取签证标准info
        VisaFeeStandardInfo() {
            var that = this
            var url = "/api/Resource/VisaFeeStandardInfo"
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + that.token
                },
                data: {
                    portType:1,
                    id: that.editid,
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.form.continent = res.data.data.continent;
                    that.form.country = res.data.data.country;
                    that.form.feeType = res.data.data.feeType;
                    that.form.id = res.data.data.id;
                    // that.feeTypechange();
                    that.visaFeessb = res.data.data.visaFees;
                } else {
                    that.$message.error(res.data.msg);
                }
            })
        },
    },
    mounted() {
        // 这里可以进行一些初始化操作，比如获取数据等
        // this.fetchData();
        this.editid = this.$route.query.id;
        console.log( this.editid);
        if (this.editid==undefined) {
            this.feeTypechange();
        }else{
            this.VisaFeeStandardInfo();
        }
        this.token = JSON.parse(localStorage.getItem('userinif')).token;
        this.userid = JSON.parse(localStorage.getItem('userinif')).userInfo.userId;
    },
}
</script>
<style>
.VisaFeeStandard-all{
    background-color: #fff;
    padding: 10px;
    box-shadow: 0 0 5px #0005;
    border-radius: 10px;
    min-height: 830px;
    
}
.VisaFeeStandard-General .el-form-item{
    width: 31%;
}
.VisaFeeStandard-el-form .clflex{
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
}
.VisaFeeStandard-el-form .el-input__inner,.el-select {
    width: 100%;
}
.VisaFeeStandard-el-form .el-select {
    width: 100%;
}
.VisaFeeStandard-title{
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 10px;
}
</style>