<template>
  <div class="device-list-box">
    <el-drawer
      title=""
      :visible.sync="drawer"
      :before-close="handleClose"
      :custom-class="isFullscreen ? 'not-fullscreen' : 'is-fullscreen'"
      :with-header="false"
      append-to-body
    >
      <div class="seek-list" style="background-color: #157a2c">
        <div
          style="
            width: 100%;
            color: #fff;
            display: flex;
            justify-content: space-between;
          "
        >
          <div>
            <b style="font-size: 14px; margin-right: 10px; color: #fff"
              >周转车列表
            </b>
          </div>

          <div class="rx-ec">
            <el-button
              icon="el-icon-full-screen"
              type="text"
              style="color: #fff; font-size: 14px"
              @click="handleFull"
              >{{ isFullscreen ? '全屏' : '缩小' }}</el-button
            >
            <el-button
              icon="el-icon-circle-close"
              type="text"
              style="color: #fff; font-size: 14px"
              @click="handleClose"
              >关闭</el-button
            >
          </div>
        </div>
      </div>

      <div class="device-list" v-if="turnoverList.length != 0">
        <div class="device-box" v-for="item in turnoverList" :key="item.id">
          <div class="status-box">
            <p v-if="item.runStatus == '0'">启动</p>
            <p v-if="item.runStatus == '1'">空闲中</p>
            <p v-if="item.runStatus == '2'">运行</p>
            <p v-if="item.runStatus == '3'">故障</p>
            <p v-if="item.runStatus == '4'">检修</p>
            <p v-if="item.runStatus == '5'">停机</p>
            <p v-if="item.runStatus == '6'">待料</p>
            <p v-if="item.runStatus == '7'">占用</p>
          </div>
          <div class="title-box">
            <span>{{ item.name }}</span>
          </div>
          <div class="image-box">
            <img
              :src="
                Object.keys(item.imageUrl).length != 0
                  ? item.imageUrl
                  : 'http://192.168.1.251:51001/eam/img/upload-placeholder.39eb69d1.svg'
              "
              alt=""
              @click="checkDetail(item)"
            />
          </div>
          <div class="info-box">
            <p>分类:</p>
            <el-input disabled v-model="item.rootCategoryLevelName"></el-input>
          </div>
          <div class="info-box">
            <p>编码:</p> <el-input disabled v-model="item.code"></el-input>
          </div>

          <div class="btn-box">
            <el-button type="primary" class="btn" @click="repairBtn(item)"
              >货位</el-button
            >
          </div>
        </div>
      </div>

      <div v-else>
        <el-empty description="暂无周转车数据"></el-empty>
      </div>
    </el-drawer>

    <detail ref="detailRef"></detail>
    <turnoverDeatail ref="turnoverDeatailRef"></turnoverDeatail>
  </div>
</template>

<script>
  import detail from './components/detail.vue';
  import turnoverDeatail from './components/details.vue';
  import { getTurnoverList } from '@/api/produce/turnover.js';
  import { typeName } from '@/views/produce/components/common.js';
  export default {
    name: 'device',

    components: { detail, turnoverDeatail },

    data() {
      return {
        isFullscreen: false,
        drawer: false,
        codeList: [],
        turnoverList: [],
        typeName
      };
    },

    methods: {
      open(idsList) {
        this.codeList = idsList;
        this.getTurnoverListData();
        this.drawer = true;
      },

      handleClose() {
        this.drawer = false;
      },

      async getTurnoverListData() {
        await getTurnoverList({ workOrderCodeList: this.codeList }).then(
          (res) => {
            this.turnoverList = res.data;
            if (this.turnoverList.length != 0) {
              this.turnoverList.forEach((item) => {
                item.rootCategoryLevelName =
                  typeName[Number(item.rootCategoryLevelId)];
              });
            }
          }
        );
      },

      handleFull() {
        this.isFullscreen = !this.isFullscreen;
        this.$forceUpdate();
      },
      repairBtn(data) {
        this.$refs.detailRef.init(data);
      },
      reload() {
        this.getTurnoverListData();
      },

      checkDetail(item) {
        this.$refs.turnoverDeatailRef.open(item.code, item.id);
      }
    }
  };
</script>

<style scoped lang="scss">
  .device-list-box {
    width: 100%;
    box-sizing: border-box;
    min-width: 1280px !important;
    // height: calc(100vh - 220px);
    /* overflow-x: auto; */
    /* 当内容超出宽度时，允许水平滚动 */
    white-space: nowrap;
    /* 防止内部文本换行，确保所有内容都在一行显示 */
    scrollbar-width: thin;
    /* 设置滚动条宽度（浏览器兼容性可能有所不同） */
    scrollbar-color: #40a9ff transparent;
    /* 设置滚动条颜色和轨道颜色（同样，浏览器兼容性） */
  }

  .seek-list {
    display: flex;
    height: 42px;
    justify-content: space-between;
    align-items: center;
    padding: 10px 10px;
  }

  .device-list {
    display: flex;
    width: 100%;
    height: 95%;
    overflow: auto;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 1rem 8rem;
    box-sizing: border-box;

    .device-box {
      display: flex;
      flex-direction: column;
      width: 23%;
      height: 40rem;
      margin: 3rem 1rem;
      border-radius: 12px;
      box-shadow: 3px 3px 10px 3px rgba(179, 175, 175, 0.5);

      .status-box {
        display: flex;
        width: 100%;
        height: 3rem;
        justify-content: flex-end;

        p {
          height: 2.5rem;
          width: 6rem;
          background-color: greenyellow;
          border-radius: 0px 12px 0 12px;
          text-align: center;
          align-content: center;
          align-items: center;
        }
      }

      .title-box {
        width: 100%;
        height: 3rem;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        color: #333;
      }

      .image-box {
        margin: 0 auto;
        width: 20rem;
        height: 20rem;
        margin-bottom: 1rem;

        img {
          width: 100%;
          height: 100%;
        }
      }

      .info-box {
        display: flex;
        flex-direction: row;
        padding: 1rem 4.5rem;
        box-sizing: border-box;
        height: 4rem;
        width: 100%;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        color: #333;
        p {
          width: 5rem;
          text-align: center;
        }
      }

      .btn-box {
        padding: 1rem 3rem 0;
        width: 100%;
        box-sizing: border-box;

        .btn {
          width: 100%;
          height: 3rem !important;
        }
      }
    }
  }

  ::v-deep .is-fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    overflow: hidden !important; /* 隐藏滚动条 */
  }
  ::v-deep .not-fullscreen {
    width: calc(100vw - 230px) !important;
    height: 100vh !important;
    overflow: hidden !important; /* 隐藏滚动条 */
  }
</style>
