<template>
  <div class="commentlist-container">
    <!-- <div class="comment-top">
      <el-select
        v-model="status"
        placeholder="评论状态"
        style="width: 260px"
        @change="initList"
      >
        <el-option
          v-for="item in statusArr"
          :key="item.key"
          :label="item.label"
          :value="item.key"
        />
      </el-select>
    </div> -->
    <el-table border :data="tableData" style="margin-top: 20px">
      <el-table-column
        v-for="item in tableColums"
        :key="item.label"
        :label="item.label"
        :width="item.widthsty"
        :min-width="item.minwidthsty"
        align="center"
        :prop="item.key"
      >
        <template slot-scope="{ row }">
          <span v-if="item.key === 'CompanyName'" :class="row.CompanyId && 'editsty'" @click="goCompanyDetail(row.CompanyId)">{{ row.CompanyId ? `${row.CompanyName}(${row.CompanyFiccStatus}) ` : '——'}}</span>
          <!-- 状态 -->
          <span v-else-if="item.key === 'Status'">{{ row.IsHot ? '精选' : '未精选'}}</span>

          <span v-else>{{ row[item.key] || "——" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <!-- <span class="editsty" @click="actionHandle('set', row)" v-if="row.IsHot">取消精选</span>
          <span class="editsty" @click="actionHandle('set', row)" v-else>精选</span> -->
          <span class="deletesty" @click="actionHandle('del', row)" style="margin-left: 10px">删除</span>
        </template>
      </el-table-column>
      <div slot="empty" style="padding: 20px 0">
        <img
          src="~@/assets/img/cus_m/nodata.png"
          alt=""
          style="display: block; width: 128px; height: 128px; margin: 0 auto"
        />
        <span>暂无数据</span>
      </div>
    </el-table>
    <div style="height: 40px; margin-top: 10px; padding: 0 20px">
      <m-page
        :page_no="page_no"
        :pageSize="10"
        :total="totals"
        @handleCurrentChange="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { interactiveInterface } from '@/api/api.js'
import mPage from "@/components/mPage";
export default {
  data() {
    return {
      status: -1,
      page_no: 1,
      pageSize: 10,
      totals: 0,
      tableData: [1],
      tableColums: [
        {
          label: "评论内容",
          key: "Content",
          minwidthsty: 150,
        },
        {
          label: "所属提问",
          key: "QuestionContent",
          minwidthsty: 150,
        },
        {
          label: "评论人",
          key: "RealName",
        },
        {
          label: "客户信息",
          key: "CompanyName",
        },
        // {
        //   label: "评论状态",
        //   key: "Status",
        // },
        {
          label: "评论时间",
          key: "CreateTime",
        },
      ],
      statusArr: [{
        label: '全部',
        key: -1
      },{
        label: '精选',
        key: 1
      },{
        label: '未精选',
        key: 0
      },]
    };
  },
  components: { mPage },
  methods: {

    //获取数据
    getList() {
      interactiveInterface.questionCommentList({
        CurrentIndex: this.page_no,
        PageSize: this.pageSize,
        HotStatus: this.status
      }).then(res => {
        if(res.Ret !== 200) return

        const { List,Paging } = res.Data;
        this.tableData = List || [];
        this.totals = Paging.Totals;
      })
    },

    initList() {
      this.page_no = 1;
      this.getList();
    },

    /* 操作 */
    actionHandle(key, item) {
      const actionMap = {
        set: this.setHotHandle,
        del: this.delHandle,
      };
      actionMap[key](item);
    },

    /* 设置精选 */
    setHotHandle(item) {
      const { CommunityQuestionCommentId,IsHot } = item;
      interactiveInterface.setHotQuestionComment({
        CommunityQuestionCommentId
      }).then(res => {
        if(res.Ret !== 200) return

        this.$message.success(IsHot ? '取消成功' : '设置精选成功')
        item.IsHot = IsHot ? 0 : 1;
      })
    },

    /* 删除 */
    delHandle({CommunityQuestionCommentId}) {
      this.$confirm("评论删除后不可恢复，确认删除吗？", "提示", {
        type: "warning",
      }).then(() => {
        interactiveInterface.questionCommentDel({ CommunityQuestionCommentId })
          .then(res => {
            if(res.Ret !== 200) return
            this.$message.success('删除成功')

            this.getList();
          })
      });
    },

    /* 改变页码 */
    handleCurrentChange(page_no) {
      this.page_no = page_no;
      this.getList();
    },

    /* 客户详情 */
    goCompanyDetail(id) {
      id && this.$router.push({
        path: '/customDetail',
        query: { id }
      })
    }
  },

  mounted() {
    this.getList()
  }
};
</script>

<style lang="scss" scoped>
* {
  box-sizing: border-box;
}
.commentlist-container {
  min-height: calc(100vh - 120px);
  padding: 20px 30px;
  background: #fff;
  border: 1px solid #ececec;
  border-radius: 4px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
  .comment-top {
    display: flex;
    justify-content: flex-end;
  }
}
</style>
