getHwList.html 4.31 KB
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="include :: header('下拉框')"/>
  <th:block th:include="include :: select2-css"/>
  <th:block th:include="include :: bootstrap-select-css"/>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
  <form class="form-horizontal m" id="form-menu-add">
    <input id="ent_name"   name="ent_name" type="hidden"/>
    <input id="ent_code" name="ent_code" type="hidden"/>
    <input id="ent_country" name="ent_country" type="hidden"/>
    <div class="form-group" id="countryDiv">
      <label class="col-sm-3 control-label"><span style="color: red; ">*</span>国别:</label>
      <div class="col-sm-8">
        <select id="country" class="form-control m-b" required>
          <option th:each="item:${countryList}" th:value="${item.jcCode}" th:text="${item.gj}"></option>
        </select>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label"><span style="color: red; ">*</span>订单名称:</label>
      <div class="col-sm-8">
        <input id="name" type="text" placeholder="请选择订单名称" class="form-control" required>
      </div>
    </div>

    <div class="form-group">
      <label class="col-sm-3 control-label"></label>
      <div class="col-sm-8">
        <button type="button" class="btn btn-success" id="select" onclick="search()">查询</button>
        <!--<button id="addEnterprise" type="button" class="btn btn-success">查询不到企业?</button>-->
      </div>
    </div>

    <div class="col-sm-12 select-table table-striped">
      <table class="table table-bordered" id="table_own">
        <thead>
          <tr>
            <th>企业名称</th>
            <th>企业状态</th>
            <th>所在城市</th>
            <th>企业地址</th>
            <th>企业注册号</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>

        </tbody>
      </table>
    </div>
  </form>


</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-select-js"/>
<script>

  let searchData = []
  function search() {
    var country = $("#country").val();
    var name = $("#name").val();
    $("#table_own tbody").html('正在查询中。。。');
    if (name === '') {
      $.modal.alertError("请输入企业名称")
      return;
    }
    $.ajax({
      url: '/web/monitorCompany/getEnterpraseInfo',
      data: {
        countryCode: country,
        name: name
      },
      type: 'get',
      dataType: 'json',
      success: function (res) {
        console.log(res)
        $("#table_own tbody").empty();
        if (res.code == '2000') {
          let itemList = res.data.items;
          searchData = res.data.items;
          let tempList = ``
          itemList.forEach((item, index) => {
            let temp = `<tr>
                    <td>${item.name}</td>
                    <td>${item.status}</td>
                    <td>${item.city}</td>
                    <td>${item.postcode},${item.street},${item.county}</td>
                    <td>${item.creditCode}</td>
                    <td><button type="button" class="btn btn-warning choiceBtn" onclick="handleChoice('${index}')">请选择</button></td>
                  </tr>`
            tempList += temp;
          })
          $("#table_own tbody").append(tempList);
        } else {
          $.modal.alertError(res.msg)
        }
      }
    })
  }

  function handleChoice(index) {
    console.log(index)
    searchData.forEach((item, dataIndex)=> {
      if (dataIndex == index) {
        $("#ent_name").val(item.name);
        $("#ent_code").val(item.creditCode);
        $("#ent_country").val(item.country);
      }
    })
    $(".choiceBtn").removeClass("btn-success");
    $(".choiceBtn").addClass("btn-warning");
    $(".choiceBtn").eq(index).addClass("btn-success");
    $(".choiceBtn").eq(index).removeClass("btn-warning");
    // $("#table_own tbody tr").not($("#table_own tbody tr").eq(index)).removeClass("btn-success");
    // $("#table_own tbody tr").not($("#table_own tbody tr").eq(index)).addClass("btn-warning");
    $(".choiceBtn").html("请选择");
    $(".choiceBtn").eq(index).html("已选择");
  }
</script>
</body>
</html>