<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.creatorTime}}
				</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.content"></view>
			</view>
			<view class="article-img" v-show="show" v-for="(it,index) in detailData.image">
				<image :src="baseUrl + it.url" style="width: 100%;"></image>
			</view>
		</view>
		<!-- 修改与删除 -->
		<view class="buttons" v-show="isAdmin">
			<button type="primary" size="mini" @click="change(detailData.id)">修改</button>
			<button type="warn" size="mini" @click="del(detailData.id)">删除</button>
		</view>
	</view>
</template>

<script>
	import utils from '../../service/utils';
	import BASE_URL from '../../common/config.js'
	import request from '@/utils/request.js'
	import {
		vShow
	} from "vue";
	export default {
		data() {
			return {
				swiperList: [{
						id: 0,
						type: 'image',
						url: '/static/img/banner_01.png'
					},
					{
						id: 1,
						type: 'image',
						url: '/static/img/banner_02.png'
					},
					{
						id: 2,
						type: 'image',
						url: '/static/img/banner_03.png'
					},
					{
						id: 3,
						type: 'image',
						url: '/static/img/banner_04.png'
					},
					{
						id: 4,
						type: 'image',
						url: '/static/img/banner_01.png'
					},
					{
						id: 5,
						type: 'image',
						url: '/static/img/banner_01.png'
					}
				],
				isComment: false,
				isGoods: false,
				// 需求详情数据
				detailData: [],
				// 存放页面跳转传递的数据
				data: [],
				baseUrl: 'http://deyanggaoxin.fengshiyun.com',
				show: false,
				isAdmin: false
			};
		},
		onLoad(options) {
			let that = this
			this.getUser()
			// 获取页面跳转传递来的数据
			this.data = JSON.parse(options.data)
			console.log(that.data)
			that.getConDetail()
		},
		methods: {
			// 获取用户信息
			getUser() {
				if (uni.getStorageSync('user')) {
					let userCode = uni.getStorageSync('user')
					// console.log("用户的code", this.userCode)
					this.userId = userCode.userInfo.userId
					this.userName = userCode.userInfo.userAccount
					this.userIcon = userCode.userInfo.headIcon
					this.organizeName = userCode.userInfo.organizeName
					// this.isAdmin = userCode.userInfo.isCompany
					console.log(userCode)
					if (userCode.userInfo.userId === 'admin') {
						this.isAdmin = true
					}
				} else {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					// setTimeout(() => {
					// 	uni.reLaunch({
					// 		url: '/pages/login/index'
					// 	})
					// })
				}
			},
			// 获取需求详情数据
			getConDetail() {
				let that = this
				let currentId = that.data
				console.log(currentId)
				that.API.getConstructDetail(currentId).then(res => {
					console.log(res)
					let createTime = utils.formatTime(res.data.creatorTime)
					res.data.creatorTime = createTime
					that.detailData = res.data
					if (that.detailData.image.length > 0) {
						this.show = true
					}
					console.log(that.detailData)
				})
			},
			// 修改信息
			change(id) {
				uni.navigateTo({
					url: `/pages/postCon/postCon?data=${JSON.stringify(id)}`
				})
			},
			// 删除信息
			del(id) {
				let that = this
				uni.showModal({
					title: "提示",
					content: "确定删除吗？",
					success: (res) => {
						request({
							url: this.baseUrl + `/api/SubDev/basepartybuilding/${id}`,
							method: 'delete',
							data: {}
						}).then(res => {
							console.log(res)
							if (res.code === 200) {
								uni.showToast({
									icon: "success",
									title: '删除成功！',
									duration:1500
								}).then(() => {
									uni.navigateTo({
										url: '/pages/construct/construct'
									})
								})
							}
						})
					}
				})
			}
		}
	}
</script>

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