<template>
  <div class="wrapper">
    <header-nav :index_num="index_num"></header-nav>
    <div id="box">
      <!-- 搜索框 -->
      <div class="search">
        <input
          type="text"
          placeholder="请输入搜索内容"
          v-model.trim="searchVal"
          @keyup.enter="getSearch()"
        />
        <label @click="getSearch()">搜索</label>
      </div>
      <!-- 分类搜索 -->
      <div class="select-box">
        <select name="type" v-model="screeOut.type" @change="scree()">
          <option value="类型" disabled style="display:none;">类型</option>
          <option value="社会">社会</option>
          <option value="团体">团体</option>
        </select>
        <select name="time" v-model="screeOut.date_time" @change="scree()">
          <option value="登记时间" disabled style="display:none;">登记时间</option>
          <option value="09-18">09-18</option>
          <option value="09-19">09-19</option>
        </select>
        <select name="year" v-model="screeOut.date_year" @change="scree()">
          <option value="年检年份" disabled style="display:none;">年检年份</option>
          <option value="2017">2017</option>
          <option value="2019">2019</option>
        </select>
        <select name="condition" v-model="screeOut.zt" @change="scree()">
          <option value="年检情况" disabled style="display:none;">年检情况</option>
          <option value="正常">正常</option>
          <option value="异常">异常</option>
        </select>
      </div>
      <!-- 搜索记录 -->
      <div class="record">
        <template v-for="(item,index) in record">
          <div class="list" :key="index" @click="searchRecord(item.nameOf)">
            <span>{{item.category + '：' + item.nameOf}}</span>
            <span class="iconfont icon-cuowu" @click="del(index)"></span>
          </div>
        </template>
      </div>
      <!-- 表格 -->
      <div class="box-table">
        <div class="caption">
          <span
            v-for="(list,index) in text"
            :class="sub == index ? 'color' : ''"
            :key="index"
            @click="btn(index)"
          >{{list}}</span>
        </div>
        <table>
          <tr>
            <th>序号</th>
            <th>社会组织名称</th>
            <th>统一社会信用代码</th>
            <th>社会组织类型</th>
            <th>法定代表人</th>
            <th>成立登记日期</th>
            <th>状态</th>
          </tr>
          <template v-if="searchValue.length == 0">
            <tr
              v-for="(item,index) in sData"
              :key="index"
              :class="index % 2 == 0 ? 'bgcbz' : 'bgcz'"
              class="tr"
            >
              <td>{{item.organization}}</td>
              <td>{{item.credit}}</td>
              <td>{{item.type}}</td>
              <td>{{item.representative}}</td>
              <td>{{item.date_year + '-' + item.date_time}}</td>
              <td v-if="item.zt == '正常'" style="color:#2fd63f">{{item.zt}}</td>
              <td v-if="item.zt == '异常'" style="color:#e13232">{{item.zt}}</td>
            </tr>
          </template>
          <template v-if="searchValue.length > 0">
            <tr
              class="tr"
              v-for="(item,index) in searchValue"
              :key="index"
              :class="index % 2 == 0 ? 'bgcbz' : 'bgcz'"
            >
              <td>{{item.organization}}</td>
              <td>{{item.credit}}</td>
              <td>{{item.type}}</td>
              <td>{{item.representative}}</td>
              <td>{{item.date_year + '-' + item.date_time}}</td>
              <td v-if="item.zt == '正常'" style="color:#2fd63f">{{item.zt}}</td>
              <td v-if="item.zt == '异常'" style="color:#e13232">{{item.zt}}</td>
            </tr>
          </template>
        </table>
      </div>
    </div>
    <footer-nav class="footer"></footer-nav>
  </div>
</template>

