<template>
	<view class="followRecord_wrap">
		<rxl-timeline class="followRecord_timeLine_wrap" v-if="!isEmpty(dataList)">
			<rxl-timeline-item :timestamp="key" :size="10" color="#108cff" v-for="(followList,key,index) in dataList"
				:key="key+index">
				<view slot="body">
					<view class="body_wrap" v-for="(item) in followList" :key="item.id">
						<view class="body_top">
							<view class="body_top_left">
								<image src="@/static/case/icon-avatar.png" mode=""></image>
								<text class="follow">{{item.createNickname}}</text>
							</view>
							<view class="body_top_right" @click="handleDelete(item)">
								删除
							</view>
						</view>
						<view class="body_center">
							{{item.content}}
						</view>
						<view class="body_bottom">
							<u-icon name="clock" color="#C0C0C7"></u-icon>
							<text class="date">{{item.createTime}}</text>
						</view>
					</view>
				</view>
			</rxl-timeline-item>
		</rxl-timeline>
		<view v-else class="empty_wrap">
			暂无跟进记录
		</view>
		
		<u-modal :show="showModal"
			@confirm="confirm" 
			ref="uModal" 
			:asyncClose="true" 
			showCancelButton
			@cancel="showModal = false"
			cancelColor="#409eff"
			:confirmText="'删除'" confirmColor="#f8836c">
			<view class="modal_box">
				确定要删除跟进记录
			</view>
		</u-modal>
	</view>
</template>
<script>
	import {
		groupBy,
		isEmpty
	} from "lodash";
	export default {
		props: {
			clueId: {
				required: true
			}
		},
		data() {
			return {
				list: [0, 1],
				dataList: {},
				
				showModal: false,
				currentDeleteFollowId : undefined
			}
		},
		methods: {
			handleDelete(item){
				const { id } = item;
				this.currentDeleteFollowId = id;
				this.showModal = true;
			},
			isEmpty,
			async getCaseFollowList() {
				const {
					data
				} = await uni.$u.api.getClueFollowList({
					clueId: this.clueId
				});
				this.dataList = data;
			},
			async confirm() {
				await uni.$u.api.deleteClueFollow([this.currentDeleteFollowId]);
				uni.$u.toast("删除成功");
				this.getCaseFollowList();
				this.showModal = false;
			},
		},
		mounted() {
			this.getCaseFollowList();
		},
		beforeDestroy(){
			uni.$off('addFollowSuccess');  
		},
		created() {
			uni.$on('addFollowSuccess',()=>{
				this.getCaseFollowList();
			});
		}
	}
</script>
<style lang="scss" scoped>
	.followRecord_wrap {
		min-height: 400px;
		background: #f5f6f8;
		position: relative;

		.empty_wrap {
			text-align: center;
			color: #999999;
			position: absolute;
			left: 50%;
			top: 50%;
			transform: translate(-50%, -50%);
		}
	}

	.followRecord_timeLine_wrap {
		background: #ffffff;

		.timeline-item {
			&:last-child {
				::v-deep .left-line .timeline-item-tail {
					display: none;
				}
			}
		}
	}

	.body_wrap {
		margin-bottom: 20rpx;
		background-color: #f6f7f8;
		padding: 20rpx;
		border-radius: 20rpx;

		&:last-child {
			margin-bottom: 0;
		}

		.body_top {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.body_top_left {
				display: flex;
				align-items: center;

				image {
					width: 46rpx;
					height: 46rpx;
					margin-right: 12rpx;
				}

				.follow {
					color: #202020;
					font-size: 30rpx;
					margin-right: 12rpx;
				}

				.debt {
					color: #999999;
					font-size: 24rpx;
				}
			}

			.body_top_right {
				color: #108CFF;
				font-size: 24rpx;
			}
		}

		.body_center {
			margin: 30rpx 0;
			padding-left: 56rpx;
			overflow: hidden;
		}

		.body_bottom {
			display: flex;
			padding-left: 56rpx;

			::v-deep .u-icon__icon {
				font-size: 24rpx !important;
			}

			.date {
				color: #c0c0c7;
				font-size: 22rpx;
				margin-left: 10rpx;
			}
		}
	}
</style>