<template>
	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='角色详情' bgColor="transparent"></cus-header>
		<div class="box">
			<div class="title adfac">角色形象</div>
			<div class="upload">
				<div class="sc">
						<div class="imgs">
							<image class="img1" :src="agentDto.avatar||'https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/6b55bb5f-14a8-450b-94e2-9e3fcdf1c843.png'"></image>
						</div>
				</div>
			</div>
		</div>
		<div class="box adfacjb">
			<div class="title">角色昵称</div>
			<input type="text" v-model="agentDto.agentName" placeholder="请输入角色昵称" placeholder-class="ph" disabled>
		</div>
		<div class="box">
			<div class="top adfacjb">
				<div class="title">设定描述</div>
			</div>
			<div class="desc"><u-textarea v-model="agentDto.systemPrompt" :focus="focus" autoHeight :maxlength="-1" border="none" disabled></u-textarea>			
			</div>
		</div>
		<div class="box adfacjb">
			<div class="title">声音</div>
			<div class="right adfac" @tap="show=true">
				<div class="mtext active">{{voiceText}}</div>
			</div>
		</div>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				agentId:'',
				deviceId:'',
				voiceText:'',
				agentDto:{
					"agentName": "",
					"asrModelId": "",
					"vadModelId": "",
					"llmModelId": "",
					"ttsModelId": "",
					"ttsVoiceId": "",
					"memModelId": "",
					"intentModelId": "",
					"systemPrompt": "",
					"langCode": "",
					"language": "",
					"deviceId": "",
					"chatHistoryConf": ""
				}
			}
		},
		onLoad(option) {
			if(option.agentId){
				this.agentId = option.agentId;
				this.getDetail();
			} 
		},
		methods:{
			getDetail(){
				this.$api.get(`/agent/${this.agentId}`).then(res=>{
					if(res.data.code!==0) return this.$showToast(res.data.msg)
					this.agentDto = {...this.agentDto,...res.data.data};
					this.getModelVoiceList();
				})
			},
			getModelVoiceList(){
				this.$api.get(`/models/${this.agentDto.ttsModelId}/voices`).then(res=>{
					if(res.data.code!==0) return this.$showToast(res.data.msg)
					this.voiceText = res.data.data.find(v=>v.id===this.agentDto.ttsVoiceId)?.name||'未选择音色';
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	::v-deep .desc .u-textarea{
		padding: 0 !important;
		background-color: transparent !important;
	}
	
	.ph{
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #A6A6A6;
		line-height: 40rpx;
		text-align: right;
	}
	.page{
		background: #F7F6F9;
		padding: 0 30rpx 30rpx;
		box-sizing: border-box;
		.box{
			background: #FFFFFF;
			border-radius: 24rpx;
			margin-top: 20rpx;
			width: 100%;
			padding: 40rpx 30rpx;
			box-sizing: border-box;
			
			.title{
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #111111;
				line-height: 32rpx;
				span{
					font-size: 32rpx;
					color: #F31616;
				}
			}
			.upload{
				margin-top: 12rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				.sc{
					width: 188rpx;
					height: 188rpx;
				}
				.text{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #A6A6A6;
					line-height: 37rpx;
					text-align: center;
					margin-top: 8rpx;
				}
			}
			.right{
				.mtext{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #A6A6A6;
					line-height: 40rpx;
					text-align: right;
					&.active{
						color: #111111;
					}
				}
				image{
					width: 36rpx;
					height: 36rpx;
					margin-left: 10rpx;
				}
			}
			.desc{
				margin-top: 20rpx;
				min-height: 200rpx;
				overflow-y: auto;
			}
			.tip{
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #1B50FF;
				line-height: 40rpx;
				text-align: right;
			}
			.imgs{
				width: 188rpx;
				height: 188rpx;
				border-radius: 50%;
				position: relative;
				.img1{
					width: 188rpx;
					height: 188rpx;
					border-radius: 50%;
					position: absolute;
					z-index: 2;
				}
				.img2{
					width: 42rpx;
					height: 42rpx;
					position: absolute;
					right: 0;
					bottom: 0;
					z-index: 3;
				}
			}
		}
		.zt_btn{
			margin-top: 54rpx;
		}
		input{
			border: none;
			text-align: right;
			font-size: 28rpx;
		}
	}
</style>