{{template "inc"}}
<!-- Main Header -->
{{template "header"}}
<!-- Left side column. 权限菜单 -->
{{template "memu"}}
<style>
    #dataTable_filter div {
        padding: 0px 10px;
    }

    .operate a {
        padding: 5px 10px;
    }
    #infos{
        height: 666px;
        overflow-y: scroll;
    }
</style>
<div class="content-wrapper">
    <section class="content-header" style="padding: 49px 15px 0 15px;">
        <h1>
            <small><a class="btn btn-primary opraaa" opraaa="newqyk" onclick='AddQYKHTML()'>新增企业库信息</a></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 企业库增删改查</a></li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-body">
                        <table id="dataTable" class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>企业名称</th>
                                {{/*<th>别名</th>*/}}
                                <th>省份</th>
                                <th>统一信用代码</th>
                                <th>企业类型</th>
                                <th>注册资本</th>
                                {{/*<th>企业地址</th>*/}}
                                <th>操作</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
        </div>
    </section>

</div>
<div class="modal fade" id="info_data">
    <div class="modal-dialog">
        <form id="update-dataform" class="form-horizontal" role="form">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="info_title"></h4>
                </div>
                <div class="modal-body" id="infos">
                </div>
            </div>
            <!-- /.modal-content -->
        </form>
    </div>
    <!-- /.modal-dialog -->
