<template>
  <div>
    <div class="op">
      <div class="nam">
        <el-input v-model="personName" size="mini" placeholder="请输入姓名"></el-input>
      </div>
      <div class="idc">
        <el-input v-model="idcard" size="mini" placeholder="请输入身份证号"></el-input>
      </div>
      <el-button type="primary" size="mini" style="background:#148A9B;margin-left:10px" icon="el-icon-search" @click="serch">搜索</el-button>
    </div>

  <el-table
    :data="tableData"
    style="width: 100%"
   >
    <el-table-column
      prop="townName"
      label="乡镇">
    </el-table-column>
    <el-table-column
      prop="villageName"
      label="村">
    </el-table-column>
     <el-table-column
      prop="idcard"
      label="身份证号">
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名">
    </el-table-column>
    <el-table-column
      prop="grade"
      label="缴费档次">
    </el-table-column>
    <el-table-column
      prop="insuredState"
      label="参保状态">
    </el-table-column>
    <el-table-column
      prop="payState"
      label="缴费状态">
    </el-table-column>
    <el-table-column
      label="操作">
      <template slot-scope="scope">
        <el-button
          type="primary"
          size="mini"
          icon="el-icon-s-check"
          @click="showDetail(scope.$index, scope.row)">详情</el-button>
      </template>
    </el-table-column>
  </el-table>
    <el-pagination
      class="pone"
      :page-size='10'
      layout="total, prev, pager, next, jumper"
      :total="totals"
      :current-page.sync="Page"
      @current-change="current_change">
    </el-pagination>



    <!--详细信息弹框-->
    <el-dialog title="详细信息" :visible.sync="dialogFormVisible" width="800px">
      <el-form :model="form" label-width="90px" >
        <el-row>
          <el-col :span="8">
            <el-form-item label="姓名">
              <el-input v-model="form.name" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="身份证">
              <el-input v-model="form.idcard" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="个人编号">
              <el-input v-model="form.personNum" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="性别">
              <el-input v-model="form.sex" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="民族">
              <el-input v-model="form.nation" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出生日期">
              <el-input v-model= "form.birthday" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="统筹区">
              <el-input v-model="form.countryName" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="乡镇/街道">
              <el-input v-model="form.townName" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="社区名称">
              <el-input v-model= "form.villageName" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="户口所在地">
              <el-input v-model="form.adress" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="户口性质">
              <el-input v-model= "form.registerType" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="险种类型">
              <el-input v-model="form.insuranceType" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="参保状态">
              <el-input v-model="form.insuredState" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否老农保">
              <el-input v-model= "form.isOldRural" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="缴费状态">
              <el-input v-model="form.payState" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="缴费档次">
              <el-input v-model="form.grade" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="人员类别">
              <el-input v-model= "form.personType" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="8">
            <el-form-item label="离退休标志">
              <el-input v-model="form.retireFlag" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="个人身份">
              <el-input v-model="form.identityType" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="参保日期">
              <el-input v-model= "form.insuredDate" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="档案编号">
              <el-input v-model="form.archivesNum" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>



<style>
  .op{
    display: flex;
    align-items: center;

  }
  .idc{

    width: 200px
  }
  .nam{
    margin-right: 20px
  }
  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
</style>
<script>
  import CryptoJS from 'crypto-js'
  import { Loading } from 'element-ui';
  import {formatDate} from '../../utils/datetime'
  export default {
    data() {
      return {
        Page: 1,
        totals: 0,
        idcard:"",
        personName:"",
        formLabelWidth:10,
        dialogFormVisible:false,
        form:{},
        tableData: [],
      }
    },
    methods: {
      showDetail(index,row){
        this.dialogFormVisible = true;
        this.form = row;
        row.birthday = formatDate(row.birthday);
        row.insuredDate = formatDate(row.insuredDate);
      },
      serch(){
        var data={
          idcard:this.idcard?this.Encrypt(this.idcard):"",
          personName:this.personName?this.Encrypt(this.personName):"",
        }
        Loading.service();
        this.$api.getlist.listAllBaseInfo(data).then((res) => {
          let loadingInstance = Loading.service();
          this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
            loadingInstance.close();
          });
          for(var i in  res.data.list){
            res.data.list[i].idcard=this.decrypt(res.data.list[i].idcard)
            res.data.list[i].name=this.decrypt(res.data.list[i].name)
            res.data.list[i].isOldRural = res.data.list[i].isOldRural == 0 ? '否': res.data.list[i].isOldRural == 1?"是":"";
            res.data.list[i].retireFlag = res.data.list[i].retireFlag == 0 ? '否': res.data.list[i].retireFlag == 1?"是":"";
          }
          this.tableData=res.data.list
          this.totals=res.data.total
          this.page=res.data.total.pageNum
        }).catch((res) => {
          let loadingInstance = Loading.service();
          this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
            loadingInstance.close();
          });
        });
      },
      current_change(ss){
        var data={
          pageNum:ss,
          pageSize:10,
          idcard:this.idcard?this.Encrypt(this.idcard):"",
          personName:this.personName?this.Encrypt(this.personName):"",
        }
        Loading.service();
        this.$api.getlist.listAllBaseInfo(data).then((res) => {
          let loadingInstance = Loading.service();
          this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
            loadingInstance.close();
          });
          for(var i in  res.data.list){
            res.data.list[i].idcard=this.decrypt(res.data.list[i].idcard)
            res.data.list[i].name=this.decrypt(res.data.list[i].name)
            res.data.list[i].isOldRural = res.data.list[i].isOldRural == 0 ? '否': res.data.list[i].isOldRural == 1?"是":"";
            res.data.list[i].retireFlag = res.data.list[i].retireFlag == 0 ? '否': res.data.list[i].retireFlag == 1?"是":"";
          }
          this.tableData=res.data.list
          this.totals=res.data.total
          this.page=res.data.total.pageNum
        }).catch((res) => {
          let loadingInstance = Loading.service();
          this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
            loadingInstance.close();
         });
        });
      },
    decrypt(word){
      var key = CryptoJS.enc.Utf8.parse("KkweInfo23255625");
      var decrypt = CryptoJS.AES.decrypt(word, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
      return CryptoJS.enc.Utf8.stringify(decrypt).toString();
    },
    Encrypt(word) { //aes加密
      var key = CryptoJS.enc.Utf8.parse("KkweInfo23255625");
      let srcs = CryptoJS.enc.Utf8.parse(word);
      let encrypted = CryptoJS.AES.encrypt(srcs, key, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
      });
      return encrypted.toString();
    }
    },
    created() {
          this.$api.getlist.listAllBaseInfo().then((res) => {
          var list = res.data.list;
          for(var i in list){
            res.data.list[i].idcard=this.decrypt(res.data.list[i].idcard)
            res.data.list[i].name=this.decrypt(res.data.list[i].name)
            res.data.list[i].isOldRural = res.data.list[i].isOldRural == 0 ? '否': res.data.list[i].isOldRural == 1?"是":"";
            res.data.list[i].retireFlag = res.data.list[i].retireFlag == 0 ? '否': res.data.list[i].retireFlag == 1?"是":"";
          }
          this.tableData=res.data.list
          this.totals=res.data.total
          this.page=res.data.total.pageNum
        }).catch((res) => {
            let loadingInstance = Loading.service();
            this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
             loadingInstance.close();
          });
        });
    }

  }

</script>
