// pages/setting/pages/security/security.js
import {
	imgServerUrl
} from '../../../../config/config.js'
import {
	logout_new
} from '../../../../services/index'
import {
	rootUrl
} from '../../../../config/config'
var app = getApp()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		phone: '',
		rootUrl,
		imgServerUrl: imgServerUrl,
		visible: false,
		actions: [{
			name: '确定注销',
			color: '#0177FF',
			fontWeight: 500
		},
		{
			name: '取消',
			color: '#0177FF',
		},
		],
	},
	toPage(e) {
		const {
			url
		} = e.currentTarget.dataset;
		wx.navigateTo({
			url,
		})
	},
	cancellation() {
		this.setData({
			visible: true
		})
	},
	handel(e) {
		const {
			index
		} = e.detail;
		this.setData({
			visible: false
		})
		if (index === 0) {
			logout_new({}).then(data => {
				wx.removeStorageSync("user_id");
				wx.removeStorageSync("member_id");
				wx.removeStorageSync("user_token");
				wx.removeStorageSync("userInfo");
				app.globalData.userId = '';
				app.globalData.userToken = '';
				app.globalData.memberId = '';
				app.globalData.userInfo = null;
				wx.showToast({
					icon: 'none',
					mask: true,
					title: '注销成功',
					success: res => {
						setTimeout(function () {
							wx.switchTab({
								url: '/pages/index/index',
							})
						}, 1500)
					}
				})
			})
		}
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {

	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		wx.getStorage({
			key: 'phone',
			success: res => {
				const _data = res.data
				this.setData({
					phone: _data.substring(0, 3) + ' **** ' + _data.substring(7, 11)
				})
			}
		})
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})