<template>
	<view class="common">
		<view class="add" @click="handleAddUser">
			<icon class="iconfont icon-tianjia"></icon>添加成员
		</view>
		<view class="box" v-if="familayList.lenght!=0">
			<view class="list" v-for="(item ,index) in familayList" :key="index">
				<view class="left">
					<image :src="item.head_pic" class="image1" />
					<view class="name">
						<view class="title">
							{{item.nickname}}
						</view>
						<view class="title2">
							<text>{{item.gender==1?'男':'女'}}</text>
							<text>{{item.birthday}}</text>
						</view>
					</view>

				</view>
				<view class="right">
					<view class="edit" @click="editorInfo(item)">编辑</view>
					<view class="edit del" @click="handleDeldet(item.id,index)">删除</view>
				</view>
			</view>
		</view>
		<view v-else>
			没有数据了！
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	export default {
		data() {
			return {
				visible: false,
				ranklist: [],
			}
		},
		computed: {
			...mapState(["familayList", "user"])
		},
		onLoad() {},
		methods: {
			//删除
			handleDeldet(id, ind) {
				let that = this
				uni.showModal({
					title: '友情提示',
					content: '确定删除该成员吗',
					success: function(res) {
						if (res.confirm) {
							that.$model.getDelUser({
								id: id,
							}).then(res => {
								if (res.code != 0) return
								that.$tools.msg("删除成功！");
								that.familayList.splice(ind, 1)
								that.$store.commit('changeFamilay', that.familayList)
							})
						} else if (res.cancel) {
							that.$tools.msg("您已取消删除！");
						}
					}
				});
			},
			//编辑
			editorInfo(item) {
				uni.navigateTo({
					url: "/pages/index/userInfo?info=" + JSON.stringify(item)
				})
			},
			//添加
			handleAddUser() {
				uni.navigateTo({
					url: "/pages/index/userInfo"
				})
			},
		}
	}
</script>

<style scoped="scoped" lang="scss">
	.common {
		padding: 15px;
		background-color: #f7f7f7;
		min-height: calc(100vh - 30px);
	}

	.add {
		width: 100%;
		height: 30px;
		line-height: 30px;
		font-size: 14px;
		margin-bottom: 10px;
		color: #fff;
		border-radius: 15px;
		display: flex;
		justify-content: center;
		background: $btncolor;
	}

	.list {
		width: auto;
		background: #fff;
		display: flex;
		border-radius: 10px;
		margin-bottom: 15px;
		padding: 5px 15px;
		font-size: 14px;
		align-items: center;
		justify-content: space-between;

		.image1 {
			width: 55px;
			height: 55px;
			border-radius: 50%;
			margin-right: 15px;
		}
	}

	.left {
		width: 75%;
		display: flex;
		align-items: center;

		.title {
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}

		.title2 {
			margin-top: 10px;
			font-size: 12px;
			color: #999;

			text {
				margin-right: 10px;
			}
		}
	}

	.right {
		width: 25%;
		float: right;
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-end;

		.edit {
			width: 50px;
			padding: 5px 0;
			border-radius: 5px;
			color: $textcolor;
			text-align: center;
		}

		.del {
			color: $btncolor;
			margin-top: 5px
		}
	}
</style>