<!-- 消息 -->
<template>
	<view id="information">
		<scroll-view scroll-y @scrolltolower="scrollGet" class="info-max-box">
			<view class="for-info-box" v-for="(item,index) in infoList" :key="index" @click="goInfoPage(item)">
				<img v-if='item.isApply==1' src="@/images/icon_xx_tz.png">
				<img v-if='item.isApply==2' src="@/images/icon_xx_tz.png">
				<img v-if='item.isApply!=1 && item.isApply!=2' src="@/images/icon_01.png">
				<view class="right-box">
					<view class="top-box">
						<view>{{item.isApply==1?'准入驳回':(item.isApply==2?item.remark:
						(item.isApply==3||item.isApply==-1?item.sendName:(item.isApply==4||item.isApply==5?item.remark:'')))}}</view>
						<view>{{item.isApply==1?item.subName:(item.isApply==2?'':
						(item.isApply==3||item.isApply==-1?item.deptName:(item.isApply==4||item.isApply==5?'':'')))}}</view>
						<view>{{item.newMessageDate}}</view>
					</view>
					<view class="bottom">{{item.newMessage}}</view>
				</view>
			</view>
			<view class="get-null-box" v-if="getData.nullDataType">暂无更多数据</view>
		</scroll-view>
		<tab-bar ref='infoAll'></tab-bar>
	</view>
</template>

<script>
    import { groupList,queryByMessage } from '@/api/index.js'
    import { tabBar } from '@/component/tabBar.vue'
	export default {
        components: {
            tabBar
        },
		data() {
			return {
				infoList:[],
				//列表请求参数
				getData:{
				    page:1,
					pageSize:20,
                    getType:true,
                    nullDataType:true,
				}
			}
		},
		onLoad() {

		},
		onShow(){

            this.clearData();
            this.getList();
            this.$refs.infoAll.getTotalList();

		},
		methods: {
            //清除
            clearData(){
                this.infoList = [];
                this.getData.page = 1;
                this.getData.getType = true;
                this.getData.nullDataType = true;
            },
            //去消息详情页面
            goInfoPage(item){

				if(item.isApply==1){

					uni.navigateTo({
					    url:'/pages/information/notPassInfo?item='+encodeURIComponent(JSON.stringify(item))
					})
				}else if(item.isApply==2){
					uni.navigateTo({
					    url: '/pages_manage/workbench/receiveCasuallyPat/casuallyPatInfo?item='+encodeURIComponent(JSON.stringify(item))
					});
				}else if(item.isApply==3 || item.isApply == -1){
					uni.navigateTo({
					    url:'/pages/information/informationInfo?item='+encodeURIComponent(JSON.stringify(item))
					})
				}else if(item.isApply==4){
					//记录详情-未执行  dynamicId       4
					let obj = {
						messageUserId:item.messageUserId,
						recordId:item.dynamicId
					}
					uni.navigateTo({
					    url:'/pages_manage/gradingControl/gradingControlDetail?item='+encodeURIComponent(JSON.stringify(obj))
					})
				}else if(item.isApply==5){
					//完成控制-页面   messageContext    5
					let obj = JSON.parse(item.messageContext);
					this.queryByMessage(obj,item.messageUserId)
					// obj.messageUserId = item.messageUserId
					// uni.navigateTo({
					//     url:'/pages/gradingControl/gradingControlAdd?obj='+encodeURIComponent(JSON.stringify(obj))
					// })
				}
            },
			async queryByMessage(obj,messageUserId){
				const {data} = await queryByMessage(obj);
				if(data.code == 200){
					uni.navigateTo({
						url:'/pages_manage/gradingControl/gradingControlAdd?item='+encodeURIComponent(JSON.stringify(data.data))+'&item2='+encodeURIComponent(JSON.stringify(data.data.detailList[0]))+'&messageUserId='+messageUserId
					})
				}
			},
            //滚动事件
            scrollGet(){
                if(this.getData.getType){
                    this.getData.page += 1;
                    this.getList();
                }
            },
            //获取列表数据
            async getList(){
                let self = this;
                let obj = {
                    pageNum:this.getData.page,
                    pageSize:this.getData.pageSize,
                };
                const {data} = await groupList(obj);
                if(data.code==200){
                    let newDataList = data.rows;
                    for(let i=0;i<newDataList.length;i++){
                        if(!newDataList[i].newMessageDate || newDataList[i].newMessageDate == null){
                            newDataList[i].newMessageDate = '';
						}else{
                            let timeOne = (new Date(newDataList[i].newMessageDate)).getTime();
                            newDataList[i].newMessageDate = self.formatDate(timeOne);
                            newDataList[i].newMessage = unescape(newDataList[i].newMessage);
                            let reg1 = RegExp(/<img/);
                            let reg2 = RegExp(/<iframe/);
                            if(newDataList[i].newMessage.match(reg1)){
                                newDataList[i].newMessage = "[图片]"
                            }if(newDataList[i].newMessage.match(reg2)){
                                newDataList[i].newMessage = "[视频]"
                            }else{
                                newDataList[i].newMessage=newDataList[i].newMessage.replace(/<\/?.+?>/g,"");
                            }
						}
					}
                    if(self.page==1){
                        if(data.rows.length > 0 && data.rows.length == self.getData.pageSize){
                            self.infoList = data.rows;
                        }else if(data.rows.length > 0 && data.rows.length != self.getData.pageSize){
                            self.infoList = data.rows;
                            self.getData.getType = false;
                            self.getData.nullDataType = true;
                        }else{
                            self.getData.getType = false;
                            self.getData.nullDataType = true;
                        }
                    }else{
                        if(data.rows.length > 0 && data.rows.length == self.getData.pageSize){
                            self.infoList = self.infoList.concat(data.rows)
                        }else if(data.rows.length > 0 && data.rows.length != self.getData.pageSize){
                            self.infoList = self.infoList.concat(data.rows);
                            self.getData.getType = false;
                            self.getData.nullDataType = true;
                        }else{
                            self.getData.getType = false;
                            self.getData.nullDataType = true;
                        }
                    }
                }
            },
            formatDate(date) {
                let newDate = new Date(date);
                let YY = newDate.getFullYear() + '-';
                let MM = (newDate.getMonth() + 1 < 10 ? '0' + (newDate.getMonth() + 1) : newDate.getMonth() + 1) + '-';
                let DD = (newDate.getDate() < 10 ? '0' + (newDate.getDate()) : newDate.getDate());
                return YY + MM + DD;
            },
		}
	}
