<template>
  <div class="msgAuthBox">
    <!-- {{ authInfo }} -->
    <div class="authInfoBox" v-loading="authloading">
      <div class="rabchaser textAreaBox">
        <h4>公田rabchaser的Authorization</h4>
        <el-input
          type="textarea"
          :rows="5"
          placeholder="请输入内容"
          v-model="rabchaser"
        >
        </el-input>
      </div>
      <div class="dahan textAreaBox">
        <h4>大汉dahan的Cookie</h4>
        <el-input
          type="textarea"
          :rows="5"
          placeholder="请输入内容"
          v-model="dahan"
        >
        </el-input>
      </div>
      <div class="m2m10086 textAreaBox">
        <h4>公田m2m10086的Cookie</h4>
        <el-input
          type="textarea"
          :rows="5"
          placeholder="请输入内容"
          v-model="m2m10086"
        >
        </el-input>
      </div>
      <div class="lwwlkj textAreaBox">
        <h4>安徽lwwlkj的Cookie</h4>
        <el-input
          type="textarea"
          :rows="5"
          placeholder="请输入内容"
          v-model="lwwlkj"
        >
        </el-input>
      </div>
      <div class="btngrop">
        <el-button type="primary" class="authbtn" @click="refresh"
          >刷新</el-button
        >
        <el-button type="primary" class="authbtn" @click="authGo"
          >授权</el-button
        >
      </div>
    </div>
    <div class="logSet">
      <h4>日志设置</h4>
      <div class="logMain">
        <div class="top">
          <h2>noSpecData</h2>
          <el-input
            v-model="logset.noSpecData"
            placeholder="请输入内容"
          ></el-input>
          <!-- <b>(不上传specdata日志 ，默认为0)</b> -->
        </div>
        <div class="bottom">
          <h2>mTime</h2>
          <el-input v-model="logset.mTime" placeholder="请输入内容"></el-input>
          <!-- <b>(日志最后修改时间为多少秒以内 ，默认为0)</b> -->
        </div>
        <el-button type="primary" class="savebtn" @click="saveLog"
          >保存</el-button
        >
      </div>
    </div>
  </div>
</template>
<script>
import { getAuthApi, updateAuthApi } from "@/utils/api/index";

export default {
  name: "msgauth",
  components: {},
  data() {
    return {
      authloading: true,
      authInfo: "",
      rabchaser: "",
      dahan: "",
      m2m10086: "",
      lwwlkj: "",

      logset: {
        noSpecData: 0,
        mTime: 0,
      },
    };
  },
  computed: {},
  watch: {},
  created() {
    let logSetparam = JSON.parse(localStorage.getItem("logset"));
    if (logSetparam !== null) {
      this.logset = logSetparam;
    } else {
      this.logset = { noSpecData: 0, mTime: 0 };
    }
  },
  mounted() {
    this.getAuthfn();
  },
  methods: {
    getAuthfn() {
      this.authloading = true;
      getAuthApi()
        .then((res) => {
          console.log(res);
          if (res.code == 200) {
            this.authloading = false;
            this.authInfo = res.data;
            this.rabchaser = res.data.rabchaser;
            this.dahan = res.data.dahan;
            this.m2m10086 = res.data.m2m10086;
            this.lwwlkj = res.data.lwwlkj;
          } else {
            this.$message({
              duration: 1500,
              showClose: true,
              message: res.msg,
              type: "error",
            });
            this.authloading = false;
          }
        })
        .catch((err) => {});
    },
    //授权
    authGo() {
      this.authloading = true;
      updateAuthApi({
        rabchaser: this.rabchaser,
        dahan: this.dahan,
        m2m10086: this.m2m10086,
        lwwlkj: this.lwwlkj,
      })
        .then((res) => {
          console.log(res);
          if (res.code == 200) {
            this.authloading = false;
            this.$message({
              duration: 1500,
              showClose: true,
              message: "短信授权成功",
              type: "success",
            });
            this.getAuthfn();
          } else {
            this.$message({
              duration: 1500,
              showClose: true,
              message: res.msg,
              type: "error",
            });
            this.authloading = false;
          }
        })
        .catch((err) => {});
    },
    //更新
    refresh() {
      this.getAuthfn();
    },

    saveLog() {
      localStorage.setItem("logset", JSON.stringify(this.logset));
    },
  },
};
</script>
<style lang="less">
.msgAuthBox {
  height: calc(100% - 24px);
  width: calc(100% - 24px);
  padding: 12px;

  .authInfoBox {
    width: 100%;
    display: flex;
    flex-direction: column;
    .textAreaBox {
      display: flex;
      margin-bottom: 16px;
      justify-content: space-between;
      h4 {
        width: 100px;
      }
    }
    .btngrop {
      // display: flex;
      margin-left: auto;
      .authbtn {
        width: 80px;
      }
    }
  }
  .logSet {
    width: 300px;
    border: 1px solid #eee;
    padding: 12px;
    .logMain {
      .top,
      .bottom {
        display: flex;
        align-items: center;
        h2 {
          font-size: 14px;
          font-weight: normal;
          margin-right: 8px;
          text-align: right;
          width: 100px;
        }
      }
      .top {
        margin-bottom: 20px;
      }
      .savebtn {
        display: flex;
        margin-top: 12px;
        margin-left: auto;
      }
    }
  }
}
</style>
