<template>
    <div class="box" ref="box">
        <div class="header">
            <img src="../../assets/image/calcBack@2x.png" style="width:100%" alt="">
            <i class="el-icon-arrow-left" @click="$router.replace('/index')"></i>
        </div>
        <div class="content">
            <div class="detail-wrap small">
                <div class="form-group row">
                    <label class="col-3 col-form-label bigname">参保城市</label>
                    <div  class="col-9 city city-boxs">
                        <select class="city-sheng" name="" id="sheng"  v-model='data.code' @change="chooseShi()">
                            <option style="color:#8e8e8e" v-for="item in data.sheng" :value="item.code"> {{item.name}} </option>
                        </select>
                        <br>
                        <select class="city-shi" name="social_city" id=""  v-model='data.codes' @change="chooseSocial()">
                            <option v-for="items in data.shi" :value="items.code" > {{items.name}} </option>
                        </select>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-3 col-form-label bigname">社保户别</label>
                    <div class="col-9 city">
                        <el-radio v-for="item in data.sociallist" v-model="data.social_type" :label="item.id">{{item.name}}</el-radio>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-3 col-form-label bigname">社保缴纳</label>
                    <div class="col-9">
                        <input type="number" placeholder="3613-27786" class="form-control"
                            v-model.number="data.social_value"
                            :min="data.social_basic.pension[0]"
                            :max="data.social_basic.pension[1]"
                            required>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-3 col-form-label bigname">公积金缴纳</label>
                    <div class="col-9">
                        <el-switch v-model="data.is_fund" active-color="#4FDCA2" />
                    </div>
                </div>
                <div id="fund" class="form-group row">
                    <label class="col-3 col-form-label bigname">公积金缴纳</label>
                    <div class="col-9" v-if="data.is_fund">
                        <input type="number" placeholder="3613-27786" class="form-control"
                            v-model.number="data.fund_value"
                            :min="data.social_basic.fund[0]"
                            :max="data.social_basic.fund[1]"
                            required>
                    </div>
                </div>
                <div class="form-group calculationBox">
                    <img @click="calcBill" src="../../assets/image/calculationBtn@2x.png" alt="" class="calculationBtn">
                </div>
            </div>
            <div class="detail-wrap">
                <div class="calcDetailTop">
                    <img src="../../assets/image/calcDetailTop@2x.png" alt="">
                    <img src="../../assets/image/calcDetailTop@2x.png" alt="">
                </div>
                <img src="../../assets/image/calcDetailTitle@2x.png" alt="" class="calcDetailTitle">
                <div class="form-group row">
                    <div class="col-12">
                        <ul class="list-group list-group-flush">
                            <li class="list-group-item d-flex justify-content-between align-items-center"
                                v-if="data.social_calc" v-for="value in data.social_calc">
                                {{value[1]}}
                                <span class="badge badge-pill">&yen;{{value[0]}}</span>
                            </li>
                        </ul>
                        <div class="mt-2 d-flex justify-content-between align-items-center"
                            v-if="data.subtotal_calc">
                            <label class="col-form-label">社保小计</label>
                            <span class="badge">&yen;{{data.subtotal_calc}}</span>
                        </div>
                        <div class="mt-2 d-flex justify-content-between align-items-center"
                            v-if="data.is_fund&&data.fund_calc">
                            <label class="col-form-label">公积金</label>
                            <span class="badge">&yen;{{data.fund_calc}}</span>
                        </div>
                        <!-- 额外费用 -->
                        <template v-if="data.append_cost.length">
                            <div
                                class="mt-2 d-flex justify-content-between align-items-center"
                                v-for="(item, idx) in data.append_cost" :key="idx">
                                <label class="col-form-label">{{item.name}}</label>
                                <span class="badge">&yen;{{item.cost}}</span>
                            </div>
                        </template>
                        <div class="mt-2 d-flex justify-content-between align-items-center"
                            v-if="data.is_fund&&data.fund_calc">
                            <label class="col-form-label">总计</label>
                            <span class="badge" style="color:red">&yen;{{data.total_calc}}</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- <div class="detail-wrap small" style="margin-bottom: 5rem">
        <div class="form-group row">
            <label class="col-3 col-form-label bigname">参保城市</label>
            <div  class="col-9 city city-boxs">
                <select class="city-sheng" name="" id="sheng"  v-model='data.code' @change="chooseShi()">
                    <option style="color:#8e8e8e" v-for="item in data.sheng" :value="item.code"> {{item.name}} </option>
                </select>
                <br>
                <select class="city-shi" name="social_city" id=""  v-model='data.codes' @change="chooseSocial()">
                    <option v-for="items in data.shi" :value="items.code" > {{items.name}} </option>
                </select>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-3 col-form-label bigname">社保户别</label>
            <div class="col-9 city">
                <el-radio v-for="item in data.sociallist" v-model="data.social_type" :label="item.id">{{item.name}}</el-radio>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-3 col-form-label bigname">社保缴纳</label>
            <div class="col-9">
                <input type="number" placeholder="3613-27786" class="form-control" v-model="data.social_value"
                       :min="data.social_basic.pension[0]"
                       :max="data.social_basic.pension[1]" required>
            </div>
        </div>
        <el-switch v-model="data.is_fund" active-text="公积金缴纳" text-color="#13ce66" active-color="#13ce66">
        </el-switch>
        <div id="fund" class="form-group row">
            <label class="col-3 col-form-label bigname">公积金缴纳</label>
            <div class="col-9" v-if="data.is_fund">
                <input type="number" placeholder="2500-27786" class="form-control" v-model="data.fund_value"
                       :min="data.social_basic.fund[0]"
                       :max="data.social_basic.fund[1]"
                       required>
            </div>
        </div> -->
        <!-- <div class="form-group row">
            <label class="col-3 col-form-label bigname">缴费明细</label>
            <div class="col-9">
                <ul class="list-group list-group-flush">
                    <li class="list-group-item d-flex justify-content-between align-items-center"
                        v-if="data.social_calc" v-for="value in data.social_calc">
                        {{value[1]}}
                        <span class="badge badge-pill">&yen;{{value[0]}}</span>
                    </li>
                </ul>
                <div class="mt-2 d-flex justify-content-between align-items-center"
                     v-if="data.subtotal_calc">
                    <label class="col-form-label">社保小计</label>
                    <span class="badge">&yen;{{data.subtotal_calc}}</span>
                </div>
                <div class="mt-2 d-flex justify-content-between align-items-center"
                     v-if="data.is_fund&&data.fund_calc">
                    <label class="col-form-label">公积金</label>
                    <span class="badge">&yen;{{data.fund_calc}}</span>
                </div> -->
                <!-- 额外费用 -->
                <!-- <template v-if="data.append_cost.length">
                    <div
                        class="mt-2 d-flex justify-content-between align-items-center"
                        v-for="(item, idx) in data.append_cost" :key="idx">
                        <label class="col-form-label">{{item.name}}</label>
                        <span class="badge">&yen;{{item.cost}}</span>
                    </div>
                </template>
                <div class="mt-2 d-flex justify-content-between align-items-center"
                     v-if="data.is_fund&&data.fund_calc">
                    <label class="col-form-label">总计</label>
                    <span class="badge">&yen;{{data.total_calc}}</span>
                </div>
            </div>
        </div> -->
        <!-- <div class="form-group">
            <a href="javascript:void(0)" class="btn btn-success btn-block"
               v-on:click="calcBill">开始计算</a>
        </div>
    </div> -->