<script>
/* eslint-disable */
import HeaderNav from "../components/HeaderNav";
/* eslint-disable */
import FooterNav from "../components/FooterNav";
export default {
  components: {
    HeaderNav,
    FooterNav
  },
  props: {},
  data() {
    return {
      index_num: 1,
      text: ["全部", "异常名单", "白名单"],
      sub: 0,
      imgUrl: {
        xa: require("../../static/img/xa.png")
      },
      searchVal: "",
      searchValue: [],
      record: [],
      screeOut: {
        type: '类型',
        date_time: '登记时间',
        date_year: '年检年份',
        zt: '年检情况'
      },
      sData: [
        {
          id: 1,
          organization: "劳动经济学会",
          credit: "51100000MJ000035X2",
          type: "团体",
          representative: "王五",
          date_time: "09-18",
          date_year: '2019',
          zt: '正常'
        },
        {
          id: 2,
          organization: "华为",
          credit: "51100000MJ000035X2",
          type: "社会",
          representative: "李四",
          date_time: "09-19",
          date_year: '2017',
          zt: '正常'
        },
        {
          id: 4,
          organization: "华为",
          credit: "51100000MJ000035X2",
          type: "团体",
          representative: "李四",
          date_time: "09-19",
          date_year: '2019',
          zt: '异常'
        },
        {
          id: 5,
          organization: "华为",
          credit: "51100000MJ000035X2",
          type: "社会",
          representative: "李四",
          date_time: "09-18",
          date_year: '2017',
          zt: '异常'
        },
        {
          id: 6,
          organization: "华为",
          credit: "51100000MJ000035X2",
          type: "社会",
          representative: "李四",
          date_time: "09-19",
          date_year: '2019',
          zt: '正常'
        },
        {
          id: 3,
          organization: "小米",
          credit: "51100000MJ000035X2",
          type: "手机",
          representative: "张三",
          date_time: "09-18",
          date_year: "2017",
          zt: '异常'
        }
      ]
    };
  },
  computed: {},
  watch: {
    record(newVal, oldVal) { }
  },
  methods: {
    /** 删除单条数据 */
    del(index) {
      let delArr = this.record.splice(index, 1)
    },
    /** 调用搜索函数 */
    searchRecord(str) {
      this.getSearch(str)
    },
    /** 筛选函数 */
    scree() {
      if (this.screeOut.type == "类型") {
        this.screeOut.type = ''
      } else {
        this.record.push({ category: '类型', nameOf: this.screeOut.type })
      }

      if (this.screeOut.date_time == "登记时间") {
        this.screeOut.date_time = ''
      } else {
        this.record.push({ category: '登记时间', nameOf: this.screeOut.date_time })
      }

      if (this.screeOut.date_year == "年检年份") {
        this.screeOut.date_year = ''
      } else {
        this.record.push({ category: '年检年份', nameOf: this.screeOut.date_year })
      }

      if (this.screeOut.zt == "年检情况") {
        this.screeOut.zt = ''
      } else {
        this.record.push({ category: '年检情况', nameOf: this.screeOut.zt })
      }

      /**
        let hash = {};
        this.record = this.record.reduce((preVal, curVal) => {
          hash[curVal.nameOf] ? '' : hash[curVal.nameOf] = true && preVal.push(curVal);
          return preVal
        }, [])
      */

      this.record = this.$tool.arrayHeavy(this.record, 'nameOf')

      let gData = this.$tool.multiFilter(this.sData, this.screeOut)
      if (gData != undefined && gData != '') {
        this.searchValue = gData
      } else {
        this.$message('您搜索的内容暂无~')
      }

      if (this.screeOut.type == "") {
        this.screeOut.type = '类型'
      }
      if (this.screeOut.date_time == "") {
        this.screeOut.date_time = '登记时间'
      }
      if (this.screeOut.date_year == "") {
        this.screeOut.date_year = '年检年份'
      }
      if (this.screeOut.zt == "") {
        this.screeOut.zt = '年检情况'
      }
    },
    /** 搜索函数 */
    getSearch(str) {
      this.searchValue = [];

      if (this.searchVal === "" && str !== "" && str !== undefined && str !== null && str !== 'null') {
        this.searchVal = str
      } else if (this.searchVal === "") {
        this.$message.warning("请输入搜索内容");
        return;
      }

      let searchData = this.$tool.setSearch(this.sData, this.searchVal)
      // console.log(searchData);


      if (searchData != undefined && searchData != '') {
        this.searchValue = searchData
        this.searchVal = "";
      } else {
        this.$message('您搜索的内容暂无~')
      }
      /*
        this.sData.forEach((item, index) => {
          if (
            item.organization.indexOf(this.searchVal) > -1 ||
            item.credit.indexOf(this.searchVal) > -1 ||
            item.type.indexOf(this.searchVal) > -1 ||
            item.representative.indexOf(this.searchVal) > -1 ||
            item.date.indexOf(this.searchVal) > -1
          ) {
            this.searchValue.push(item);
          }
        });
      */
    },
    /** 名单切换 */
    btn(index) {
      let s = this.sub;
      s = index;
      this.sub = s;
    },
    /** 获取后台数据 */
    getData() { }
  },
  created() {

  },
  mounted() {
    this.getData();
  }
};
</script>

