|
@@ -2,8 +2,8 @@
|
|
|
<div>
|
|
|
<!-- 图书id{{bookid}} -->
|
|
|
<BookInfo :info='info'></BookInfo>
|
|
|
- <!-- <button open-type='share' class="btn">转发给好友</button> -->
|
|
|
- <div class="comment">
|
|
|
+ <CommentList :comments="comments"></CommentList>
|
|
|
+ <div class="comment" v-if="showAdd">
|
|
|
<textarea v-model="comment"
|
|
|
class="textarea"
|
|
|
:maxlength="100"
|
|
@@ -20,17 +20,24 @@
|
|
|
</div>
|
|
|
<button class="btn" @click="addComment">评论</button>
|
|
|
</div>
|
|
|
+ <div v-else class="text-footer">
|
|
|
+ 未登录或者已经评论过啦
|
|
|
+ </div>
|
|
|
+ <button open-type='share' class="btn">转发给好友</button>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
import {get, post, showModal} from '@/util'
|
|
|
import BookInfo from '@/components/BookInfo'
|
|
|
+import CommentList from '@/components/CommentList'
|
|
|
export default {
|
|
|
components: {
|
|
|
- BookInfo
|
|
|
+ BookInfo,
|
|
|
+ CommentList
|
|
|
},
|
|
|
data () {
|
|
|
return {
|
|
|
+ comments: [],
|
|
|
userinfo: {},
|
|
|
bookid: '',
|
|
|
info: {},
|
|
@@ -39,6 +46,19 @@ export default {
|
|
|
phone: ''
|
|
|
}
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ showAdd () {
|
|
|
+ //未登录
|
|
|
+ if(!this.userinfo.openId) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 评论页面里查到有自己的openid
|
|
|
+ if (this.comments.filter(v => v.openid === this.userinfo.openId).length) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ },
|
|
|
methods: {
|
|
|
async addComment () {
|
|
|
if (!this.comment) {
|
|
@@ -56,6 +76,7 @@ export default {
|
|
|
console.log(data)
|
|
|
await post('/weapp/addcomment', data);
|
|
|
this.comment = '';
|
|
|
+ this.getComments();
|
|
|
} catch (e) {
|
|
|
showModal('失败', e.msg)
|
|
|
}
|
|
@@ -109,6 +130,11 @@ export default {
|
|
|
})
|
|
|
console.log(info)
|
|
|
this.info = info
|
|
|
+ },
|
|
|
+ async getComments () {
|
|
|
+ const comments = await get('/weapp/commentlist', {bookid: this.bookid});
|
|
|
+ console.log('comments', comments);
|
|
|
+ this.comments = comments.list || []
|
|
|
}
|
|
|
},
|
|
|
onShareAppMessage: function(res) {
|
|
@@ -134,6 +160,7 @@ export default {
|
|
|
mounted () {
|
|
|
this.bookid = this.$root.$mp.query.id; // 跳转页面使用this.$root.$mp.query获取参数
|
|
|
this.getDetail();
|
|
|
+ this.getComments();
|
|
|
const userinfo = wx.getStorageSync('userInfo')
|
|
|
console.log('userInfo', userinfo);
|
|
|
if (userinfo) {
|