<template>
  <div class="cancellation-page">
    <div class="cancellation-page-wrap">
      <image
        src="../../assets/imgs/angrey.png"
        class="cancellation-img"
      ></image>
      <text class="issure">
        确定注销当前账号吗
      </text>
      <text class="issure_msg">
        注销后你将无法使用当前账号，相关数据也将被删除
      </text>
      <text class="issure_msg">
        无法找回
      </text>
      <div class="current_account">
        <text>当前账号:{{ loginPhone }}</text>
      </div>
    </div>
    <div class="notify-things">
      <text>注销前需要注意以下事项</text>
    </div>
    <div class="clean_money">
      <div class="clean_money_wrap">
        <text>账户书币余额清零</text>
        <text>当前书币余额{{ fee }}</text>
      </div>
      <div class="handle-button">
        <text @click="handleBack">
          去处理
        </text>
      </div>
    </div>
    <div class="cancellation-button">
      <text class="cancellation-button-wrap" @click="logOut">
        立即注销
      </text>
    </div>
  </div>
</template>

<script>
import storage from '@system.storage'
import { logOff } from '../../api/index'
import router from '@system.router'
import prompt from '@system.prompt'

export default {
  public: {
    haslogin: '',
    loginPhone: '',
    fee: 0
  },
  async onReady() {
    this.haslogin = (await storage.get({ key: 'hasLogin' })).data
    this.loginPhone = (await storage.get({ key: 'loginPhone' })).data
  },
  handleBack() {
    router.replace({ uri: '/views/Index' })
  },
  logOut() {
    prompt.showDialog({
      title: '温馨提示',
      message: '你确认要注销账户吗，注销将丢失之前的用户数据哦~',
      buttons: [
        {
          text: '确定注销',
          color: '#EF5952'
        },
        {
          text: '我再想想',
          color: '#999'
        }
      ],
      success: function(data) {
        console.log(data)
        if (data.index == 0) {
          console.log('开始注销---------')
          logOff().then(res => {
            storage.delete({
              key: 'hasLogin',
              success: function(data) {
                console.log('handling success')
              }
            })
            storage.delete({
              key: 'loginPhone',
              success: function(data) {
                console.log('handling success')
              }
            })

            prompt.showToast({
              message: '注销成功！即将回到首页'
            })

            router.replace({ uri: '/views/Index' })
          })
        }
      },
      cancel: () => {
        console.log('cancel')
      }
    })
  }
}
</script>

<style lang="less">
.cancellation-page {
  flex-direction: column;
  background-color: #f2f2f2;
  .cancellation-page-wrap {
    margin-top: 10px;
    padding-bottom: 50px;
    width: 100%;
    flex-direction: column;
    align-items: center;
    background-color: #fff;
    .cancellation-img {
      margin-top: 60px;
      margin-bottom: 30px;
    }
    .issure {
      font-size: 32px;
      font-weight: 600;
      margin-bottom: 30px;
    }
    .issure_msg {
      font-size: 26px;
    }
    .current_account {
      margin-top: 20px;
      flex-direction: row;
      background-color: #f5f5f5;
      border-radius: 10px;
      color: #000000;
      font-size: 26px;
      padding: 10px 30px;
      border-radius: 30px;
      text {
        margin: 0 auto;
      }
    }
  }
  .notify-things {
    margin-top: 30px;
    margin-bottom: 2px;
    background-color: #fff;
    padding: 30px;
    text {
      padding: 20px;
      font-size: 30px;
      font-weight: 500;
    }
  }
  .clean_money {
    padding: 30px;
    background-color: #fff;
    margin-top: 2px;
    justify-content: space-between;
    .clean_money_wrap {
      flex-direction: column;
    }
    .handle-button {
      background-color: #f34d2c;
      border-radius: 30px;
      width: 120px;
      height: 50px;
      text {
        color: #ffffff;
        text-align: center;
        margin: 0 auto;
      }
    }
  }
  .cancellation-button {
    padding: 30px;
    flex-direction: row;
    margin-top: 50px;
    border-radius: 10px;
    color: #000000;
    align-items: center;
    padding: 10px;
    .cancellation-button-wrap {
      font-size: 26px;
      background-color: #cccccc;
      border-radius: 70px;
      height: 70px;
      width: 550px;
      margin: 0 auto;
      text-align: center;
    }
  }
}
</style>
