<!--
  Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.

  https://www.mall4j.com/

  未经允许，不可做商业用途！

  版权所有，侵权必究！
-->

<template>
  <view class="Mall4j page-cancellation login-success">
    <view class="top">
      <!-- <view class="img-text">
        <view class="circle">
          <image src="/static/images/search-col.png" mode="heightFix" />
        </view>
        <view class="text">当前登录</view>
      </view>
      <view class="text">我是昵称</view> -->
    </view>
    <view class="card">
      <view class="card-title">
        1. {{ $t('cancellation.cancellationNotice') }}
      </view>
      <view class="text">
        {{ $t('cancellation.cancellationCon') }}
      </view>
      <view class="text">
        1.1. {{ $t('cancellation.cancellationTips1') }}
      </view>
      <view class="text">
        1.2. {{ $t('cancellation.cancellationTips2') }}
      </view>
      <view class="text">
        1.3. {{ $t('cancellation.cancellationTips3') }}
      </view>
      <view class="text">
        1.4. {{ $t('cancellation.cancellationTips4') }}
      </view>
    </view>
    <!-- 其他登录方式 -->
    <view class="footer">
      <view class="logout-text">
        {{ $t('cancellation.cancellationConfirmTips') }}
      </view>
      <view class="logout-btn">
        <button
          class="btn-left"
          @tap="onCancellation"
        >
          {{ $t('cancellation.cancellationConfirm') }}
        </button>
        <button
          class="btn-right"
          @tap="onBack"
        >
          {{ $t('cancellation.cancellationCancel') }}
        </button>
      </view>
    </view>
  </view>
</template>

<script setup>

/**
   * 生命周期函数--监听页面加载
   */
onLoad(() => {
  // 头部导航标题
  uni.setNavigationBarTitle({
    title: $t('cancellation.accountCancellation')
  })
})

/**
   * 生命周期函数--监听页面显示
   */
onShow(() => {
  // 头部导航标题
  uni.setNavigationBarTitle({
    title: $t('cancellation.accountCancellation')
  })
})

const onBack = () => {
  uni.switchTab({
    url: '/pages/my/my'
  })
}
/**
   * 注销
   */
const onCancellation = () => {
  uni.showModal({
    title: '提示',
    content: '是否确认注销账号？',
    success: res => {
      if (res.confirm) {
        onDestroyUser(false)
      }
    }
  })
}
const onDestroyUser = (forceDestroy) => {
  const params = {
    url: '/mall4cloud_user/user/destroy_user?forceDestroy=' + forceDestroy,
    method: 'GET',
    withoutPrompting: true
  }
  http.request(params).then(() => {
    uni.removeStorageSync('cloudToken')
    uni.removeStorageSync('cloudLoginResult')
    uni.removeStorageSync('cloudExpiresTimeStamp')
    uni.removeStorageSync('cloudUserDetails')
    // 变更uuid (数据分析)
    uni.removeStorageSync('cloudOid')
    http.getOid()
    uni.reLaunch({
      url: '/package-user/pages/user-login/user-login'
    })
  }).catch(err => {
    // 弹窗
    if (err.code === 'A00001') {
      uni.showModal({
        title: '提示',
        content: err.msg,
        confirmText: '强制注销',
        success: res => {
          if (res.confirm) {
            onDestroyUser(true)
          }
        }
      })
    } else if (err.code === 'A06001') {
      uni.showModal({
        title: '提示',
        content: err.msg,
        showCancel: false
      })
    } else {
      uni.showToast({
        title: err.msg || 'Error',
        icon: 'none'
      })
    }
  })
}

</script>
<style lang="scss" scoped>
@use "./cancellation.scss";
</style>
