<template>
  <div class="preview-protocol-wrapper dialog-title-border">
    <el-dialog
      title="用户协议"
      :model-value="dialogVisible"
      @close="close"
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="800px"
    >
      <template v-slot:title>
        <div style="text-align: left">
          <span style="font-weight: 700">用户协议</span>
        </div>
      </template>
      <div
        style="margin: 20px 20px; height: 400px; padding: 10px 0"
        v-html="protocolContent"
      ></div>
      <template v-slot:footer>
        <div class="dialog-footer">
          <el-button @click="close(false)">不同意</el-button>
          <el-button type="primary" @click="signProtocol">同意</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { $on, $off, $once, $emit } from '../../../../utils/gogocodeTransfer'
export default {
  data() {
    return {}
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    protocolId: {
      type: String | Number,
      default: 1,
    },
    protocolContent: {
      type: String,
      default: '',
    },
  },
  computed: {},
  mounted() {
    // this.getProtocolInfoById();
  },
  methods: {
    // 签署协议
    signProtocol() {
      let req = {
        setEntry: true,
      }
      this.POST('smartcontract/protocol/sign?type=' + this.protocolId, req)
        .then((res) => {
          if (res.code == '000000') {
            this.close(true)
          } else {
            vm.$message.info(res.message)
            this.close(false)
          }
        })
        .catch((err) => {
          vm.$message.warning('请稍后重试')
          this.close(false)
        })
    },

    close(status) {
      $emit(this, 'close', status)
    },
  },
  emits: ['close'],
}
</script>
