<template>
  <div class="div_page_bg">
    <div class="div_body_bg" v-if="hasLoaded">
      <div class="div_page_detail_top">
        <div class="div_page_detail_line">
          <span class="span_light" style="width: 60px;text-align: left">设备名称</span>
          <span class="span_dark" style="margin-left: 10px">{{deviceDetail.deviceName}}</span>
        </div>
        <div class="div_page_detail_line" style="margin-top: 10px">
          <span class="span_light" style="width: 60px;text-align: left">编码</span>
          <span class="span_dark" style="margin-left: 10px">{{deviceDetail.deviceCode}}</span>
        </div>
        <div class="div_page_detail_line" style="margin-top: 10px">
          <span class="span_light" style="width: 60px;text-align: left">品牌名称</span>
          <span class="span_dark" style="margin-left: 10px">{{deviceDetail.brandName}}</span>
        </div>
        <div class="div_page_detail_line" style="margin-top: 10px">
          <span class="span_light" style="width: 60px;text-align: left">规格型号</span>
          <span class="span_dark" style="margin-left: 10px">{{deviceDetail.model}}</span>
        </div>
        <div class="div_page_detail_line" style="margin-top: 10px">
          <span class="span_light" style="width: 60px;text-align: left">质保年份</span>
          <span class="span_dark" style="margin-left: 10px">{{deviceDetail.pledgeYear}}</span>
        </div>
        <div class="div_page_detail_line" style="margin-top: 10px">
          <span class="span_light" style="width: 60px;text-align: left">投入日期</span>
          <span class="span_dark" style="margin-left: 10px">{{deviceDetail.useDate}}</span>
        </div>
      </div>

      <div class="div_page_detail_bottom">
        <span class="span_dark" style="padding: 10px">文件</span>
        <div class="line_h"></div>
        <d-p-cell is-link title="巡检标准" @on-cell-click="onClickStandard"></d-p-cell>
      </div>

      <div class="div_page_detail_bottom" v-if="type === '2'">
        <d-p-cell show-bottom-line title="借入时间" :value="deviceDetail.lendTime"></d-p-cell>
        <d-p-cell show-bottom-line title="预计归还时间" :value="deviceDetail.planReturnTime"></d-p-cell>
      </div>

      <div class="div_button">
        <span class="btn_operate" v-if="(deviceDetail.lendStatus === '0'||deviceDetail.lendStatus === '3') && type === '1'" @click="onClickBorrow">借入</span>
        <!--<span class="btn_operate" v-if="deviceDetail.lendStatus === '0' && type === '1'" @click="onClickNewOrder">报修</span>-->
        <span class="btn_operate" v-if="(deviceDetail.lendStatus === '1'||deviceDetail.lendStatus === '2'||deviceDetail.lendStatus === '4') && type === '1'" @click="onClickTranslate">转借</span>
        <span class="btn_operate" v-if="type === '2'" @click="onClickSubmit">确定</span>
      </div>
    </div>
  </div>

</template>

