<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="veteransName">
        <el-input
          v-model="queryParams.veteransName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="veteransIdcard">
        <el-input
          v-model="queryParams.veteransIdcard"
          placeholder="请输入身份证"
          clearable
          size="small"
          @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="handleAdd"-->
<!--          v-hasPermi="['hj:info:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['hj:info:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['hj:info:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->


      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdateRow"
          v-hasPermi="['hj:info:edit']"
        >修改</el-button>
      </el-col>


      <el-col :span="1.5">
      <el-button
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        :disabled="multiple"
        @click="handleUpDateOK"
      >批量通过</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleUpDateNO"
        >批量不通过</el-button>
      </el-col>



      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['hj:info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键" align="center" prop="veteransId" />-->
      <el-table-column label="姓名" align="center" prop="veteransName" />
      <el-table-column label="身份证" align="center" prop="veteransIdcard" />
      <el-table-column label="电话号码" align="center" prop="veteransTel" />

      <el-table-column label="人员分类" align="center" prop="level">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.basics_level" :value="scope.row.level"/>
        </template>
      </el-table-column>

      <el-table-column label="审核状态" align="center" prop="veteransStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.hj_exa_status" :value="scope.row.veteransStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="属性" align="center" prop="veteransType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.hj_from" :value="scope.row.veteransType"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="证照" align="center" prop="veteransPic" />-->
<!--      <el-table-column label="审核人" align="center" prop="veteransReviewer" />-->
<!--      <el-table-column label="审核时间" align="center" prop="veteransTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.veteransTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <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-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hj:info:edit']"
          >查看详情</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateRow(scope.row)"
            v-hasPermi="['hj:info:edit']"
          >修改</el-button>

<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['hj:info:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    <!-- 添加或修改军人认证对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="审核理由" prop="remark">
          <el-input v-model="form.remark" placeholder="请输审核理由" type="textarea" />
        </el-form-item>

        <el-form-item label="审核时间" prop="veteransTime">
          <el-date-picker clearable size="small"
                          v-model="form.veteransTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择审核时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="姓名" prop="veteransName">
          <el-input v-model="form.veteransName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="身份证" prop="veteransIdcard">
          <el-input v-model="form.veteransIdcard" placeholder="请输入身份证" />
        </el-form-item>




        <el-form-item label="电话号码" prop="veteransTel">
          <el-input v-model="form.veteransTel" placeholder="请输入电话号码" />
        </el-form-item>


        <el-form-item label="人员分类" prop="level">
          <el-select v-model="form.level" placeholder="请选择人员分类">
            <el-option
              v-for="dict in dict.type.basics_level"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>


        <el-form-item label="审核状态" prop="veteransStatus">
          <el-select v-model="form.veteransStatus" placeholder="请选择审核状态">
            <el-option
              v-for="dict in dict.type.hj_exa_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="属性" prop="veteransType">
          <el-select v-model="form.veteransType" placeholder="请选择属性">
            <el-option
              v-for="dict in dict.type.hj_from"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证照">
          <imageUpload v-model="form.veteransPic"/>
        </el-form-item>
        <!--        <el-form-item label="审核人" prop="veteransReviewer">-->
        <!--          <el-input v-model="form.veteransReviewer" placeholder="请输入审核人" />-->
        <!--        </el-form-item>-->

      </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>

    <!-- 添加或修改军人认证对话框 -->
    <el-dialog :title="title" :visible.sync="openRow" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">





        <el-form-item label="人员分类" prop="level">
          <el-select v-model="form.level" placeholder="请选择人员分类">
            <el-option
              v-for="dict in dict.type.basics_level"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="证照">
          <imageUpload v-model="form.veteransPic"/>
        </el-form-item>
<!--        <el-form-item label="审核人" prop="veteransReviewer">-->
<!--          <el-input v-model="form.veteransReviewer" placeholder="请输入审核人" />-->
<!--        </el-form-item>-->

      </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>


    <el-dialog :title="title" :visible.sync="openhandleUpDateNO" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="审核理由" prop="remark">
          <el-input v-model="form.remark" placeholder="请输审核理由" type="textarea" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitHandleUpDateNOForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>



    <el-dialog :title="title" :visible.sync="openhandleUpDateOK" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="审核理由" prop="remark">
          <el-input v-model="form.remark" placeholder="请输审核理由" type="textarea" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitHandleUpDateOKForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>




  </div>
</template>

<script>
  import { listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo,handleUpDateOKShops } from "@/api/hj/info";

  export default {
    name: "Info",
    dicts: ['hj_exa_status', 'hj_from','basics_level'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 军人认证表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        openhandleUpDateOK:false,
        openhandleUpDateNO:false,
        openRow:false,

        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          veteransName: null,
          veteransIdcard: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询军人认证列表 */
      getList() {
        this.loading = true;
        listInfo(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.openhandleUpDateOK= false;
        this.openhandleUpDateNO= false;
        this.openShow=false;
        this.openRow=false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          veteransId: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          veteransName: null,
          veteransIdcard: null,
          veteransTel: null,
          veteransStatus: null,
          veteransType: null,
          veteransPic: null,
          veteransReviewer: null,
          veteransTime: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.veteransId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加军人认证";
      },


      handleUpdateRow(row) {
        this.reset();
        const veteransId = row.veteransId || this.ids
        getInfo(veteransId).then(response => {
          this.form = response.data;
          this.openRow = true;
          this.title = "修改军人认证";
        });
      },

      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const veteransId = row.veteransId || this.ids
        getInfo(veteransId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改军人认证";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.veteransId != null) {
              updateInfo(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addInfo(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const veteransIds = row.veteransId || this.ids;
        this.$modal.confirm('是否确认删除军人认证编号为"' + veteransIds + '"的数据项？').then(function() {
          return delInfo(veteransIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$modal.confirm('是否确认导出所有军人认证数据项？').then(() => {
          this.exportLoading = true;
          return exportInfo(queryParams);
        }).then(response => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      },


      submitHandleUpDateOKForm(){
        this.form.veteransStatus=2
        this.formSubmit()
      },
      submitHandleUpDateNOForm(){
        this.form.veteransStatus=3
        this.formSubmit()
      },

      handleUpDateOK(){

        this.reset();
        this.openhandleUpDateOK = true;
        this.title = "批量审核通过";
      },

      handleUpDateNO(){

        this.reset();
        this.openhandleUpDateNO = true;
        this.title = "批量审核拒绝";
      },


      formSubmit(){
        const shopsIds =  this.ids;
        console.log(this.ids)
        handleUpDateOKShops(shopsIds,this.form).then(response => {
          this.$modal.msgSuccess("批量审核成功");
          this.open = false;
          this.openhandleUpDateOK= false;
          this.openhandleUpDateNO= false;
          this.openShow=false;
          this.reset();
          this.getList();
        });
      }


    }
  };
</script>
