<template>
	<view>

		<scroll-view class="echo-tab-title" scroll-x="true" id="echo-tab-title" :scroll-into-view="'cateTab-'+cateIndex">
			<view v-for="(tab, index) in catelist" :key="index" :class="[cateIndex == index ? 'echo-tab-current' : '']" :id="'cateTab-'+index"
			 @tap="tabChange(index)">{{tab}}</view>
		</scroll-view>

		<view class="uni-list echo-myjobs-list">
			<block v-for="(item,index) in list" :key="index">
				<view class="uni-list-cell" hover-class="uni-list-cell-hover" @click="goDetails(item.id)">
					<view class="uni-media-list">
						<image class="uni-media-list-logo" mode="aspectFill" :src="item.tilpic"></image>
						<view class="uni-media-list-body">
							<view class="uni-media-list-text-top uni-ellipsis">
								{{item.title}}
							</view>
							<view class="uni-media-list-text-bottom uni-ellipsis">
								<text>{{item.tags}}</text>
							</view>
							<view class="uni-media-list-text-bottom">
								<text class="echo-wagall">{{item.minwagall}}-{{item.maxwagall}}元/月</text>
								<text class="wagbox1" v-if="item.status==1">{{item.wagstatus==1 ? '工价' : '补贴'}}：{{item.wagstatus==1 ? item.waghourvip : item.wagsubsidyvip}}</text>
								<text class="wagbox2" v-if="item.status==2">已停招：{{item.wagstatus==1 ? item.waghourvip : item.wagsubsidyvip}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="echo-myjobs-btn">
					<view hover-class="uni-list-cell-hover" @click="delStar(index)">取消关注</view>
					<view hover-class="uni-list-cell-hover" @click="goDetails(item.id)">查看详情</view>
				</view>
			</block>
		</view>
		<uni-load-more :status="pstatus"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var that;
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				catelist: ['全部', '招工中', '已停招'],
				cateIndex: 0,

				ppage: 1,
				pstatus: 'more',
				list: []
			}
		},
		onLoad: function() {
			that = this;
			that.userinfo = uni.getStorageSync('userinfo') || null;
			if (that.userinfo == null) {
				uni.reLaunch({
					url: "/pages/login/login"
				});
				return false;
			}
			that.getMore();
		},
		onPullDownRefresh: function() {
			that.ppage = 1;
			that.pstatus = 'more';
			that.list = [];
			that.getMore();
		},
		onReachBottom: function() {
			if (that.pstatus !== 'more') {
				return;
			}
			that.getMore();
		},
		methods: {
			getMore: function() {
				that.pstatus = 'loading';
				that.$req.ajax({
					data: {
						do: 'my',
						op: 'mystar',
						ppage: that.ppage,
						userid: that.userinfo.id,
						status: that.cateIndex
					}
				}).then((data) => {
					that.pstatus = data.pstatus;
					that.list = that.list.concat(data.list);
					that.ppage += 1;
					uni.stopPullDownRefresh();
				}).catch((err) => {
					console.log("err: " + JSON.stringify(err));
				});
			},
			// 取消关注
			delStar: function(index) {
				that.$req.ajax({
					title: "取消关注",
					data: {
						do: 'my',
						op: 'delstar',
						comjobsid: that.list[index].id,
						userid: that.userinfo == null ? 0 : that.userinfo.id
					}
				}).then((data) => {
					that.list.splice(index, 1);
				}).catch((err) => {
					console.log("err: " + JSON.stringify(err));
				});
			},
			goDetails: function(comjobsid) {
				uni.navigateTo({
					url: '/pages/comjobs/details?id=' + comjobsid
				});
			},
			tabChange: function(index) {
				that.cateIndex = index;
				that.ppage = 1;
				that.pstatus = 'more';
				that.list = [];
				that.getMore();
			},
		}
	}
</script>

<style lang="scss">
</style>
