<template>
	<view class="content">
		<view class="list" v-if="type=='1'">
			<block v-for="(item,index) in pageList" :key="index">
				<view class="box" @click="toDetail(index)">
					<view class="hflex acenter">
						<view class="dian" v-if="item.is_read == 0"></view>
						<view class="title">{{item.title}}</view>
					</view>
					<u-parse :content="item.content"></u-parse>
				</view>
			</block>
		</view>
		<view class="list vflex acenter" v-if="type == '2'">
			<block v-for="(item,index) in pageList" :key="index">
				<view class="time">{{item.create_time}}</view>
				<view class="box">
					<view class="status" v-if="item.title == '买家拍下商品'">{{item.title}}</view>
					<view class="status" v-if="item.title == '买家已经付款'" style="color: #4D6DFF;">{{item.title}}</view>
					<view class="status" v-if="item.title == '订单被取消了'" style="color: #FF4D4D;">{{item.title}}</view>
					<view class="hflex acenter">
						<image :src="item.image" class="image" mode="aspectFill"></image>
						<view class="vflex jcenter">
							<view class="name">{{item.content}}</view>
							<view class="text">{{item.remark}}</view>
						</view>
					</view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	var that = ''
	export default {
		data() {
			return {
				id: '',
				pageList: [],
				page: 1,
				total: 1,
				type: '',
			}
		},
		onLoad(options) {
			that = this
			that.type = options.index
			// that.getList()
		},
		onShow() {
			that.getList()
		},
		methods: {
			getList() {
				console.log('type=' +that.type);
				$api.req({
					url: '/data/api.business.User/message_list',
					method: 'POST',
					data: {
						page:that.page,
						type: that.type
					}
				}, function(res) {
					console.log(res)
					if(res.code == 1) {
						
						if(that.page == 1) {
							that.pageList = res.data.data
						} else {
							that.pageList = that.pageList.concat(res.data.data)
						}
						that.total = res.data.length
					}
				})
			},
			// 查看详情
			toDetail(index) {
				$api.jump('/pages/mine/message/detail?id=' + that.pageList[index].id)
			},
			onReachBottom() {
				if (Number(that.page) * 15 >= Number(that.total)) {
					$api.info("没有更多了")
				} else {
					that.page++
					that.getList()
				}
				
			}
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #F4F4F4;
		padding: 0 30rpx;
		.list {
			width: 100%;
			.time {
				margin-top: 20rpx;
				max-width: 100%;
				width: max-content;
				text-align: center;
				font-size: 20rpx;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 28rpx;
				padding: 6rpx 24rpx;
				background: #CECECE;
				border-radius: 20rpx;
			}
			.box {
				width: 100%;
				box-sizing: border-box;
				padding: 20rpx 20rpx ;
				background-color: #fff;
				border-radius: 24rpx;
				margin-top: 20rpx;
				.dian {
					width: 12rpx;
					height: 12rpx;
					border-radius: 50%;
					background-color: #ff4646;
					margin-right: 8rpx;
				}
				.title {
					font-size: 32rpx;
					color: #222;
					font-weight: 600;
					margin-bottom: 20rpx;
				}
				.status {
					font-size: 26rpx;
					font-weight: 500;
					color: #FF874D;
					line-height: 36rpx;
					padding-bottom: 16rpx;
				}
				.image {
					width: 156rpx;
					height: 156rpx;
					border-radius: 16rpx;
					margin-right: 18rpx;
				}
				.name {
					font-size: 28rpx;
					font-weight: 400;
					color: #222222;
					line-height: 40rpx;
					max-width: 470rpx;
					text-overflow: ellipsis;
					overflow: hidden;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					box-orient: vertical;
					line-clamp: 2;
					-webkit-line-clamp: 2;
				}
				.text {
					font-size: 24rpx;
					font-weight: 400;
					color: #929292;
					line-height: 34rpx;
					padding-top: 22rpx;
				}
			}
		}
	}
</style>