<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="案件编号" prop="caseNum">
        <el-input
          v-model="queryParams.caseNum"
          placeholder="请输入案件编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="申请人" prop="applicant">
        <el-input
          v-model="queryParams.applicant"
          placeholder="请输入申请人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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="filingApplication"
          v-hasPermi="['monitor:job:add']"
          >立案申请</el-button
        >
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="batchApplication"
          v-hasPermi="['monitor:job:add']"
          >批量立案</el-button
        >
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="dataList" style="width: 100%">
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="案件编号"
        align="center"
        prop="caseNum"
        :show-overflow-tooltip="true"
      />
      <!-- <el-table-column
        label="申请人"
        align="center"
        prop="caseAffiliates[0].name"
        :show-overflow-tooltip="true"
      /> -->
      <el-table-column
        label="案件标的"
        align="center"
        prop="caseSubjectAmount"
      />
      <el-table-column
        label="立案日期"
        align="center"
        prop="registerDate"
        :show-overflow-tooltip="true"
      />
      <!-- <el-table-column label="仲裁方式" align="center" prop="arbitratMethod" /> -->
      <el-table-column label="案件状态" align="center" prop="caseStatus" />
      <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-check"
            @click="onsubmitRow(scope.row)"
            v-hasPermi="['monitor:online:forceLogout']"
            >提交</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="editRow(scope.row)"
            v-hasPermi="['monitor:online:forceLogout']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-zoom-in"
            @click="detailRow(scope.row)"
            v-hasPermi="['monitor:online:forceLogout']"
            >详情</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="deleteRow(scope.row)"
            v-hasPermi="['monitor:online:forceLogout']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getcaseApply"
    />

    <!-- 立案申请弹框 -->
    <caseentryDialog
      :visible="visible"
      @cancel="cancel"
      :form="form"
      :dialogtitle="dialogtitle"
      :getcaseApply="getcaseApply"
      :flag="flag"
      :initpaymentArr="initpaymentArr"
      :initpaymentArr1="initpaymentArr1"
    ></caseentryDialog>
    <!-- 批量申请弹框 openbatch-->
    <batchDialog
    :openbatch="openbatch"
    @cancelBatch="cancelBatch"
    :getcaseApply="getcaseApply"
    ></batchDialog>
  </div>
</template>

<script>
import caseentryDialog from "./components/caseentryDialog";
import batchDialog from "./components/batchDialog";
import {
  caseApply,
  removeCaseApply,
  submitCaseApply,
  selectCaseApply
} from "@/api/caseAccess/caseEntry";
export default {
  name: "caseEntry",
  dicts: ["sys_identity_type"],
  components: {
    caseentryDialog,
    batchDialog
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      isapply: "申请人：",
      // 表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        caseNum: undefined,
        // applicant: undefined,
        caseStatus: 0,
        pageNum: 1,
        pageSize: 10,
      },
      dialogtitle: "", //弹框标题
      visible: false, //申请弹框控制
      form: {},
      starttime: "", //开始时间
      endtime: "", //结束时间
      formData: {},
      flag:"-1",
      initpaymentArr:[],
      initpaymentArr1:[],
      // 批量申请弹框
      openbatch: false,
    };
  },
  created() {
    this.getcaseApply();
  },
  methods: {
    cancel() {
      this.visible = false;
    },
    cancelBatch() {
      this.openbatch = false
    },
    /** 查询登录日志列表 */
    getcaseApply() {
      this.loading = true;
      caseApply(this.queryParams).then((response) => {
        this.dataList = response.rows;
        this.dataList.forEach((item) => {
          item.caseStatus = item.caseStatus == 0 ? "立案申请" : "待缴费";
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getcaseApply();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 立案申请
    filingApplication() {
      this.form = {};
        this.paymentArr = [
        {
          identityType: 1,
          name: "",
          identityNum: "",
          contactTelphone: "",
          workAddress: "",
          workTelphone: "",
          contactAddress: "",
          nameAgent: "",
          contactTelphoneAgent: "",
          contactAddressAgent: "",
        },
      ];
        this.paymentArr1 = [
        {
          identityType: 2,
          name: "",
          identityNum: "",
          contactTelphone: "",
          workAddress: "",
          workTelphone: "",
          contactAddress: "",
          nameAgent: "",
          contactTelphoneAgent: "",
          contactAddressAgent: "",
        },
      ]

      this.visible = true;
      this.dialogtitle = "立案申请";
      this.flag = "2"
    },
    // 批量立案
    batchApplication() {
      this.openbatch = true
    },
    // 列表提交立案
    onsubmitRow(row) {
      this.$modal
        .confirm("是否提交立案？")
        .then(function () {
          return submitCaseApply({ id: row.id });
        })
        .then(() => {
          this.getcaseApply();
          this.$modal.msgSuccess("立案成功");
        })
        .catch(() => {});
    },

    // 修改
    editRow(row) {
      this.flag = "1"
      this.form = row;
      this.visible = true;
      this.dialogtitle = "立案修改";
      this.getInfo(row);
    },
    // 详情
    detailRow(row) {
      this.flag = "0"
      this.form = row;
      this.visible = true;
      this.dialogtitle = "立案详情";
      this.getInfo(row);
    },
    // 查找主体信息数据
    getInfo(row) {
      const id = row.id;
      selectCaseApply({ id }).then((res) => {
        this.visible = true;
        this.formData = res.data;
        this.initpaymentArr = [];
        this.initpaymentArr1 = [];
        res.data.caseAffiliates.forEach((item) => {
          if (item.identityType == 1) {
            this.initpaymentArr.push(item);
          } else {
            this.initpaymentArr1.push(item);
          }
        });
      });
    },
    // 删除
    deleteRow(row) {
      // const id = row.id;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          return removeCaseApply({ id: row.id });
        })
        .then((res) => {
          this.getcaseApply();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
#formContainer {
}
</style>
