<template>
	<view>

		<view class="u-page">
			<u-swipe-action :show="item.show" :index="index" v-for="(item, index) in msgList" :key="item.id" @click="click" @content-click="inSystem" @open="open"
			 :options="options">
				<view class="item u-border-bottom">
					<image mode="aspectFill" :src="item.images" />
					<!-- 此层wrap在此为必写的，否则可能会出现标题定位错误 -->
					<view class="title-wrap">
						<text class="title u-line-2">{{ item.title }}</text>
						<view class="title-wrap-one">
							【{{ item.text }} 】
						</view>
					</view>
					<view class="title-wrap-two">
						<view>
							{{ item.time }}
						</view>
						<view>
							{{ item.ip }}
						</view>
					</view>
				</view>
			</u-swipe-action>
		</view>
		<!-- <u-tabbar v-model="current" :list="list"></u-tabbar> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				msgList: [{
						id: 1,
						ip: 1,
						time: '14.23',
						title: '青岛市市北区赛轮轮胎经销部',
						text: '订单信息',
						images: 'https://cdn.uviewui.com/uview/common/logo.png',
						show: false
					},
					{
						id: 2,
						ip: 2,
						time: '17.23',
						title: '青岛市市北区赛轮轮胎经销部',
						text: '订单信息',
						images: 'https://cdn.uviewui.com/uview/common/logo.png',
						show: false
					},
					{
						id: 3,
						ip: 3,
						time: '19.23',
						title: '青岛市市北区赛轮轮胎经销部',
						text: '订单信息',
						images: 'https://cdn.uviewui.com/uview/common/logo.png',
						show: false,
					}
				],
				disabled: false,
				btnWidth: 180,
				show: false,
				options: [{
						text: '收藏',
						style: {
							backgroundColor: '#007aff'
						}
					},
					{
						text: '删除',
						style: {
							backgroundColor: '#dd524d'
						}
					}
				]
			};
		},
		methods: {
			click(index, index1) {
				if (index1 == 1) {
					this.list.splice(index, 1);
					this.$u.toast(`删除了第${index}个cell`);
				} else {
					this.list[index].show = false;
					this.$u.toast(`收藏成功`);
				}
			},
			// 如果打开一个的时候，不需要关闭其他，则无需实现本方法
			open(index) {
				// 先将正在被操作的swipeAction标记为打开状态，否则由于props的特性限制，
				// 原本为'false'，再次设置为'false'会无效
				this.list[index].show = true;
				this.list.map((val, idx) => {
					if (index != idx) this.list[idx].show = false;
				})
			},
			inSystem(){
				this.$u.route({
					url: 'pages/msg/System-message/index',
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.item {
		display: flex;
		padding: 20rpx;
	}

	image {
		width: 120rpx;
		flex: 0 0 120rpx;
		height: 120rpx;
		margin-right: 20rpx;
		border-radius: 12rpx;
	}

	.title {
		text-align: left;
		font-size: 29rpx;
		color: #333333;
		font-weight: bold;
		margin-top: 20rpx;
	}

	.title-wrap-one {
		margin-top: 10rpx;
		font-size: 23rpx;
		color: #999999;
	}

	.title-wrap-two {
		margin-left: 120rpx;
		margin-top: 10rpx;
	}

	.title-wrap-two>view:nth-child(1) {
		font-size: 19rpx;
		color: #999999;
	}

	.title-wrap-two>view:nth-child(2) {
		width: 35rpx;
		height: 35rpx;
		background: #FC3228;
		border-radius: 50%;
		color: #fff;
		text-align: center;
		font-size: 19rpx;
		margin: 0 auto;
		margin-top: 5rpx;
	}
</style>
