<!--
 * @Descripttion: 应用授权
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2020-10-16 10:18:02
 * @LastEditors: 无尘
 * @LastEditTime: 2020-10-20 16:21:58
-->
<template>
  <div class="app-auth-body">
    <div class="app-auth-head cursor-pointer" @click="toHome">
      <img src="../../assets/logo.png" alt="logo" /><span class="web-name">好办管理平台</span>
    </div>
    <div class="app-auth-info">
      <div class="app-info-body">
        <div class="app-info-title">应用授权</div>
        <div class="app-info-detail">
          <div class="flex app-top">
            <div class="app-img">
              <img :src="appInfo.iconUrl" alt="app" />
            </div>
            <div class="flex flex-column p-l-12 flex-space-between">
              <div class="font-14 color-303133 line-h-22">{{appInfo.applicationName}}</div>
              <div class="font-12 color-606266 line-h-20">{{appInfo.introduction}}</div>
            </div>
          </div>
          <div class="auth-rights">
            <div class="auth-rights-title font-14 color-909399">授权后将允许{{appInfo.applicationName || ''}}应用进行以下权限操作</div>
            <div>
              <ul>
                <li v-for="(item, index) in rightsList" class="font-14 color-303133" :key="index + 'right'">{{item.rightsName}}</li>
              </ul>
            </div>
          </div>
        </div>
        <form
          action="/application-auth-center/oauth/authorize"
          method="post">
          <input
            type="text"
            :value="appInfo.appId"
            style="display:none"
            name="appId"/>
          <input
            type="text"
            :value="appInfo.authorize"
            style="display:none"
            name="authorize"/>
          <input
            type="text"
            :value="appInfo.user_oauth_approval"
            style="display:none"
            name="user_oauth_approval"/>
          <input
            type="text"
            :value="appInfo.rights"
            style="display:none"
            name="rights"/>

          <div class="app-info-btn">
            <el-checkbox v-model="checkAuth" class="p-r-10" /><el-button type="text" @click="toProtocol">授权同意《达摩授权服务协议》</el-button><button
              id="btn"
              ref="submitBtn"
              :disabled="checkAuth ? false : true"
              type="submit"
              :class="['el-button el-button--primary', !checkAuth ? 'is-disabled' : '']">
              授权
            </button>
          </div>
        </form>

      </div>
    </div>
  </div>
</template>

<script>
import fetch from '@/api/app-controls';
const { getAuthAppDetail, getAppAuthInfo } = fetch;
export default {
  name: 'AppAuth',
  components: {},
  data() {
    return {
      appInfo: {
        appId: '',
        authorize: 'authorize',
        // eslint-disable-next-line
        user_oauth_approval: true,
        applicationName: '',
        introduction: '',
        iconUrl: 'https://pic01-10001430.image.myqcloud.com/69918371857506304/1594638566081_O1zMw.jpg',
        rights: '[]'
      },
      checkAuth: false,
      rightsList: []
    };
  },
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    const that = this;
    that.getAppData();
  },
  // methods
  methods: {
    /**
     * @description: 跳转工作台
     * @author: 无尘
     */
    toHome() {
      const that = this;
      that.$router.push('/app-list');
    },
    /**
     * @description: 跳转协议
     * @author: 无尘
     */
    toProtocol() {
      window.open('/haoban-4/#/gic-protocol', '_blank', 'noopener');
    },
    toAuthRights() {
      const that = this;
      that.$router.push('/');
    },
    /**
     * @description: 获取应用详情
     * @author: 无尘
     */
    getAppData() {
      const that = this;
      const param = {
        appId: that.$route.query.appId
      };
      getAuthAppDetail(param)
        .then(res => {
          that.appInfo = Object.assign(that.appInfo, res.result || {});
          that.getAuthInfo();
        })
        .catch(function(error) {
        });
    },
    /**
     * @description: 获取授权信息
     * @author: 无尘
     */
    getAuthInfo() {
      const that = this;
      const param = {
        appId: that.$route.query.appId
      };
      getAppAuthInfo(param)
        .then(res => {
          that.rightsList = res.result || [];
          that.appInfo.rights = JSON.stringify(res.result) || '[]';
        })
        .catch(function(error) {
        });
    }
  },
  watch: {}
};
</script>
<style lang='less' scoped>
  .line-h-22 {
    line-height: 22px;
  }
  .line-h-20 {
    line-height: 20px;
  }
  .app-auth-body {
    width: 100%;
    .app-auth-head {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      text-align: left;
      padding: 0 20px;
      height: 46px;
      color: #fff;
      background-color: #fff;
      -webkit-box-shadow: 0 4px 6px 0 rgba(221,227,237,.29);
      box-shadow: 0 4px 6px 0 rgba(221,227,237,.29);
      img {
        width: 22px;
      }
      .web-name {
        padding-left: 10px;
        font-size: 16px;
        font-weight: 600;
        color: #303133;
        line-height: 22px;
        background: -webkit-gradient(linear,right top,left top,from(#5b4adb),to(#2da8ff));
        background: linear-gradient(270deg,#5b4adb,#2da8ff);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
    }
    .app-auth-info {
      width: 100%;
      .app-info-body {
        width: 498px;
        min-height: 374px;
        margin: 50px auto;
        padding: 20px 30px;
        background: #FFFFFF;
        box-shadow: 0px 5px 9px 0px rgba(222, 222, 222, 0.28);
        box-sizing: border-box;
        .app-info-title {
          font-size: 16px;
          font-weight: 600;
          color: #303133;
          line-height: 22px;
        }
        .app-info-detail {
          min-height: 227px;
          margin-top: 25px;
          padding: 15px 20px;
          box-sizing: border-box;
          border: 1px solid #E4E7ED;
          .app-top {
            border-bottom: 1px solid #EBECF0;
            padding-bottom: 15px;
          }
          .app-img {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 42px;
            height: 42px;
            max-width: 42px;
            max-height: 42px;
            border-radius: 6px;
            img {
              max-width: 42px;
              max-height: 42px;
              border-radius: 6px;
            }
          }
          .app-name {
            font-weight: 600;
          }
          .auth-rights {
            .auth-rights-title {
              padding: 10px 0;
            }
            ul {
              li {
                line-height: 20px;
                margin-bottom: 5px;
              }
            }
          }
        }
      }
    }
    .app-info-btn {
      margin-top: 30px;
      text-align: right;
    }
  }

</style>