<style lang='scss' scoped>
.wrapper {
  min-width: 1280px;
  box-sizing: border-box;
  position: relative;

  #box {
    width: 1200px;
    background-color: #ffffff;
    margin: 40px auto 80px;
    box-sizing: border-box;
    padding: 35px 30px 86px;

    .box-table {
      width: 100%;
      margin-top: -25px;

      table {
        width: 1130px;
        counter-reset: items 0; /* 0 可以省略 */
        counter-increment: counter-name integer;
        box-sizing: border-box;

        .tr {
          counter-increment: items 1; /* 1 同样可以省略 */
          &:before {
            content: counter(items);
            font-family: "MicrosoftYaHei";
            font-size: 16px;
            font-weight: normal;
            font-stretch: normal;
            letter-spacing: 0px;
            color: #595959;
            width: 86px;
            height: 40px;
            display: inline-block;
            text-align: center;
            line-height: 40px;
            box-sizing: border-box;
          }
        }

        th {
          line-height: 40px;
          text-align: center;
          height: 40px;
          font-family: "MicrosoftYaHei";
          font-size: 16px;
          font-weight: normal;
          font-stretch: normal;
          letter-spacing: 0px;
          color: #666666;
          background-color: #f6fafd;
          box-sizing: border-box;

          &:nth-of-type(1) {
            width: 86px;
          }
          &:nth-of-type(2) {
            width: 160px;
            border-left: 1px solid #dcebf6;
          }
          &:nth-of-type(3) {
            width: 240px;
            border-left: 1px solid #dcebf6;

          }
          &:nth-of-type(4) {
            width: 160px;
            border-left: 1px solid #dcebf6;
          }
          &:nth-of-type(5) {
            width: 160px;
            border-left: 1px solid #dcebf6;

          }
          &:nth-of-type(6) {
            width: 160px;
            border-left: 1px solid #dcebf6;
          }
          &:nth-of-type(7) {
            width: 140px;
            border-left: 1px solid #dcebf6;

          }
        }

        .bgcz {
          background-color: #f6fafd;
        }
        .bgcbz {
          background-color: #fff;
        }

        td {
          line-height: 40px;
          text-align: center;
          height: 40px;
          font-family: "MicrosoftYaHei";
          font-size: 16px;
          font-weight: normal;
          font-stretch: normal;
          letter-spacing: 0px;
          box-sizing: border-box;
          color: #595959;

          &:nth-of-type(1) {
            width: 160px;
            border-left: 1px solid #dcebf6;
          }
          &:nth-of-type(2) {
            width: 240px;
            border-left: 1px solid #dcebf6;
          }
          &:nth-of-type(3) {
            width: 160px;
            border-left: 1px solid #dcebf6;
          }
          &:nth-of-type(4) {
            width: 160px;
            border-left: 1px solid #dcebf6;
          }
          &:nth-of-type(5) {
            width: 160px;
            border-left: 1px solid #dcebf6;
          }
          &:nth-of-type(6) {
            width: 140px;
            border-left: 1px solid #dcebf6;
          }
          /*
          &:nth-of-type(7) {
            width: 144px;
          }
          */
        }
      }

      .caption {
        width: 1140px;
        height: 38px;
        border-bottom: 1px solid #dedede;
        margin-top: 76px;
        margin-bottom: 30px;
        padding-left: 30px;
        box-sizing: border-box;

        span {
          display: inline-block;
          height: 38px;
          text-align: center;
          font-family: "MicrosoftYaHei";
          font-size: 20px;
          font-weight: normal;
          font-stretch: normal;
          letter-spacing: 0px;
          color: #333333;
          margin-right: 49px;

          &:nth-of-type(1) {
            width: 60px;
          }
          &:nth-of-type(2) {
            width: 110px;
          }
          &:nth-of-type(3) {
            width: 89px;
          }
        }

        .color {
          color: #e60012;
          position: relative;

          &::after {
            content: "";
            width: 100%;
            height: 2px;
            background-image: linear-gradient(#e60012, #e60012),
              linear-gradient(#ff7f7f, #ff7f7f);
            background-blend-mode: normal, normal;
            position: absolute;
            left: 0%;
            bottom: 0%;
          }
        }
      }
    }

    .record {
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;

      .list {
        margin-right: 25px;
        border-radius: 4px;
        border: solid 1px #c7c7c7;
        padding: 10px 24px;
        font-family: "MicrosoftYaHei";
        font-size: 18px;
        font-weight: normal;
        font-stretch: normal;
        letter-spacing: 0px;
        color: #666666;
        margin-bottom: 25px;

        .iconfont {
          margin-left: 10px;
        }
      }
    }

    .select-box {
      display: flex;
      align-items: center;

      select {
        color: #666 !important;
        font-size: 18px;
        &:nth-of-type(1) {
          /* 清除默认的箭头样式 */
          appearance: none;
          -moz-appearance: none;
          -webkit-appearance: none;
          /* 右侧添加小箭头的背景图 */
          background: url("../../static/img/xa.png") 90px center no-repeat;
          background-size: 14px 8px;
          width: 134px;
          height: 38px;
          background-color: #f9f8f8;
          border-radius: 4px;
          border: solid 1px #c7c7c7;
        }
        /* 清除默认的箭头样式 */
        appearance: none;
        -moz-appearance: none;
        -webkit-appearance: none;
        /* 右侧添加小箭头的背景图 */
        background: url("../../static/img/xa.png") 126px center no-repeat;
        background-size: 14px 8px;
        width: 170px;
        height: 38px;
        background-color: #f9f8f8;
        border-radius: 4px;
        border: solid 1px #c7c7c7;
        margin-right: 55px;
        padding-left: 30px;
        box-sizing: border-box;
        outline: none;
        margin-bottom: 30px;
      }
    }

    .search {
      width: 100%;
      height: 50px;
      box-sizing: border-box;
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 30px;

      input {
        font-family: "MicrosoftYaHei";
        font-size: 18px;
        font-weight: normal;
        font-stretch: normal;
        letter-spacing: 2px;
        color: #666666;
        padding: 0 18px;
        box-sizing: border-box;
        width: 1025px;
        height: 50px;
        border: solid 1px #c7c7c7;
        outline: none;
      }

      label {
        width: 96px;
        height: 50px;
        background-color: #e60012;
        font-family: "MicrosoftYaHei";
        font-size: 18px;
        font-weight: normal;
        font-stretch: normal;
        line-height: 50px;
        letter-spacing: 0px;
        color: #ffffff;
        text-align: center;
      }
    }
  }
}
</style>
