<script lang="ts" setup>
import Taro from '@tarojs/taro';

const toPage = (url: string) => {
  if (url === '1') return Taro.showToast({title: '暂未开放', icon: 'none'});
  Taro.navigateTo({
    url: url,
  });
};

const logOut = () => {
  Taro.showModal({
    title: '提示',
    content: '确定退出登录吗？',
    success: function (res) {
      if (res.confirm) {
        Taro.removeStorageSync('token');
        Taro.removeStorageSync('userInfo');
        Taro.removeStorageSync('mer_type');
        Taro.reLaunch({
          url: '/pages/index/index',
        });
      } else if (res.cancel) {
        console.log('用户点击取消');
      }
    },
  });
};

const clickText = (type: number, text: string) => {
  Taro.navigateTo({
    url: `/pages/users/user_agreement/index?type=${type}&name=${text}`,
  });
};
</script>

<template>
  <view class="app">
    <nut-cell-group>
      <nut-cell
        title="个人信息"
        is-link
        @click="toPage('/pages/users/user_setting/index')"></nut-cell>
      <nut-cell
        title="服务协议"
        is-link
        @click="clickText(1, '用户协议')"></nut-cell>
      <nut-cell
        title="隐私政策协议"
        is-link
        @click="clickText(2, '隐私政策')"></nut-cell>
      <nut-cell
        title="平台积分使用规则"
        is-link
        @click="clickText(3, '积分使用规则')"></nut-cell>
      <nut-cell
        title="修改交易密码"
        is-link
        @click="toPage('/pages/users/pwd/index')"></nut-cell>
    </nut-cell-group>
    <view class="w-[90%] m-auto">
      <nut-button
        block
        type="primary"
        shape="square"
        style="border-radius: 10px"
        @click="logOut"
        >退出登录</nut-button
      >
    </view>
  </view>
</template>

<style lang="scss">
.app {
  width: 100%;
  height: 100vh;
  background-color: #f5f5f5;
}
</style>
