<!-- 企业详情 -->
<template>
	<view class="business-details">
		<!-- 背景 -->
		<view class="business-details-bg"></view>
		<!-- 内容 -->
		<view class="business-details-content">
			<view class="business-details-content-logo">
				<image :src="companyInfo.logoUrl" mode=""></image>
			</view>
			<view class="business-details-content-name">{{ companyInfo.companyName }}</view>
			<!-- <view class="business-details-content-evaluate">
				<view class="left">
					<view class="evaluate">优秀</view>
					<view class="describe">综合评分</view>
					<view class="star">
						<u-icon name="star-fill" color="#EF651F"></u-icon>
						<u-icon name="star-fill" color="#EF651F"></u-icon>
						<u-icon name="star-fill" color="#EF651F"></u-icon>
						<u-icon name="star-fill" color="#EF651F"></u-icon>
						<u-icon name="star-fill" color="#EF651F"></u-icon>
					</view>
					<view class="grade">4.8</view>
				</view>
				<view class="right">
					详情
					<u-icon class="icon" name="arrow-right" color="#666666"></u-icon>
				</view>
			</view> -->
			
			<!-- 公司概况 -->
			<view class="business-details-content-survey">
				<view class="title">公司概况</view>
				<view class="item">
					<view>公司全称：{{ companyInfo.companyName }}</view>
					<view>公司简称：{{ companyInfo.nickName }}</view>
					<view>所属行业：{{ getCompanyTradeName(companyInfo.trade) }}</view>
					<view>公司规模：{{ getCompanyScopeName(companyInfo.scope) }}</view>
					<view>联系方式：{{ companyInfo.linkPhone }}</view>
					<view class="address">
						<view>公司地址：{{ companyInfo.companyAddress }}</view>
						<view>
							<!-- <image src="../../static/img/dingwei.png"/>
							查看位置 -->
						</view>
					</view>
				</view>
			</view>
			
			<!-- 公司介绍 -->
			<view class="business-details-content-introduce">
				<view class="title">公司介绍</view>
				<view class="content">
					<view class="content" v-if="companyInfo.detatil">
						<u-parse :html="companyInfo.detatil"/>
					</view>
					<u-empty v-else text="暂无公司介绍" mode="data"></u-empty>
				</view>
			</view>
			
			<!-- 公司相册 -->
			<view class="business-details-content-album">
				<view class="title">公司相册</view>
					<scroll-view scroll-x="true" class="pic" style="width: 100%; overflow:hidden; white-space: nowrap;" v-if="companyInfo.environmentUrlList && companyInfo.environmentUrlList.length > 0">
						<view class="pic-list">
							<view class="pic-list-item" v-for="(item, index) in companyInfo.environmentUrlList" :key="index">
								<u-image :src="item" mode="" height="206" @tap="picClick(index)"/>
							</view>
						</view>
					</scroll-view>
					<u-empty v-else text="该公司暂未发布公司相册" mode="data"></u-empty>
			</view>
			
			<!-- 公司职位 -->
			<view class="business-details-content-position">
				<view class="title">公司职位</view>
				<view class="position-list" v-if="positionList.length > 0">
					<view
						class="position-list-item"
						v-for="(item, index) in positionList"
						:key="index"
						@click="jumpPage('/pages/jobDetails/jobDetails', { id: item.id })"
					>
						<view class="left">
							<view class="logo">
								<image :src="item.companyLogoUrl" mode=""></image>
							</view>
							<view class="info">
								<view>{{ item.postName }}</view>
								<view>{{ `${item.workPlace} | 经验${item.workYear ? item.workYear + '年' : '不限'} | ${item.educationBg}` }}</view>
								<view>{{ item.workPlace }}</view>
							</view>
						</view>
						<view class="right">
							<view>{{ `${item.lowestSalary || ''} ~ ${item.highestSalary || ''}k` }}</view>
							<view>{{ item.createTime ? item.createTime.split(' ')[0] : '-' }}</view>
						</view>
					</view>
				</view>
				<u-empty v-else text="该公司暂未发布职位" mode="data"></u-empty>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 公司id
				companyId: '',
				// 公司详情
				companyInfo: '',
				companyScopeList: [],
				companyTradeList: [],
				// 公司职位
				positionList: []
			}
		},
		onLoad(page) {
			this.getDict('company_scope');
			this.getDict('company_trade');
			if (page.id) {
				this.companyId = page.id
			}
		},
		onShow() {
			if (this.companyId) {
				this.getDetails(this.companyId)
				this.getCompanyPost(this.companyId, 1, 1000)
			} else {
				this.$refs.uToast.show({
					title: '参数不全!',
					type: 'warning'
				})
			}
		},
		methods: {
			/**
			 * 获取详情
			 * @param { String } id 获取详情企业id
			 */
			getDetails(id) {
				this.$u.api.company.getCompanyDetails({
					id: id
				}).then(res => {
					if (res.code === 200) {
						this.companyInfo = res.data
					} else {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error'
						})
					}
				}).catch((err) => {
					this.$refs.uToast.show({
						title: '系统异常!',
						type: 'error'
					})
				})
			},
			/**
			 * 获取字典
			 * company_scope  公司规模
			 * company_trade  公司类型
			 */
			getDict(key) {
				this.$u.api.getDictdataUrl({
					key: key
				}).then(res => {
					if (res.code === 200) {
						if (key === 'company_scope') {
							this.companyScopeList = res.data
						} else if (key === 'company_trade') {
							this.companyTradeList = res.data;
						}
					}
				})
			},
			/**
			 * @param {Object} val
			 */
			getCompanyScopeName(val) {
				let name;
				this.companyScopeList.forEach(item => {
					if (Number(item.text) === Number(val)) {
						name = item.label
					}
				})
				return name;
			},
			/**
			 * @param {Object} val
			 */
			getCompanyTradeName(val) {
				let name;
				this.companyTradeList.forEach(item => {
					if (Number(item.text) === Number(val)) {
						name = item.label
					}
				})
				return name;
			},
			/**
			 * @param {Object} url
			 */
			getCompanyPost(id, pageNum, pageSize) {
				this.$u.api.company.getCompanyPostList({ id, pageNum, pageSize}).then(res => {
					if (res.code === 200) {
						this.positionList = res.rows
					} else {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error'
						})
					}
				}).catch((err) => {
					this.$refs.uToast.show({
						title: '系统异常!',
						type: 'error'
					})
				})
			},
			/**
			 * 跳转到指定页面
			 */
			jumpPage(url, params) {
				this.$u.route({
					url,
					params
				})
			},
			/**
			 * 图片预览
			 * @param { Number } index
			 */
			picClick(index) {
				uni.previewImage({
					current: index,
					urls: this.companyInfo.environmentUrlList
				})
			}
		}
	}
</script>

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