<template>
  <div>
    <el-dialog
      title="书面审理"
      :visible="showadjudicaterecord"
      @close="cancel"
      :destroy-on-close="true"
      center
    >
      <el-form
        ref="form"
        :model="formData"
        label-width="180px"
        :disabled="true"
      >
        <div class="caseInfo">案件信息：</div>
        <el-divider></el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="案件编号：" prop="caseNum">
              <el-input
                v-model="formData.caseNum"
                placeholder="请输入案件编号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请人：" prop="applicantName">
              <el-input v-model="adjudicatename.applicantName" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="被申请人：" prop="respondentName">
              <el-input v-model="adjudicatename.respondentName" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="借款开始日期：" prop="loanStartDate">
              <el-date-picker
                v-model="formData.loanStartDate"
                type="datetime"
                placeholder="借款开始日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="借款结束日期：" prop="loanEndDate">
              <el-date-picker
                v-model="formData.loanEndDate"
                type="datetime"
                placeholder="借款结束日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="案件标的：" prop="caseSubjectAmount">
              <el-input
                v-model="formData.caseSubjectAmount"
                placeholder="请输入案件标的"
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
          <el-form-item label="逾期天数：" prop="caseSubjectAmount">
            <el-input
              v-model="formData.caseSubjectAmount"
              placeholder="请输入逾期天数"
            />
          </el-form-item>
        </el-col> -->
          <el-col :span="12">
            <el-form-item label="仲裁费用：" prop="feePayable">
              <el-input
                v-model="adjudicatename.feePayable"
                placeholder="请输入仲裁费用"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请人主张欠本金：" prop="claimPrinciOwed">
              <el-input
                v-model="formData.claimPrinciOwed"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
          <el-form-item label="案件顾问：" prop="claimPrinciOwed">
            <el-input v-model="formData.claimPrinciOwed" placeholder="请输入" />
          </el-form-item>
        </el-col> -->
          <el-col :span="12">
            <el-form-item label="案件状态：" prop="caseStatus">
              <el-input
                v-model="formData.caseStatusName"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="仲裁员：" prop="arbitratorName">
              <el-input
                v-model="adjudicatename.arbitratorName"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="开庭日期：" prop="hearDate">
              <el-date-picker
                v-model="adjudicatename.hearDate"
                type="datetime"
                placeholder="开庭日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-col :span="24">
          <el-form-item label="案件资料：" prop="claimPrinciOwed">
            <el-input v-model="formData.claimPrinciOwed" placeholder="请输入" />
          </el-form-item>
        </el-col> -->
        <el-col :span="24">
            <el-form-item
              label="申请人案件证据："
            >
              <div v-if="applicateArr.length == 0">申请人暂未提供证据！</div>
              <div v-else v-for="(item, index) in applicateArr" :key="index">
                <a href="#" @click="toFile(item, index)" style="color: blue">
                  {{ item.annexName }}
                </a>
              </div>
            </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item
              label="被申请人案件证据："
            >
            <div v-if="quiltArr.length == 0">被申请人暂未提供证据！</div>
            <div v-else v-for="(item, index) in quiltArr" :key="index">
                <a href="#" @click="toFile1(item, index)" style="color: blue">
                  {{ item.annexName }}
                </a>
            </div>
            </el-form-item>
        </el-col>
      </el-form>
      <el-form ref="form2" :model="form2" label-width="150px">
        <el-form-item label="笔录内容：" prop="responCrossOpin">
            <el-input type="textarea" :autosize="{ minRows: 6 }" v-model="form2.responCrossOpin" placeholder="请输入" />
          </el-form-item>
        <!-- <el-col :span="24">
          <el-form-item
            label="经庭审质证，对各方提供的证据认定如下："
            prop="evidenDetermi"
            :rules="[
              {
                required: true,
                message: '请输入仲裁结果',
                trigger: 'blur',
              },
            ]"
          >
            <el-input
              type="textarea"
              :autosize="{ minRows: 4 }"
              placeholder="请输入仲裁结果"
              v-model="form2.evidenDetermi"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            label="仲裁庭经审理查明(写明仲裁庭认定的事实)："
            prop="factDetermi"
            :rules="[
              {
                required: true,
                message: '请输入',
                trigger: 'blur',
              },
            ]"
          >
            <el-input
              type="textarea"
              :autosize="{ minRows: 4 }"
              placeholder="请输入"
              v-model="form2.factDetermi"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            label="综上所述："
            prop="caseSketch"
            :rules="[
              {
                required: true,
                message: '请输入',
                trigger: 'blur',
              },
            ]"
          >
            <el-input
              type="textarea"
              autosize
              placeholder="请输入"
              v-model="form2.caseSketch"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            label="本庭认为："
            prop="arbitrateThink"
            :rules="[
              {
                required: true,
                message: '请输入',
                trigger: 'blur',
              },
            ]"
          >
            <el-input
              type="textarea"
              autosize
              placeholder="请输入"
              v-model="form2.arbitrateThink"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            label="裁决如下："
            prop="rulingFollows"
            :rules="[
              {
                required: true,
                message: '请输入',
                trigger: 'blur',
              },
            ]"
          >
            <el-input
              type="textarea"
              autosize
              placeholder="请输入"
              v-model="form2.rulingFollows"
            >
            </el-input>
          </el-form-item>
        </el-col> -->
      </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 { writtenHear } from "@/api/caseManagement/caseManagement.js";

export default {
  props: ["showadjudicaterecord", "form", "adjudicatename", "queryParams"],
  data() {
    return {
      formData: {},
      form2: {},
      applicateArr: [],//申请人案件资料
      quiltArr: [],//被申请人案件资料
    };
  },
  watch: {
    showadjudicaterecord: {
      handler(val) {
        if (val) {
          this.applicateArr = [];
          this.quiltArr = [];
          this.formData = this.form;
          setTimeout(() => {
            if (this.adjudicatename.caseAttachList.length > 0) {
              this.adjudicatename.caseAttachList.forEach(item => {
                if (item.annexType == 2) {
                    this.applicateArr.push({
                      annexName: item.annexName,
                      annexPath: item.annexPath,
                    });
                  }
                  if (item.annexType == 6) {
                    this.quiltArr.push({
                      annexName: item.annexName,
                      annexPath: item.annexPath,
                    });
                  }
              });
            }          
          }, 500);
          this.form2 = {};
        }
      },
    },
  },
  methods: {
     // 详情显示，展示申请人案件文件
    toFile(item, index) {
      window.open(
        window.location.origin + "/API" + this.applicateArr[index].annexPath,
        "_black"
      );
    },
    // 被申请人文件
    toFile1(item, index) {
      window.open(
        window.location.origin + "/API" + this.quiltArr[index].annexPath,
        "_black"
      );
    },
    submitForm() {
      this.$refs["form2"].validate((valid) => {
        if (valid) {
          writtenHear({
            ids: [this.formData.id],
            evidenDetermi: this.form2.evidenDetermi,
            factDetermi: this.form2.factDetermi,
            caseSketch: this.form2.caseSketch,
            arbitrateThink: this.form2.arbitrateThink,
            rulingFollows: this.form2.rulingFollows,
          })
            .then((res) => {
              this.$modal.msgSuccess("提交成功");
              this.cancel();
              this.$emit("getcaseApply",this.queryParams);
            })
            .catch((err) => {});
        }
      });
    },
    cancel() {
      this.$emit("canceladjudicaterecord");
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
  width: 900px;
  background: #ffffff;
  border-radius: 20px;
}
.caseInfo {
  font-size: 17px;
  font-weight: 600;
}
</style>