<template>
  <div id="as-centerRight1">
    <div class="bg-color-black">
      <div class="d-flex pt-2 pl-2">
        <span>
          <icon name="chart-line" class="text-icon"></icon>
        </span>
        <div class="d-flex">
          <span class="fs-xl text mx-2">线体当日产量统计</span>
        </div>
      </div>
      <div class="d-flex jc-center body-box">
        <dv-scroll-board class="dv-scr-board" :config="config" ref="scroll-board" />
      </div>
      <div class="photo-box">
        <div>
          <div>
            <img :src="imgSrc1" class="responsive-img">
          </div>
          <div>
            <p>拉长: {{ upitem.v_leadname }}</p>
            <p>产线人数: {{zzmancount}}</p>
          </div>
        </div>
        <div>
          <div>
            <img :src="imgSrc2" class="responsive-img">
          </div>
          <div>
            <p>IPQC: {{ upitem.v_quaname }}</p>
            <p>品检人数: {{bzmancount}}</p>
          </div>
        </div>
        <div>
          <div>
            <img :src="imgSrc3" class="responsive-img">
          </div>
          <div>
            <p>PE: {{ upitem.v_engineername }}</p>
            <p>管理人数: {{glmancount}}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      upitem:{},
      imgSrc1:'',
      imgSrc2:'',
      imgSrc3:'',
      zzmancount:0,
      bzmancount:0,
      glmancount:0,
      config: {
        header:  ['线别', '投入','产出','老化','不良','良率%','待维修','已维修'],
        data: [
        ],
        rowNum: 1, //表格行数
        headerHeight: 35,
        headerBGC: '#0f1325', //表头
        oddRowBGC: '#0f1325', //奇数行
        evenRowBGC: '#171c33', //偶数行
        columnWidth: [110,100,100,80,80,95,95,90],
        align: ['center','center','center','center','center','center','center','center']
      },
      timing :null
    }
  },
  mounted() {
    this.refreshdata()
  },
  beforeDestroy () {
    clearInterval(this.timing)
  },
  methods: {
    refreshdata() {
      this.getdata(); //获取-数据
      this.timing = setInterval(() => {
        this.getdata(); //获取--数据
      }, 30000);
    },
    async getdata() {
      var caller = 'DPLANTOUTPUT!ZZ';
      await this.$http.get("kanban/datalist.action?caller="+caller+"&_noc=1&page=1&pageSize=100",{
        params: {
          condition: "1=1",
        }
      }).then((result)=>{
            let dataList = JSON.parse(result.data.data);
            let resultList = new Array();
            for (let index = 0; index < dataList.length; index++) {
              const element = dataList[index];
              let item = new Array();
              item.push(element.v_licode);
              item.push("<span  class='colorGrass'>"+element.inqty+"</span>");
              item.push("<span  class='colorGrass'>"+element.outqty+"</span>");
              item.push("<span  class='colorGrass'>"+element.agingqty+"</span>");
              item.push("<span  class='colorGrass'>"+element.ngqty+"</span>");
              item.push("<span  class='colorGrass'>" + element.okrate + "</span>");
              item.push("<span  class='colorGrass'>"+element.needrepairqty+"</span>");
              item.push("<span  class='colorGrass'>"+element.repairqty+"</span>");
              resultList.push(item);
            }
            const scrollBoard = this.$refs['scroll-board'];
            //刷新数据
            scrollBoard.updateRows(resultList);
          },(result)=>{
            console.error(result)
          }
      );

      caller = 'KB!UpLineManInfo';
      await this.$http.get("kanban/datalist.action?caller=" + caller + "&_noc=1&page=1&pageSize=100", {
        params: {
          condition: "1=1",
        }
      }).then((result) => {
            let dataList = JSON.parse(result.data.data);
            if (dataList.length > 0) {
              this.upitem = dataList[0];
              if (null != this.upitem.v_leadimageurl && '' != this.upitem.v_leadimageurl) {
                this.fetchImage('imgSrc1', this.upitem.v_leadimageurl);
              }
              if (null != this.upitem.v_quaimageurl && '' != this.upitem.v_quaimageurl) {
                this.fetchImage('imgSrc2', this.upitem.v_quaimageurl);
              }
              if (null != this.upitem.v_engineerimageurl && '' != this.upitem.v_engineerimageurl) {
                this.fetchImage('imgSrc3', this.upitem.v_engineerimageurl);
              }
            } else {
              this.upitem = {},
              this.imgSrc1 = '';
              this.imgSrc2 = '';
              this.imgSrc3 = '';
            }
          }, (result) => {
            console.error(result)
          }
      );

      caller = 'KB!UpLineManTotalNew';
      await this.$http.get("kanban/datalist.action?caller=" + caller + "&_noc=1&page=1&pageSize=100", {
        params: {
          condition: "1=1",
        }
      }).then((result) => {
            let dataList = JSON.parse(result.data.data);
            if (dataList.length > 0) {
              this.zzmancount = dataList[0].zzmancount;
              this.bzmancount = dataList[0].bzmancount;
              this.glmancount = dataList[0].glmancount;
            }
          }, (result) => {
            console.error(result)
          }
      );
    },
    async fetchImage(param,url) {
      try {
        console.log(param);
        // 假设你已经有了token，并且知道图片的URL
        let response = await this.$httpImg.get("/kanban/download.action?path="+url+"&_noc=1");
        if (response.status === 200) {
          // 创建一个URL，并且使用这个URL作为img的src
          this[param] = URL.createObjectURL(new Blob([response.data]));
        }else{
          this[param] = '';
        }
      } catch (error) {
        console.error('Error fetching image:', error);
      }
    },
  }
}
</script>

<style lang="scss" scoped>
$box-height: 420px;
$box-width: 640px;
#as-centerRight1 {
  padding: 10px;
  height: $box-height;
  width: $box-width;
  border-radius: 5px;
  .bg-color-black {
    height: $box-height - 30px;
    border-radius: 10px;
  }
  .text {
    color: #c3cbde;
    //  font-size: 15px;
  }
  .body-box {
    border-radius: 10px;
    overflow: hidden;
    .dv-scr-board {
      width: 600px;
      height: 60px;
    }
  }
  .photo-box{
    width: 100%;
    height: 280px;
    margin-top: 15px;
    display: flex;
    justify-content: space-between;

    >div{
      width: 30%;
      height: 100%;
      >div:first-child{
        height: calc(100% - 60px);
        border-radius: 5px 5px 0 0;
        >img{
          display: block;
          height: 100%;
          width: 100%;
          border-radius: 3px;
        }
      }
      >div:nth-child(2){
        width: 100%;
        height: 60px;
        text-align: center;
        >p:first-child{
          font-size: 22px;
          color: #fff;
          line-height: 40px;
        }
        >p{
          line-height: 20px;
          font-size: 18px;
          color: #33cea0;
        }
      }
    }
  }
}
</style>
