<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="评价状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择评价状态"
          clearable
          filterable
        >
          <el-option
            v-for="dict in judgeList"
            :key="dict.value + 'judgeList'"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="咨询标签" prop="mark">
        <el-select
          v-model="queryParams.mark"
          placeholder="请选择或输入咨询标签"
          clearable
          filterable
        >
          <el-option
            v-for="dict in markList"
            :key="dict.mark + 'markList'"
            :label="dict.mark"
            :value="dict.mark"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="checkStatus">
        <el-select
          v-model="queryParams.checkStatus"
          placeholder="请选择审核状态"
          clearable
          filterable
        >
          <el-option
            v-for="dict in checkStatusList"
            :key="dict.value + 'checkStatusList'"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:QUESTION:add']"
          >新增</el-button
        >
      </el-col> -->

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table :data="QUESTIONList">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="提问标题">
              {{ props.row.question }}
            </el-form-item>
            <el-form-item label="专家回答">
<!--             {{ props.row.expertAnswer }}-->
              <div class="clear_p" v-html="props.row.expertAnswer"></div>
            </el-form-item>
            <el-form-item label="提问详情">
              {{ props.row.detail }}
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="标签名称" align="center" prop="mark">
        <template slot-scope="scope">
          {{ scope.row.mark }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="提问标题" align="center" prop="question">
        <template slot-scope="scope">
          {{ scope.row.question }}
        </template>
      </el-table-column> -->
      <el-table-column label="专家姓名" align="center" prop="expertName">
        <template slot-scope="scope">
          {{ scope.row.expertName }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="专家回答" align="center" prop="expertAnswer">
        <template slot-scope="scope">
          {{ scope.row.expertAnswer }}
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="提问详情" align="center" prop="detail">
        <template slot-scope="scope">
          {{ scope.row.detail }}
        </template>
      </el-table-column> -->
      <el-table-column label="评价状态" align="center" prop="status">
        <template slot-scope="scope">
          <!-- <el-tag v-if="scope.row.status == 0">未回复</el-tag> -->
          <el-tag v-if="scope.row.status == 1" type="success"
            >已回复</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column
        label="期望回复时间"
        align="center"
        prop="responseTime"
        width="120px"
      >
        <template slot-scope="scope">
          {{ scope.row.responseTime }}
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="checkStatus" width="100px">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.checkStatus == 0">待审核</el-tag>
          <el-tag v-else-if="scope.row.checkStatus == 1" type="success"
            >已审核</el-tag
          >
          <el-tag v-else-if="scope.row.checkStatus == 2" type="danger"
            >审核拒绝</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column label="评价" align="center" prop="judge">
        <template slot-scope="scope">
          <!-- <el-tag v-if="scope.row.judge == 0">未评价</el-tag> -->
          <el-tag v-if="scope.row.judge == 1" type="success">好评</el-tag>
          <el-tag v-else-if="scope.row.judge == 2" type="warning">中评</el-tag>
          <el-tag v-else-if="scope.row.judge == 3" type="danger">差评</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="回复时间" align="center" prop="replyTime">
        <template slot-scope="scope">
          {{ scope.row.replyTime }}
        </template>
      </el-table-column>

      <!-- <el-table-column label="提问人姓名" align="center" prop="ansName">
        <template slot-scope="scope">
          {{ scope.row.ansName }}
        </template>
      </el-table-column> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:QUESTION:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:QUESTION: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>-->
<!--    ↑不知道是不是没删干净，我先注释了-->
  </div>
</template>

<script>
import {
  listQUESTION,
  getQUESTION,
  delQUESTION,
  addQUESTION,
  updateQUESTION,
  getMarkListAll
} from "@/api/portal/QUESTION/QUESTION.js";
import edit from "./edit.vue";

export default {
  name: "QUESTION",
  data() {
    return {
      markList:[],
      judgeList: [
        { label: "未评价", value: "0" },
        { label: "好评", value: "1" },
        { label: "中评", value: "2" },
        { label: "差评", value: "3" },
      ],
      checkStatusList: [
        { label: "待审核", value: "0" },
        { label: "已审核", value: "1" },
        { label: "审核拒绝", value: "2" },
      ],
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 咨询信息表格数据
      QUESTIONList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        expertName: null,
        expertId: null,
        expertAnswer: null,
        detail: null,
        status: null,
        responseTime: null,
        checkStatus: null,
        judge: null,
        replyTime: null,
        answerId: null,
        id: null,
        cbId: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        delFlag: null,
        deptId: null,
        question: null,
        mark: null,
        ansName: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList()
    this.getMark()
  },
  methods: {
    getMark(){
      getMarkListAll().then(res=>{
        this.markList = res.data
      })
    },
    /** 查询咨询信息列表 */
    getList() {
      this.loading = true;
      listQUESTION(this.queryParams).then((response) => {
        this.QUESTIONList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        expertName: null,
        expertId: null,
        expertAnswer: null,
        detail: null,
        status: "0",
        responseTime: null,
        checkStatus: "0",
        judge: null,
        replyTime: null,
        answerId: null,
        id: null,
        cbId: null,
        delFlag: null,
        deptId: null,
        question: null,
        mark: null,
        ansName: 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.expertName);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加咨询信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids;
      this.iframe({ obj: edit, param: { id: id }, title: '修改咨询请求', width: '1050px', height: '80%' });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.expertName != null) {
            updateQUESTION(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addQUESTION(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const expertIds = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除？')
        .then(function () {
          return delQUESTION(expertIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "business/QUESTION/export",
        {
          ...this.queryParams,
        },
        `QUESTION_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>

<style scoped>
 .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
    padding-left: 90px;
  }

  ::v-deep .el-form-item__content p{
    margin: 0 !important;
  }

</style>
