mattercontent.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view>
  3. <view class="rnwdList">
  4. <ul >
  5. <li >
  6. <h3>{{matterlist.title }}</h3>
  7. <p>{{ matterlist.content }}</p>
  8. <button @click="toggleFavorite">{{ isFavorite ? '❤️' : '🤍' }}</button>
  9. </li>
  10. </ul>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import {
  16. getDept, addsc, delDept, getsc
  17. } from '@/api/handleAffairs/matter.js';
  18. export default {
  19. data() {
  20. return {
  21. matterlist:[],
  22. isFavorite: false,
  23. };
  24. },
  25. created() {
  26. this.getList();
  27. },
  28. methods: {
  29. getList(){
  30. const _that = this;
  31. const id = uni.getStorageSync('id');
  32. console.log(uni.getStorageSync('id'),"11111111")
  33. getDept(id).then(res =>{
  34. _that.matterlist = res.data
  35. this.checkFavorite();
  36. })
  37. },
  38. toggleFavorite() {
  39. const userId = getApp().globalData.userId;
  40. if (this.isFavorite) {
  41. delDept(this.matterlist.id).then(() => {
  42. this.isFavorite = false;
  43. });
  44. } else {
  45. const userId = getApp().globalData.userId
  46. const matterId = this.matterlist.id
  47. addsc({ matterId:this.matterlist.id , userId }).then(() => {
  48. this.isFavorite = true;
  49. });
  50. }
  51. },
  52. checkFavorite() {
  53. const userId = getApp().globalData.userId
  54. getsc(userId).then(res => {
  55. this.isFavorite = res.data;
  56. });
  57. },
  58. },
  59. }
  60. </script>
  61. <style scoped>
  62. </style>