<template>
  <view class="device-card__body">
    <view class="device-card">
      <view :class=" dataSource.status == 1 ?'online-status':'offline-status'">{{ dataSource.status === 1 ? '在线' : '离线' }}</view>
      <view class="device-card__title">设备ID</view>
      <view class="device-card__content">
        <text class="device-id-text">{{ dataSource.id  }}</text>
        <img class="copy-icon" :src="copy" @click="copyDeviceId"/>
      </view>
    </view>
    <view class="device-card">
      <view class="device-card__title">上报时间</view>
      <view class="device-card__content">{{ dataSource.uptime | timeFormat()}}</view>
    </view>
    <view class="device-card">
      <view class="device-card__title">设备位置</view>
      <view class="device-card__content address">{{ dataSource.address || '-' }}</view>
    </view>
  </view>
</template>
<script>
export default {
  props: {
    dataSource: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      copy:'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/newImg/home/copy.png',
      title: ''
    }
  },
  methods: {
    copyDeviceId() {
      uni.setClipboardData({
        data: this.dataSource.id,
        success: () => {
          uni.showToast({
            title: '复制成功',
            icon: 'success'
          })
        }
      })
    }
  }
}
</script>
<style scoped lang="scss">
.device-card__body {
  display: flex;
  padding: 16px 12px;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  border-radius: 8px;
  background: linear-gradient(180deg, #EFF 0%, #FFF 23.56%);
  margin-top: 34rpx;
  position: relative;
  .device-card {
    display: flex;
    gap: 16px;
    .device-card__title {
      width: 120rpx;
      color: #4E5969;
      font-size: 14px;
      font-style: normal;
      font-weight: 400;
      text-align: right;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
    .online-status {
      width: 136rpx;
      height: 56rpx;
      line-height: 56rpx;
      position: absolute;
      text-align: center;
      top: 0;
      right: 0;
      background: url('https://s3.hnyfwlw.com/webstaticimg/bigdata_app/newImg/home/online1.png') no-repeat center center;
      background-size: 100% 100%;
      color: #0bbc58;
      font-family: "Source Han Sans CN VF";
      font-size: 28rpx;
    }
    .offline-status{
      width: 136rpx;
      height: 56rpx;
      line-height: 56rpx;
      position: absolute;
      text-align: center;
      top: 0;
      right: 0;
      background: url('https://s3.hnyfwlw.com/webstaticimg/bigdata_app/newImg/home/offline.png') no-repeat center center;
      background-size: 100% 100%;
      color: #ff3546;
      font-family: "Source Han Sans CN VF";
      font-size: 28rpx;
    }
    .device-card__content {
      color: #4E5969;
      font-size: 14px;
      font-style: normal;
      font-weight: 400;
      display: flex;
      align-items: center;
      gap: 8rpx;
      .device-id-text {
        flex: 1;
      }
      .copy-icon {
        font-family: 'iconfont';
        font-size: 32rpx;
        color: #86909C;
        cursor: pointer;
        width: 28rpx;
        height: 28rpx;
        &:active {
          opacity: 0.6;
        }
      }
    }
    .address {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
</style>