<template>
	<view>
		<u-navbar 	:is-back="true"
					back-icon-color="#333333"
					title="打招呼的人" 
					:background="{ background: '#f0f0f0'}" 
					title-color="#000000"
					:title-bold="true" 
					title-size="34" 
					:border-bottom="false" 
					z-index="1001">
			<view slot="right" class="u-p-r-30 u-font-34" @click="clear()">
				<text :style="linkedUsers.length<1?'color:#909399;':'color:#000000'">清空</text>
			</view>				
		</u-navbar>
		<view class="u-p-30">
			<view  v-if="linkedUsers.length>0">
				<view class="u-p-b-20">
					<text>近三天</text>
				</view>
				<view v-for="(user,uIndex) in linkedUsers" :key="uIndex" 
						class="u-flex u-row-left u-col-center u-p-b-12">
					<view style="width:100rpx;" class="u-flex u-row-left u-col-center">
						<view @longpress="delUser(user,uIndex)">
							<u-image :src="user.avatar" :width="76" :height="76" border-radius="8rpx">
								<view 	slot="error"
										class="u-flex u-row-center u-col-center  u-p-t-10 "
										style="width: 76rpx;height: 76rpx;background-color: #f0f0f0;border-radius: 12rpx;">
									<view>
										<image src="/static/image/default/default-user/default-user.png"
												style="width: 40rpx;height: 40rpx;"></image>
									</view>
								</view>
							</u-image>
						</view>
					</view>
					<view 	@click="toPersonInfo(user)"
							style="width: 600rpx;"
							class="u-flex u-row-between u-col-center u-p-t-6  u-p-b-12 u-border-bottom">
						<view style="text-align: left;">
							<view class="u-line-1" style="font-size: 32rpx;color: #000000;">
								<text>{{user.nickName}}</text>
							</view>
							<view class="u-tips-color u-font-28">
								<text>{{user.userRemark}}</text>
							</view>
						</view>
						<template v-if="!idAdd(user)">
							<view  style="background-color: #f0f0f0;color: #000000;padding: 10rpx 20rpx;border-radius: 6rpx;text-align: center;font-size: 30rpx;">
								<text>查看</text>
							</view>
						</template>
						<template v-else>
							<view class="u-font-28" style="position:relative;top: -16rpx;color: #595b5f;">
								<text>已添加</text>
							</view>
						</template>
					</view>
				</view>
			</view>
			<view v-else style="padding-top: 40%;">
				<view style="text-align: center;color: #000000;font-size: 34rpx;">
					<text>暂时没有人向你打招呼</text>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				linkedUsers:[],
			};
		},
		onLoad:function(){
			this.linkedUsers=JSON.parse(JSON.stringify(this.vuex_linkedUsers));
		},
		methods:{
			idAdd:function(user){
				let that=this;
				if(that.vuex_yyyFriendList.length<1){
					return false;
				}else{
					for (var i = 0; i < that.vuex_yyyFriendList.length; i++) {
						let item= that.vuex_yyyFriendList[i];
						if(item.chatNumber==user.chatNumber){
							return true;
						}
					}
				}
				return false;
			},
			clear:function(){
				this.$u.vuex("vuex_linkedUsers",[]);
				this.$u.vuex("vuex_yyyFriendList",[]);
				this.$u.vuex("vuex_lastestZhuanFaUsers",[]);
				this.$u.vuex("yyy_current_user",null);
				this.linkedUsers=[];
			},
			toPersonInfo:function(user){
				let that=this;
				that.$u.vuex("yyy_current_user",user);
				this.$u.route({
					url:'/pages/tabbar/find/yaoyiyao/yaoyiyao-user-detail',
				});
			},
			delUser:function(user,index){
				let that=this;
				uni.showModal({
					title: '操作',
					content: user.sendTimeStr,
					cancelText:'删除',
					confirmText:'修改时间',
					editable:true,
					success: function (res) {
						if (res.confirm) {
							let newTime=res.content;
							if(newTime.length>0){
								that.linkedUsers[index].sendTimeStr=newTime;
								that.$u.vuex("vuex_linkedUsers",that.linkedUsers);
							}
							return;
						} else if (res.cancel) {
							that.linkedUsers.splice(index,1);
							that.$u.vuex("vuex_linkedUsers",that.linkedUsers);
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">

</style>
