<template>
	<view class="main">
		<!--搜索-->
		<view class="search">
			<view class="usearch">
				<u-search placeholder="请输入职位名称" bgColor="white" :showAction="false"></u-search>
			</view>
			<view class="address">
				<text class="icon">&#xe62e;</text>
				<text>南宁市</text>
			</view>
		</view>
		<!--轮播图-->
		<view class="banner">
			<u-swiper circular :radius="5" :indicator="true" keyName="pic" :list="bannerList" :height="150" class="uni-swiper" @click="click"></u-swiper>
		</view>
		<!--找工作-->
		<view class="tab">
			<u-tabs :scrollable="false" :inactiveStyle="{ fontSize: '17px' }" :activeStyle="{ color: '#3c9cff', fontSize: '17px' }" :list="tab" :current="current" @click="click"></u-tabs>
		</view>
		<view class="jobs" v-if="current == 0">
			<view class="full_time" v-for="(item, index) in jobs" :key="index" @click="detail(item)">
				<view class="out">
					<view class="int">
						<image :src="item.url" mode="aspectFill"></image>
						<view class="title omit">{{ item.name }}</view>
						<view class="desc">{{ item.job }}</view>
						<view class="price">{{ item.price }}/月</view>
						<view class="address">
							<text class="icon">&#xe62e;</text>
							<text>南宁青秀山</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="jobs" v-if="current == 1">
			<view class="full_time" v-for="(item, index) in jobs" :key="index" @click="detail(item)">
				<view class="out">
					<view class="int">
						<image :src="item.url" mode="aspectFill"></image>
						<view class="title omit">{{ item.name }}</view>
						<view class="desc">{{ item.job }}</view>
						<view class="price">{{ item.price }}元/月</view>
						<view class="address">
							<text class="icon">&#xe62e;</text>
							<text>距你2km</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="jobs" v-if="current == 2">
			<view class="part_time" v-for="(item, index) in jobs" :key="index" @click="detail(item)">
				<view class="title omit">兼职{{ item.job }}</view>
				<view class="price">
					300/天
					<text class="icon">&#xe619;</text>
					日结
				</view>
				<text class="date">4.16-4.17</text>
				<view class="address">
					<text @click.stop="company()">{{ item.name }}</text>
					<text class="add">申请</text>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			ip: this.http.ip,
			current: 0,
			tab: [{ name: '你的工作' }, { name: '身边工作' }, { name: '现结工作' }],
			user: {},
			jobs: [
				{
					name: '广西龙坚贸易有限公司',
					job: '装卸搬运工',
					price: '4000',
					url: 'https://chenglantimes.com/prod-api/profile/upload/2024/04/29/1714401904451.jpg'
				},
				{
					name: '韵达速递',
					job: '快递装卸工',
					price: '4700',
					url: 'https://chenglantimes.com/prod-api/profile/upload/2024/04/29/1714401871968.jpg'
				},
				{
					name: '北京滴滴有限公司',
					job: '滴滴快车专车司机',
					price: '4200',
					url: 'https://chenglantimes.com/prod-api/profile/upload/2024/04/29/1714401886712.jpg'
				},
				{
					name: '北京美团外卖有限公司',
					job: '美团骑手送餐员',
					price: '3700',
					url: 'https://chenglantimes.com/prod-api/profile/upload/2024/04/29/1714401895824.jpg'
				},
				{
					name: '字节跳动有限公司',
					job: '女主播',
					price: '5500',
					url: 'https://chenglantimes.com/prod-api/profile/upload/2024/04/29/1714402008141.jpg'
				},
				{
					name: '广西龙坚贸易有限公司',
					job: '装卸搬运工',
					price: '4000',
					url: 'https://chenglantimes.com/prod-api/profile/upload/2024/04/29/1714402008141.jpg'
				}
			],
			bannerList: [],
			noticeList: []
		};
	},
	onShow() {
		this.getLocation();
		if (this.hasLogin()) {
			//this.getUserInfo();
		}
	},
	onLoad() {
		this.getData();
		this.http.request({
			url: '/app/common/column/city/all',
			success: (res) => {
				uni.setStorageSync('city_all', res.data.data);
			}
		});
	},
	methods: {
		getLocation() {
			uni.authorize({
				scope: 'scope.userLocation',
				success: (s) => {
					uni.getLocation({
						type: 'wgs84',
						success: (res) => {
							uni.setStorageSync('location', res);
						}
					});
				},
				fail(res) {
					uni.showModal({ title: '提示', content: '定位失败,请检查是否允许定位', showCancel: false });
				}
			});
		},
		detail() {
			uni.navigateTo({
				url: '/pages/clsd/job/detail'
			});
		},
		company() {
			uni.navigateTo({
				url: '/pages/clsd/job/company'
			});
		},
		click(e) {
			this.current = e.index;
		},
		getUserInfo() {
			this.http.request({
				url: '/app/user/info',
				success: (res) => {
					this.user = res.data.data;
				}
			});
		},
		getData() {
			this.http.request({
				url: '/app/home/index',
				success: (res) => {
					this.contract = res.data.data.contract;
					this.bannerList = res.data.data.bannerList;
					res.data.data.noticeList.forEach((item) => {
						this.noticeList.push(item.title);
					});
				}
			});
		},
		go(url) {
			if (this.hasLogin()) {
				uni.navigateTo({
					url: '/pages/index/index'
				});
			} else {
				uni.navigateTo({ url: '/pages/user/login' });
			}
		}
	}
};
</script>

<style lang="scss">
@import './index.scss';
</style>
