<template>
  <div>
    <div>
      <p class="agreement-txt">
        {{ content }}
      </p>
      <button
        type="button"
        class="btn btn-success"
        style="width: 100%;"
        @click="savePrivacyStatement"
      >
        同意（I agree with the privacy policy）
      </button>
    </div>
  </div>
</template>

<script>

import Common from '../common/Common.js';
import PrivacyStatementResource from '../api/base/PrivacyStatementResource.js';
import { SqlApi } from 'pc-component-v3';
import { Notify } from 'pc-component-v3';

export default {
  data:function(){
    return{
      content:null,
    };
  },

  mounted: function () {
    let _self = this;
    _self.readFile();
  },

  methods:{
    readFile:function (){
      let fileUrl = 'static/other/prodogTerm1.txt';
      let xhr = null,
        okStatus = document.location.protocol === 'file' ? 0 : 200;
      xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new XMLHttpRequest();      
      xhr.open('GET', fileUrl, false);
      xhr.overrideMimeType('text/html;charset=utf-8');
      xhr.send(null);
      this.content = xhr.status === okStatus ? xhr.responseText : null;
      // SqlApi.execute('20220726_194611', null).then(
      //   successData => {
      //     if (successData.errorCode == 0) {
      //       console.log(successData);
      //       let fileUrl = Common.getResourceUrl('file', 'com.leanwo.prodog.asset.model.AssetConfig', successData.results.privacyStatement);
      //       let xhr = null,
      //         okStatus = document.location.protocol === 'file' ? 0 : 200;
      //       xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new XMLHttpRequest();      
      //       xhr.open('GET', fileUrl, false);
      //       xhr.overrideMimeType('text/html;charset=utf-8');
      //       xhr.send(null);
      //       this.content = xhr.status === okStatus ? xhr.responseText : null;
      //     } else {
      //       Notify.error('查询隐私声明信息', successData.errorMessage, true);
      //     }
      //   },
      //   errorData => {
      //     Common.processException(errorData);
      //   },
      // );
      
    },

    /**
     * 保存隐私声明
     * @author XiongLiuJie
     * @date 2022-07-21
     */
    savePrivacyStatement: function () {
      let _self = this;
      let privacyStatementSaveRequest = {
        content: _self.content,
      };
      PrivacyStatementResource.savePrivacyStatement(
        privacyStatementSaveRequest,
      ).then(
        baseObjectResponse => {
          if (baseObjectResponse.errorCode === 0) {
            console.log(baseObjectResponse);
            _self.$emit('finishTask');
          }
        },
        errorData => {
          Common.processException(errorData);
        },
      );
    },
  },

};
</script>
<style>
.agreement-txt{
    height: 650px;
    text-align:left;
    font-size: x-large;
    white-space: break-spaces;
    font-family: Avenir, Helvetica, Arial, sans-serif;
}
</style>