<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" :size="ELsize" label-width="auto">
      <el-form-item label="用户昵称" prop="userNickname">
        <el-input v-model="queryParams.userNickname" placeholder="请输入用户昵称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="商品名称" prop="productTitle">
        <el-input v-model="queryParams.productTitle" placeholder="请输入商品名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="评价内容" prop="comment">
        <el-input v-model="queryParams.comment" placeholder="请输入评价内容" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="list" :border="TableBorder" :size="ELTableSize">
      <el-table-column type="index" width="55" label="序号" align="center">
        <template slot-scope="{$index}">
          {{ $getTableIndex(queryParams, $index + 1) }}
        </template>
      </el-table-column>
      <el-table-column label="用户昵称" align="center" prop="userNickname">
        <template slot-scope="{row}">
          {{ row.userNickname || '--' }}
        </template>
      </el-table-column>
      <el-table-column label="商品名称" align="center" prop="productTitle">
        <template slot-scope="{row}">
          {{ row.productTitle || '--' }}
        </template>
      </el-table-column>
      <el-table-column prop="commentScore" align="center" label="评价">
        <template slot-scope="{row}">
          <el-rate v-model="row.commentScore" disabled text-color="#ff0000">
          </el-rate>
        </template>
      </el-table-column>
      <el-table-column label="评价内容" align="center" show-overflow-tooltip prop="comment">
        <template slot-scope="{row}">
          {{ row.comment || '--' }}
        </template>
      </el-table-column>
      <el-table-column label="评论时间" align="center" prop="commentTime">
        <template slot-scope="{row}">
          {{ row.commentTime || '--' }}
        </template>
      </el-table-column>
      <!-- <el-table-column prop="show" align="center" label="是否显示">
        <template slot-scope="{row}">
          <el-switch v-model="row.show" :active-value="true" active-color="#13ce66" inactive-color="#B9B9B9" @change="switchChange(row)" />
        </template>
      </el-table-column> -->
      <el-table-column fixed="right" header-align="center" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" :size="ELTableSize" @click="showFun(scope.row)">查看</el-button>
          <el-button type="text" :size="ELTableSize" @click="reply(scope.row)" v-if="!scope.row.reply">回复</el-button>
          <el-button type="text" :size="ELTableSize" class="c-error" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 回复 -->
    <el-dialog title="回复" :visible.sync="dialogVisible" width="60%" :before-close="handleClose">
      <el-input type="textarea" :rows="2" placeholder="请输入内容" maxlength="200" v-model="textarea">
      </el-input>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="btnLoading" @click="replySave()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 弹窗, 查看 -->
    <evaluate-look v-if="visible" ref="evaluateLook"></evaluate-look>
  </div>
</template>

<script>
import { shopOrderCommentPage, shopOrderCommentDel, shopOrderCommentReplyAdd } from "@/api/order"
import evaluateLook from './evaluate-look.vue'
export default {
  components: { evaluateLook },
  data() {
    return {
      //按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测试单表表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 创建时间时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productTitle: undefined,
        userNickname: undefined,
        comment: undefined
      },
      rules: {},
      select: {},
      dialogVisible: false,
      visible: false,
      textarea: "",
      btnLoading: false
    }
  },
  created() {
    this.getList();
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    getList() {
      this.loading = true;
      this.queryParams["createTimeStart"] = undefined;
      this.queryParams["createTimeEnd"] = undefined;
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams["createTimeStart"] = this.daterangeCreateTime[0] + ' 00:00:00';
        this.queryParams["createTimeEnd"] = this.daterangeCreateTime[1] + ' 23:59:59';
      }
      shopOrderCommentPage(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.commentId;
      this.$modal.confirm('是否确认删除此的数据项？').then(() => {
        this.loading = true;
        return shopOrderCommentDel(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).finally(() => {
        this.loading = false;
      });
    },
    reply(row) {
      this.select = row;
      this.textarea = "";
      this.dialogVisible = true
    },
    handleClose() {
      this.dialogVisible = false
    },
    replySave() {
      if (!this.textarea) {
        this.$message.error('请输入回复内容')
        return
      }
      this.btnLoading = true;
      shopOrderCommentReplyAdd({ content: this.textarea, commentId: this.select.commentId })
        .then((res) => {
          if (res && res.code == 200) {
            this.$message.success('操作成功')
            this.dialogVisible = false
            this.getList()
          }
        }).finally(() => {
          this.btnLoading = false;
        })
    },
    // 查看
    showFun(row) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.evaluateLook.init(row)
      })
    }
  },
}
</script>

<style lang='scss' scoped></style>