<template>
	<view>
		<view class="gwList flex justify-center" v-if="dataList.length>0">
			<view class="gwList-box">
				<view class="gwList-box-item flex justify-center" @click="gotoInfo(item.postPushId)"
					v-for="(item,index) in dataList" :key="index">
					<view class="gwList-box-item-box">
						<view v-if="item" class="gwList-box-item-box-title flex justify-between align-center">
							<text>{{item.stationName}}</text>
							<text>{{item.salaryRange}}</text>
						</view>
						<view class="gwList-box-item-box-label flex align-center flex-wrap">
							<text
								style="color: #666666;font-size: 26rpx;padding: 10rpx 25rpx 10rpx 25rpx;background-color: #F6F6F6;border-radius: 8rpx;margin-right: 20rpx;margin-bottom: 20rpx;"
								v-for="(ite,ind) in item.positionWelfare" :key="ind">{{ite}}</text>
						</view>
						<block v-if="title=='我的收藏'">
							<view class="gwList-box-item-box-name flex justify-between align-center">
								<text>{{item.companyName?item.companyName:'匿名公司'}}</text>
								<text v-if="item.companyPeople">{{item.companyPeople}}</text>
							</view>
							<view class="gwList-box-item-box-line"></view>
							<view class="gwList-box-item-box-info flex justify-between align-center">
								<view class="gwList-box-item-box-info-l flex align-center">
									<image :src="item.companyLogo?item.companyLogo:'../../static/logo.png'"
										style="width: 58rpx;height: 58rpx;border-radius: 50%;margin-right: 20rpx;"
										mode=""></image>
									<text v-if="item.companyLegalPerson">{{item.companyLegalPerson}}·创始人</text>
								</view>
								<view class="gwList-box-item-box-info-r">
									{{item.county}}
									{{item.address}}

								</view>
							</view>
						</block>
						<block v-else-if="title=='浏览记录'">
							<view class="gwList-box-item-box-name flex justify-between align-center">
								<text>{{item.companyName?item.companyName:'匿名公司'}}</text>
								<text>{{item.companyPeople?item.companyPeople:0}}</text>
							</view>
							<view class="gwList-box-item-box-line"></view>
							<view class="gwList-box-item-box-info flex justify-between align-center">
								<view class="gwList-box-item-box-info-l flex align-center">
									<image :src="item.companyLogo?item.companyLogo:'../../static/logo.png'"
										style="width: 58rpx;height: 58rpx;border-radius: 50%;margin-right: 20rpx;"
										mode=""></image>
									<text v-if="item.companyLegalPerson">{{item.companyLegalPerson}}·创始人</text>
								</view>
								<view class="gwList-box-item-box-info-r">
									{{item.county}}
									{{item.address}}

								</view>
							</view>
						</block>
						<block v-else>
							<view class="gwList-box-item-box-name flex justify-between align-center">
								<text>{{item.companyName?item.companyName:'匿名公司'}}</text>
								<text v-if="item.companyPeople">{{item.companyPeople}}</text>
							</view>
							<view class="gwList-box-item-box-line"></view>
							<view class="gwList-box-item-box-info flex justify-between align-center">
								<view class="gwList-box-item-box-info-l flex align-center">
									<image :src="item.companyLogo?item.companyLogo:'../../static/logo.png'"
										style="width: 58rpx;height: 58rpx;border-radius: 50%;margin-right: 20rpx;"
										mode=""></image>
									<text v-if="item.companyLegalPerson">{{item.companyLegalPerson}}·创始人</text>
								</view>
								<view class="gwList-box-item-box-info-r">
									{{item.county}}
									{{item.address}}
								</view>
							</view>
						</block>

					</view>
				</view>
			</view>
		</view>

		<!-- 暂无数据 -->
		<view class="gwList" v-else>
			<empty />
		</view>
		<!-- 筛选悬浮 -->
		<view class="filterSe" @click="goScreen()">
			<image src="../../static/images/my/filterSe.png" mode=""></image>
		</view>
	</view>
