<template>
  <div class="div_device_item" @click="onClickItem">
    <div class="div_top">
      <div class="div_top_title">
        <span class="span_dark">{{deviceDetail.deviceName}}</span>
        <span class="span_light">{{deviceDetail.deviceCode}}</span>
      </div>
      <span :class="backClass" v-if="backDismiss" style="margin-right: 10px" @click.stop="onClickBack">归还</span>
    </div>
    <div class="line_h"></div>
    <div class="div_bottom">
      <div class="div_bottom_item">
        <div class="div_bottom_item_child">
          <span class="span_light">品牌名称</span>
          <span class="span_dark">{{deviceDetail.brandName}}</span>
        </div>
        <div class="div_bottom_item_child">
          <span class="span_light">规格型号</span>
          <span class="span_dark">{{deviceDetail.deviceModel}}</span>
        </div>
      </div>
      <div class="div_bottom_item" style="margin-top: 6px">
        <div class="div_bottom_item_child">
          <span class="span_light">归还日期</span>
          <span class="span_dark">{{util.isNotEmpty(deviceDetail.lendTime)?util.formatDateTimeOfYMD(deviceDetail.lendTime):""}}</span>
        </div>
        <div class="div_bottom_item_child">
          <span class="span_light">管理人</span>
          <span class="span_dark">{{deviceDetail.managerName}}</span>
        </div>
      </div>

      <div class="div_bottom_item" style="margin-top: 6px" v-if="showLendName">
        <div class="div_bottom_item_child">
          <span class="span_light">借用人</span>
          <span class="span_dark">{{deviceDetail.lendUserName}}</span>
        </div>
        <div class="div_bottom_item_child">
        </div>
      </div>
    </div>
  </div>
</template>

<script>

  export default {
    name: "DeviceBorrowItem",
    data(){
      return{
        userId:localStorage.getItem('memberId'),
        spanBack:"span_back",
        spanBackDark:"span_back_dark",
      }
    },
    props:{
      deviceDetail:{
        type:Object,
      },
      showLendName:{
        type: Boolean,
      },
      showBack:{
        type: Boolean,
      },
      backDismiss:{
        type: Boolean,
      }
    },
    computed:{
      backClass(){
        let classes = {};
        if (this.showBack) {
          classes[this.spanBack] = true;
        } else {
          classes[this.spanBackDark] = true;
        }

        return classes;
      }
    },
    methods:{
      onClickItem(){
        this.$router.push({
          path:'myDeviceBorrowDetail',
          query:{
            type:'0',
            deviceNumber:this.deviceDetail.deviceNumber
          }
        })
      },
      onClickBack(){
        if (this.showBack) {
          this.$emit("onClickBack",this.deviceDetail.deviceId);
        }

      }
    }
  }
</script>

<style scoped>
  .div_device_item{
    display: flex;
    flex-direction: column;
    border-width: 1px;
    border-color: #DBDBDB;
    border-style: solid;
    border-radius: 5px;
    margin: 10px 10px 0;
    background-color: #ffffff;
  }
  .div_top{
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .div_top_title{
    display: flex;
    flex-direction: column;
    margin: 10px;
    flex: 1;
  }
  .line_h{
    width: 100%;
    background-color: #DBDBDB;
    height: 1px;
  }
  .span_dark{
    color: #333333;
    font-size: 14px
  }
  .span_light{
    color: #999999;
    font-size: 14px
  }
  .span_back{
    color: #269FD5;
    font-size: 14px;
    border-width: 1px;
    border-radius: 2px;
    border-style: solid;
    border-color: #269FD5;
    padding: 2px 7px;
  }
  .span_back_dark{
    color: #999999;
    font-size: 14px;
    border-width: 1px;
    border-radius: 2px;
    border-style: solid;
    border-color: #999999;
    padding: 2px 7px;
  }
  .div_bottom{
    display: flex;
    flex-direction: column;
    margin: 10px;
  }
  .div_bottom_item{
    display: flex;
    flex-direction: row;
  }
  .div_bottom_item_child{
    flex: 1;
  }

</style>