</script>

<style lang="stylus" scoped>
	#information{
		height:100%;
		display flex
		background #fff
		.info-max-box{
			flex:1;
			overflow: scroll
			padding-bottom:100rpx;
			background #fff
			margin:0 20rpx;
			.for-info-box:nth-child(1){
				border:none;
			}
			.for-info-box{
				height:150rpx;
				border-top:1rpx solid #F5F5F5;
				display flex
				img{
					border-radius:50%;
					margin:25rpx 28rpx 25rpx 20rpx;
					width:100rpx;
					height:100rpx;
				}
				.right-box{
					flex:1;
					.top-box{
						display flex
						line-height:67rpx;
						margin-top:7rpx;
						view:nth-child(1){
							font-size:30rpx;
							color:#333333;
							margin-right:28rpx;
						}
						view:nth-child(2){

							font-size:24rpx;
							color:#CCCCCC;
							flex:1;
							white-space:nowrap;
							overflow:hidden;
							text-overflow:ellipsis;


						}
						view:nth-child(3){
							font-size:20rpx;
							color:#CCCCCC;
							text-align right;
						}
					}
					.bottom{
						width:530rpx;
						line-height:62rpx;
						font-size:25rpx;
						color: #666666;
						display block
						overflow:hidden;
						text-overflow:ellipsis;
						white-space:nowrap;
					}
				}
			}
			.get-null-box{
				height:100rpx;
				line-height:100rpx;
				color:#999;
				text-align center
			}
		}
	}
</style>
