<template>
  <div>
    <el-dialog
      :title="title"
      :visible="mediationVisable"
      @close="cancel"
      center
      :distroy-on-close="true"
      width="1000px"
    >
      <el-form ref="form" :model="formData" label-width="180px">
        <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="请输入案件编号" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请人：" prop="affiliate.applicationOrganName">
              <el-input v-model="formData.affiliate.applicationOrganName" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="被申请人：" prop="respondentName">
              <el-input v-model="mediationData.respondentName" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="案件标的：" prop="caseSubjectAmount">
              <el-input
                v-model="formData.caseSubjectAmount"
                placeholder="请输入案件标的"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="调解费用：" prop="feePayable">
              <el-input v-model="formData.feePayable" placeholder="请输入仲裁费用" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="调解员：" prop="mediatorName">
              <el-input v-model="formData.mediatorName" placeholder="请输入" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
        <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" v-if="item.annexType==2">
              <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-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-col :span="24" v-if="recordArr.length > 0">
          <el-form-item label="庭审笔录：">
            <div v-for="(item, index) in recordArr" :key="index" style="color: blue">
              <a href="#" @click="toFile2(item.annexPath)">{{ item.annexName }}</a>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="mediationType">
          <el-form-item label="预约会议房间号：">
            <div>{{ formData.roomId }}</div>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="mediationType">
          <el-form-item label="开庭时间：">
            <div>{{ formData.hearDate }}</div>
          </el-form-item>
        </el-col>
        <!-- </el-form> -->
      </el-form>
      <el-button @click="openmeeting" type="primary" v-if="mediationType">发起会议</el-button>
      <el-button
        @click="openArbitrationresults"
        type="primary"
        v-if="this.recordArr.length <= 0 && mediationData.mediationMethod == '1'"
      >确认会议结果</el-button>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel" class="endbutton1" round>
          <span>取 消</span>
        </el-button>
        <el-button
          @click="submitMediation"
          :disabled="this.recordArr.length <= 0 && mediationData.mediationMethod == '1'"
          class="endbutton1"
          type="primary"
          round
        >
          <span>提 交</span>
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<!-- hearDate -->
<script>
import {
  caseApplicationSelectById,
  mediation
} from "@/api/caseManagement/caseManagement.js";
import { getUserProfile } from "@/api/system/user";
import { reserveConferenceList } from "@/api/metting/metting.js";
export default {
  props: ["mediationVisable", "mediationData", "queryParams"],
  data() {
    return {
      loanStartDate: "",
      title: "开庭调解",
      applicateArr: [],
      quiltArr: [],
      recordArr: [],
      roomId: null,
      startTime: null,
      formData: {
        affiliate: {}
      },
      user: "",
      userId: null,
      flieList: [],
      mediationType: true
    };
  },
  watch: {
    mediationVisable(val) {
      this.recordArr = [];
      if (this.mediationData.mediationMethod == "1") {
        this.title = "开庭调解";
        this.mediationType = true;
      } else if (this.mediationData.mediationMethod == "2") {
        this.title = "书面调解";
        this.mediationType = false;
      }
      if (val) {
        this.caseApplicationSelectByIdFn({
          id: this.mediationData.id
        });
        this.getUser();
      }
    }
  },
  created() {},
  methods: {
    /** 获取案件详情信息 */
    caseApplicationSelectByIdFn(data) {
      caseApplicationSelectById(data).then(res => {
        this.formData = res.data;
        this.applicateArr = res.data.caseAttachList;
        res.data.caseAttachList.forEach(item => {
          if (item.annexType == 6) {
            this.recordArr.push(item);
          }
        });
      });
    },
    /** 获取用户信息 */
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data.userName;
        this.userId = response.data.userId;
      });
    },
    /** 发起会议 */
    openmeeting() {
      window.open(
        // `http://localhost:8080/#/home?name=${this.user}&id=${this.formData.id}&userId=${this.userId}&roomId=${this.formData.roomId}&type=tiaojie`
        `https://txroom.xayunmei.com/#/home?name=${this.user}&id=${this.formData.id}&userId=${this.userId}&roomId=${this.formData.roomId}&type=tiaojie`
      );
    },
    /**提交仲裁结果 */
    openArbitrationresults() {
      caseApplicationSelectById({
        id: this.mediationData.id
      }).then(res => {
        res.data.caseAttachList.forEach(item => {
          if (item.annexType == 6) {
            this.recordArr.push(item);
          }
        });
      });
    },
    /** 庭审笔录附件 */
    toFile2(annexPath) {
      window.open(window.location.origin + "/API" + annexPath, "_black");
    },
    /** 生成调解书 */
    mediationFn(data) {
      mediation(data).then(res => {
        this.$modal.msgSuccess("成功");
        this.$emit("cancelMediation");
        this.$emit("getList", this.queryParams);
      });
    },
    cancel() {
      this.$emit("cancelMediation");
    },
    submitMediation() {
      this.mediationFn({
        id: this.mediationData.id,
        caseFlowId: this.mediationData.caseFlowId
      });
    }
  }
};
</script>
  
<style lang="scss" scoped>
.steps {
  display: flex;
  flex-wrap: wrap;
}
</style>