</template>

<script lang="ts">
    import {Component, Vue, Watch} from "vue-property-decorator";
    import Http from "../../extend/Http";
    import router from "../../router";
    import Utils from "../../extend/Utils";
    import {Message} from "element-ui";
    @Component({

    })
    export default class OrderList extends Vue {
        public data: any = {
            is_fund: true,
            is_discounts: false,
            social_calc: null,
            sum_calc:0,
            service_calc: 0,
            fund_calc: 0,
            subtotal_calc: 0,
            total_calc: 0,
            social_basic: {pension: 3400, fund: 3400},
            social_type: 1,
            social_value: 3613,
            fund_value: 3613,
            sheng: '',
            shi:'',
            code:'11',
            codes:'1101',
            sociallist:[{id: 1, name: "本地城镇"}, {id: 2, name: "本地农村"}, {id: 3, name: "外埠城镇"}, {id: 4, name: "外埠农村"}],
            // 附加费用 残保金
            append_cost: []
        };
        async created() {
            this.data.citycode = localStorage.getItem('citycode')
            let res = await Http.getInstance().getProvinceList();
            this.data.sheng = res.data.prolist
            this.data.shi = res.data.citylist

            this.socialLimit()
        }
        async chooseShi(){
            let res = await Http.getInstance().getCityList({
                code: this.data.code
            });
            if(res.data){
                this.data.shi = res.data
            }
        }
        async chooseSocial(){
            let res = await Http.getInstance().getSociallist({
                code: this.data.codes
            });
            if(res.data){
                this.data.sociallist = res.data
            }
        }
        async socialLimit(event?: any) {
            if (this.data.social_type != null) {
                let res = await Http.getInstance().socialLimit({
                    socialType: this.data.social_type,
                    code: this.data.codes
                });
                console.log('社保公积金缴纳', res);
                if(res.data){
                    this.data.social_basic = res.data;
                }
            }
        }

        async calcBill(event?: any) {
            if (this.data.social_value < 3613 || this.data.social_value > 27786) {
                Message({
                    message: '社保缴纳的范围必须在3613-27786之间', duration: 2000, type: "error"
                });
                return
            }
            if (this.data.fund_value < 3613 || this.data.fund_value > 27786) {
                Message({
                    message: '公积金缴纳的范围必须在3613-27786之间', duration: 2000, type: "error"
                });
                return
            }
            let res = await Http.getInstance().calcBilll({
                'bill_type': 'calc',
                'social_type': this.data.social_type,
                'social_basic': this.data.social_value,
                'fund_basic': this.data.fund_value,
                'code' : this.data.codes
            });
            console.log('开始计算', res);
            this.data.social_calc = res.data.social;
            this.data.service_calc = res.data.service;
            this.data.fund_calc = res.data.fund;
            this.data.subtotal_calc = res.data.subtotal;
            this.data.total_calc = res.data.total;
            this.data.is_discounts = res.data.discounts;
            this.data.append_cost = res.data.append_cost;
            // 滚动到最底部
            this.$nextTick(() => {
                let box= this.$refs["box"];
                (box as any).scrollTop = (box as any).scrollHeight;
            })
        }

        // 监听器 社保缴纳和公积金缴纳范围 3613-27786
        // @Watch('data.social_value') changeSocialValue(newVal: any) {
        //     if (newVal < 3613 || newVal > 27786) {
        //         Message({
        //             message: '社保缴纳的范围必须在3613-27786之间', type: "error"
        //         });
        //     }
        // }

    }