<script>
  import DPCell from "../../components/itemPassport/DPCell";
  import {getDeviceLendStatus, getLendDeviceDetail, returnDevice} from "../../service/getData";
  export default {
    name: "myDeviceBorrowDetail",
    components: {DPCell},
    data(){
      return {
        hasLoaded:false,
        deviceNumber:'',
        deviceDetail:{},
        companyId:localStorage.getItem('companyId'),
        userId:localStorage.getItem('memberId'),
        type:'',
      }
    },
    created(){
      try {
        EbeiPlugins.cleanNavigationRightButton();
        EbeiPlugins.setNavigationItemTitle("设备详情");
      }
      catch (e) {

      }
      this.type = this.$route.query.type;
      this.deviceNumber = this.$route.query.deviceNumber;
      this.getLendDeviceDetailJs();
    },
    methods:{
      getLendDeviceDetailJs(){
        let that = this;
        let params = {
          deviceNumber:this.deviceNumber,
          companyId:this.companyId,
        }
        this.$vux.loading.show({
          text: '加载中...'
        })
        getLendDeviceDetail(params).then(res => {
          that.$vux.loading.hide();
          if (res.resultCode === 200) {

            that.hasLoaded = true;
            that.deviceDetail = res.data;
          } else {
            that.showTips(res.resultDesc)
          }
        }).catch(error => {
          that.$vux.loading.hide();
          console.log(error)
        })
      },
      onClickStandard(){
        this.$router.push({
          path:'/xunJianStandard',
          query:{
            deviceNumber:this.deviceNumber,
            type:this.type
          }
        })
      },
      onClickBorrow(){
        this.$router.push({
          path:'/borrowDevice',
          query:{
            deviceName:this.deviceDetail.deviceName,
            deviceCode:this.deviceDetail.deviceCode,
            deviceNumber:this.deviceNumber,
            type:1
          }
        })
      },
      onClickTranslate(){
        let that = this;
        let params = {
          deviceId:this.deviceDetail.deviceId,
          userId:this.userId
        }
        this.$vux.loading.show({
          text: '加载中...'
        })
        getDeviceLendStatus(params).then(res => {
          console.log(res)
          that.$vux.loading.hide();
          if (res.resultCode === 200) {
            that.$router.push({
              path:'/borrowDevice',
              query:{
                deviceName:this.deviceDetail.deviceName,
                deviceCode:this.deviceDetail.deviceCode,
                deviceNumber:this.deviceNumber,
                type:2
              }
            })
          } else {
            that.$vux.confirm.show({
              // 组件除show外的属性
              title:'提示',
              content:res.resultDesc,
              showCancelButton:false,
              onConfirm:() => {
                that.$vux.confirm.hide();
              }
            })
          }
        }).catch(error =>{
          console.log(error)
          that.$vux.loading.hide();
        });
      },
      onClickNewOrder(){
        try {
          EbeiPlugins.openNativePage("takeFixOrder", {
            deviceNumber:this.deviceNumber
          });
        }
        catch (e) {
          alert(e)
        }
      },
      onClickSubmit(){
        let that = this;
        let params = {
          deviceNumber:this.deviceNumber,
          userId:this.userId
        }
        this.$vux.loading.show({
          text: '加载中...'
        })
        returnDevice(params).then(res => {
          console.log(res)
          that.$vux.loading.hide();
          if (res.resultCode === 200) {
            that.$router.go(-1);
          } else {
            that.$vux.confirm.show({
              // 组件除show外的属性
              title:'提示',
              content:res.resultDesc,
              showCancelButton:false,
              onConfirm:() => {
                that.$vux.confirm.hide();
              }
            })
          }
        }).catch(error => {
          console.log(error)
          that.$vux.loading.hide();
        })
      },
      showTips (tip) {
        this.$vux.toast.show({
          type: 'text',
          text: tip,
          position: 'bottom'
        })
      }
    }
  }
</script>

<style scoped lang="less">
  .div_page_bg{
    width: 100%;
    height: 100vh;
    background-color: #F9F9F9;
  }
  .div_body_bg{
    width: 100%;
    height: 100vh;
    background-color: #F9F9F9;
  }

  .div_page_detail_top{
    display: flex;
    flex-direction: column;
    background-color: #ffffff;
    padding: 10px;
  }
  .div_page_detail_line{
    display: flex;
    flex-direction: row;
  }
  .span_dark{
    color: #333333;
    font-size: 14px
  }
  .span_light{
    color: #999999;
    font-size: 14px
  }

  .div_page_detail_bottom{
    display: flex;
    flex-direction: column;
    background-color: #ffffff;
    margin-top: 10px;
  }

  .div_button{
    display: flex;
    flex-direction: row;
    justify-content: center;
    margin-top: 30px;

  }
  .line_h{
    width: 100%;
    background-color: #e8e8e8;
    height: 1px;
    transform-origin: 0 100%;
    transform: scaleY(0.5);
  }
  .btn_operate{
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-width: 1px;
    border-color: #269FD5;
    border-style: solid;
    border-radius: 2px;
    height: 40px;
    width: 80px;
    color: #269FD5;
    font-size: 14px;
    margin: 10px;
  }
  .weui-dialog /deep/ .weui-dialog__title{
    color: black;
  }
</style>
