<template>
	<view>
		<view class="demand-box" v-for="(item,index) in list" :key="index">
			<view>
				<text>时间:</text>
				<text class="demand-information">{{item.createdAt}}</text>
			</view>
			<view>
				<text>联系人:</text>
				<text class="demand-information">{{item.contacts}}</text>
			</view>
			<view>
				<text>联系电话:</text>
				<text class="demand-information">{{item.contactPhone}}</text>
			</view>
			<view>
				<text>内容:</text>
				<view class="demand-content">{{item.content}}</view>
			</view>
			<view v-if="item.isFile-0 === 1">
				<text>附件:</text>
				<text class="demand-information down-text" @click="jump(item.id)">点击此处浏览下载</text>
			</view>
		</view>
	</view>
</template>
<script>
	import { history } from 'api/history'
	
	export default {
		props: {
				typeList: {
				},
				num: {
					default:1
				}
		},
		data() {
			return {
				pageSize:3,
				list:[],
			};
		},
		methods:{
			jump(id){
				uni.navigateTo({
					url:`/pages/DownFile/DownFile?id=${id}`
				})
			}
		},
		async created(){
			const that = this
			try{
				const params = {
					param:{
						pageNum:that.num,
						pageSize:that.pageSize,
						sortL:that.typeList[1],
						type:that.typeList[0]
					}
				}
				const data = await history(params)
				// console.log(data)
				that.list = data.list
				for(let i=0;i<data.list.length;i++){
					let a = data.list[i].contacts.split('')
					a.splice(0,1,'*')
					that.list[i].contacts = a.join("")
				}
				for(let i=0;i<data.list.length;i++){
					let a = data.list[i].contactPhone.split('')
					a.splice(3,4,'*','*','*','*')
					that.list[i].contactPhone = a.join("")
				}
				console.log(that.list)
			}catch(e){
				//TODO handle the exception
				console.log(e)
			}
		},
		watch:{
			async typeList(val){
				console.log(val)
				const that = this
				try{
					const params = {
						param:{
							pageNum:that.pageNum,
							pageSize:that.pageSize,
							sort:val[1],
							type:val[0]
						}
					}
					const data = await history(params)
					console.log(data.list)
					that.list = data.list
					for(let i=0;i<data.list.length;i++){
						let a = data.list[i].contacts.split('')
						a.splice(0,1,'*')
						that.list[i].contacts = a.join("")
					}
					for(let i=0;i<data.list.length;i++){
						let a = data.list[i].contactPhone.split('')
						a.splice(3,4,'*','*','*','*')
						that.list[i].contactPhone = a.join("")
					}
				}catch(e){
					//TODO handle the exception
					console.log(e)
				}
			},
			async num(val){
				const that = this
				if(that.num === 1){
					try{
						const params = {
							param:{
								pageNum:that.pageNum,
								pageSize:that.pageSize,
								sort:val[1],
								type:val[0]
							}
						}
						const data = await history(params)
						console.log(data.list)
						that.list = data.list
						for(let i=0;i<data.list.length;i++){
							let a = data.list[i].contacts.split('')
							a.splice(0,1,'*')
							that.list[i].contacts = a.join("")
						}
						for(let i=0;i<data.list.length;i++){
							let a = data.list[i].contactPhone.split('')
							a.splice(3,4,'*','*','*','*')
							that.list[i].contactPhone = a.join("")
						}
					}catch(e){
						//TODO handle the exception
						console.log(e)
					}
				}else{
					try{
						const params = {
							param:{
								pageNum:val,
								pageSize:that.pageSize,
								sortL:that.typeList[1],
								type:that.typeList[0]
							}
						}
						const data = await history(params)
						for(let i=0;i<data.list.length;i++){
							let a = data.list[i].contacts.split('')
							a.splice(0,1,'*')
							data.list[i].contacts = a.join("")
						}
						for(let i=0;i<data.list.length;i++){
							let a = data.list[i].contactPhone.split('')
							a.splice(3,4,'*','*','*','*')
							data.list[i].contactPhone = a.join("")
						}
						console.log(data.list)
						that.list = that.list.concat(data.list)
					}catch(e){
						//TODO handle the exception
						console.log(e)
					}
				}
			},
			async '$store.state.policy.release'(val){
				const that = this
				try{
					const params1 = {
						param:{
							pageNum:that.num,
							pageSize:that.pageSize,
							sortL:that.typeList[1],
							type:that.typeList[0]
						}
					}
					const data1 = await history(params1)
					that.list = data1.list
					for(let i=0;i<data1.list.length;i++){
						let a = data1.list[i].contacts.split('')
						a.splice(0,1,'*')
						that.list[i].contacts = a.join("")
					}
					for(let i=0;i<data1.list.length;i++){
						let a = data1.list[i].contactPhone.split('')
						a.splice(3,4,'*','*','*','*')
						that.list[i].contactPhone = a.join("")
					}
				}catch(e){
					//TODO handle the exception
					console.log(e)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.demand-box{
	padding: 10px;
	margin: 10px;
	background-color: $white;
	border-radius: 5px;
	
	view{
		padding: 5px 0;
		position: relative;
		display: flex;
		
		.demand-information{
			position: absolute;
			right: 0;
		}
		.demand-content{
			padding: 10px;
			margin-left: 30upx;
			
			border: 1px solid $grey;
			border-radius: 10px;
			height: auto;
			min-height: 150upx;
			flex: 1;
		}

	}
}
.down-text{
	color: $blue;
}
</style>
