<template>
	<view class="container">
    <view class="foot-item-box" v-for="(item, index) in list" :index="index" :key="index" >
      <view class="list-click-item" @click="clickItem(item)">
        <uni-icons class="listIconImage" :custom-prefix="item.iconType" :type="item.icon" size="20" :color="iconColor" ></uni-icons>
        <div class="text uni-white">{{item.title}}</div>
        <uni-icons type="right" size="12" color="#ffffff" />
      </view>
    </view>
	</view>
</template>

<script>
	import {
		logout
	} from '@/api/auth.js'
	export default {
		data() {
			return {
			  iconColor: '#0b6375',
        list: [{
          url: '/pages-userInfo/setting/compoSign',
          title: '艺术家合作协议',
          click: 'link',
          iconType: '',
          icon: 'compose'
        }, {
          url: '/pages-userInfo/setting/secretSign',
          title: '艺术家隐私协议',
          click: 'link',
          iconType: '',
          icon: 'eye-slash'
        }, {
          url: 'logoutUser',
          title: '注销登录',
          click: 'click',
          iconType: '',
          icon: 'redo'
        }
        ],
				userInfo:{}
			}
		},
		created() {
			const userInfo = uni.getStorageSync('userInfo')
			if (!userInfo) {
				console.log('havent userInfo')
				uni.showModal({
					content: '艺术家账户过期,请重新登录！',
					showCancel: false,
					success() {
						//没有缓存则跳转登录页面
						uni.reLaunch({
							url: '/pages/login/login'
						});
					}
				});
			} else {
				this.userInfo = userInfo;
				console.log('have userInfo')
			}
		},
		methods: {
			//注销
			logoutUser(){
				let that = this;
				uni.showModal({
				  title: "提示",
				  content: "确定注销吗！",
				  showCancel: true,
				  success: function(ress){
					  if(ress.confirm){
						 logout().then(res => {
						 	 if (res.data.code === 200) {
						 	   uni.reLaunch({
						 	   	url: '/pages/login/login',
								success() {
									uni.clearStorage();
									uni.showToast({
										title: '注销成功!',
										duration: 2000
									});
								}
						 	   });
						 	 } else {
						 	   uni.showModal({
						 	     content: "注销失败，请联系管理员!",
						 	     showCancel: false,
						 	   });
						 	 }
						 }); 
					  }
				  }
				});
			},
      clickItem(item) {
        if (item.click === 'link') {
          /** 跳转指定页面*/
          uni.navigateTo({
            url: item.url
          });
        } else if (item.click === 'click') {
          this[item.url]();
        }
      }
		}
	}
</script>

<style lang="scss" scoped>
.container {
  width: 670rpx;
  margin: 20rpx auto;

  .foot-item-box {
    width: calc(100% - 40rpx);
    background: #1d2734;
    border-radius: 20rpx;
    padding: 20rpx;
    margin-bottom: 20rpx;

    .list-click-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 60rpx;

      .listIconImage{
        width: 40rpx;
        height: 40rpx;
      }

      .text {
        font-size: 24rpx;
        line-height: 40rpx;
        width: 500rpx;
      }

    }

  }
}

</style>
