<template>
	<view class="p-root-person-enrollList g_w_all g_bg_f_5 g_kuaishou">
		<view v-show="computeCode == -1" class="g_flex_column_center">
			<rh-loading marginBottom="g_mb_130" />
		</view>
		<view v-show="computeCode == 0" class="g_flex_column_center" style="height: 100vh;">
			<rh-empty text="暂无数据" style="padding-top: 160px;"></rh-empty>
		</view>
		<view v-show="computeCode > 0">
			<!-- 列表区 -->
			<!-- :style="{ height: `calc(${navInfo.windowHeight}px - ${navInfo.navigationBarHeight + navInfo.statusBarHeight}px)` }" -->
			<scroll-view class="m-list" id="listBox"
				:style="{ height: `${wheight}px)` }"
				:scroll-y="true" @scrolltolower="reachBottom">
				<view class="link">
					<view v-for="(item,index) in query.list" :key="index"
								class="item"
								@click="goDetail(item,index)"
					>
						<view class="g_flex_row_between">
							<view class="g_fs_16 g_fw_600 g_flex_1 g_ell_1">{{item.storeJobName}}</view>
							<view class="g_fs_14 g_c_9 g_flex_none g_ml_16">{{item.createTime}}</view>
						</view>
						<view class="g_flex_row_start_c g_mt_8 g_fs_14 g_c_6">
							<view v-if="item.addresa" class="g_mr_6">{{item.addresa}}</view>
							<view>{{item.ageStr}}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		onReady() {
			
		},
		onShareAppMessage() {
			return this.G.shareFun();
		},
		onLoad() {
			let that = this;
		},
		data() {
			return {
				wheight:uni.getSystemInfoSync().windowHeight,
				computeCode: -1,
				cdnBaseImg: this.G.store().cdnBaseImg,
				localBaseImg: this.G.store().localBaseImg,
				loading: true,
				speed: -1,
				query: {
					page: 1,
					size: 50,
					list: [],
					isFinish: -1,
				},
			};
		},
		onShow() {
			let that = this;
			that.getList();
		},
		onReachBottom() {
			let that = this;
			this.G.isLogin();
			if (this.G.isLogin()) {
				if (that.query.isFinish == -1 || that.query.isFinish == that.query.size) {
					that.query.page++;
					that.getList("concat");
				}
			}
		},
		methods: {
			getEmptyDom(text = "暂无数据", subText = ""){
			this.G.getEmptyDom(text, subText)
		},
			reachBottom() {
				let that = this;
				this.G.isLogin();
				if (this.G.isLogin()) {
					if (that.query.isFinish == -1 || that.query.isFinish == that.query.size) {
						that.query.page++;
						that.getList("concat");
					}
				}
			},
			getList($type = "init") {
				let that = this;
				that.G.Post(
					that.api.yi_my_apply_list, {
						pageNum: that.query.page,
						pageSize: that.query.size,
					},
					(res) => {
						console.log('我的报名：', res)
						that.computeCode = res.length;
						if (res.length == 0) {
							that.loading = false;
						} else {
							that.loading = true;
						}
						that.speed = res.length;
						that.query.isFinish = res.length;
						if(res && res.length > 0){
							res = that.G.toGetAddress(res);
							res = that.G.toGetAge(res);
							res = that.G.yijobCopy(res);
						}
						if ($type == "init") {
							that.query.list = [];
							that.query.list = res.map((item,index)=>{
								return {
									...item,
									createTime: that.G.getPointTime(item.createTime,'YY--MM--DD HH:MM'),
									ageStr:that.setAge(item),
									addresa:item.storeDistrict.split(',').join(' | '),
								}
							});
						} else {
							that.query.list = that.query.list.concat(res.map((item,index)=>{
								return {
									...item,
									createTime: that.G.getPointTime(item.createTime,'YY--MM--DD HH:MM'),
									ageStr:that.setAge(item),
									addresa:item.storeDistrict.split(',').join(' | '),
								}
							}));
						}
					}
				);
			},
			goDetail($item){
				console.log('前往详情页',$item)
				if($item.id){
					uni.navigateTo({
						url:'/root/person/enrollDetail?id=' + $item.id
					})
				}else{
					uni.showToast({
						icon:'none',
						title:'暂不支持查看'
					})
				}
			},
			setAge(item){
				let str = '';
				if (item.minAge && item.maxAge) {
				  item["age"] = item.minAge + '-' + item.maxAge + '岁';
				} else if (item.minAge) {
				  item["age"] = item.minAge + "岁以上";
				} else if (item.maxAge) {
				  item["age"] = item.maxAge + "岁以下";
				} else {
				  let newArr = [item.minAgeMan, item.maxAgeMan, item.minAgeWoman, item.maxAgeWoman]
				  newArr.sort()
				  // console.log('newArr', newArr)
				  let minAge = (newArr[0] == 0) ? newArr[2] : newArr[0]
				  let maxAge = newArr[3]
				  item["age"] = minAge + '-' + maxAge + '岁';
				}
				return item["age"];
			},
		},
	};
</script>

<style lang="scss">
	.p-root-person-enrollList {
		background-color: #ededed;
		min-height: 100%;
		.link{
			.item{
				background-color: #fff;
				border-top: 1px solid #eee;
				padding: 16px;
			}
		}
	}
</style>