var clickState = 1;
var quote = {
    add: function (source) {
        if (clickState == 1) {
                clickState = 0;
                var area = $('.area').val();
                var username = $('.username').val();
                var city = $('.city').val();
                var mobile = $('.mobile').val();
                var type = -1;
                var quoteType = $('.quoteType').val();
                if (quoteType != undefined) {
                    type = quoteType;
                }
                var data = {
                    'name': username,
                    'phone': mobile,
                    'area': city,
                    'space': area,
                    'source': source,
                    'type': type
                }
                $.post('/api/cn/obtainoffer/quote', data, function (data) {
                    clickState = 1;
                    if (data.errcode == 0) {
                        alert('提交成功');
                        location.reload();
                    } else {
                        alert(data.errmsg);
                    }
                }, 'json');
        }
        
    },
    check: function (source,hasType) {
        var area = $('.area').val();
        var username = $('.username').val();
        var city = $('.city').val();
        var mobile = $('.mobile').val();
        var url = location.href;
        if (city == null || city == undefined || city == '') {
            alert("请输入城市");
            return false;
        }
        if (area == null || area == undefined || area == '') {
            alert("请输入面积");
            return false;
        } else if (!/^[0-9]+$/.test(area)) {
            alert("请输入数字");
            return false;
        }
        if (hasType == 0) {
            if (username == null || username == undefined || username == '') {
                alert("请输入姓名");
                return false;
            }
        }
        if (mobile == null || mobile == undefined || mobile == '') {
            alert("请输入手机号");
            return false;
        }
        else if (mobile.substring(0, 1) == 1 && !/^1[34578]\d{9}$/.test(mobile)) {
            alert("请输入正确的手机号");
            return false;
        }
        else if (!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(mobile)) {
            alert("请输入正确的手机号");
            return false;
        }
        else {
            var web = parseInt($('#webSource').attr("data-id"));
            if (web === 1) {
                source = "PC-汽车棚-底部";
            }
            else if (web === 2) {
                source = "PC-非机动车棚-底部";
            }
            else if (web === 3) {
                source = "PC-遮阳雨棚-底部";
            }
            else if (web === 4) {
                source = "PC-产品中心-底部";
            }
            else if (web === 5) {
                source = "PC-精品案例-底部";
            }
            else if (web === 6) {
                source = "PC-用户服务-底部";
            }
            else if (web === 7) {
                source = "PC-关于至尊卡尔-底部";
            }
            else if (web === 8) {
                source = "PC-联系至尊卡尔-底部";
            }
            else if (web === 9) {
                source = "PC-报价-输入面积快速报价";
            }
            quote.add(source);
        }
    },
    carShelter(reqData) {
        if (clickState == 1) {
            clickState = 0;
            $.post('/api/cn/obtainoffer/quote', reqData, function (data) {
                clickState = 1;
                if (data.errcode == 0) {
                    $('.mask-box').css("display", "flex");
                    $('html').css("overflow", "hidden");
                    quote.clearCarData();
                    quote.clearNonCarData();
                } else {
                    alert(data.errmsg);
                }
            }, 'json');
        }
    },
    clearCarData() {
        $('.select-box').val('');
        $(".area").val('');
        $(".name").val('');
        $(".mobile").val('');
        $('.select-city').val('');
        $(".areas").val('');
        $(".phone").val('');
        radioVal = 'jy';
    },
    clearNonCarData() {
        $('.select-box').val('');
        $('.area-val').val('');
        $('.name-val').val('');
        $('.phone-val').val('');

        $('.select-message').val('');
        $('.area-message').val('');
        $('.name-message').val('');
        $('.phone-message').val('');
    },
    rainShelter(reqData) {
        if (clickState == 1) {
            clickState = 0;
            $.post('/api/cn/obtainoffer/quote', reqData, function (data) {
                clickState = 1;
                if (data.errcode == 0) {
                    var displayCss = $('.mask-box').css("display");
                    if (displayCss == 'flex') {
                        $('.mask-box').css("display", "none");
                        $('html').css("overflow", "auto");
                    } else {
                        $('.mask-box').css("display", "flex");
                        $('html').css("overflow", "hidden");

                    }
                    quote.clearNonCarData();
                } else {
                    alert(data.errmsg);
                }
            }, 'json');
        }
    },
    quote(reqData) {
        if (clickState == 1) {
            clickState = 0;
            $.post('/api/cn/obtainoffer/quote', reqData, function (data) {
                clickState = 1;
                if (data.errcode == 0) {

                    var displayCss = $('.mask-box').css("display");
                    if (displayCss == 'flex') {
                        $('.mask-box').css("display", "none");
                        $('html').css("overflow", "auto");
                    } else {
                        $('.mask-box').css("display", "flex");
                        $('html').css("overflow", "hidden");

                    }
                    $('.form-select-box').val("");
                    $('.form-area-val').val("");
                    $('.form-name-val').val("");
                    $('.form-phone-val').val("");
                } else {
                    alert(data.errmsg);
                }
            }, 'json');
        }
    },
}