mattercontent.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. getDept(id).then(res =>{
  33. _that.matterlist = res.data
  34. this.checkFavorite();
  35. })
  36. },
  37. toggleFavorite() {
  38. const userId = getApp().globalData.userId;
  39. if (this.isFavorite) {
  40. delDept(this.matterlist.id).then(() => {
  41. this.isFavorite = false;
  42. });
  43. } else {
  44. const userId = getApp().globalData.userId
  45. const matterId = this.matterlist.id
  46. addsc({ matterId:this.matterlist.id , userId }).then(() => {
  47. this.isFavorite = true;
  48. });
  49. }
  50. },
  51. checkFavorite() {
  52. const userId = getApp().globalData.userId
  53. getsc(userId).then(res => {
  54. this.isFavorite = res.data;
  55. });
  56. },
  57. },
  58. }
  59. </script>
  60. <style scoped>
  61. </style>