<template>
  <div class="department">
    <div class="container">
      <div class="title">
        <div class="title__text">所有部门</div>
        <el-input placeholder="搜索部门" v-model="input" class="title__input">
          <template #append>
            <el-button class="title__input--btn" icon="el-icon-search" @click="getDepts"></el-button>
          </template>
        </el-input>
      </div>

      <el-skeleton :loading="loading" animated>
        <template #template>
          <div>
            <div class="list">
              <el-skeleton-item variant="rect" class="list__item" v-for="i in 8">
              </el-skeleton-item>
            </div>
          </div>
        </template>
        <template>
          <div>
            <div class="list">
              <div class="list__item" v-for="i in departments">
                {{ i.name }}
                <el-image class="list__item--icon" mode="coutain" :src="require('@/assets/reception/department-list-item-bkg.png')"></el-image>
              </div>
            </div>
          </div>
        </template>
      </el-skeleton>
    </div>
  </div>
</template>

<script>
import { departments } from '@/api/reception'
export default {
  data() {
    return {
      loading: false,
      departments: [],
      input: ''
    }
  },
  methods: {
    async getDepts () {
      this.loading = true
      const res = await departments({
        keyword: this.input,
        table_name: 'departments'
      })
      this.departments = res.department
      this.loading = false
    }
  },
  computed: {},
  mounted() {
    this.getDepts()
  }
}
</script>

<style scoped lang="scss">
.department {
  background: #f8f8f8;

  padding: 31px 18.75%;
}

.container {
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 0 15px 0 rgba(130,127,126,0.1);

  padding: 24px 23px 44px 22px;
  .title {
    display: flex;
    justify-content: space-between;
    align-items: center;

    &__text {

      padding-left: 5px;
    }
    &__input {
      width: 207px;

      & ::v-deep .el-input__inner {
        height: 35px;
      }

      &--btn {
        width: 48px;
        height: 35px;
        background: #3788D6;
        color: #fff;
        border: none;
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
        display: flex;
        justify-content: center;
        align-items: center;
      }
    }
  }
}

.list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-gap: 17px;

  margin-top: 21px;

  &__item {
    color: #247EC3;
    font-weight: 500;
    font-size: 16px;
    text-align: center;
    background: linear-gradient(to bottom,#fff 25%, #f0f7fc);
    border: 1px solid #F8F8F8;
    cursor: pointer;
    transition: all .2s;

    padding: 34px 41px;
    margin-bottom: 16px;
    position: relative;

    &:hover {
      color: #fff;
      background: #3c7ac0;
    }
    &--icon {
      width: 44px;
      height: 50px;

      position: absolute;
      bottom: 0;
      right: 0;
    }
  }
}
</style>
