<template>
  <div class="inspectorList">
    <div class="header-info">
      <van-image
        width="63"
        height="63"
        :src="require('../../assets/img_touxiang.png')"
      />
      <div class="text">
        <div class="name">{{ userInfo.nickname }}</div>
        <div class="sub">督察员</div>
      </div>
      <div class="btn" @click="goLogin">切换账号</div>
    </div>

    <div class="list">
      <div class="empty" v-if="empty">
        <img src="../../assets/img_cailiao_kong.svg" alt="" />
        <div class="text">暂无分组列表</div>
      </div>
      <div
        class="item"
        v-for="item in tableData"
        :key="item.id"
        @click="handleEdit(item)"
      >
        <div class="left">
          <div class="name">{{ item.name }}</div>
          <div class="status">
            <img src="../../assets/icon_status.svg" alt="" />
            <span>{{ item.date }}</span>
          </div>
          <div class="status">
            <img src="../../assets/icon_status.svg" alt="" />
            <span
              >{{ formatTime(item.startTime) }} -
              {{ formatTime(item.endTime) }}</span
            >
          </div>

          <div class="location" v-if="item.address">
            <img src="../../assets/icon_dizhi.svg" alt="" />
            <span>{{ item.address }}</span>
          </div>
        </div>
        <van-icon name="arrow" :size="16" color="#000000" />
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import dayjs from "dayjs";
export default {
  name: "inspectorList",
  metaInfo() {
    return {
      title: "分组列表"
    };
  },
  data() {
    return {
      tableData: [],
      empty: false
    };
  },
  computed: {
    ...mapState(["userInfo"])
  },
  methods: {
    handleEdit(row) {
      this.$router.push({
        name: "programmeList",
        query: {
          id: row.id
        }
      });
    },
    statusFormatter(row, column, cellValue) {
      return this.status[cellValue] || "";
    },
    goLogin() {
      localStorage.removeItem("token");
      this.$router.push("/login");
    },
    formatTime(time) {
      return dayjs("2018-02-02 " + time, "YYYY-MM-DD HH:mm:ss").format("HH:mm");
    }
  },
  mounted() {
    this.$http
      .post(
        "/arrange/byExpert",
        {
          size: 100
        },
        { body: "json" }
      )
      .then(res => {
        this.tableData = res.content;
        this.empty = res.empty;
      });
  }
};
</script>
<style lang="less" scoped>
.inspectorList {
  .title {
    font-size: 36px;
    text-align: center;
    font-weight: 700;
    margin: 20px;
  }
  .table {
    margin-top: 50px;
  }

  background: linear-gradient(180deg, #ffffff 0%, #f5f7fa 235px);
}
// /deep/.el-table--scrollable-x .el-table__body-wrapper {
//   overflow-x: hidden;
// }
// /deep/.el-table__body {
//   width: 100%;
// }

.header-info {
  display: flex;
  padding: 16px;
  align-items: center;
  .text {
    flex-grow: 1;
    margin-left: 12px;
    .name {
      font-size: 22px;
      font-weight: bold;
      color: #000000;
      line-height: 30px;
    }

    .sub {
      font-size: 14px;
      color: #939599;
      line-height: 20px;
      margin-top: 2px;
    }
  }

  .btn {
    font-size: 14px;
    color: #c4c7cc;
    line-height: 20px;
    align-self: flex-end;
  }
}

.list {
  padding: 20px 16px;
  .item {
    padding: 20px;
    background: #ffffff;
    border-radius: 12px;
    display: flex;
    align-items: center;

    .left {
      flex-grow: 1;
    }

    .name {
      font-size: 18px;
      font-weight: bold;
      color: #313233;
      line-height: 28px;
    }

    .status {
      display: flex;
      align-items: center;
      margin-top: 10px;
      img {
        margin-right: 6px;
      }
    }

    .location {
      display: flex;
      align-items: center;
      margin-top: 8px;
      img {
        margin-right: 6px;
      }
      span {
        font-size: 14px;
        color: #939599;
        line-height: 22px;
      }
    }

    &:not(:first-child) {
      margin-top: 12px;
    }
  }
}
</style>
