12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <template>
- <view class="questionBankAnswer-bottom-flex" :class="{'collect': current_timu.is_fav == 1}" @tap="collect_opt">
- <view class="iconfont icon-shoucang1"
- :class="{'': current_timu.is_fav != 1, 'yellow': current_timu.is_fav == 1}"></view>
- <view>{{ current_timu.is_fav == 1 ? '已收藏' : '收藏'}}</view>
- </view>
- </template>
- <script>
- export default {
- props: {
- current_timu: {
- type: Object,
- default: function() {
- return {}
- },
- },
- type: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- }
- },
- watch: {
- current_timu: {
- handler(newVal, oldVal) {
- // console.log(newVal)
- },
- deep: true,
- immediate: true
- }
- },
- methods: {
- // 收藏
- async collect_opt() {
- let url = ''
- // 1:章节练习 2:历年真题
- if (this.type == 1) {
- // 1:章节练习
- url = this.$myHttp.urlMap.unitshoucangeedit
- } else if (this.type == 2) {
- // 2:历年真题
- url = this.$myHttp.urlMap.zhentishoucangeedit
- }
- let res = await this.$myHttp.post({
- url: url,
- data: {
- id: this.current_timu.id
- },
- needLogin: true
- });
- if (res.code == 1) {
- if (this.current_timu.is_fav == 1) {
- this.$emit('collect_opt', 0)
- // this.$set(this.current_timu, 'is_fav', 0)
- uni.showToast({
- icon: 'none',
- title: '取消成功'
- });
- } else {
- this.$emit('collect_opt', 1)
- // this.$set(this.current_timu, 'is_fav', 1)
- uni.showToast({
- icon: 'none',
- title: '收藏成功'
- });
- }
- }
- },
- }
- }
- </script>
- <style>
- </style>
|