<template>
  <view class="content">
    <uni-nav-bar left-icon="back" @clickLeft="back" statusBar fixed title="生产设备详情"></uni-nav-bar>
    <view class="flex-col items-center group_1" v-if="info.videoUrl">
      <image src="/static/imgs/digital-workshops/camera-tip-bg.png" class="image_2" @click="go2('video-play', { url: info.videoUrl })" />
    </view>
    <view class="flex-col group_6">
      <view class="flex-col">
        <text class="text_5">{{ info.name }}</text>
        <view class="flex-row group_8">
          <text>{{ translate(info.latestWorkTime) }}</text>
          <text class="text_7">{{ info.belongWorkshop }}</text>
        </view>
      </view>
      <view class="flex-col group_9">
        <text>品牌：{{ info.brand }}</text>
        <text class="text_9">供应商：{{ info.supplier }}</text>
        <text class="text_10">出厂年月：{{ info.outFactoryDate | formatDate }}</text>
        <text class="text_11">平均产能：{{ info.avgCapacity }}件/小时</text>
        <text class="text_12">电压/功率：{{ info.voltage }}V/10KW</text>
      </view>
    </view>
    <view class="flex-col line-tabs">
      <view class="flex-col section_3">
        <view class="flex-row group_2">
          <view
            class="text-wrapper"
            :class="{ 'text-wrapper_selected': curTab === item.key }"
            v-for="item in tabList"
            :key="item.key"
            @click="selectTab(item.key)"
          >
            <text>{{ item.name }}</text>
            <view v-show="curTab === item.key" class="divider"></view>
          </view>
        </view>
      </view>
      <view class="flex-row section_4" v-show="curTab == 1">
        <view class="flex-col group_11">
          <view class="flex-row group_12">
            <image
              src="https://project-user-resource-1256085488.cos.ap-guangzhou.myqcloud.com/611dd17441a9be0011f45822/620ccb0962a7d90011fe5c8f/16510517429533841051.png"
              class="image_6"
            />
            <text class="text_16">当月产能(件)</text>
          </view>
          <text class="text_17">{{ info.monthCapacity }}</text>
          <text class="text_18">今日：{{ info.todayCapacity }}</text>
          <text class="text_19">昨日：{{ info.yesterdayCapacity }}</text>
          <text class="text_20">累计：{{ info.totalCapacity }}</text>
        </view>
        <view class="flex-col group_13">
          <view class="flex-row group_14">
            <image
              src="https://project-user-resource-1256085488.cos.ap-guangzhou.myqcloud.com/611dd17441a9be0011f45822/620ccb0962a7d90011fe5c8f/16510517429532568250.png"
              class="image_6 image_8"
            />
            <text class="text_21">当月工作</text>
          </view>
          <text class="text_22">{{ info.monthWorkHour }} h</text>
          <text class="text_23">今日：{{ info.todayWorkHour }}</text>
          <text class="text_24">昨日：{{ info.yesterdayWorkHour }}</text>
          <text class="text_25">累计：{{ info.totalWorkHour }}</text>
        </view>
        <view class="flex-col equal-division-item">
          <view class="flex-row group_15">
            <image
              src="https://project-user-resource-1256085488.cos.ap-guangzhou.myqcloud.com/611dd17441a9be0011f45822/620ccb0962a7d90011fe5c8f/16510517429530126367.png"
              class="image_6 image_9"
            />
            <text class="text_26">开机率</text>
          </view>
          <text class="text_27">{{ info.startupRate }}%</text>
        </view>
      </view>
      <view class="flex-col items-center empty-info" v-show="curTab == 2">
        <text>暂无维修信息</text>
      </view>
      <view class="flex-col items-center empty-info" v-show="curTab == 3">
        <text>暂无购置信息</text>
      </view>
    </view>
  </view>
</template>

<script>
import { go2, back } from '@/utils/hook.js'
import { getEquipmentInfo } from '@/apis/deviceApi'
const tabList = [
  { name: '生产情况', key: 1 },
  { name: '维修保养', key: 2 },
  { name: '购置信息', key: 3 }
]
export default {
  data() {
    return {
      id: null,
      info: {},
      tabList: Object.freeze(tabList),
      curTab: 1
    }
  },
  onLoad(options) {
    if (options.id) {
      this.id = options.id
    }
  },
  watch: {
    id(val) {
      this.getInfo()
    }
  },
  methods: {
    go2,
    back,
    getInfo() {
      if (this.id) {
        getEquipmentInfo({ id: this.id }).then((res) => {
          if (res) {
            this.info = res
          }
        })
      }
    },
    translate(time) {
      if (!time) {
        return ''
      }
      time = time.replace(/-/g, '/')
      let date = new Date(time)
      let month = date.getMonth() + 1
      let day = date.getDate()
      let hour = date.getHours()
      let minute = date.getMinutes()
      if (minute < 10) {
        minute = '0' + minute
      }
      return `最近开机 ${month}月${day}日 ${hour}:${minute}`
    },
    selectTab(key) {
      this.curTab = key
    }
  },
  filters: {
    formatDate(time) {
      if (!time) {
        return ''
      }
      time = time.replace(/-/g, '/')
      let date = new Date(time)
      let year = date.getFullYear()
      let month = date.getMonth() + 1
      return `${year}年${month}月`
    }
  }
}
</script>

