<template>
  <div class="monitor-total-wrapper">
    <div class="token-wrapper">
      <div class="access-token-title">产品密钥(appKey)</div>
      <div
        class="access-token-input"
        contenteditable="true"
        spellcheck="false"
        ref="appkey"
      ></div>
    </div>
    <div class="token-wrapper">
      <div class="access-token-title">产品秘密(appSecret)</div>
      <div
        class="access-token-input"
        contenteditable="true"
        spellcheck="false"
        ref="appsecret"
      ></div>
    </div>
    <div class="token-wrapper">
      <div class="access-token-title">设备标识(mId)</div>
      <div
        class="access-token-input"
        contenteditable="true"
        spellcheck="false"
        ref="mid"
      ></div>
    </div>
    <div class="token-wrapper">
      <div class="access-token-title">通道编号(channel 以.live结尾)</div>
      <div
        class="access-token-input"
        contenteditable="true"
        spellcheck="false"
        ref="channel"
      ></div>
    </div>
    <!--<div class="serial-wrapper">
      <div class="serial-title">访问标识</div>
      <div
        class="serial-input"
        contenteditable="true"
        spellcheck="false"
        ref="accesstoken"
      ></div>
    </div>-->
    <!--
    <div class="channel-wrapper">
      <div class="channel-title">频道标题</div>
      <div
        class="channel-input"
        contenteditable="true"
        spellcheck="false"
        @input="inputChannel"
      ></div>
    </div>
    -->
    <div style="display:flex;justify-content:flex-end;">
      <!--<button @click="confirmInput">确认修改</button>-->
      <el-button @click="confirmInput">确认修改</el-button>
    </div>
  </div>
</template>

<script>
// import axios from 'axios'
// axios({
//   url: 'https://env.jingkongyun.com:9089/monitorvideo',
//   method: 'get'
// })
import { getMonitor, updateMonitor } from "../api/opemonitorv.js";
export default {
  data() {
    return {
      newRes: {}
    };
  },
  mounted() {
    getMonitor().then(res => {
      if (res && res.length) {
        this.newRes = { ...res[0] };
      }
      if (this.$refs.appkey) {
        if (res && res.length) {
          this.$refs.appkey.innerText = res[0].appkey;
        }
      }
      if (this.$refs.appsecret) {
        if (res && res.length) {
          this.$refs.appsecret.innerText = res[0].appsecret;
        }
      }
      if (this.$refs.mid) {
        if (res && res.length) {
          this.$refs.mid.innerText = res[0].mid;
        }
      }
      if (this.$refs.channel) {
        if (res && res.length) {
          this.$refs.channel.innerText = res[0].channel;
        }
      }
    });
    // updateMonitor()
  },
  methods: {
    confirmInput() {
      /*
        appkey
        appsecret
        mid
        channel
      */
      if (
        this.$refs.appkey &&
        this.$refs.appsecret &&
        this.$refs.mid &&
        this.$refs.channel
      ) {
        if (
          this.$refs.appkey.innerText &&
          this.$refs.appsecret.innerText &&
          this.$refs.mid.innerText &&
          this.$refs.channel.innerText
        ) {
          updateMonitor({
            ...this.newRes,
            appkey: this.$refs.appkey.innerText,
            appsecret: this.$refs.appsecret.innerText,
            mid: this.$refs.mid.innerText,
            channel: this.$refs.channel.innerText
          }).then(res => {
            if (!res) {
              this.$message.error("修改失败");
            } else {
              this.$message({
                type: "success",
                message: "修改成功"
              });
            }
          });
        } else {
          this.$message.error("请输入正确数据");
        }
      }
      // if (this.$refs.previewurl && this.$refs.accesstoken) {
      //   updateMonitor({
      //     ...this.newRes,
      //     appsecret: this.$refs.accesstoken.innerText,
      //     channel: this.$refs.previewurl.innerText
      //   }).then(res => {
      //     if (!res) {
      //       this.$message.error("修改失败");
      //     } else {
      //       this.$message({
      //         type: "success",
      //         message: "修改成功"
      //       });
      //     }
      //   });
      // }
    }
  }
};
</script>

<style lang="scss">
.monitor-total-wrapper {
  width: 80%;
  margin: 30px auto;
  padding: 20px;
  border-radius: 20px;
  box-shadow: 0 0 9px 1px #eee;
  .token-wrapper {
    display: flex;
    justify-content: center;
    margin: 30px auto;
    .access-token-title {
      flex-grow: 0;
      flex-shrink: 0;
      font-size: 14px;
      margin-right: 12px;
      min-width: 200px;
    }
    .access-token-input {
      flex-grow: 1;
      flex-shrink: 1;
      outline: none;
      border: 1px solid black;
      border-radius: 3px;
      // height: 20px;
      padding: 4px;
      font-size: 16px;
      line-height: 16px;
      max-width: 420px;
      white-space: pre;
      &::-webkit-scrollbar {
        display: none;
      }
    }
  }
  .serial-wrapper {
    display: flex;
    justify-content: center;
    margin: 30px auto;
    align-items: center;
    .serial-title {
      flex-grow: 0;
      flex-shrink: 0;
      font-size: 14px;
      margin-right: 12px;
    }
    .serial-input {
      flex-grow: 1;
      flex-shrink: 1;
      outline: none;
      border: 1px solid black;
      border-radius: 3px;
      padding: 4px;
      font-size: 16px;
      line-height: 16px;
      max-width: 420px;
      white-space: pre;
      overflow-x: scroll;
      &::-webkit-scrollbar {
        display: none;
      }
    }
  }
  .channel-wrapper {
    display: flex;
    justify-content: center;
    margin: 30px auto;
    .channel-title {
      flex-grow: 0;
      flex-shrink: 0;
      font-size: 14px;
      margin-right: 12px;
    }
    .channel-input {
      flex-grow: 1;
      flex-shrink: 1;
      outline: none;
      border: 1px solid black;
      height: 20px;
      padding: 2px;
      font-size: 16px;
      line-height: 16px;
      max-width: 420px;
      color: #09d0ff;
    }
  }
}
</style>
