<template>

	<view>
		<view class="rnwdList">
			<ul >
				<li >
					<h3>{{matterlist.title }}</h3>
				    <p>{{ matterlist.content }}</p>
					<image class="uni-header-image" :src="'http://127.0.0.1:8080'+matterlist.picture"></image>
					   <button @click="toggleFavorite">{{ isFavorite ? '❤️' : '🤍' }}</button>
				</li>
				</ul>
		</view>
	</view>


</template>

<script>
	import {
		 getDept, scadd, delDept, getsc
	} from '@/api/handleAffairs/matter.js';

	export default {
		data() {
			return {
				matterlist:[],
				 isFavorite: false,
			};
		},
		created() {
		    this.getList();

		},

		methods: {
		      getList(){
		        const _that = this;
		        const id = uni.getStorageSync('id');

		        getDept(id).then(res =>{
		          _that.matterlist = res.data
					this.checkFavorite();
		        })
		      },
		      toggleFavorite() {
		        const userId = getApp().globalData.userId;
		        if (this.isFavorite) {
		          delDept(this.matterlist.id).then(() => {
		            this.isFavorite = false;
		          });
		        } else {
					const userId = getApp().globalData.userId
					const matterId = this.matterlist.id
		         scadd({ matterId:this.matterlist.id , userId }).then(() => {
		             this.isFavorite = true;
		         });
		        }
		      },

		   checkFavorite() {
		   	const userId = getApp().globalData.userId
		   	const matterId = this.matterlist.id
		     getsc({ matterId , userId }).then(res => {
		       this.isFavorite = res.data;
		     });
		   },
	},
	}
</script>
<style scoped>

</style>

