<template>
	<view class="content">
		<view v-if="con">
			<view class="phonetop">
				<view class="headbox">
					<view class="head">
						<view class="image">
							<image :src='con.avatarurl' mode="aspectFit"></image>
						</view>
						<view class="info">
							<view class="name">
								{{con.name}}<text>{{con.posname}}</text>
							</view>
							<view class="post">{{con.orgname}}<text v-if="con.place" class="ml-5 mr-5">|</text>{{con.place}}</view>
							<view class="phone">电话:{{con.phone}}</view>
							<view class="phone" v-if="con.email">邮箱:{{con.email}}</view>
						</view>
					</view>
					<view class="call" @click="$tools.getCall(user.authlist,con.phone)" v-if="con.phone">
						<icon class="iconfont icon-dianhua1 mr-10"></icon>
						合作联系
					</view>
				</view>
			</view>
			<!--  -->
			<view class="box">
				<view class="tabbar">
					<view :class="[active==1?'active':'']" @click="active=1">企业简介</view>
					<view :class="[active==2?'active':'']" @click="active=2">产品展示</view>
					<view :class="[active==3?'active':'']" @click="active=3">个人简介</view>
				</view>
				<!-- 企业简介 -->
				<view class="title">
					<image src="../../static/title.png"></image>
					{{active==1?'企业简介':active==2?'产品展示':'个人简介'}}
				</view>
				<view class="show" v-if="active==1">
					<view class="logo">
						<image :src="con.cominfo.logourl" mode="aspectFit"></image>
					</view>
					<view class="postName">{{con.cominfo.name}}</view>
					<view class="mt-15">
						<text class="text ml-15">企业所在片区:</text>{{con.cominfo.area}}
					</view>
					<view class="mt-10 ml-15">
						<text
							class="text">公司地址:</text>{{con.cominfo.province}}{{con.cominfo.city}}{{con.cominfo.area}}{{con.cominfo.address}}
					</view>
					<view class="mt-10 ml-15">
						<text class="text">公司电话:</text>{{con.cominfo.mobile}}
					</view>
					<view class="mt-10 ml-15">
						<text class="text">企业年营收（万元）:</text>{{con.cominfo.yearlyincome}}
					</view>
					<view class="mt-10 ml-15">
						<text class="text">企业年税收（万元）:</text>{{con.cominfo.yearlytax}}
					</view>
					<view class="mt-10 ml-15">
						<text class="text">员工人数:</text>{{con.cominfo.staffcnt}}人
					</view>
					<view class="con">
						{{con.cominfo.desc}}
					</view>
					<view class="image mt-10" v-for="(ite,ind) in con.cominfo.pics" :key="ind">
						<image :src="ite.url" @click="previewImage(ind)" mode="widthFix"></image>
					</view>
				</view>
				<!-- 产品展示 -->
				<view class="show " v-if="active==2">
					<list :isName="false" :list="list" @handleDetail="handleDetail" v-if="list.length"></list>
					<view class="nolist" v-else>
						<image src="@/static/none.png"></image>
						<text>暂无数据</text>
					</view>
				</view>
				<!--个人简介  -->
				<view class="show" v-if="active==3">
					<view class="headimage">
						<image :src='con.avatarurl' mode="aspectFit"></image>
					</view>
					<view class="name">
						{{con.name}}<text>{{con.posname}}</text>
					</view>
					<view class="post">{{con.orgname}}<text v-if="con.place" class="ml-5 mr-5">|</text>{{con.place}}
					</view>
					<view class="mt-10"><text>性别:</text>{{con.sex==1?'男':con.sex==2?'女':'未知'}}</view>
					<view class="mt-10"><text>出生年月:</text>{{con.birthday.substring(0,10)}}</view>
					<view class="mt-10"><text>籍贯:</text>{{con.place}}</view>
					<view class="mt-10 ml-15" v-if="con.interests">
						<text class="text">爱好:</text>{{con.interests}}
					</view>
					<view class="mt-10 ml-15" v-if="con.provide">
						<text class="text">能给平台带来什么:</text>{{con.provide}}
					</view>
					<view class="mt-10 ml-15" v-if="con.demand">
						<text class="text">加入智照团想收获什么:</text>{{con.demand}}
					</view>
				</view>
			</view>
			<!-- 秘书处弹框 -->
			<secratary></secratary>
		</view>
		<view class="nolist" v-else>
			<image src="@/static/none.png"></image>
			<text>暂无数据</text>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	import list from "@/components/productList.vue"
	import uParse from '@/uni_modules/u-parse/u-parse.vue'
	export default {
		data() {
			return {
				active: 1,
				page: 1,
				list: [],
				lastPage: 1,
				con: null,
				id: ""

			}
		},
		components: {
			list,
			uParse
		},
		computed: {
			...mapState(["user"]),
		},
		onLoad(options) {
			this.id = options.id
			this.handleInfo(options.id)
			this.handleList()
		},
		onReachBottom() {
			let that = this
			if (this.active != 2) return
			console.log("this.lastPage", this.lastPage)
			if (!this.lastPage || this.page >= this.lastPage) {
				uni.showToast({
					title: '没有更多数据！',
					icon: 'none'
				})
				return
			}
			this.page++
			this.handleList()
		},
		methods: {
			handleInfo(id) {
				let that = this
				return that.$model.getVipDetail({
					id: id,
				}).then((res) => {
					console.log("详情", res)
					that.con = res.data
				})
			},
			handleList() {
				let that = this
				that.$model.getProductList({
					pageNo: that.page,
					pageSize: 10,
					type: 3,
					userId: that.id
				}).then(res => {
					if (res.code == 0) {
						that.list = that.list.concat(res.data.rows)
						that.lastPage = res.data.totalpage
					} else {
						that.$tools.msg(res.message);
					}
				});
			},
			handleDetail(item) {
				console.log("详情", item)
				let that = this
				that.$model.getProductDetail({
					id: item.id,
					type: 3
				}).then(res => {
					if (res.code == 0) {
						res.data.type = 3
						uni.navigateTo({
							url: "/pageTwo/product/detail?type=3" + '&id=' + item.id
						})
					} else {
						that.$tools.msg(res.message);
					}

				});
			},
			previewImage(ind) {
				let that = this
				console.log("pics", that.con.cominfo.pics.map(item => item.url))
				uni.previewImage({
					urls: that.con.cominfo.pics.map(item => item.url),
					current: ind
				}).catch((e) => {
					console.log(e) //用catch(e)来捕获错误{makePhoneCall:fail cancel}
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		padding: 0;
		min-height: 100vh;
	}

	image {
		width: 100%;
		height: 100%;
	}

	.title {
		font-size: 16px;
		font-weight: bold;
		margin: 15px;
		display: flex;
		align-items: center;

		image {
			width: 30px;
			height: 20px;
			margin-right: 5px;
		}
	}

	.box {
		margin-top: 170px;
		background-color: #fff;
		width: 100%;
		border-radius: 5px;

		.tabbar {
			display: flex;
			height: 45px;
			align-items: center;
			justify-content: space-between;
			font-size: 16px;
			font-weight: bold;
			margin: 0 15px;
			border-bottom: 1px solid #dfdfdf;

			view {
				height: 45px;
				line-height: 45px;
				width: 33%;
				text-align: center;
			}

			.active {
				color: $blue;

				border-bottom: 2px solid $blue;
			}
		}

		.show {
			padding: 10px 15px 15px;

			.logo {
				width: 145px;
				height: 52px;
				padding: 10px;
				border: 1px solid #dfdfdf;
				margin: auto;
				margin: 15px auto;
			}

			.postName {
				margin: 20px 0;
				font-size: 16px;
				font-weight: bold;
			}

			text,
			.text {
				color: #999;
				padding-left: 13px;
				position: relative;
				left: -15px;
			}

			.text::before {
				content: "";
				position: absolute;
				width: 8px;
				height: 8px;
				left: 0;
				background-color: $orange;
				border-radius: 50%;
				top: 6px;
			}

			.con {
				margin-top: 15px;
				color: #666;
				line-height: 25px;
			}

			.image {
				width: 100%;
				height: auto;
				text-align: center;
				margin-top: 5px;

				image {
					width: 100%;
					height: auto;
					object-fit: scale-down;
				}
			}

			// 
			.headimage {
				width: 85px;
				height: 110px;
				border: 1px solid #dfdfdf;
				border-radius: 5px;
				margin: auto;
			}

			.name {
				width: 100%;
				font-size: 16px;
				text-align: center;
				margin-top: 15px;

				text {
					width: auto;
					display: inline-block;
					background-color: #F7B133;
					text-align: center;
					font-size: 12px;
					padding: 2px 10px;
					border-radius: 5px;
					color: #fff;
					margin-left: 15px;
					left: 0;
				}

			}

			.post {
				color: #999;
				text-align: center;
				margin-top: 10px;

				text {
					position: inherit;
					padding-left: 0;
				}
			}
		}
	}

	.productList {
		margin-bottom: 0 !important;
	}
</style>