@using MES.Production.Service;
@using Central.Control.Domain;
@using Ant.Service.Common;
@using CommonToolHelper;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var codelist = ViewData["codelist"] as List<SYS_CODE>;
}
@model PageInfo<COM_CUSCONTACT>
<!-- table star -->
<div class="row col-lg-12">
    <div class="wrapper wrapper-content animated fadeInUp">
        <div class="ibox">
            <div class="ibox-title">
                <h5>我的通讯录</h5>
                <div class="ibox-tools rboor">
                    <a class="btn btn-primary btn-xs p310" id="insert"><i class="im-plus"></i> 新增</a>
                    <a class="btn btn-primary btn-xs p310" id="modify"><i class="im-pencil2"></i> 编辑</a>
                    <a class="btn btn-primary btn-xs p310" id="delete" action="remove"><i class="im-remove4"></i> 删除</a>
                </div>
            </div>
            <div class="ibox-content">
                <!-- search star -->
                @using (Ajax.BeginForm("Index", null, new AjaxOptions() { }, new { @id = "form1", @class = "form-horizontal", @method = "get" }))
                {
                    <div class="form-horizontal clearfix">
                        <div class="col-lg-4 col-sm-3 pl0" style="width:50%;">
                            <div class="form-group">
                                <label class="control-label" style="width:100px; float:left;">客户类别:</label>
                                <div class="col-lg-8 col-sm-7" style="width:150px !important;">
                                    <select id="code" name="code" class="input-sm form-control input-s-sm inline" style="width:auto;" onchange="submit()">
                                        <option value="" @(ViewData["code"].ToString() == "" ? "selected=\"selected\"" : "")>全部</option>
                                        @{
                                            foreach (var item in codelist)
                                            {
                                                <option value="@item.ID" @(ViewData["code"].ToString() == item.ID.ToString() ? "selected=\"selected\"" : "")>@item.NAMETEXT</option>
                                            }
                                        }
                                    </select>
                                </div>
                                <label class="control-label" style="width:50px; float:left;">性别:</label>
                                <div class="col-lg-8 col-sm-7" style="width:120px !important;">
                                    <select id="sex" name="sex" class="input-sm form-control input-s-sm inline" onchange="submit()">
                                        <option value="" @(ViewData["sex"].ToString() == "" ? "selected" : "")>全部</option>
                                        <option value="1" @(ViewData["sex"].ToString() == "1" ? "selected" : "")>男</option>
                                        <option value="0" @(ViewData["sex"].ToString() == "0" ? "selected" : "")>女</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-4 col-sm-4" style="float:right;">
                            <div class="form-group">
                                <div class="col-lg-12 col-sm-12 input-group">
                                    @Html.TextBox("Search", null, new { @class = "input-sm form-control", @placeholder = "请输入查询关键词" })
                                    <span class="input-group-btn">
                                        <button type="button" onclick="submit()" class="btn btn-sm btn-primary"> 搜索</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                <!-- search end -->
                                            <div id="example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                                                <table id="example" class="table table-striped table-bordered table-hover dataTables-example dataTable" cellspacing="0" width="100%">
                                                    <thead>
                                                        <tr>
                                                            <th class="tn" style="padding: 10px 5px !important;width:50px !important;"><input name="checkall" id="checkall" type="checkbox" value=""></th>
                                                            <th>类型</th>
                                                            <th>姓名</th>
                                                            <th>性别</th>
                                                            <th>手机号</th>
                                                            <th>固话</th>
                                                            <th>QQ</th>
                                                            <th>公司名称</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        @{foreach (var item in Model.List)
                                                            {
                                                                <tr>
                                                                    <td class="tn"><input name="checkbox_name" type="checkbox" value="@item.ID"></td>
                                                                    <td>
                                                                        @{var it = codelist.Find(p => p.ID.ToString() == item.FK_TYPE);
                                                                            if (it != null)
                                                                            {
                                                                                @Html.Raw(it.NAMETEXT);
                                                                            }
                                                                        }
                                                                    </td>
                                                                    <td><a href="javascript:Show('@item.ID')"> @item.NAME</a></td>
                                                                    <td>@(item.SEX == 0 ? "女" : "男")</td>
                                                                    <td>@item.PHOME</td>
                                                                    <td>@item.TELNO</td>
                                                                    <td>@item.QQ</td>
                                                                    <td>@item.COMPANY</td>
                                                                </tr>
                                                                            }
                                                        }
                                                    </tbody>
                                                </table>
                                                <!-- page -->
                                                <div class="bottom">
                                                    <div class="dataTables_info" id="example_info" post="status" aria-live="polite">显示第 @Model.BeginPage 至 @Model.EndPage 项结果,共 @Model.Count 项</div>
                                                    <div class="dataTables_length" id="example_length">
                                                        <label>
                                                            显示
                                                            <select name="example_length" onchange="submit()" aria-controls="example" class="form-control input-sm">
                                                                <option value="10" @(Model.PageSize == 10 ? "selected" : "")>10</option>
                                                                <option value="25" @(Model.PageSize == 25 ? "selected" : "")>25</option>
                                                                <option value="50" @(Model.PageSize == 50 ? "selected" : "")>50</option>
                                                                <option value="100" @(Model.PageSize == 100 ? "selected" : "")>100</option>
                                                            </select> 项结果
                                                        </label>
                                                    </div>
                                                    @CommonHtmlHelper.PaginationPager(Model.Index, Model.PageSize, Model.Count, 7, Model.Url)
                                                    <div class="clear"></div>
                                                </div>
                                                <!-- page -->
                                            </div>
                                                                            }
            </div>
        </div>
    </div>
</div>
<!-- table end -->
@section scripts{
    <script type="text/javascript">
        //列表增加
        $("#insert").click(function () {
            dig.addModel('添加/编辑模块', "/Com/CusContact/Detail", 750, 700, function () {
                if (this.returnValue == 'yes') {
                    location.reload();
                }
            });
        });
        //列表选择修改
        $('#modify').click(function () {
            var vals = '';
            var num = 0;
            $('input[name="checkbox_name"]:checked').each(function () {
                vals = $(this).val();
                num++;
            });
            if (!vals) {
                dig.alertError("提示", "对不起,请选中您要操作的记录!");
                return;
            }
            if (num > 1) {
                dig.alertError("提示", "对不起,每次只能修改一条记录!");
                return;
            }
            dig.addModel("添加/编辑模块", "/Com/CusContact/Detail/" + vals, 700, 450, function () {
                if (this.returnValue == 'yes') {
                    location.reload();
                }
            });
        });
        //点击详情
        function Show(n) {
            dig.addModel('查看', "/Com/CusContact/Detail/" + n, 700, 450, function () {
                if (this.returnValue == 'yes') {
                    location.reload();
                }
            });
        };
    </script>
}