<template>
  <div>
    <el-dialog
      :title="title"
      :visible="openDialog"
      width="1000px"
      @close="cancel"
      :destroy-on-close="true"
    >
      <el-descriptions title="案件信息" border style="margin-bottom: 30px">
        <el-descriptions-item label="案件编号">{{
          form.caseNum
        }}</el-descriptions-item>
        <el-descriptions-item label="案件标的">{{
          form.caseSubjectAmount
        }}</el-descriptions-item>
        <el-descriptions-item label="借款开始日期">{{
          form.loanStartDate
        }}</el-descriptions-item>
        <el-descriptions-item label="借款结束日期">{{
          form.loanEndDate
        }}</el-descriptions-item>
        <el-descriptions-item label="合同编号">{{
          form.contractNumber
        }}</el-descriptions-item>
        <el-descriptions-item label="申请人主张欠本金">{{
          form.claimPrinciOwed
        }}</el-descriptions-item>
        <el-descriptions-item label="申请人主张欠利息">{{
          form.claimInterestOwed
        }}</el-descriptions-item>
        <el-descriptions-item label="申请人主张违约金">{{
          form.claimLiquidDamag
        }}</el-descriptions-item>
        <el-descriptions-item label="申请人案件证据资料">{{
          form.aaa
        }}</el-descriptions-item>
        <el-descriptions-item label="被申请人案件证据资料">{{
          form.aaa
        }}</el-descriptions-item>
        <el-descriptions-item label="裁决书附件">{{
          form.aaa
        }}</el-descriptions-item>
      </el-descriptions>
      <el-form
        ref="form"
        :model="arbitrateRecord"
        label-width="300px"
        label-position="left"
        :rules="rules"
      >
        <el-form-item
          label="经庭审质证，对各方提供的证据认定如下"
          prop="evidenDetermi"
        >
          <el-input
            type="textarea"
            autosize
            placeholder="请输入内容"
            v-model="arbitrateRecord.evidenDetermi"
          />
        </el-form-item>
        <el-form-item
          label="仲裁庭经审理查明(写明仲裁庭认定的事实)"
          prop="factDetermi"
        >
          <el-input
            type="textarea"
            autosize
            placeholder="请输入内容"
            v-model="arbitrateRecord.factDetermi"
          />
        </el-form-item>
        <el-form-item label="综上所述" prop="caseSketch">
          <el-input
            type="textarea"
            autosize
            placeholder="请输入内容"
            v-model="arbitrateRecord.caseSketch"
          />
        </el-form-item>
        <el-form-item label="本庭认为" prop="arbitrateThink">
          <el-input
            type="textarea"
            autosize
            placeholder="请输入内容"
            v-model="arbitrateRecord.arbitrateThink"
          />
        </el-form-item>
        <el-form-item label="裁决如下" prop="rulingFollows">
          <el-input
            type="textarea"
            autosize
            placeholder="请输入内容"
            v-model="arbitrateRecord.rulingFollows"
          />
        </el-form-item>
        <el-form-item label="核验裁决书意见：" prop="verificaOpinion">
          <el-input
            type="textarea"
            autosize
            placeholder="请输入内容"
            v-model="arbitrateRecord.verificaOpinion"
          />
        </el-form-item>
        <el-form-item
          label="审核裁决书意见："
          prop="checkOpinion"
          v-if="flag == 2"
        >
          <el-input
            type="textarea"
            autosize
            placeholder="请输入内容"
            v-model="arbitrateRecord.checkOpinion"
          />
        </el-form-item>
      </el-form>
      <!-- 画布 -->
      <h4 v-if="flag == 3">签名区域</h4>
      <div class="esign" v-if="flag == 3">
        <vue-esign ref="esign" :width="900" :height="300" bgColor="#ffffff" />
      </div>
      <!-- 清除画布 -->
      <el-button v-if="flag == 3" type="info" @click="handleReset"
        >清除画布</el-button
      >
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm(0)" v-if="flag == 1"
          >提 交</el-button
        >
        <el-button type="primary" @click="submitForm(1)" v-if="flag == 2"
          >同 意</el-button
        >
        <el-button type="danger" @click="submitForm(2)" v-if="flag == 2"
          >驳 回</el-button
        >
        <el-button type="primary" @click="submitForm(3)" v-if="flag == 3"
          >提 交</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  verificationArbitrateRecord,
  checkArbitrateRecord,
} from "@/api/awardManagement/awardManagement";
export default {
  props: ["openDialog", "title", "flag", "detailform"],
  data() {
    return {
      // key: value
      form: {},
      arbitrateRecord: {},
      // 表单校验
      rules: {
        evidenDetermi: [
          {
            required: true,
            message: "不能为空",
            trigger: "blur",
          },
        ],
        factDetermi: [
          {
            required: true,
            message: "不能为空",
            trigger: "blur",
          },
        ],
        caseSketch: [
          {
            required: true,
            message: "不能为空",
            trigger: "blur",
          },
        ],
        arbitrateThink: [
          {
            required: true,
            message: "不能为空",
            trigger: "blur",
          },
        ],
        rulingFollows: [
          {
            required: true,
            message: "不能为空",
            trigger: "blur",
          },
        ],
        verificaOpinion: [
          {
            required: true,
            message: "意见不能为空",
            trigger: "blur",
          },
        ],
        checkOpinion: [
          {
            required: true,
            message: "意见不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  watch: {
    openDialog: {
      handler(val) {
        if (val) {
          setTimeout(() => {
            this.form = this.detailform;
            this.arbitrateRecord = this.form.arbitrateRecord;
            console.log(this.form, "this.form");
          }, 1000);
        }
      },
    },
  },
  methods: {
    // 校验裁决书
    verificationArbitrateRecordFn(parms) {
      verificationArbitrateRecord(parms).then((res) => {
        this.cancel();
        this.$emit("updataList");
        this.$message("成功");
      });
    },
    //审核裁决书
    checkArbitrateRecordFn(parms) {
      checkArbitrateRecord(parms).then((res) => {
        this.cancel();
        this.$emit("updataList");
        this.$message("成功");
      });
    },
    submitForm(parms) {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (parms == 0) {
            this.verificationArbitrateRecordFn({
              id: this.form.id,
              arbitrateRecord: this.arbitrateRecord,
            });
          } else if (parms == 1) {
            this.checkArbitrateRecordFn({
              id: this.form.id,
              agreeOrNotCheck: 1,
              arbitrateRecord: this.arbitrateRecord,
            });
          } else if (parms == 2) {
            this.checkArbitrateRecordFn({
              id: this.form.id,
              agreeOrNotCheck: 2,
              arbitrateRecord: this.arbitrateRecord,
            });
          }
        }
      });
    },
    cancel() {
      this.$emit("cancelpaymentdetails");
    },
    // 清除画布
    handleReset() {
      this.$refs["esign"].reset(); //清空画布
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
  border-radius: 30px;
}

.esign {
  border: 1px solid;
}
</style>