c_BottomBtnLeft.vue 8.29 KB
<template>
  <div class="service_bottom_btn_left">
    <div class="icon" @click="backHome">
      <img src="@/assets/service/bottom_btn1.png" alt="" />
      <p>首页</p>
    </div>
    <template v-if="centerNo">
      <div class="icon" @click="handleComment">
        <img src="@/assets/service/bottom_btn2.png" alt="" />
        <p>{{ commentNum.commentNum }}</p>
      </div>
      <div class="icon" @click="handleLike">
        <img v-if="commentNum.thumbFlag == 1" src="@/assets/service/bottom_btn5.png" alt="" />
        <img v-else src="@/assets/service/bottom_btn3.png" alt="" />
        <p>{{ commentNum.thumbNum }}</p>
      </div>
      <div class="icon" @click="handleCollect">
        <img v-if="commentNum.collectFlag == 1" src="@/assets/service/bottom_btn6.png" alt="" />
        <img v-else src="@/assets/service/bottom_btn4.png" alt="" />
        <p>{{ commentNum.collectNum }}</p>
      </div>
    </template>
    <van-action-sheet v-model="showComment" title="全部评论" :closeable="false" close-on-click-action>
      <div class="comment_box">
        <div class="comment_item" v-for="(item, index) in commentList" :key="index">
          <img v-if="item.headImg" class="head" :src="item.headImg" alt="" />
          <img v-else class="head" src="@/assets/home/head.png" alt="" />
          <div class="center">
            <p class="name">{{ item.nickName }}</p>
            <van-icon v-if="item.centerNo == centerNo" class="del" name="delete-o" @click="handleDel(item.id)" />
            <p class="date">{{ Moment(item.createTime).format('MM-DD') }}</p>
            <p class="comment">{{ item.msg }}</p>
          </div>
        </div>
      </div>
      <div class="comment_bottom">
        <p @click="showCommentSubmit = true">发表评论...</p>
      </div>
    </van-action-sheet>
    <van-popup v-model="showCommentSubmit" round>
      <div class="comment_submit_box">
        <textarea class="comment_content" cols="30" rows="10" v-model="comment_content" placeholder="分享你的研学心得和成果…"></textarea>
        <van-button class="release_btn" round color="#3074FF" type="primary" :disabled="comment_content == ''" @click="handleRelease"
          >发表评论</van-button
        >
      </div>
    </van-popup>
  </div>
