<% define_admin_breadcrumbs do %>
  <% add_admin_breadcrumb('用户管理', admins_users_path) %>
<% end %>

<div class="box search-form-container user-list-form">
  <%= form_tag(admins_users_path, method: :get, id: "user-search-form", class: 'form-inline search-form flex-1', remote: true) do %>
    <div class="form-group mr-2">
      <label for="status">状态：</label>
      <% status_options = [['全部', ''], ['正常', User::STATUS_ACTIVE], ['未激活', User::STATUS_REGISTERED], ['已锁定', User::STATUS_LOCKED]] %>
      <%= select_tag(:status, options_for_select(status_options), class: 'form-control') %>
    </div>

    <div class="form-group mr-2">
      <label for="identity">用户类型：</label>
      <% user_type_options = [['全部', ''], ['事业单位', 0], ['企业单位', 1], ['科研人员', 2], ['高校教师', 3], ['高校学生', 4], ['程序员', 5], ['其他', 6]] %>
      <%= select_tag(:user_type, options_for_select(user_type_options), class: 'form-control') %>
    </div>
    <div class="form-group mr-2">
      <label for="identity">专业领域：</label>
      <% user_type_options = [['全部', '']] + Site.get_dict_data("professional_field").pluck(:name,:value)%>
      <%= select_tag(:professional_field, options_for_select(user_type_options), class: 'form-control') %>
    </div>

    用户：
    <%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ', placeholder: 'ID/姓名/邮箱/手机号检索') %>
    单位：
    <%= text_field_tag(:company_name, params[:company_name], class: 'form-control col-sm-2 ', placeholder: '输入单位名称检索') %>

    <div class="form-group mr-2" style="width: 100%;padding-top: 10px;">
      <label for="user_admin">
        是否管理员
      </label>
      <%= check_box_tag("admin", true, false, id: "user_admin", style: 'margin-left: 2px;') %>
      <label for="user_authentication">
        实名认证
      </label>
      <%= check_box_tag("authentication", true, false, id: "user_authentication", style: 'margin-left: 2px;') %>
      <label for="user_enterprise_certification">
        企业认证
      </label>
      <%= check_box_tag("enterprise_certification", true, false, id: "user_enterprise_certification", style: 'margin-left: 2px;') %>
      <label for="user_bank_certification">
        财务认证
      </label>
      <%= check_box_tag("bank_certification", true, false, id: "user_bank_certification", style: 'margin-left: 2px;') %>
      <%= submit_tag('搜索', class: 'btn btn-primary mr-3', style: 'margin-left:50px;', 'data-disable-with': '搜索中...') %>
<!--      <button type="reset" class="btn btn-default">清除</button>-->
      <a href="javascript:void(0)" class="btn btn-outline-primary export-action" style="margin-left:20px;" id="users-export" data-disable-with = '导出中...'>导出</a>
    </div>
  <% end %>
<% if current_user.admin? %>
  <%= link_to '下载导入模板', "/导入用户模板.xlsx", class: 'btn btn-secondary mr-3' %>

  <%= javascript_void_link '导入用户', class: 'btn btn-secondary', data: { toggle: 'modal', target: '.admin-import-user-modal'} %>
<% end %>
</div>

<div class="box admin-list-container users-list-container">
  <%= render partial: 'admins/users/shared/user_list', locals: { users: @users } %>
</div>

<%= render partial: 'admins/users/shared/reward_grade_modal' %>
<%= render partial: 'admins/users/shared/import_user_modal' %>
<script>
    $(function () {
        var search_form = $("#user-search-form");
        //导出
        $("#user-search-form").on("click", "#users-export", function () {
            window.location.href = "/admins/users/export.xlsx?" + search_form.serialize();
            $('#users-export').removeAttr('data-disable-with');
        });
    })

</script>
