<template>
	<view>
		<block v-for="(item,index) in plist" :key="index">
			<view class="cu-card dynamic no-card solid-bottom echo-comjobs-item padding-top-sm padding-lr-sm radius" @tap="join(item.id)">
				<view class="cu-item shadow padding-top-sm padding-bottom">
					<view class="padding-lr flex justify-between align-center">
						<view class="basis-lg text-bold text-lg text-cut">{{item.title}}</view>
					</view>
					<view class="padding-lr flex justify-between align-bottom">
						<view class="basis-lg text-bold text-df text-cut">
							<view class="text-gray">{{item.contact}}</view>
						</view>
						<view class="basis-sm text-cut text-right text-gray text-sm">
							{{item.mobile}}
						</view>
					</view>
					<view class="padding-lr padding-tb-xs text-cut">
						<view class="basis-sm text-cut text-left text-gray text-sm">{{item.address}}</view>
					</view>
				</view>
			</view>
		</block>
		<uni-load-more :status="pstatus"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var _this;
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				userinfo: {},
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: []
			};
		},
		onLoad: function(){
			_this = this;
			_this.userinfo = _this.checkLogin("/pages/train/list");
			if (_this.userinfo===false){
				return false;
			}
			_this.getMore();
		},
		onPullDownRefresh: function() {
			_this.ppage = 1;
			_this.pstatus = 'more';
			_this.plist = [];
			_this.getMore();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		methods: {
			join: function(id) {
				uni.showModal({
					title: '温馨提示',
					content: '确定要添加吗？',
					success(res) {
						if (res.confirm) {
							_this.$req.ajax({
								path: "train/join",
								data: {
									train_id: id,
									userid: _this.userinfo.id
								}
							}).then((data) => {
								uni.showModal({
									title: '添加成功',
									content: '恭喜您已报名成功!具体开班时间视报名人数而定,会有老师统一通知,如需加急或有其他疑问,可同柯老师联系,联系电话18659000595 （微信同号）。',
									showCancel: false,
									success: (res) => {
										if(res.confirm) {  
											uni.navigateBack();
										}
									} 
							});
							}).catch((err) => {
								uni.showModal({
									title: '信息提示',
									content: err,
									showCancel: false
								});
							});
						}
					}
				});
				
			},
			getMore: function() {
				_this.$req.ajax({
					path: "train/list",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						userid: _this.userinfo.id
					}
				}).then((data) => {
					_this.pstatus = data.pstatus;
					_this.plist = _this.plist.concat(data.plist);
					_this.ppage += 1;
					uni.stopPullDownRefresh();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			}
		}
	}
</script>

<style>
</style>
