<template>
  <a-modal :visible="visible" title="评论详情" @cancel="visible=false" :footer="null">
    <div v-for="(item,index) in list" :key="index" class="comment">
      <div>
        <div>
          <b>{{ item.buyer_name }}</b>
        </div>
        <a-rate v-model="item.stars" disabled style="font-size: 12px" />
      </div>
      <div>
        <span style="color:#ccc">{{ moment(item.create_time).format('YYYY-MM-DD HH:mm:ss') }}</span>
        <a style="color:#d9001b;margin-left:10px" @click="delComment(item)">删除</a>
      </div>
      <div>
        <span v-if="item.evaluation">{{ item.evaluation }}</span>
        <span v-if="!item.evaluation" style="color:#ccc">未评论</span>
      </div>
      <div>
        <a-textarea v-model="item.reply" :rows="2" />
        <div style="text-align:right"><a style="color:#95f204;" @click="replyComment(item)">回复</a></div>
      </div>
      <a-divider />
    </div>
  </a-modal>
</template>

<script>
import moment from 'moment'
import { updateEvaluation } from '@/api/guide'

export default {
  data () {
    return {
      visible: false,
      list: []
    }
  },
  methods: {
    moment,
    show (data) {
      this.list = data
      this.visible = true
    },
    async replyComment (record) {
      if (!record.reply) return
      await updateEvaluation({ id: record.id, reply: record.reply })
      this.$message.success('回复成功')
    },
    async delComment (record) {
      this.visible = false
      await updateEvaluation({ id: record.id, status: 2 })
      this.$message.success('删除成功')
      this.$emit('update')
    }
  }
}
</script>

  <style lang="scss" scoped>
.comment{
    margin-bottom:20px;
}
.ant-modal-body{
    max-height: 70vh;
    overflow: auto;
}
  </style>
