<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          size="mini"
          @click="getList"
        >刷新</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="storeProductReplyList" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="用户" align="center" prop="username" />
      <el-table-column label="商品" align="center" prop="productName" />
      <el-table-column label="商品分数" align="center" prop="productScore" />
      <el-table-column label="服务分数" align="center" prop="serviceScore" />
      <el-table-column label="评论内容" align="center" prop="comment" />
      <el-table-column  label="评论图片"  align="center" prop="pics">
        <template slot-scope="scope">
          <div>
             <el-image
             v-if="scope.row.pics!=null"
              :fit="cover"
              style="width: 50px; height: 50px"
              :src="scope.row.pics.split(',')[0]"
              :preview-src-list="scope.row.pics.split(',')">
            </el-image>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="评价时间" align="center" prop="createTime" width="180" />
      <el-table-column label="回复内容" align="center" prop="replyContent" />
      <el-table-column label="回复时间" align="center" prop="replyTime" width="180">
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
          v-if="scope.row.isReply==0"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleReply(scope.row)"
            v-hasPermi="['store:storeProductReply:reply']"
          >回复</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['store:storeProductReply:remove']"
          >删除</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="title" :visible.sync="open" width="650px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户" prop="userId">
          <el-input v-model="form.username" disabled placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="产品" prop="productId">
          <el-input v-model="form.productName" disabled placeholder="请输入产品id" />
        </el-form-item>
        <el-form-item label="商品分数" prop="productScore">
          <el-input v-model="form.productScore" disabled placeholder="请输入商品分数" />
        </el-form-item>
        <el-form-item label="服务分数" prop="serviceScore">
          <el-input v-model="form.serviceScore" disabled placeholder="请输入服务分数" />
        </el-form-item>
        <el-form-item label="评论内容" prop="comment">
          <el-input v-model="form.comment" disabled type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="评论图片" prop="pics">
            <el-image
             v-if="form.pics!=null"
              :fit="cover"
              style="width: 50px; height: 50px"
              :src="form.pics.split(',')[0]"
              :preview-src-list="form.pics.split(',')">
            </el-image>
        </el-form-item>
        <el-form-item label="回复内容" prop="replyContent">
          <el-input v-model="form.replyContent" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { replyStoreProductReply,listStoreProductReply, getStoreProductReply, delStoreProductReply, addStoreProductReply, updateStoreProductReply, exportStoreProductReply } from "@/api/hisStore/storeProductReply";
import Editor from '@/components/Editor';

export default {
  name: "HisStoreProductReply",
  components: { Editor },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 评论表格数据
      storeProductReplyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        orderId: null,
        productId: null,
        replyType: null,
        productScore: null,
        serviceScore: null,
        comment: null,
        pics: null,
        replyContent: null,
        replyTime: null,
        isDel: null,
        isReply: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        replyContent: [
          { required: true, message: "回复内容不能为空", trigger: "blur" }
        ],

      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询评论列表 */
    getList() {
      this.loading = true;
      listStoreProductReply(this.queryParams).then(response => {
        this.storeProductReplyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        orderId: null,
        productId: null,
        replyType: null,
        productScore: null,
        serviceScore: null,
        comment: null,
        pics: null,
        createTime: null,
        updateTime: null,
        replyContent: null,
        replyTime: null,
        isDel: null,
        isReply: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加评论";
    },
    /** 修改按钮操作 */
    handleReply(row) {
      this.reset();
      const id = row.id || this.ids
      getStoreProductReply(id).then(response => {
        this.form = response.data;
        this.form.username=row.username;
        this.form.productName=row.productName
        this.open = true;
        this.title = "回复评论";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          replyStoreProductReply(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess("回复成功");
              this.open = false;
              this.getList();
            }
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除评论编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delStoreProductReply(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有评论数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportStoreProductReply(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
