<template>
  <view class="work-container">
    <view style="margin-top: 10px">
      <u-cell @click="resetUser"  title="扫码注销" :isLink="true" arrow-direction="left"></u-cell>
      <u-cell  title="注销记录" :isLink="true" url="/pages/device/reset/resetrecord" arrow-direction="left"></u-cell>
<!--      <u-cell  title="已注销列表" :isLink="true" url="/pages/device/index?deptId=-1" arrow-direction="left"></u-cell>-->

    </view>
    <u-modal :show="show" :title="dlgTitle" @cancel="cancel" :showCancelButton="true" @confirm="bingDevice" >
      <view class="slot-content">

        <view>设备名称：{{ scanDevice.deviceName }}</view>
        <view>产品名称：{{ scanDevice.productName }}</view>
        <view>设备编号：{{ scanDevice.serialNumber }}</view>
        <view>激活日期：{{ scanDevice.activeTime }}</view>

      </view>
    </u-modal>
  </view>

</template>

<script>
import {getDevcieByQrcode,resetDevice} from '@/api/device/device';
export default {
  data() {
    return {
      dlgTitle:"",
      current: 0,
      swiperDotIndex: 0,
      show:false,
      scanDevice:{},
    }
  },
  onLoad(){
  },
  methods: {
    bingDevice(){
      this.show = false;
      resetDevice(this.scanDevice).then(res=>{
        if(res.code == 200){
          this.$modal.showToast('操作成功')
        }else{
          this.$modal.showToast(res.msg);
        }

      })
    },
    cancel(){
      this.show = false;
      this.scanDevice = {};
    },
    resetUser(){
      let self = this;
      uni.scanCode({
        success: function (res) {
          console.log('条码内容：' + res.result);
          getDevcieByQrcode(res.result).then(res=>{
            let device = res.data;
            if(!device){
              self.$modal.showToast('未查到设备信息')
            }else{
              if(device.deptId == null){
                self.$modal.showToast('该设备未绑定用户')
              }else{
                self.scanDevice = device;
                self.dlgTitle = "解绑设备";
                device.deptId = -1;
                self.show = true;
              }
            }
          });
        },
        fail(res){
          console.log(res);
        }
      });
    },
  }
}
</script>

<style lang="scss">
/* #ifndef APP-NVUE */
.u-collapse-content{
  display: flex;
  flex-direction: column;
}
page {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  background-color: #fff;
  min-height: 100%;
  height: auto;
}

view {
  font-size: 14px;
  line-height: inherit;
}

/* #endif */

.text {
  text-align: center;
  font-size: 26rpx;
  margin-top: 10rpx;
}

.grid-item-box {
  flex: 1;
  /* #ifndef APP-NVUE */
  display: flex;
  /* #endif */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 15px 0;
}

.uni-margin-wrap {
  width: 690rpx;
  width: 100%;
;
}

.swiper {
  height: 300rpx;
}

.swiper-box {
  height: 150px;
}

.swiper-item {
  /* #ifndef APP-NVUE */
  display: flex;
  /* #endif */
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #fff;
  height: 300rpx;
  line-height: 300rpx;
}

@media screen and (min-width: 500px) {
  .uni-swiper-dot-box {
    width: 400px;
    /* #ifndef APP-NVUE */
    margin: 0 auto;
    /* #endif */
    margin-top: 8px;
  }

  .image {
    width: 100%;
  }
}
</style>