<style lang="scss" scoped>
.content {
  width: 750rpx;
  .group_1 {
    color: rgb(255, 255, 255);
    font-size: 28rpx;
    font-weight: 500;
    line-height: 40rpx;
    white-space: nowrap;
    position: relative;
    .image_2 {
      width: 91.5vw;
      height: 51.5vw;
    }
    .text_18 {
      position: absolute;
      left: 24rpx;
      top: 16rpx;
    }
  }
}
.group_6 {
  padding: 24rpx 32rpx 32rpx;
  .group_9 {
    margin-top: 24rpx;
    color: rgb(51, 51, 51);
    font-size: 28rpx;
    line-height: 40rpx;
    white-space: nowrap;
    .text_9 {
      margin-top: 10rpx;
    }
    .text_10 {
      margin-top: 10rpx;
    }
    .text_11 {
      margin-top: 10rpx;
    }
    .text_12 {
      margin-top: 10rpx;
    }
  }
  .text_5 {
    color: rgb(0, 0, 0);
    font-size: 34rpx;
    font-weight: 500;
    line-height: 48rpx;
    white-space: nowrap;
  }
  .group_8 {
    margin-top: 8rpx;
    color: rgb(136, 136, 136);
    font-size: 20rpx;
    line-height: 28rpx;
    white-space: nowrap;
    .text_7 {
      margin-left: 11rpx;
    }
  }
}
.line-tabs {
  margin-top: 20rpx;
  .section_3 {
    padding-bottom: 3rpx;
    background-color: rgb(255, 255, 255);
    .group_2 {
      padding: 0 40rpx;
      border-bottom: solid 2rpx rgb(221, 221, 221);
      .text-wrapper {
        color: rgb(136, 136, 136);
        font-size: 28rpx;
        height: 86rpx;
        line-height: 86rpx;
        white-space: nowrap;
        position: relative;
        text-align: center;
        margin-right: 40rpx;
        min-width: 80rpx;
      }
      .text-wrapper_selected {
        color: rgb(51, 51, 51);
        font-weight: 500;
      }
      .divider {
        background-color: rgb(0, 122, 255);
        border-radius: 3rpx;
        width: 80rpx;
        height: 6rpx;
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
      }
    }
  }
  .section_4 {
    padding: 0 32rpx 25rpx;
    background-color: rgb(255, 255, 255);
    .group_11 {
      margin-top: 30rpx;
      flex: 1 1 auto;
      .group_12 {
        padding-left: 8rpx;
        color: rgb(136, 136, 136);
        font-size: 24rpx;
        line-height: 33rpx;
        white-space: nowrap;
        .text_16 {
          margin-left: 9rpx;
        }
      }
      .text_17 {
        margin-top: 12rpx;
        align-self: center;
        color: rgb(51, 51, 51);
        font-size: 28rpx;
        font-weight: 500;
        line-height: 40rpx;
        white-space: nowrap;
      }
      .text_18 {
        margin-top: 6rpx;
        color: rgb(136, 136, 136);
        font-size: 24rpx;
        line-height: 33rpx;
        white-space: nowrap;
      }
      .text_19 {
        margin-top: 5rpx;
        color: rgb(136, 136, 136);
        font-size: 24rpx;
        line-height: 33rpx;
        white-space: nowrap;
      }
      .text_20 {
        margin-top: 5rpx;
        align-self: left;
        color: rgb(136, 136, 136);
        font-size: 24rpx;
        line-height: 33rpx;
        white-space: nowrap;
      }
    }
    .group_13 {
      margin-left: 40rpx;
      margin-top: 30rpx;
      .group_14 {
        padding-left: 28rpx;
        color: rgb(136, 136, 136);
        font-size: 24rpx;
        line-height: 33rpx;
        white-space: nowrap;
        .image_8 {
          margin-bottom: 2rpx;
        }
        .text_21 {
          margin-left: 8rpx;
        }
      }
      .text_22 {
        margin-top: 12rpx;
        align-self: center;
        color: rgb(51, 51, 51);
        font-size: 28rpx;
        font-weight: 500;
        line-height: 40rpx;
        white-space: nowrap;
      }
      .text_23 {
        margin-top: 6rpx;
        color: rgb(136, 136, 136);
        font-size: 24rpx;
        line-height: 33rpx;
        white-space: nowrap;
      }
      .text_24 {
        margin-top: 5rpx;
        color: rgb(136, 136, 136);
        font-size: 24rpx;
        line-height: 33rpx;
        white-space: nowrap;
      }
      .text_25 {
        margin-top: 5rpx;
        color: rgb(136, 136, 136);
        font-size: 24rpx;
        line-height: 33rpx;
        white-space: nowrap;
      }
    }
    .equal-division-item {
      margin-left: 30rpx;
      padding: 29rpx 25rpx 67rpx 25rpx;
      .group_15 {
        color: rgb(136, 136, 136);
        font-size: 24rpx;
        line-height: 33rpx;
        white-space: nowrap;
        .image_9 {
          margin-left: 75rpx;
        }
        .text_26 {
          margin-left: 8rpx;
        }
      }
      .text_27 {
        margin-right: 23rpx;
        margin-top: 12rpx;
        align-self: flex-end;
        color: rgb(51, 51, 51);
        font-size: 28rpx;
        font-weight: 500;
        line-height: 40rpx;
        white-space: nowrap;
      }
    }
    .image_6 {
      width: 28rpx;
      height: 28rpx;
    }
  }
}
.empty-info {
  padding: 50rpx 0 58rpx;
  color: rgb(0, 0, 0);
  font-size: 28rpx;
  font-weight: 500;
  line-height: 40rpx;
  white-space: nowrap;
  background-color: rgb(255, 255, 255);
  overflow: hidden;
  height: 148rpx;
}
</style>
