<template>
	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='对话记录'></cus-header>
		<template v-if="list.length">
			<div class="list">
				<div class="item adfacjb" v-for="(item,index) in list" :key="index" @tap="toDetail(item)">
					<div class="i_l adfac">
						<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/9cb78d90-5d88-4bcf-984d-be4c6edbd3de.png"></image>
						<div class="info">
							<p>{{item.createdAt}}</p>
							<p class="name">{{'玩具名称'}}</p>
						</div>
					</div>
					<div class="i_r adfac">
						<text>{{item.chatCount}}条</text>
						<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/5c18aa1c-5d76-4d2e-9799-84464d1200f9.png"></image>
					</div>
				</div>
			</div>
		</template>
		<template v-else>
			<page-empty :height="'calc(100vh - 200rpx)'"></page-empty>
		</template>
	</view>
</template>

<script>
	import pageEmpty from '@/components/pageEmpty/index.vue'
	export default {
		components:{pageEmpty},
		data(){
			return {
				agentId:'',
				deviceId:'',
				page:1,
				limit:10,
				list:[],
				isOver:false
			}
		},
		onLoad(option) {
			this.agentId = option?.agentId;
			this.deviceId = option?.deviceId;
			this.getList()
		},
		onReachBottom() {
			if(this.isOver) return
			this.getList();
		},
		methods:{
			getList(){
				this.$api.get(`/agent/${this.agentId}/${this.deviceId}/sessions`,{page:this.page,limit:this.limit}).then(res=>{
					if(res.data.code!==0) return this.$showToast(res.data.msg)
					if(this.list.length<res.data.data.total){
						this.page++;
						this.list = [...this.list,...res.data.data.list];
					}else this.isOver = true
				})
			},
			toDetail(item){
				uni.navigateTo({
					url:`/pagesHome/dialogDetail?agentId=${this.agentId}&deviceId=${this.deviceId}&sessionId=${item.sessionId}`
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.page{
		background: #FFFFFF;
		padding: 0 30rpx 30rpx;
		box-sizing: border-box;
		.list{
			.item{
				margin-top: 72rpx;
				&:first-child{
					margin-top: 36rpx;
				}
				.i_l{
					image{
						width: 78rpx;
						height: 78rpx;
						border-radius: 50%;
					}
					.info{
						padding-left: 28rpx;
						p{
							font-family: PingFang-SC, PingFang-SC;
							font-weight: bold;
							font-size: 32rpx;
							color: #333333;
							line-height: 34rpx;
							&.name{
								font-weight: 400;
								font-size: 24rpx;
								color: #8D8D8D;
								line-height: 24rpx;
								margin-top: 20rpx;
							}
						}
					}
				}
				.i_r{
					text{
						font-family: PingFang-SC, PingFang-SC;
						font-weight: bold;
						font-size: 30rpx;
						color: #72832B;
						line-height: 30rpx;
					}
					image{
						width: 36rpx;
						height: 36rpx;
						margin-left: 10rpx;
					}
				}
			}
		}
	}
</style>