<!-- 企业信息管理-企业查询(新增) -->
<style>
    .base-extend .col-xs-10{
        padding:0 0.1rem;
    }
    .base-extend .form-horizontal .required:after{
        top:0.05rem;
    }
</style>

<div class="modal fade businessDialog" id="myModal-addEnterPriseBusinessEntry" data-backdrop="static">
    <div class="modal-dialog" style="width:8rem;">
        <form class="form-horizontal" id="addEnterPriseBusinessEntryForm">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true" style="font-size:0.18rem">×</span><span class="sr-only">关闭</span>
                </button>
                <span class="modal-title">企业查询</span>
            </div>
            <div class="modal-content" style="height:3.5rem;overflow-y:auto;overflow-x:hidden;">
                <div class="newTabAddUpdateBox" style="position:static;border:none;padding-left:0.2rem;padding-right:0.2rem;padding-bottom:0;">
                    <span tag:token/>
                    <div class="row">
                        <table>
                            <tr>
                                <td width="20%">
                                    <span class="">输入关键字</span>：
                                </td>
                                <td width="70%" class="enter">
                                    <input type="text" name="keyWord" maxlength="30" placeholder="请输入关键字" id="keyWord" class="form-control">
                                    <div class="wholeKeyWordResult" style="left:0;right:0;"></div>
                                </td>
                                <td width="10%" style="padding-top:0;padding-bottom:0;">
                                    <div id="searchWholename" class="btn btn-default btn-white btn-info colorbtn" style="height:0.31rem;line-height:0.31rem;margin:0;">查询</div>
                                </td>
                            </tr>
                            <tr>
                                <td width="20%">
                                    <span class="required_fileds_star">企业全称</span>：
                                </td>
                                <td colspan="2" class="enter" style="background-color:#F1F1F1">
                                    <input type="text" name="wholeKeyWord" id="wholeKeyWord" readOnly class="form-control" style="background-color:#F1F1F1 !important;color:#808080;margin:0 !important;">
                                    <input type="hidden" name="socialCreditCode" id="socialCreditCode" readOnly class="form-control">
                                </td>
                            </tr>
                            <tr>
                                <td width="20%">
                                    <span >综合贸易平台账号</span>：
                                </td>
                                <td colspan="2" class="enter">
                                    <input type="text" name="tradeAccount" maxlength="50" placeholder="请输入账号名,例如:gysdenglu" id="tradeAccount" class="form-control">
                                </td>
                            </tr>
                            <input type="hidden" name="phoneNumber">
                            <input type="hidden" name="address">
                        </table>
                        <p style="font-size: 12px; margin-top: 5px; color: #333;">特别说明:初始登录密码为a123456,登录后请及时修改密码</p>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary btn-default btn-white btn-info colorbtn addSure">确定</button>
                <button class="btn btn-default btn-default btn-white btn-info canclebtn" data-dismiss="modal">取消</button>
            </div>
        </form>
    </div>
</div>
<script>

    $(function(){
        $('.addSure,#searchWholename').removeClass("loadingCircle");


        //输入关键字查询企业
        $("#searchWholename").click(function(){
            if( $('#keyWord').val().split(' ').join('')=='' ){
                new $.zui.Messager('请输入关键字', {
                    type: 'danger'
                }).show();
                return;
            };
            $('#searchWholename').addClass("loadingCircle");
            $.ajax({
                url:'/customer/doFindEnterpriseBySop',
                type:'get',
                data:{
                    'condition':$('#keyWord').val().split(' ').join('')
                },
                success:function(data){
                    $(".wholeKeyWordResult").empty().removeClass("show").hide();
                    var wholeKeyWordResult = '';
                    if( data.data.length > 0 ){
                        for( var i=0;i<data.data.length;i++ ){
                            wholeKeyWordResult += '<p code="'+data.data[i].socialCreditCode+'" phoneNumber="'+data.data[i].phoneNumber+'" address="'+data.data[i].address+'">'+data.data[i].enterpriseName+'</p>'
                        };
                        i = null;
                    }else{
                        wholeKeyWordResult = '<div style="padding:0.1rem 0;text-align:center">无查询结果</div>'
                    };
                    $(".wholeKeyWordResult").append(wholeKeyWordResult).show().addClass("show");
                    $('#searchWholename').removeClass("loadingCircle");
                },
                error:function(status){
                    $(".wholeKeyWordResult").empty().removeClass("show").hide();
                    new $.zui.Messager('查询企业完整名称时出错:'+status, {
                        type: 'danger'
                    }).show();
                    $('#searchWholename').removeClass("loadingCircle");
                }
            });
            return false;
        });

        //选择企业全称
        $(".wholeKeyWordResult").on('click','p',function(){
            $(".wholeKeyWordResult").removeClass('show').empty().hide();
            $('#wholeKeyWord').val($(this).text());
            $('#socialCreditCode').val($(this).attr('code'));
            $('[name=phoneNumber]').val($(this).attr('phoneNumber'));
            $('[name=address]').val($(this).attr('address'));
            $("#wholeKeyWord").removeClass('error');
            $("#wholeKeyWord-error").hide();
        });
        $("body").on("click",function(){
            $(".wholeKeyWordResult").removeClass('show').empty().hide();
        })

        //表单验证
        function entBusinessEntryFormValid(e){
            $("#addEnterPriseBusinessEntryForm").validate({
                promptPosition : "bottomLeft",
                submitHandler : function(form) {
                    var postdata = {
                        'enterpriseName': $("#wholeKeyWord").val(),
                        'socialCreditCode' : $('#socialCreditCode').val(),
                        'phoneNumber' : $('[name=phoneNumber]').val(),
                        'address' : $('[name=address]').val(),
                        'supplier': 1,
                        'account' : $("#tradeAccount").val()
                    },formchoose = '#myModal-addEnterPriseBusinessEntry';

                    $('.addSure').addClass("loadingCircle");

                    $.ajax({
                        url:'/customer/add',
                        type:'post',
                        data:postdata,
                        success:function(data){
                            if( data.success ){
                                new $.zui.Messager('添加供应商成功', {
                                    type: 'success'
                                }).show();
                                $('.addSure').removeClass("loadingCircle");
                                //关闭弹框
                                $(formchoose).modal("hide");
                                //弹框被隐藏, 且过渡效果执行完毕
                                $(formchoose).off('hidden.zui.modal').on('hidden.zui.modal', function(){
                                    //刷新表格
                                    $(".yk_rightcontent").load('/customer/listPage');
                                });
                            }else{
                                new $.zui.Messager('添加供应商失败:'+ data.msg, {
                                    type: 'danger'
                                }).show();
                                $('.addSure').removeClass("loadingCircle");
                                //关闭弹框
                                //$(formchoose).modal("hide");
                            }
                        },
                        error:function(status){
                            new $.zui.Messager('添加供应商时出错:'+status, {
                                type: 'danger'
                            }).show();
                            $('.addSure').removeClass("loadingCircle");
                            //关闭弹框
                            //$(formchoose).modal("hide");
                        }
                    })
                },
                rules : {
                    'wholeKeyWord':{
                        required : true
                    },
                    // 'tradeAccount':{
                    //     required : true
                    // }
                },
                messages : {
                    'wholeKeyWord':{
                        required:'请输入关键字查询选择企业全称'
                    },
                    'tradeAccount':{
                        required : '请输入贸易综合平台账号'
                    }
                }
            })
        };
        entBusinessEntryFormValid();

        //确定保存按钮
        $(".addSure").click(entBusinessEntryFormValid);
    })

</script>
