<template>
  <div class="upload_links">
    <div class="header">
      <div class="search">
        <div class="input">
          <img src="../../img/search.png" />
          <input
            type="text"
            @focus="focusInput"
            v-model="inputValue"
            class="inputFocus"
            placeholder="DLR Code / 经销商"
          />
        </div>
        <div class="area">
          <p>所属区域</p>
          <select v-model="areaValue">
            <option value="">请选择</option>
            <option v-for="(item, index) in areaList" :key="index">
              {{ item }}
            </option>
          </select>
        </div>
        <div class="time">
          <p>请选择时间段</p>
          <input type="date" v-model="startTime" />
          <span>至</span>
          <input type="date" v-model="endTime" />
        </div>
        <div class="current_button" @click="search">搜索</div>
      </div>
    </div>
    <div class="count">
      <p>针对论坛及其它平台链接上传</p>
      <Count :sum="sum" />
    </div>
    <div class="tableBox">
      <Table :tableData="tableData" @go_detail="ulrJump"></Table>
    </div>
    <TablePage
      :currentPage="currentPage"
      :totalPage="totalPage"
      @change_page="changePage"
      @jump_page="jumpPage"
    ></TablePage>
  </div>
</template>

<script>
import TablePage from "../../components/TablePage";
import Count from "../../components/Count";
import Table from "./components/UploadLinksTable";
export default {
  components: {
    TablePage,
    Count,
    Table,
  },
  data() {
    return {
      inputValue: "",
      sum: 0,
      currentPage: 1,
      pageSize: 20,
      tableData: [],
      areaList: [],
      areaValue: "",
      startTime: "",
      endTime: "",
    };
  },
  computed: {
    // 表格总页数
    totalPage() {
      return Math.ceil(this.sum / this.pageSize);
    },
  },
  methods: {
    // 当焦点在选择框时，清空选择框
    focusInput: function () {
      this.inputValue = "";
    },
    search: function () {
      let data = {
        queryParams: this.inputValue,
        localArea: this.areaValue,
        startTime: this.startTime,
        endTime: this.endTime,
      };
      this.firmsLinkUpload(data);
    },
    changePage: function (page) {
      this.currentPage = page;
      let req = {
        page: this.currentPage,
        rows: this.pageSize,
      };
      this.firmsLinkUpload(req);
    },
    // 点击上一页，下一页，首页，尾页
    jumpPage: function (item) {
      switch (item) {
        case 1:
          this.currentPage = 1;
          break;
        case 2:
          this.currentPage = this.currentPage - 1;
          break;
        case 3:
          this.currentPage = this.currentPage + 1;
          break;
        case 4:
          this.currentPage = this.totalPage;
          break;
      }
      let req = {
        page: this.currentPage,
        rows: this.pageSize,
      };
      this.firmsLinkUpload(req);
    },
    ulrJump: function (url) {
      window.open(url);
    },
    // 获取表格数据
    firmsLinkUpload: function (data = {}) {
      this.$http({
        method: "post",
        url: "/firmsLinkUpload",
        data: data,
      })
        .then((res) => {
          console.log(res.data.data)
          this.tableData = res.data.data;
          this.sum = res.data.count;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 获取 所有区域  接口
    getAreaList: function () {
      this.$http({
        method: "post",
        url: "/sys/agent/selectAgentAreaInfoList",
      })
        .then((res) => {
          if (res.data && res.data.code === 200) {
            this.areaList = res.data.data;
          } else {
            console.log(res);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
  created() {
    let req = {
      page: this.currentPage,
      rows: this.pageSize,
    };
    this.firmsLinkUpload(req);
    this.getAreaList();
  },
};
</script>

<style scoped lang="less">
.upload_links {
  .header {
    padding: 10px;
    border: 1px solid #ccc;
    .search {
      display: flex;
      align-items: center;
      .input {
        background-color: #fff;
        border: 1px solid #ccc;
        padding: 2px;
        display: flex;
        img {
          width: 22px;
          height: 22px;
          border: 1px solid #ccc;
        }
        input {
          background-color: #fff;
          border: 1px solid #ccc;
          margin-left: 3px;
          color: #555;
          font-size: 12px;
          height: 18px;
        }
      }
    }
    .area {
      margin-left: 20px;
      display: flex;
      height: 28px;
      line-height: 28px;
      select {
        margin-left: 10px;
        height: 28px;
        width: 120px;
        font-size: 12px;
        color: #555;
        border: 1px solid #ccc;
        option {
          font-size: 12px;
          border: 1px solid #ccc;
        }
      }
    }
    .time {
      display: flex;
      margin-left: 20px;
      p {
        height: 28px;
        line-height: 28px;
        margin-right: 10px;
      }
      input {
        height: 26px;
        padding: 0;
        outline: none;
        border: 1px solid #ccc;
        margin-right: 10px;
      }
      span {
        height: 28px;
        line-height: 28px;
        margin-right: 10px;
      }
    }
  }
  .count {
    display: flex;
    justify-content: space-between;
    margin-top: 5px;
    p {
      margin-top: 10px;
      font-weight: 600;
    }
  }
  .tableBox {
    width: 1030px;
    overflow: auto;
    text-align: center;
  }
}
.inputFocus {
  outline: none;
  border: 1px solid #ccc;
}
.inputFocus:focus {
  animation: shadowAni 200ms linear forwards;
}
@keyframes shadowAni {
  0% {
    border-color: #cccccc;
    box-shadow: inset 0px 0px 0 #ccc;
  }
  100% {
    border-color: #75b9f0;
    box-shadow: 0px 0px 5px #75b9f0;
  }
}
</style>
