<template>
  <div class="detail">
    <AiTopFixed>
      <div class="tab">
        <u-tabs :list="tab" :is-scroll="false" :current="currIndex" @change="change" height="96" :bar-style="barStyle"></u-tabs>
      </div>
    </AiTopFixed>
    <div class="content">
      <div class="info-content" v-if="currIndex != 1">
        <p>{{info.name}}</p>
        <div class="info">
          <span>设备编号</span>
          <span class="color-333">{{info.serialNo}}</span>
        </div>
        <div class="info">
          <span>设备状态</span>
          <span style="color: #4E8EEE">{{ $dict.getLabel('dlbDevStatus', info.devStatus) }}</span>
        </div>
        <div class="info">
          <span>信号强度</span>
          <span class="color-333">{{ $dict.getLabel('dlbDevSignal', info.devSignal) }}</span>
        </div>
        <div class="info">
          <span>音量</span>
          <span class="color-333">{{info.volume}}</span>
        </div>
        <div class="info">
          <span>所属区划</span>
          <span class="color-333">{{info.areaName}}</span>
        </div>
      </div>
      <div class="list-content" v-else>
        <div class="list">
          <div class="item" @click="toTaskDetail">
            <div class="left">
              <p>韩红-我的祖国.mp3</p>
              <div>李毅 2022-06-09 09:43:05</div>
              <div>日常 立即播发</div>
            </div>
            <div class="right">
              <div class="status">已下发</div>
              <div class="cancel-btn">撤销</div>
            </div>
          </div>
        </div>
        <!-- <AiEmpty v-if="!list.length"></AiEmpty> -->
      </div>
    </div>
    
    <div class="btn" @click="setVolume">设置音量</div>
    <u-popup v-model="isShow" mode="bottom" class="popup">
      <div class="title">
        <span @click="isShow=false">取消</span>
        <p>设置音量</p>
        <span @click="confirmAdd">保存</span>
      </div>
      <div class="slider-content">
        <span>1</span>
        <div class="slider">
          <u-slider v-model="volume" min="1" max="100" :use-slot="true" block-color="#007BFF" step="10">
            <view class="">
              <view class="badge-button">
                {{volume}}
              </view>
            </view>
          </u-slider>
        </div>
        <span>100</span>
      </div>
    </u-popup>
  </div>
</template>
<script>

export default {
  name: "detail",
  data() {
    return {
      barStyle: {width: '98px', bottom: '-3px', left: '-38px'},
      tab: [{name: '基本信息'}, {name: '播发任务'}],
      list: [],
      currIndex: 0,
      current: 1,
      isShow: false,
      volume: 10,
      info: {},
      id: ''
    }
  },
  onLoad(query) {
    this.id = query.id
    this.$dict.load(['dlbDevStatus', 'dlbDevSignal']).then(() => {
      this.getDetail()
    })
  },

  onShow() {
    document.title = '设备详情'
  },

  methods: {
    change(index) {
      this.currIndex = index
    },
    toTaskDetail(item) {
      uni.navigateTo({url: `./taskDetail`})
    },
    setVolume() {
      this.isShow = true
      this.volume = this.info.volume * 10 || 10
    },
    confirmAdd() {
      var volume = parseInt(this.volume/10)
      this.$http.post(`/app/appdlbquipment/volumeControl?deviceId=${this.info.deviceId}&volume=${volume}`).then((res) => {
        if (res.code == 0) {
          this.getDetail()
          this.isShow = false
          this.$u.toast('音量设置成功')
        }
      })
    },
    getDetail() {
      this.$http.post(`/app/appdlbquipment/queryDetailById?id=${this.id}`).then((res) => {
        if (res.code == 0) {
          this.info = res.data
        }
      })
    }
  },

  onReachBottom() {
    if(this.currIndex == 1) {
      this.current ++
      this.getList()
    }
  }
}
</script>
<style lang="scss" scoped>
.detail {
  padding-bottom: 128px;
  ::v-deep .AiTopFixed{
    .content{
      padding: 0;
    }
  }
  .tab {
    border-bottom: 1px solid #ddd;
    margin-bottom: 4px;
  }
  .content{
    margin-top: 8px;
    .info-content{
      padding-left: 32px;
      background-color: #fff;
      p{
        padding: 32px 32px 32px 0;
        font-size: 38px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #333;
        line-height: 56px;
        word-break: break-all;
      }
      .info{
        display: flex;
        justify-content: space-between;
        font-size: 32px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #999;
        line-height: 44px;
        padding: 34px 32px 32px 0;
        border-bottom: 1px solid #ddd;
        .color-333{
          color: #333;
        }
      }
    }
    .list-content{
      .list{
        padding-left: 32px;
        background-color: #fff;
        .item{
          display: flex;
          padding: 16px 40px 16px 0;
          box-sizing: border-box;
          border-bottom: 1px solid #ddd;
          .left{
            width: calc(100% - 176px);
            p{
              font-size: 34px;
              font-family: PingFang-SC-Medium, PingFang-SC;
              font-weight: 500;
              color: #333;
              line-height: 48px;
              word-break: break-all;
              margin-bottom: 8px;
            }
            div{
              font-size: 26px;
              font-family: PingFang-SC-Medium, PingFang-SC;
              font-weight: 500;
              color: #999;
              line-height: 36px;
              margin-bottom: 8px;
            }
          }
          .right{
            width: 160px;
            text-align: center;
            .status{
              font-size: 34px;
              font-family: PingFang-SC-Medium, PingFang-SC;
              font-weight: 500;
              color: #4E8EEE;
              line-height: 48px;
              margin-bottom: 28px;
            }
            .cancel-btn{
              width: 154px;
              height: 60px;
              line-height: 60px;
              text-align: center;
              background: #3975C6;
              border-radius: 8px;
              font-size: 30px;
              font-family: PingFang-SC-Medium, PingFang-SC;
              font-weight: 500;
              color: #FFF;
            }
            .bg-AFD0FC{
              background: #AFD0FC;
            }
          }
        }
      }
    }

  }
  .btn {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 112px;
    line-height: 112px;
    text-align: center;
    background: #3975C6;
    font-size: 32px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #FFFFFF;
  }
  .popup{
    background-color: #fff;
    .title{
      padding: 24px 0;
      line-height: 48px;
      text-align: center;
      span{
        display: inline-block;
        width: 120px;
        font-size: 28px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #5297FF;
        
      }
      p{
        display: inline-block;
        width: calc(100% - 240px);
        font-size: 36px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #0F1826;
      }
    }
    .slider-content{
      padding: 56px 44px 120px;
      display: flex;
      span{
        display: inline-block;
        font-size: 40px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #666;
        line-height: 56px;
      }
      .slider{
        display: inline-block;
        flex: 1;
        margin: 26px 30px 0;
      }
    }
  }

  ::v-deep .u-slider__button-wrap{
    margin-top: -40px;
    font-size: 44px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #666;
  }
}
</style>