</div>
{{template "dialog"}}
{{template "footer"}}
<script>
    menuActive("qiyeku_info")
    var ttable = {};
    var editor_add = null;
    var editor_update = null;
    $(function () {
        ttable = $('#dataTable').DataTable({
            "paging": true,
            "lengthChange": false,
            "searching": true,
            "ordering": false,
            "info": true,
            "autoWidth": false,
            "serverSide": true,
            "ajax": {
                "url": "/admin/audit/query_qyk/list",
                "type": "post",
            },
            "language": {
                "url": "/res/dist/js/dataTables.chinese.lang"
            },
            "columns": [
                {
                    "data": "company_name", "width": "18%", render: function (val, a, row) {
                        if (val == null) {
                            return ""
                        }
                        return "<text  title=" + val + ">" + val + "</text >"
                    }
                },
                /*{
                    "data": "alias", "width": "5%", render: function (val, a, row) {
                        if (val == null) {
                            return ""
                        }
                        return val
                    }
                },*/
                {
                    "data": "province", "width": "4%", render: function (val, a, row) {
                        if (val == null) {
                            return ""
                        }
                        return "<text  title=" + val + ">" + val + "</text >"
                    }
                },
                {
                    "data": "credit_no", "width": "10%", render: function (val, a, row) {
                        if (val == null) {
                            return ""
                        }
                        return "<text  title=" + val + ">" + val + "</text >"
                    }
                },
                {
                    "data": "company_type", "width": "8%", render: function (val, a, row) {
                        if (val == null) {
                            return ""
                        }
                        return "<text  title=" + val + ">" + val + "</text >"
                    }
                },
                {
                    "data": "capital", "width": "4%", render: function (val, a, row) {
                        if (val == null) {
                            return ""
                        }
                        return "<text  title=" + val + ">" + val + "</text >"
                    }
                },
                /*   {
                       "data": "company_address", "width": "17%", render: function (val, a, row) {
                           if (val == null) {
                               return ""
                           }
                           return val
                       }
                   },*/
                {
                    "data": "_id", "width": "8%", render: function (val, a, row) {
                        var valueStr = JSON.stringify(row);
                        return "<div class='operate'>" +
                            "<a class='btn btn-primary' onclick='editdata(" + valueStr + ")'>编辑</a>&nbsp;" +
                            /*"<a class='btn btn-default' onclick='showHylxs(\"" + val + "\")'>详细行业类型</a>&nbsp;" +
                            "<a class='btn btn-sm btn-warning' onclick='showTels(\"" + val + "\")'>详细联系方式</a>&nbsp;" +*/
                            "<a class='btn btn-sm btn-danger' onclick='deleteQyk(\"" + row._id + "\",\"" + row.company_name + "\" )'>删除</a>&nbsp;" +
                            "</div>"
                    }
                }
            ]
        });
        /*新增企业库*/
        /*ttable.on('init.dt', function () {
            $(".opraaa").click(function () {
                var n = $(this).attr("opraaa");
                var _tit = "", htmlObj = {}, obj, tag = [];
                switch (n) {
                    case "newqyk":
                        tag = [
                            {label: "企业名称：", s_label: "s_company_name", must: true},
                            {label: "别名：", s_label: "s_alias"},
                            {label: "行政区划代码：", s_label: "s_area_code"},
                            {label: "省份：", s_label: "s_province"},
                            {label: "城市：", s_label: "s_city"},
                            {label: "区县：", s_label: "s_district"},
                            {label: "注册资本：", s_label: "s_capital", placeholder: "示例：45678.98元；456.78万元；1234.25；"},
                            {label: "企业地址：", s_label: "s_company_address"},
                            {label: "经营范围：", s_label: "s_business_scope"},
                            {label: "微信公众号：", s_label: "s_wechat_accounts"},
                            {label: "网址：", s_label: "s_website"},
                            {label: "联系方式：", s_label: "s_contact",type:"tpl_json"},
                        ];
                        //新增企业库按钮
                        htmlObj = {
                            title: "新增企业库信息",
                            tag: tag,
                            bts: [
                                {
                                    label: "Save", class: "btn-danger",
                                    fun: function () {
                                        var company_name = $("#s_company_name").val();
                                        var alias = $("#s_alias").val();
                                        var province = $("#s_province").val();
                                        var city = $("#s_city").val();
                                        var district = $("#s_district").val();
                                        var capital = $("#s_capital").val();
                                        var company_address = $("#s_company_address").val();
                                        if (company_name === "") {
                                            alert("红色标签的表单不能为空！");
                                            return
                                        }
                                        //新增企业库api
                                        $.post("/admin/audit/qiyeku_info/save", {
                                            "company_name": company_name,
                                            "alias": alias,
                                            "province": province,
                                            "city": city,
                                            "district": district,
                                            "capital": capital,
                                            "company_address": company_address,
                                        }, function (data) {
                                            if (data && data.rep) {
                                                $("#myModal").modal("hide");
                                                alert("保存成功");
                                                setTimeout(function () {
                                                    ttable.search(company_name).draw();
                                                    //    history.go(0) //刷新本页
                                                }, 1500) //停1.5秒

                                            } else {
                                                alert("内部错误");
                                            }
                                        }, 'json')
                                    }
                                }
                            ]
                        };
                        OpenDialog(htmlObj, obj);
                        break;
                }
            });
        })*/
    });

    var vastrjson = [{
        "infoid": "招标信息id",
        "contact_person": "联系人",
        "contact_type": "联系人类型",
        "phone": "联系人电话",
        "topscopeclass": "项目类型"
    }];

    /*新增企业库html*/
    function AddQYKHTML() {
        $("#infos").html("");
        $("#info_title").html("新增企业库信息");
        com = "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\" style=\"color: red;\">企业名称：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_company_name\" must=\"true\"></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">别名：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_alias\" ></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">历史名称：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_history_name\" placeholder=\"多个;隔开\" ></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">行政区划：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_area_code\" ></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">省份：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_province\"></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">城市：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_city\" ></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">区县：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_district\"></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">注册资本：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_capital\"  placeholder=\"示例：45678.98元；456.78万元；1234.25；\"></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">企业地址：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_company_address\"></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">经营范围：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_business_scope\"></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">公众号：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_wechat_accounts\" placeholder=\"多个;隔开\"></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">网址：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_website\"></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">联系方式：</label>" +
            "<div class=\"col-sm-9\" id='s_contact' style=\"height:250px\"></div>" +
            "<div class=\"row form-group\">" +
            "<button type='button' class='btn btn-sm btn-default col-md-offset-5 col-md-2'  data-dismiss='modal' aria-label='Close'>取消</button>" +
            "<button type='button' class='btn btn-sm btn-danger col-md-2' onclick='Add()'>新增企业库</button></div>";
        $("#infos").html(com);
        $("#s_contact").html('');
        var container = document.getElementById('s_contact');
        showJson("add", vastrjson, container);
        $("#info_data").modal("show");
    }

    /*保存企业库*/
    function Add() {
        var company_name = $("#s_company_name").val();//企业名称
        var alias = $("#s_alias").val();//别名
        var history_name = $("#s_history_name").val();//历史名称
        var area_code = $("#s_area_code").val();//行政区划代码
        var province = $("#s_province").val();//省份
        var city = $("#s_city").val();//城市
        var district = $("#s_district").val();//区县
        var capital = $("#s_capital").val();//注册资本
        var company_address = $("#s_company_address").val();//企业地址
        var business_scope = $("#s_business_scope").val();//经营范围
        var wechat_accounts = $("#s_wechat_accounts").val();//微信公众号
        var website = $("#s_website").val();//网址
        var contact = editor_add.getText();//联系人
        if (typeof contact == 'string') {
            try {
                var obj=JSON.parse(contact);
                if(typeof obj == 'object' && obj ){
                    // alert("格式正确");
                }else{
                    alert("联系人的表单json格式不正确");
                    return
                }
            } catch(e) {
                alert("联系人的表单json格式不正确");
                return
            }
        }
        if (company_name === "") {
            alert("红色标签的表单不能为空！");
            return
        } else if (contact === JSON.stringify(vastrjson, null, 2)) {
            alert("联系人的表单未填写！");
            return
        }
        //新增企业库api
        $.post("/admin/audit/qiyeku_info/save", {
            "company_name": company_name,
            "alias": alias,
            "history_name": history_name,
            "area_code": area_code,
            "province": province,
            "city": city,
            "district": district,
            "capital": capital,
            "company_address": company_address,
            "business_scope": business_scope,
            "wechat_accounts": wechat_accounts,
            "website": website,
            "contact": contact
        }, function (data) {
            if (data && data.rep) {
                alert("保存成功");
                $("#info_data").modal("hide");
                setTimeout(function () {
                    ttable.search(company_name).draw();
                    //    history.go(0) //刷新本页
                }, 1500) //停1.5秒

            } else {
                alert("内部错误");
            }
        }, 'json')
    }


    //详细行业类型
    function showHylxs(_id) {
        $("#infos").html("");
        $("#info_title").html("详细行业类型");
        $.post("/admin/audit/query_qyk/ById", {
            "_id": _id,
            "q_field": "industry",
        }, function (data) {
            if (data && data.rep) {
                // console.log(data);
                var tmp = "<div class='row'>";
                for (var i in data.data.industry) {
                    tmp = tmp +
                        "<div class=\"col-lg-10\">\n" +
                        "<div class=\"input-group\">\n" +
                        "   <input type='text' class='form-control' name='industry'  placeholder=\"请填写行业类型\" value='" + data.data.industry[i] + "'>" +
                        "   <span class=\"input-group-btn\">" +
                        '       <button class="btn btn-info " type="button" data-toggle="tooltip" title="删除" id="delCenterIpGrp"><span class="glyphicon glyphicon-minus"></span></button>' +
                        "   </span> " +
                        "  </div>" +
                        "</div>";
                    // console.log(i, data.data.industry[i]);
                }
                tmp = tmp +
                    "<div class=\"col-lg-10\">\n" +
                    "<button class='btn btn-info col-md-3' type='button'  id='addCenterIpGrpBtn' onclick='addCenterIpGrp(this)' >新增行业类型</button> " +
                    "<button type='button' class='btn btn-sm btn-default col-md-offset-5 col-md-2'  data-dismiss='modal' aria-label='Close'>取消</button>" +
                    "<button type='button' class='btn btn-sm btn-danger col-md-2' onclick='updateIndustrys(\"" + _id + "\")'>保存</button>" +
                    "</div>" +
                    "</div>";
                $("#infos").html(tmp);


            } else {
                alert("内部错误");
            }
        }, 'json');
        //展示详细行业类型
        $("#info_data").modal("show");
    }

    //添加行业详情
    function addCenterIpGrp(obj) {
        html = '<div class="input-group centerIp">' +
            '<input type="text" name="industry" class="form-control" id="ipInput" placeholder="请填写行业类型">' +
            '<span class="input-group-btn">' +
            '<button class="btn btn-info" type="button" data-toggle="tooltip" title="删除" id="delCenterIpGrp"><span class="glyphicon glyphicon-minus"></span></button>' +
            '</span>' +
            '</div>'
        obj.insertAdjacentHTML('beforebegin', html);
    }

    //更新行业详情
    function updateIndustrys(_id) {
        if (_id === "") {
            alert("参数id不存在");
            return
        }
        var params = $("#update-dataform").serialize();
        // console.log(_id, params);
        $.ajax({
            type: "POST",
            url: "/admin/audit/query_qyk/UpdateIndustrys",
            data: params + "&_id=" + _id,
            success: function (msg) {
                $("#info_data").modal("hide");
                if (msg.data) {
                    alert("success");
                } else {
                    alert("更新失败");
                }
            }
        });
    }

    $(document).on('click', '#delCenterIpGrp', function () {
        var el = this.parentNode.parentNode;
        if (confirm('您确定要删除选中的命令？')) {
            el.parentNode.removeChild(el);
        }
    });

    //详细联系方式
    function showTels(_id) {
        $("#infos").html("");
        $("#info_title").html("详细联系方式");
        $.post("/admin/audit/query_qyk/ById", {
            "_id": _id,
            "q_field": "contact",
        }, function (data) {
            if (data && data.rep) {
                // console.log(data);
                // var tmp = "<div class='row'>";
                var tmp = "";
                for (var i in data.data.contact) {
                    tmp += "<div class='row'>" +
                        "<div class=\"col-lg-10\">" +
                        '<h1><div class="input-group centerIp">' +
                        '<input type="text" name="contact_persons" class="form-control" id="ipInput" placeholder="请填写联系人" value=' + data.data.contact[i].contact_person + '>' +
                        '<select class="form-control" name="contact_types" value=' + data.data.contact[i].contact_type + '><option value ="法定代表人">法定代表人</option><option value ="项目联系人">项目联系人</option></select>' +
                        '<input type="text" name="phones" class="form-control" id="ipInput" placeholder="请填写联系电话" value=' + data.data.contact[i].phone + '>' +
                        '<select class="form-control" name="topscopeclasss" value=' + data.data.contact[i].topscopeclass + '><option value ="企业公示">企业公示</option><option value ="剑鱼标讯">剑鱼标讯</option></select>' +
                        '<span class="input-group-btn">' +
                        '<button class="btn btn-info" type="button" data-toggle="tooltip" title="删除" id="delCenterIpGrp"><span class="glyphicon glyphicon-minus"></span></button>' +
                        '</span>' +
                        '</div><h1>' +
                        '</div></div>';
                    // console.log(i, data.data.contact[i]);
                }
                tmp = tmp +
                    "<div class='row'>" +
                    "<div class=\"col-lg-10\">" +
                    "<button class='btn btn-info col-md-3' type='button'  id='addCenterIpGrpBtn' onclick='addCenterIpGrpTels(this)' >新增联系方式</button> " +
                    "<button type='button' class='btn btn-sm btn-default col-md-offset-5 col-md-2'  data-dismiss='modal' aria-label='Close'>取消</button>" +
                    "<button type='button' class='btn btn-sm btn-danger col-md-2' onclick='updateTels(\"" + _id + "\")'>保存</button>" +
                    "</div>" +
                    "</div>";
                $("#infos").html(tmp);
            } else {
                alert("内部错误");
            }
        }, 'json');
        $("#info_data").modal("show");
    }

    //添加联系方式
    function addCenterIpGrpTels(obj) {
        html = '<h1><div class="input-group centerIp">' +
            '<input type="text" name="contact_persons" class="form-control" id="ipInput" placeholder="请填写联系人">' +
            '<select class="form-control" name="contact_types"><option value ="法定代表人">法定代表人</option><option value ="项目联系人">项目联系人</option></select>' +
            '<input type="text" name="phones" class="form-control" id="ipInput" placeholder="请填写联系电话">' +
            '<select class="form-control" name="topscopeclasss"><option value ="企业公示">企业公示</option><option value ="剑鱼标讯">剑鱼标讯</option></select>' +
            '<span class="input-group-btn">' +
            '<button class="btn btn-info" type="button" data-toggle="tooltip" title="删除" id="delCenterIpGrp"><span class="glyphicon glyphicon-minus"></span></button>' +
            '</span>' +
            '</div><h1>'
        obj.insertAdjacentHTML('beforebegin', html);
    }

    //更新联系方式
    function updateTels(_id) {
        if (_id === "") {
            alert("参数id不存在");
            return
        }
        var params = $("#update-dataform").serialize();
        $.ajax({
            type: "POST",
            url: "/admin/audit/query_qyk/UpdateTels",
            data: params + "&_id=" + _id,
            // contentType: "application/json; charset=utf-8",
            dataType: "json",
            traditional: true,
            success: function (msg) {
                $("#info_data").modal("hide");
                if (msg.data) {
                    alert("success");
                } else {
                    alert("更新失败");
                }
            }
        });
    }

    //删除
    function deleteQyk(_id, company_name) {
        if (_id === "") {
            alert("参数id为空");
            return
        }
        if (confirm("您确认要提交此操作？")) {
            $.post("/admin/audit/qiyeku_info/deleteQyk", {
                "_id": _id,
                "company_name": company_name,
            }, function (data) {
                if (data && data.rep) {
                    setTimeout(function () {
                        alert("删除成功");
                        ttable.search("").draw();
                        //    history.go(0) //刷新本页
                    }, 800) //停1.5秒

                } else {
                    alert("内部错误");
                }
            }, 'json');
            ttable.draw();
        }
    }

    function editdata(_obj) {
        $("#infos").html("");
        $("#info_title").html("编辑企业库信息");
        com = "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\" style=\"color: red;\">企业名称：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_company_name\"  readonly=\"true\" must=\"true\" value='" + _obj.company_name + "'></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">别名：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_alias\" value='" + _obj.alias + "'></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">历史名称：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_history_name\" placeholder=\"多个;隔开\" value='" + _obj.history_name + "'></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">行政区划：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_area_code\" value='"+_obj.area_code+"' ></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">省份：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_province\" value='" + _obj.province + "'></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">城市：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_city\" value='" + _obj.city + "'></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">区县：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_district\" value='" + _obj.district + "'></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">注册资本：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_capital\" value='" + _obj.capital + "'  placeholder=\"示例：45678.98元；456.78万元；1234.25；\"></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">企业地址：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_company_address\" value='" + _obj.company_address + "'></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">经营范围：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_business_scope\" value='"+_obj.business_scope+"'></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">公众号：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_wechat_accounts\" placeholder=\"多个;隔开\" value='"+_obj.wechat_accounts.join(";")+"'></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">网址：</label>" +
            "<div class=\"col-sm-9\"><input type=\"text\" class=\"form-control\" id=\"s_website\" value='"+_obj.website+"'></div></div>" +
            "<div class=\"row form-group\"><label for=\"lastname\" class=\"col-sm-3 control-label\">联系方式：</label>" +
            "<div class=\"col-sm-9\" id='s_contact' style=\"height:250px\"></div>" +
            "<div class=\"row form-group\">" +
            "<button type='button' class='btn btn-sm btn-default col-md-offset-5 col-md-2'  data-dismiss='modal' aria-label='Close'>取消</button>" +
            "<button type='button' class='btn btn-sm btn-danger col-md-2' onclick='updatedate(\"" + _obj._id + "\")'>更新</button></div>";
        $("#infos").html(com);
        var container = document.getElementById('s_contact');
        showJson("update", _obj.contact, container);
        $("#info_data").modal("show");
    }

    function updatedate(_id) {
        if (_id === "") {
            alert("id不存在！");
            return
        }
        var company_name = $("#s_company_name").val();//企业名称
        var alias = $("#s_alias").val();//别名
        var history_name = $("#s_history_name").val();//历史名称
        var area_code = $("#s_area_code").val();//行政区划代码
        var province = $("#s_province").val();//省份
        var city = $("#s_city").val();//城市
        var district = $("#s_district").val();//区县
        var capital = $("#s_capital").val();//注册资本
        var company_address = $("#s_company_address").val();//企业地址
        var business_scope = $("#s_business_scope").val();//经营范围
        var wechat_accounts = $("#s_wechat_accounts").val();//微信公众号
        var website = $("#s_website").val();//网址
        var contact = editor_update.getText();//联系人
        if (typeof contact == 'string') {
            try {
                var obj=JSON.parse(contact);
                if(typeof obj == 'object' && obj ){
                    // alert("格式正确");
                }else{
                    alert("联系人的表单json格式不正确");
                    return
                }
            } catch(e) {
                alert("联系人的表单json格式不正确");
                return
            }
        }
        if (company_name === "") {
            alert("红色标签的表单不能为空！");
            return
        }
        //新增企业库api
        $.post("/admin/audit/qiyeku_info/save", {
            "_id": _id,
            "company_name": company_name,
            "alias": alias,
            "history_name": history_name,
            "area_code": area_code,
            "province": province,
            "city": city,
            "district": district,
            "capital": capital,
            "company_address": company_address,
            "business_scope": business_scope,
            "wechat_accounts": wechat_accounts,
            "website": website,
            "contact": contact
        }, function (data) {
            if (data && data.rep) {
                $("#info_data").modal("hide");
                alert("更新成功");
                setTimeout(function () {
                    ttable.search(company_name).draw();
                    //    history.go(0) //刷新本页
                }, 800) //停1.5秒
            } else {
                alert("内部错误");
            }
        }, 'json')
    }

    function showJson(ptype, content, container) {
        var options = {
            mode: 'code',
            modes: ['code', 'tree'], // allowed modes
            onError: function (err) {
                alert(err.toString());
            }
        };
        if (ptype == "add") {
            editor_add = new JSONEditor(container, options, content);
        } else if (ptype == "update") {
            editor_update = new JSONEditor(container, options, content);
        }
    }
</script>

