<template>
  <div class="cmain">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="提问标题" prop="question">
        <el-input
          v-model="form.question"
          placeholder="请输入提问标题"
        ></el-input>
      </el-form-item>

      <el-form-item label="标签名称">
        <el-select
          v-model="form.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="detail">
        <editor v-model="form.detail" />
      </el-form-item>

      <el-form-item label="专家回答" prop="expertAnswer">
        <editor v-model="form.expertAnswer" />
      </el-form-item>

      <el-form-item label="专家姓名" prop="expertName">
        <el-input
          v-model="form.expertName"
          placeholder="请输入专家姓名"
        ></el-input>
      </el-form-item>

      <el-form-item label="评价状态">
        <el-select
          v-model="form.judge"
          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>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="$layer.close(layerid)">取 消</el-button>
    </div>
  </div>
</template>
  
  <script>
import {
  listQUESTION,
  getQUESTION,
  delQUESTION,
  addQUESTION,
  updateQUESTION,
  getMarkListAll,
} from "@/api/portal/QUESTION/QUESTION.js";
export default {
  data() {
    return {
      markList: [],
      judgeList: [{ label: "未评价", value: "0" }],
      judgeList: [
        { label: "未评价", value: "0" },
        { label: "好评", value: "1" },
        { label: "中评", value: "2" },
        { label: "差评", value: "3" },
      ],
      checkStatusList: [
        { label: "待审核", value: "0" },
        { label: "已审核", value: "1" },
        { label: "审核拒绝", value: "2" },
      ],
      form: {},
      // 表单校验
      rules: {
        expertName: [
          { required: true, message: "专家姓名不能为空", trigger: "blur" },
        ],
        expertId: [
          { required: true, message: "专家id不能为空", trigger: "blur" },
        ],
        expertAnswer: [
          { required: false, message: "专家回答不能为空", trigger: "blur" },
        ],
        detail: [
          { required: false, message: "提问详情不能为空", trigger: "blur" },
        ],
        status: [
          { required: true, message: "评价状态不能为空", trigger: "blur" },
        ],
        responseTime: [
          { required: true, message: "期望回复时间不能为空", trigger: "blur" },
        ],
        checkStatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" },
        ],
        judge: [{ required: true, message: "评价不能为空", trigger: "blur" }],
        replyTime: [
          { required: true, message: "回复时间不能为空", trigger: "blur" },
        ],
        answerId: [
          { required: true, message: "$comment不能为空", trigger: "blur" },
        ],
        id: [{ required: true, message: "$comment不能为空", trigger: "blur" }],
        cbId: [{ required: true, message: "标签_id不能为空", trigger: "blur" }],
        delFlag: [
          { required: true, message: "删除标识不能为空", trigger: "blur" },
        ],
        deptId: [
          { required: true, message: "部门id不能为空", trigger: "blur" },
        ],
        question: [
          { required: true, message: "提问标题不能为空", trigger: "blur" },
        ],
        mark: [
          { required: true, message: "标签名称不能为空", trigger: "blur" },
        ],
        ansName: [
          { required: true, message: "提问人姓名不能为空", trigger: "blur" },
        ],
      },
    };
  },
  props: {
    param: {
      type: Object,
      default: () => {
        return {};
      },
    },
    layerid: {
      type: String,
    },
  },
  mounted() {
    if (this.param.id) {
      getQUESTION(this.param.id).then((response) => {
        this.form = response.data;
        if (this.form.expertAnswer) {
          this.form.expertAnswer = response.data.expertAnswer.replace(
            new RegExp("/profile/upload/", "g"),
            this.baseUrl + "/profile/upload/"
          );
        }
        if (this.form.detail) {
          this.form.detail = response.data.detail.replace(
            new RegExp("/profile/upload/", "g"),
            this.baseUrl + "/profile/upload/"
          );
        }
      });
    }
    this.getMark();
  },
  methods: {
    getMark() {
      getMarkListAll().then((res) => {
        this.markList = res.data;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateQUESTION(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.$layer.close(this.layerid);
              this.$parent.getList();
            });
          } else {
            addQUESTION(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.$layer.close(this.layerid);
              this.$parent.getList();
            });
          }
        }
      });
    },
  },
};
</script>
  