</template>

<script>
	import empty from '../../components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				dataList: [],
				page: 1,
				limit: 10,
				pages: '',
				title: '',
				filter: {
					education: '', //学历
					salaryRange: '', //薪资
					experience: '', //经验
					companyPeople: '', //公司规模
					industry: '', //行业
				}
			};
		},
		onLoad(option) {
			uni.setNavigationBarTitle({
				title: option.title
			})
			uni.showLoading({
				title: '加载中'
			})
			this.title = option.title
			if (option.title == '我的收藏') {
				this.getMyCollectionList()
			} else if (option.title == '浏览记录') {
				this.getDataList()
			} else {
				this.getDataLists()
			}

		},
		onUnload() {
			uni.removeStorageSync('browse')
		},
		watch: {
			filter: {
				handler() {
					this.page = 1
					if (this.title == '我的收藏') {
						this.getMyCollectionList()
					} else if (this.title == '浏览记录') {
						this.getDataList()
					} else {
						this.getDataLists()
					}
				},
				deep: true,
				immediate: true
			}
		},
		onShow() {
			if (uni.getStorageSync('browse') && (uni.getStorageSync('browse')).length > 0) {
				let browse = uni.getStorageSync('browse')
				console.log(browse, '2222222222')
				browse.map(item => {
					let arr = []
					item.list.map(ite => {
						if (ite.value != '不限') {
							arr.push(ite.value)
						}
					})
					switch (item.name) {
						case '学历':
							this.filter.education = arr.join(',')
							break;
						case '薪资':
							this.filter.salaryRange = arr.join(',')
							break;
						case '经验':
							this.filter.experience = arr.join(',')
							break;
						case '公司规模':
							this.filter.companyPeople = arr.join(',')
							break;
						case '行业':
							this.filter.industry = arr.join(',')
							break;
					}

				})
			} else {
				this.filter.education = '' //学历
				this.filter.experience = '' //经验
				this.filter.industry = '' //行业
				this.filter.salaryRange = '' //薪资
				this.filter.companyPeople = '' //公司规模
			}
		},
		onReachBottom() {
			if (this.page < this.pages) {
				this.page += 1
				if (this.title == '我的收藏') {
					this.getMyCollectionList()
				} else if (this.title == '浏览记录') {
					this.getDataList()
				} else {
					this.getDataLists()
				}
			}
		},
		onPullDownRefresh() {
			this.page = 1
			if (this.title == '我的收藏') {
				this.getMyCollectionList()
			} else if (this.title == '浏览记录') {
				this.getDataList()
			} else {
				this.getDataLists()
			}
		},
		methods: {
			// 去筛选
			goScreen() {
				uni.navigateTo({
					url: '/package/screen/screen?isBrowse=1'
				})
			},
			/**
			 * 我的收藏记录列表
			 */
			getMyCollectionList() {
				let data = {
					page: this.page,
					limit: this.limit,
					education: this.filter.education, //学历
					salaryRange: this.filter.salaryRange, //薪资
					experience: this.filter.experience, //经验
					companyPeople: this.filter.companyPeople, //公司规模
					industry: this.filter.industry, //行业
				}
				this.$Request.getT('/app/myCollection/getMyCollectionListV2', data).then(res => {
					uni.stopPullDownRefresh()
					uni.hideLoading()
					if (res.code == 0) {
						res.data.records.map(item => {
							if (item.positionWelfare) {
								item.positionWelfare = item.positionWelfare.split(',')
							}
						})
						this.pages = res.data.pages
						if (this.page == 1) {
							this.dataList = res.data.records
						} else {
							this.dataList = [...this.dataList, ...res.data.records]
						}
					}
				})
			},
			gotoInfo(postPushId) {
				if (!postPushId) {
					uni.showToast({
						title: '岗位不存在',
						icon: 'none'
					})
					return
				}
				uni.navigateTo({
					url: '/pages/index/game/order?postPushId=' + postPushId
				})
			},
			getDataLists() {
				let data = {
					page: this.page,
					limit: this.limit,
					userId: uni.getStorageSync('userId'),
					education: this.filter.education, //学历
					salaryRange: this.filter.salaryRange, //薪资
					experience: this.filter.experience, //经验
					companyPeople: this.filter.companyPeople, //公司规模
					industry: this.filter.industry, //行业
				}
				this.$Request.getT('/app/sendRecord/getMyRecordListV2', data).then(res => {
					uni.stopPullDownRefresh()
					uni.hideLoading()
					if (res.code == 0) {
						res.data.records.map(item => {
							if (item.positionWelfare) {
								item.positionWelfare = item.positionWelfare.split(',')
							}
						})
						this.pages = res.data.pages
						if (this.page == 1) {
							this.dataList = res.data.records
						} else {
							this.dataList = [...this.dataList, ...res.data.records]
						}
					}
				})
			},
			getDataList() {
				let data = {
					page: this.page,
					limit: this.limit,
					education: this.filter.education, //学历
					salaryRange: this.filter.salaryRange, //薪资
					experience: this.filter.experience, //经验
					companyPeople: this.filter.companyPeople, //公司规模
					industry: this.filter.industry, //行业
					// browseType:1
				}
				this.$Request.getT('/app/userBrowse/selectMyBrowseV2', data).then(res => {
					uni.stopPullDownRefresh()
					uni.hideLoading()
					if (res.code == 0) {
						res.data.records.map(item => {
							if (item.positionWelfare) {
								item.positionWelfare = item.positionWelfare.split(',')
							} else {
								item.positionWelfare = []
							}
						})
						this.pages = res.data.pages
						if (this.page == 1) {
							this.dataList = res.data.records
						} else {
							this.dataList = [...this.dataList, ...res.data.records]
						}
					}
				})
			},
		},
	}
