<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">
				<view class="cu-item shadow padding-top-sm padding-bottom" @tap="goDetail(item.comjobs.id)">
					<view class="padding-lr flex justify-between align-center">
						<view class="basis-lg text-bold text-df text-cut">
							{{item.comjobs.title}}
							<text class="text-red text-sm" v-if="item.comjobs.wtype==1">(按月)</text>
							<text class="text-red text-sm" v-if="item.comjobs.wtype==2">(按时)</text>
							<text class="text-red text-sm" v-if="item.comjobs.wtype==3">(按件)</text>
							<text class="text-red text-sm" v-if="item.comjobs.wtype==4">(按项目)</text>
						</view>
						<view class="basis-sm text-cut text-right text-gray text-sm">
							<view class="basis-xs text-cut text-right text-gray text-sm" @tap.stop="delStar(index, item.id)">取消关注</view>
						</view>
					</view>
					<view class="padding-lr flex justify-between align-bottom" @tap="goDetail(item.comjobs.id)">
						<view><text class="text-red text-bold">{{item.comjobs.zwagall}}</text></view>
					</view>
					<view class="padding-lr padding-tb-xs text-cut">
						<view v-for="(titem,tindex) in item.comjobs.tags" :key="tindex" class="cu-tag light bg-blue lg echo-tags-item">{{titem}}</view>
					</view>
					<view class="padding-lr text-cut text-sm flex justify-between align-center">
						<view class="basis-lg text-df text-cut">{{item.comjobs.worker.title}}</view>
						<view class="basis-sm text-cut text-right text-sm">
							浏览量:{{item.comjobs.volume}}
						</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/comjobs/star");
			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: {
			delStar: function(index,starid) {
				_this.$req.ajax({
					path: "comjobs/delstar",
					data: {
						starid: starid,
						userid: _this.userinfo.id
					}
				}).then((data) => {
					_this.plist.splice(index, 1);
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			getMore: function() {
				_this.$req.ajax({
					path: "comjobs/liststar",
					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
					});
				});
			},
			goDetail: function(comjobsid) {
				uni.navigateTo({
					url: '/pages/comjobs/detail?comjobsid=' + comjobsid
				});
			},
			goShop: function(workerid) {
				uni.navigateTo({
					url: '/pages/worker/shop?workerid=' + workerid
				});
			},
		}
	}
</script>

<style>
</style>
