<template>
	<view class="content">
		<view class="gq-list">
			<view class="gq-item" v-for="item in list" @click="goDetail(item)">
				<view class="gq-logo">
					<image src="" mode="" class=""></image>
				</view>
				<view class="store-name">
					{{item.staffName}}
				</view>
				<template v-if="type == 'gz'">
					<view class="info">
						<view class="info-tit">
							电话：
						</view>
						<view class="info-val">
							{{item.mobile}}
						</view>
					</view>
					<view class="info">
						<view class="info-tit">
							提成：
						</view>
						<view class="info-val">
							￥{{(item.reward*1).toFixed(2)}}
						</view>
					</view>
				</template>
				<template v-if="type == 'yg'">
					<view class="info">
						<view class="info-tit">
							职务：
						</view>
						<view class="info-val">
							{{item.departmentName}}
						</view>
					</view>
					<view class="info">
						<view class="info-tit">
							工号：
						</view>
						<view class="info-val">
							{{item.staffCode}}
						</view>
					</view>
				</template>
			</view>
		</view>
		<u-loadmore :status="loadingType" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadingType: 'loadmore',
				type: '',
				list: [],
				page: 1,
				pageSize: 24,
				loaded: false,
			}
		},
		onLoad(opt) {
			if (opt.type) {
				this.type = opt.type
				if (opt.type == 'gz') {
					uni.setNavigationBarTitle({
						title: '工资表'
					})
				}
				if (opt.type == 'yg') {
					uni.setNavigationBarTitle({
						title: '员工'
					})
				}
				this.loadData()
			}

		},
		onShow() {

		},
		onReachBottom() {
			this.loadData()
		},
		onReady() {

		},
		methods: {
			loadData(type) {
				let that = this
				if (type == 'reload') {
					that.loaded = false
					that.loadingType = 'loadmore'
					that.page = 1
					that.list = []
				}
				if (type == 'tab' && that.loaded) {
					return
				}
				if (that.loadingType == 'loading' || that.loadingType == 'nomore') {
					return
				}

				that.loadingType = 'loading'
					
					
				that.$u.api.getYgList({
					page: that.page,
					pageSize: that.pageSize
				}).then(({data}) => {
					that.list = that.list.concat(data)
					that.page++
					if(that.pageSize == data.length) {
						that.loadingType = 'loadmore'
					}else {
						that.loadingType = 'nomore'
					}
					that.loaded = true
				})

			},
			goDetail(item) {
				let that = this
				uni.navigateTo({
					url: that.type == 'gz' ? ('/pagesS/yg/gzdetail?id=' + item.id): ('/pagesS/yg/ygdetail?id=' + item.id)
				})
			}
		}
	}
</script>

<style lang="scss">
	.gq-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		// justify-content: space-between;
		padding: 20rpx 0 20rpx 20rpx;
	}

	.gq-item {
		margin: 0 0 20rpx 14rpx;
		width: 227rpx;
		// height: 351rpx;
		background: #FFFFFF;
		box-shadow: 0px 5rpx 5rpx 0px rgba(35, 24, 21, 0.06);
		border-radius: 10rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx 14rpx 20rpx;

		.gq-logo {
			width: 140rpx;
			height: 140rpx;
			border-radius: 50%;
			border: 1px solid #262261;
			display: flex;
			justify-content: center;
			align-items: center;
			image {
				width: 135rpx;
				height: 135rpx;
				background-color: #eee;
				border-radius: 50%;
			}
		}

		.store-name {
			padding-top: 10rpx;
			text-align: center;
			width: 100%;
			font-size: 26rpx;
			font-weight: 500;
			color: #262261;
			overflow: hidden;
		}

		.info {
			width: 100%;
			display: flex;
			padding: 5rpx 0;

			.info-tit {
				font-size: 18rpx;
				flex-shrink: 0;
			}

			.info-val {
				text-align: center;
				font-size: 20rpx;
				width: 140rpx;
				border-bottom: 1px #C7C7C7 solid;
			}
		}

	}
</style>