</template>
<script>
export default {
  props: ['centerNo', 'courseId'],
  data() {
    return {
      showComment: false,
      showCommentSubmit: false,
      comment_content: '', //评论内容
      commentNum: '', //评论点赞收藏数
      commentList: [], //评论列表
    }
  },
  mounted() {
    if (this.centerNo) {
      this.getCommentNum()
    }
  },
  methods: {
    // 获取商品评论点赞信息
    getCommentNum() {
      this.yxAxios
        .post(`${this.proxyUrl}//api/product/commentDetail`, {
          centerNo: this.centerNo,
          productId: this.courseId,
        })
        .then((res) => {
          if (res.data.code == 200) {
            this.commentNum = res.data.data
          } else {
            this.$toast.fail(res.data.message)
          }
        })
    },
    // 获取商品评论列表
    getCommentList() {
      this.yxAxios
        .post(`${this.proxyUrl}//api/product/getComment`, {
          centerNo: this.centerNo,
          productId: this.courseId,
          pageSize: 999,
          pageNum: 1,
        })
        .then((res) => {
          if (res.data.code == 200) {
            this.commentList = res.data.rows
          } else {
            this.$toast.fail(res.data.message)
          }
        })
    },
    // 返回首页
    backHome() {
      this.$router.push('/')
    },
    // 点击评论按钮
    handleComment() {
      this.getCommentList() // 获取商品评论列表
      this.showComment = true
    },
    // 点击点赞按钮
    handleLike() {
      let requestLink = ''
      if (this.commentNum.thumbFlag == 1) {
        requestLink = '/api/product/cancelThumb'
      } else {
        requestLink = '/api/product/thumb'
      }
      this.yxAxios
        .post(`${this.proxyUrl}/${requestLink}`, {
          centerNo: this.centerNo,
          productId: this.courseId,
        })
        .then((res) => {
          if (res.data.code == 200) {
            this.getCommentNum()
          } else {
            this.$toast.fail(res.data.message)
          }
        })
    },
    // 点击收藏按钮
    handleCollect() {
      let requestLink = ''
      if (this.commentNum.collectFlag == 1) {
        requestLink = '/api/product/cancelCollect'
      } else {
        requestLink = '/api/product/collect'
      }
      this.yxAxios
        .post(`${this.proxyUrl}/${requestLink}`, {
          centerNo: this.centerNo,
          productId: this.courseId,
        })
        .then((res) => {
          if (res.data.code == 200) {
            this.getCommentNum()
          } else {
            this.$toast.fail(res.data.message)
          }
        })
    },
    // 发表评论
    handleRelease() {
      this.yxAxios
        .post(`${this.proxyUrl}//api/product/comment`, {
          centerNo: this.centerNo,
          productId: this.courseId,
          msg: this.comment_content,
        })
        .then((res) => {
          if (res.data.code == 200) {
            this.$toast('评论成功')
            this.showCommentSubmit = false
            this.getCommentNum()
            this.getCommentList()
          } else {
            this.$toast.fail(res.data.message)
          }
        })
    },
    // 删除自己的评论
    handleDel(id) {
      this.$dialog
        .confirm({
          title: '警告',
          message: '删除后无法撤回操作,确定删除?',
        })
        .then(() => {
          this.yxAxios.post(`${this.proxyUrl}//api/product/deleteComment/${id}`).then((res) => {
            if (res.data.code == 200) {
              this.$toast('删除成功')
              this.getCommentNum()
              this.getCommentList()
            } else {
              this.$toast.fail(res.data.message)
            }
          })
        })
        .catch(() => {
          // on cancel
        })
    },
  },
}
</script>
<style lang="scss">
.service_bottom_btn_left {
  display: inline-flex;
  vertical-align: middle;
  color: #666666;
  width: 55%;
  justify-content: space-between;
  .icon {
    img {
      display: block;
      width: 48px;
    }
    p {
      font-size: 24px;
      color: #333;
      margin-top: 8px;
      text-align: center;
    }
  }
  .box_btn {
    width: 214px;
    border-radius: 42px;
    box-sizing: border-box;
    font-size: 34px;
    border: 2px solid #d8d8d8;
    text-align: center;
    line-height: 72px;
    font-weight: bold;
  }
  .comment_box {
    max-height: 700px;
    overflow: auto;
    .comment_item {
      padding: 40px 24px;
      border-top: 1px solid #f3f6fb;
      .head {
        display: inline-block;
        width: 74px;
        height: 74px;
        border-radius: 14px;
        vertical-align: top;
      }
      .center {
        display: inline-block;
        margin-left: 14px;
        width: 600px;
        position: relative;
        .name {
          font-size: 28px;
          color: #999;
          line-height: 40px;
          margin-bottom: 14px;
        }
        .del {
          font-size: 28px;
          line-height: 40px;
          position: absolute;
          top: 0;
          right: 0;
        }
        .date {
          font-size: 24px;
          color: #999;
          line-height: 34px;
          margin-bottom: 4px;
        }
        .comment {
          font-size: 28px;
          color: #333;
          line-height: 48px;
          white-space: pre-wrap;
        }
      }
    }
  }
  .comment_bottom {
    width: 100%;
    height: 214px;
    box-shadow: 0px -2px 8px 0px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    p {
      font-size: 28px;
      color: #999;
      width: 702px;
      height: 76px;
      line-height: 76px;
      padding-left: 36px;
      box-sizing: border-box;
      background: #f5f6fa;
      border-radius: 38px;
      margin: 0 auto;
      margin-top: 28px;
    }
  }
  .comment_submit_box {
    width: 600px;
    padding: 24px;
    padding-bottom: 40px;

    .release_btn {
      width: 100%;
      font-size: 32px;
    }
    .comment_content {
      display: block;
      font-size: 32px;
      width: 100%;
      height: 280px;
      padding: 0 24px;
      margin: 20px 0;
      box-sizing: border-box;
      border: none;
      background: transparent;
    }
  }
}
</style>