<template>
	<view>
		<nav-bar title="操作日志"></nav-bar>
		<view v-if="!listData.length"><u-empty text="操作日志为空" mode="message"></u-empty></view>
		<view v-else v-for="(item, index) in listData" :key="index" style="padding-bottom: 20rpx;" class="item">
			<view class="headers">
					<view class="header_left">
						<image :src="item.type === 1||item.type === 2 ? img1 : img2" style="width: 40rpx;height: 40rpx;margin-right: 10rpx;"></image>
						<text class="msgTitle">
							{{ (item.type === 1||item.type === 2 ? '登录日志' : '操作日志')}}
						</text>
					</view>
					<view class="header_right">{{ $method.timestampToTime(item.createTime, false) }}</view>
				</view>
				<u-line color="#D6D6DB" />
				<view style="display: flex;justify-content: space-between;padding: 25rpx;color: #666666;">
					操作内容：{{ item.type==1?"登录":item.type==2?"退出登录":item.type==3?"修改密码":item.type==4?"修改个人信息":"其他"}}
				</view>
				<u-line color="#D6D6DB" />
		</view>
		<u-divider v-if="totals !== 0 && listData.length === totals" bg-color="#eaeef1">到底了</u-divider>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';
export default {
	components: {},
	data() {
		return {
			current: 0,
			img1: '/static/icon/msg_icon1.png',
			img2: '/static/icon/msg_icon2.png',
			listData: [],
			totals: 0,
			formData: {
				pageNum: 1,
				pageSize: 10
			}
		};
	},
	onPullDownRefresh() {
		this.formData.pageNum = 1
		this.$api
			.userloglist(this.formData)
			.then(res => {
				if (res.data.code === 200) {
					this.listData = res.data.rows;
					this.totals = res.data.total;
				}
			})
			.finally(() => {
				uni.stopPullDownRefresh();
			});
	},
	onLoad(option) {
		this.$store.getters.dictObj;
		this.getInfo();
	},
	onShow() {
		// this.getInfo();
	},
	onShareAppMessage(res) {
		return {
			title: '中正',
			path: `/pages/index/index?inviteCode=` + userInfo == null ? '' : userInfo.userAccount
		};
	},
	methods: {
		getInfo() {
			this.$api.userloglist(this.formData).then(res => {
				if (res.data.code === 200) {
					this.listData = res.data.rows;
					this.totals = res.data.total;
				}
			});
		},
		againGetApi() {
			this.$api.userloglist(this.formData).then(res => {
				if (res.data.code === 200) {
					this.listData = this.listData.concat(res.data.rows);
				}
			});
		}
	},
	onReachBottom() {
		if (this.listData.length < this.totals) {
			this.formData.pageNum++;
			this.againGetApi();
		}
	},
	computed: { ...mapGetters(['userInfo']) }
};
</script>
<style>
page {
	background: #eaeef1;
}
</style>
<style lang="scss" scoped>
.btn2 {
	width: 144rpx;
	height: 48rpx;
	background: #ffffff;
	border: 2rpx solid #007aff;
	border-radius: 16rpx;
	text-align: center;
	line-height: 48rpx;
	color: #007aff;
	margin: 0 8rpx;
}
.btn1 {
	width: 144rpx;
	height: 48rpx;
	background: #ffffff;
	border: 2rpx solid #999999;
	border-radius: 16rpx;
	text-align: center;
	line-height: 48rpx;
	color: #999999;
	margin: 0 8rpx;
}
.item {
	background: #ffffff;
	border-radius: 16rpx;
	padding: 15rpx;
}
.priceTag {
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #ff2d55;
	display: flex;
	flex-direction: row-reverse;
}

.bottomBox {
	position: fixed;
	bottom: 0;
	width: 100%;
	left: 0;
	height: 98rpx;
	background-color: #ffffff;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0 30rpx;
}
.headers {
	display: flex;
	justify-content: space-between;
	align-items: center;
	height: 60rpx;
	.header_left {
		color: #333333;
		font-size: 30rpx;
		font-weight: bold;
		display: flex;
		align-items: center;
	}
	.header_right {
		color: #999999;
		font-size: 24rpx;
	}
}
.msgTitle {
	width: 420rpx;
	overflow: hidden;
	text-overflow:ellipsis; 
	white-space: nowrap;
}
</style>
