<template>
	<view class="page">
		<!-- 文章内容 -->
		<view class="article-data">
			<view class="article-top">{{detailData.title}}</view>
			<view class="article-title">
				<view class="article-title-left">
					{{ detailData.createTime}}
				</view>
				<view class="article-title-right"><image src="../../static/kan.png"></image>{{detailData.ViewCount ? detailData.ViewCount : 0}}人</view>
			</view>
			<view class="article-content">
				<view class="" v-html="detailData.bodyContent"></view>
			</view>
			<view class="article-img">
				<image :src="baseUrl + detailData.images" mode="widthFix"></image>
			</view>
			<view class="namePhone">
				<!-- 公司名称 -->
				<view>
					发布企业：{{detailData.orgName}}
				</view>
				<view v-if="detailData.userName">
					联系人：{{detailData.userName}}
				</view>
				<view v-if="detailData.userPhone">
					联系人电话：{{detailData.userPhone}}
				</view>
			</view>
		</view>
		<!-- 底部 -->
		<view class="page-footer">
			<!-- <view class="footer-fn">
				<view class="list">
					<image src="../../static/detail2.png"></image>
					<text>收藏</text>
				</view>
			</view> -->
			<!-- <view class="footer-buy" style="width:100%">
				<view class="buy-at" @click="callPhone(phoneNumber)">  
					<image src="../../static/detail1.png"></image>
					<text>打电话</text>
				</view>
			</view> -->
		</view>
	</view>
</template>

<script>
import utils from '../../service/utils';
import BASE_URL from '../../common/config.js'
import request from '@/utils/request.js'
	export default {
		data() {
			return {
				isComment: false,
				isGoods: false,
				// 需求详情数据
				detailData:[],
				// 存放页面跳转传递的数据
				data:[],
				baseUrl:'https://www.dygxq-es.cn',
				// 公司id
				companyId:'',
				// 电话号码
				phoneNumber:''
			};
		},
		onLoad(options){
			let that = this
			// 获取页面跳转传递来的数据
			this.data = JSON.parse(options.data)
			console.log(that.data)
			that.getNewsDetail()
		},
		methods:{
			// 获取需求详情数据
			getNewsDetail(){
				let that = this
				let currentId = that.data.id
				console.log(currentId)
				request({
					url:`/api/Extend/basetalentrecruitment/${currentId}`,
					method:'get',
					data:{}
				}).then(res =>{
					console.log(res)
					let createTime = utils.formatTime(res.data.createTime)
					res.data.createTime = createTime
					that.detailData = res.data
					let detailContent = res.data.bodyContent.replace(/img/g,"<img style='max-width:100%;height:auto;'")
					that.detailData.bodyContent = detailContent
					this.companyId = that.detailData.orgId
					console.log(that.detailData)
					console.log(this.companyId)
				}).then(data=>{
					request({
						url:`/api/permission/organize/${this.companyId}`,
						// url:`/api/permission/organize/bbf6effe-6354-11ed-b582-00163e2cec73`,
						method:'get',
						data:{}
					}).then(res=>{
						console.log('电话号码返回结果',res)
						if(res.code === 200){
							this.phoneNumber = res.data.fuzerendianhua
							console.log("电话号码", this.phoneNumber)
						}else{
							uni.showToast({
								icon:'error',
								title:"获取信息失败，请重试！"
							})
						}
					})
				})
			},
			
			// 拨打电话
			callPhone(phoneNumber){
				if (uni.getSystemInfoSync().platform == 'android' || uni.getSystemInfoSync().platform == 'ios') {
				    uni.showModal({
				        title: '温馨提示',
				        content: '确定要拨打电话吗？',
				        success: function (res) {
				            if (res.confirm) {
				                // 使用plus的API拨打电话
				                plus.device.dial(phoneNumber, true);
				            }
				        }
				    })
				} else {
				    // 非APP平台时，使用uniapp自带的API拨打电话
				    uni.makePhoneCall({
				        phoneNumber: phoneNumber,
				        success: function () {
				            console.log('拨打电话成功！');
				        },
				        fail: function () {
				            console.log('拨打电话失败！');
				        }
				    });
				}
			}
		}
	}
</script>

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