import { Component } from 'react' import { View, Text, Button, Image, scrollView, Input } from '@tarojs/components' import * as api from '../../../../service/index' import tool from '../../../../common/tool' import Taro, { getCurrentInstance } from '@tarojs/taro' import './index.less' export default class collection extends Component { $instance = getCurrentInstance() state = { booksinfo: {}, is_collect: 0,//是否加入书架,0|1 likeBookList: [], lastTime: 0 } componentWillMount () { this.getBookinfo() this.getBookLike() } componentDidShow () { } getBookLike () { api.getBookLike().then(res => { if (res.code == 200) { this.setState({ likeBookList: res.data.book_like }) } }) } getBookinfo () { let routers = this.$instance.router.params api.getBookinfo({ book_id: routers.book_id }).then(res => { if (res.code == 200) { this.setState({ booksinfo: res.data.book_info[0], is_collect: res.data.is_collect }) } }) } bookCollect () { if (this.state.is_collect == 1) return let routers = this.$instance.router.params api.bookCollect({ book_id: routers.book_id }).then(res => { if (res.code == 200) { this.getBookinfo() } }) } onReachBottom () { // if (!this.state.total) { // this.setState({ // page: this.state.page + 1 // }) // } } toDetail (item, index) { Taro.navigateTo({ url: '/pages/index/subpages/novel/index' }) } toNovelText () { Taro.navigateTo({ url: `/pages/index/subpages/novelText/index?book_id=${this.state.booksinfo.id}` }) } toDirectory () { Taro.navigateTo({ url: `/pages/index/subpages/directory/index?book_id=${this.state.booksinfo.id}` }) } toLikeBooks (item, index) { Taro.navigateTo({ url: `/pages/index/subpages/novel/index?book_id=${item.id}` }) } copyCode () { let lastTime = this.state.lastTime; let now = new Date().getTime(); if (now - lastTime < 2000) return this.setState({ lastTime: now }, () => { api.getCommand({ book_id: this.state.booksinfo.id }).then(res => { if (res.code == 200) { let text = res.data // if (process.env.TARO_ENV == 'tt') { // text = res.data // } Taro.setClipboardData({ data: text, success: function (res) { Taro.showModal({ title: '口令复制成功', content: "是否前往了解赚钱计划?", success: function (res) { if (res.confirm) { Taro.navigateTo({ url: `/pages/mine/subpages/moneyPlay/index` }) } else if (res.cancel) { console.log('用户点击取消') } } }) } }) } }) }) } render () { return ( {tool.ellipsis(this.state.booksinfo.name, 15)} {this.state.booksinfo.paly_cnt}游览 (this.copyCode())}> 书籍简介 {this.state.booksinfo.intro} (this.toDirectory())}> 查看目录已更新到{this.state.booksinfo.album_cnt}章 猜你喜欢 (this.getBookLike())}> 换一换 { this.state.likeBookList.map((item, index) => ( (this.toLikeBooks(item, index))}> {tool.ellipsis(item.name, 4)} )) } 精选内容 {this.state.booksinfo.short_name} (this.bookCollect())}> {this.state.is_collect == 0 ? '加入书架' : '已在书架'} (this.toNovelText())}> 继续阅读 ) } }