</script>

<style lang="scss">
	page {
		background: #F2F2F7;
	}

	.filterSe {
		position: fixed;
		bottom: 10vh;
		right: 30rpx;

		image {
			width: 100rpx;
			height: 100rpx;
			// border-radius: 50%;
		}
	}

	.gwList {
		width: 100%;

		.gwList-box {
			width: 686rpx;
			height: 100%;

			.gwList-box-item {
				width: 100%;
				// height: 329rpx;
				background-color: #ffffff;
				border-radius: 24rpx;
				margin-bottom: 20rpx;
				padding-bottom: 20rpx;
				margin-top: 20rpx;
			}

			.gwList-box-item-box {
				width: 623rpx;
				height: 100%;

				.gwList-box-item-box-title {
					margin-top: 30rpx;

					text:nth-of-type(1) {
						color: #1F1F1F;
						font-size: 38rpx;
						font-weight: 800;
					}

					text:nth-of-type(2) {
						color: #00B88F;
						font-size: 38rpx;
						font-weight: bold;
					}
				}

				.gwList-box-item-box-label {
					margin-top: 30rpx;
				}

				.gwList-box-item-box-name {
					margin-top: 24rpx;
					color: #999999;
					font-size: 28rpx;
					font-weight: 500;

					text:nth-of-type(1) {
						width: 450rpx;
					}
				}

				.gwList-box-item-box-line {
					width: 100%;
					border: 1rpx solid #E6E6E6;
					margin-top: 30rpx;
					margin-bottom: 20rpx;
				}

				.gwList-box-item-box-info {
					font-size: 26rpx;

					.gwList-box-item-box-info-l {
						color: #1A1A1A;
					}

					.gwList-box-item-box-info-r {
						color: #999999;
						max-width: 340rpx;
					}
				}
			}
		}
	}
</style>