<template>
  <view class="device-card" @click="handleClick">
    <view class="device-card__status">
      <image
        class="img"
        :src="dataSource.devStatus == '1' ? successImg : errorImg"
      />
      <view
        class="status-text"
        :class="{ offline: dataSource.devStatus != '1' }"
        >{{ dataSource.devStatusName || '' }}</view
      >
    </view>
    <view class="device-card__header">
      <view class="device-card__title u-line-1">
        <view class="name">{{ dataSource.devName || '' }}</view>
        <view class="tips">{{ dataSource.devCode || '' }}</view>
      </view>
    </view>
    <view class="device-card__body">
      <view class="device-card__row">
        <view class="device-card__label">上报时间</view>
        <view class="device-card__value">{{ dataSource.devUpdateddate }}</view>
      </view>
      <view class="device-card__row">
        <view class="device-card__label">设备位置</view>
        <view class="device-card__value">{{
          `${dataSource.devProvincealign || dataSource.devProvince || ''}  ${
            dataSource.devCityalign || dataSource.devCity || ''
          } ${dataSource.devDistrictalign || dataSource.devDistrict || ''}`
        }}</view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'DeviceCard',
  props: {
    dataSource: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      successImg:
        'https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/image/zhongshui/success.png',
      errorImg:
        'https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/image/zhongshui/error.png',
    };
  },
  methods: {
    handleClick() {},
  },
};
</script>

<style lang="scss" scoped>
.device-card {
  background: linear-gradient(180deg, #8ae4c93d 0%, #14a47800 25.54%), #fff;
  position: relative;
  padding: 28rpx;
  border-radius: 16rpx;
  background-color: #fff;
  margin-bottom: 32rpx;
  margin: 0 auto;
  &__status {
    position: absolute;
    right: 0;
    top: 0;
    width: 150rpx;
    height: 56rpx;
    display: flex;
    align-items: center;
    justify-content: center;

    .img {
      position: absolute;
      width: 100%;
      height: 100%;
      right: 0;
      top: 0;
      overflow: hidden;
    }

    .status-text {
      font-size: 28rpx;
      color: #14a478;

      &.online {
        color: #14a478;
      }

      &.offline {
        color: #ff3546;
      }
    }
  }

  &__header {
    margin-bottom: 18rpx;
  }

  &__title {
    align-items: center;
    line-height: 48rpx;
    display: flex !important;
    .name {
      width: 140rpx;
      font-size: 32rpx;
      color: #042118;
      margin-right: 32rpx;
      // 超出隐藏
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      text-align: left;
      font-family: 'Source Han Sans CN VF';
      font-weight: 700;
    }

    .tips {
      width: 410rpx;
      font-size: 32rpx;
      color: #687a74;
      // 超出隐藏
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      text-align: left;
    }
  }

  &__body {
    padding: 16rpx 0;
    background-color: #fff;
    border-radius: 12rpx;
  }

  &__row {
    display: flex;
    align-items: center;
    margin-bottom: 16rpx;

    &:last-child {
      margin-bottom: 0;
    }
  }

  &__label {
    width: 140rpx;
    color: #9ba6a3;
    text-align: left;
    margin-right: 32rpx;
  }

  &__value {
    width: 470rpx;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
</style>