</script>

<style lang="scss" scoped>
    .box {
        position: absolute;
        width: 100%;
        height: 100%;
        background-color: #F6F6F6;
        overflow: auto;
    }
    // 背景图
    .header {
        position: relative;
        i {
           position: absolute;
           top: 1.667rem;
           left: 1.66rem; 
           color: #fff;
           font-size: 1.667rem;
        }
    }
    // 内容
    .content {
        padding: 2rem;
        position: relative;
        top: -6.8rem;
    }
    .detail-wrap {
        width: 100%;
        padding: 2rem;
        background-color:#fff;
        border-radius: 2.5rem;
    }
    .detail-wrap:last-child {
        margin-top: 3.167rem;
        padding-top: 0;
        position: relative;
    }
    .box /deep/.el-radio {
        line-height: 2;
    }
    .box /deep/.el-radio__input.is-checked .el-radio__inner{
        // border-color: #28a745;
        // background: #28a745;
        background: #2CB37B;
        border-color: #2CB37B;
    }
    .box /deep/.el-radio__inner::after {
        width: 6px;
        height: 6px;
    }
    .box /deep/.el-radio__input.is-checked+.el-radio__label{
        // color: #28a745 ;
        color: #333333 ;
    }
    .box /deep/.el-radio:nth-child(2n) {
        margin-right: 0;
    }
    .el-switch__label.is-active {
        // color: #28a745;
        color: #4FDCA2;
    }
    hr {
        margin: 0.5rem 0;
    }
    .badge-pill{
        font-size: 1.25rem;
    }
    .badge{
        font-size: 1.25rem;
    }
    .form-group{
        margin-top: 1rem;
    }
    .form-group:last-child {
        margin-top: 1.3rem;
    }
    .col-3{
        padding-right: 0;
    }
     .col-9{
         font-size: 1.25rem;
     }
     .city{
         margin-top: 0.3rem;
     }
     .bigname{
         width: 10rem;
     }
    .col-form-label{
        font-size: 1.25rem;
    }
    .list-group-flush {
        /*border-bottom: 1px solid rgba(0, 0, 0, .125);*/
    }

    .list-group-flush .list-group-item {
        border-top: 0;
        background: transparent;
        border-color: #e5e5e5;
    }

    .list-group-flush .list-group-item:not(:last-child) {
        border-bottom: 0;
        // border-bottom: 1px solid #ccc;
        // transform: scaleY(0.5);
    }

    .subtotal {
        padding: .75rem 1.25rem;
        padding-left: 2.5rem;
    }
  .form-control{
      margin-bottom: 1rem;
      color:#b8b8b8;
      width: 15rem;
  }
    // 开始计算按钮背景
    // .btn-success {
    //     // background-color: #D3D3D3;
    //     // border-color: #D3D3D3;
    //     background-color: #4FDBA1;
    //     border-color: #4FDBA1;
    // }
    // .btn-success:hover {
    //     background-color: #4FDBA1;
    //     border-color: #4FDBA1;
    // }
    // 图片
    .calculationBox {
        text-align: center;
    }
    .calculationBtn {
        width: 80%;
    }

    .btn-block{
        font-size: 1.25rem;
        line-height: 2.5rem;
    }
    .city-boxs{
        display: flex;
    }
    .city-sheng{
        width: 10rem;
        height: 2.5rem;
        font-size: 14px;
        background: white;
        border-radius: 3px;
        border-color: #d2d2d2;
        color: #666666;
    }
    .city-shi{
        width: 10rem;
        height: 2.5rem;
        font-size: 14px;
        background: white;
        border-radius: 3px;
        border-color: #d2d2d2;
        color: #666666;
        margin-left: 1rem;
    }

    // 缴费明细
    .mt-2 {
        padding: 0 1rem;
    }
    .calcDetailTop {
        width: 100%;
        height: 4.083rem;
        position: relative;
        top: -1.333rem;
        left: 0;
        padding: 0 3rem;
        display: flex;
        justify-content: space-between;
        img {
            width: 2.333rem;  
        }
    }
    .calcDetailTitle {
        display: block;
        margin: 0 auto;
        width: 40%;
    }
</style>

