<template>
	<view class="translation">
		<view style="width: 690rpx;height: 64rpx;margin: 0 auto;margin-top: 30rpx;background: #F2F2F2;border-radius: 32rpx;
		display: flex;align-items: center;">
			<view style="width: 10%;height: 64rpx;display: flex;align-items: center;">
				<image style="width: 28rpx;height: 28rpx;margin-left: 30rpx;" src="/static/images/search.png" mode=""></image>
			</view>
			<view style="width: 90%;height: 64rpx;display: flex;align-items: center;">
				<input type="text" @input="searchinfo" :disabled="disabled" v-model="keyword" placeholder="请输入关键字"
				style="width: 100%;color: #999999;font-size: 24rpx;"/>
			</view>
		</view>
		<view style="width: 690rpx;margin: 0 auto;margin-top: 10rpx;">
			
			<view style="width: 100%;border-bottom: 1px solid #E0E0E0;display: flex;padding-bottom: 10rpx;margin-top: 40rpx;"
			v-for="(item,index) in listarr" :key='index' @click="toaidoinfo(item.Content,item.corpusId,item.index)">
				<view style="width: 26rpx;height: 36rpx;margin-top: 4rpx;">
					<image style="width: 26rpx;height: 28rpx;" src="/static/images/testimg.png" mode=""></image>
				</view>
				<view v-html="item.Content.text" style="color: #666666;font-size: 28rpx;line-height: 36rpx;margin-left: 10rpx;width: 80%;"></view>
				<view style="font-size: 28rpx;width: 10%;width: 14%;text-align: right;">{{item.Content.time}}</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	var util = require("../../../utils/util.js");
	var config = require("../../../config");
	export default {
		data() {
			return {
				customerId:'',
				listarr:[],
				keyword:'',
				skpl:'',
				disabled:false,
				tipsFncEvent: "",
			};
		},
		onLoad(options) {
			this.customerId = options.customerId;
			this.keyword=options.keyword;
			this.skpl=options.skpl;
			if (options.UpDateEvent) this.tipsFncEvent = options.UpDateEvent
			
		},
		methods: {
			formatTime(num) {
				//格式化时间格式
				num = num.toFixed(0);
				let second = num % 60;
				if (second < 10) second = '0' + second;
				let min = Math.floor(num / 60);
				if (min < 10) min = '0' + min;
				return min + ":" + second;
			},
			searchinfo(){
				if(this.keyword.length==0){
					return
				}else{
					let parames={
						keyword:this.keyword,
						customerId:this.customerId
					}
					this.$u.post("/corpus/keyWordsMatching", parames).then(res => {
						res.forEach(item=>{
							item.Content=JSON.parse(item.transferContent)
						})
						res.forEach(cet=>{
							cet.Content.time=this.formatTime(cet.Content.bg/1000)
							cet.Content.text=this.brightKeyword(cet.Content.onebest)
						})
						this.listarr=res;
					})
				}
			},
			//替换方法
			brightKeyword(val) {
				if (val.indexOf(this.keyword) !== -1) {
					return val.replace(this.keyword, `<font style='color: red'>${this.keyword}</font>`);
				} else {
					return val;
				}
			},
			//跳转
			toaidoinfo(item,id,index){
				item.customerId=this.customerId;
				item.id=id;
				item.index=index;
				
				if(this.skpl==2){
					this.infostust(item)
				}else{
					let pages = getCurrentPages()  //获取当前页面栈的信息
					let prevPage = pages[pages.length - 2]   //获取上一个页面
					uni.$emit(this.tipsFncEvent, item)
					prevPage.setData({   //把需要回传的值保存到上一个页面
					  info: item
					});
					 wx.navigateBack({   //然后返回上一个页面
					  delta: 1
					})
				}
			},
			//只有一条的时候
			infostust(item){
				let d = JSON.parse(JSON.stringify([item]))
				var itemobjhh={
					bg:d[0].bg,
					customerId:d[0].customerId,
					id:'',
					onebest:d[0].onebest,
				}
				const parames = {
					pageNum: 1,
					pageSize: 100,
					query: {
						customerId: this.customerId,
					}
				}
				console.log(item)
				this.$u.post("/corpus/findByPage", parames).then(res => {
					if(res[0].merge==0){
						let newobj = res[0];
						uni.navigateTo({
							url: `/pages/learning/Thefulltext/index2?customerId=${newobj.customerId}&status=${newobj.status}&itemobj=${JSON.stringify(itemobjhh)}&stateisshow=${'2'}`
						})
					}else{
						let newobj = res[0];
						uni.navigateTo({
							url: `/pages/learning/Thefulltext/index?customerId=${newobj.customerId}&status=${newobj.status}&itemobj=${JSON.stringify(itemobjhh)}&stateisshow=${'2'}`
						})
					}
				})
			},
			
		},
	}
</script>
<style lang="scss" scoped>

</style>
