question-fav.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view class="questionBankAnswer-bottom-flex" :class="{'collect': current_timu.is_fav == 1}" @tap="collect_opt">
  3. <view class="iconfont icon-shoucang1"
  4. :class="{'': current_timu.is_fav != 1, 'yellow': current_timu.is_fav == 1}"></view>
  5. <view>{{ current_timu.is_fav == 1 ? '已收藏' : '收藏'}}</view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. props: {
  11. current_timu: {
  12. type: Object,
  13. default: function() {
  14. return {}
  15. },
  16. },
  17. type: {
  18. type: String,
  19. default: ''
  20. }
  21. },
  22. data() {
  23. return {
  24. }
  25. },
  26. watch: {
  27. current_timu: {
  28. handler(newVal, oldVal) {
  29. // console.log(newVal)
  30. },
  31. deep: true,
  32. immediate: true
  33. }
  34. },
  35. methods: {
  36. // 收藏
  37. async collect_opt() {
  38. let url = ''
  39. // 1:章节练习 2:历年真题
  40. if (this.type == 1) {
  41. // 1:章节练习
  42. url = this.$myHttp.urlMap.unitshoucangeedit
  43. } else if (this.type == 2) {
  44. // 2:历年真题
  45. url = this.$myHttp.urlMap.zhentishoucangeedit
  46. }
  47. let res = await this.$myHttp.post({
  48. url: url,
  49. data: {
  50. id: this.current_timu.id
  51. },
  52. needLogin: true
  53. });
  54. if (res.code == 1) {
  55. if (this.current_timu.is_fav == 1) {
  56. this.$emit('collect_opt', 0)
  57. // this.$set(this.current_timu, 'is_fav', 0)
  58. uni.showToast({
  59. icon: 'none',
  60. title: '取消成功'
  61. });
  62. } else {
  63. this.$emit('collect_opt', 1)
  64. // this.$set(this.current_timu, 'is_fav', 1)
  65. uni.showToast({
  66. icon: 'none',
  67. title: '收藏成功'
  68. });
  69. }
  70. }
  71. },
  72. }
  73. }
  74. </script>
  75. <style>
  76. </style>