<template>
  <div class="archive-expect">
    <el-backtop target=".archive-expect" :right="70" :bottom="70"></el-backtop>
    <el-table
      v-loading.fullscreen.lock="loading"
      :data="tableData"
      border
      style="width: 100%">
<!--      <el-table-column-->
<!--        align="center"-->
<!--        type="selection"-->
<!--        width="50">-->
<!--      </el-table-column>-->
      <el-table-column
        fixed
        align="center"
        label="序号"
        type="index"
        width="50"
        :index="this.indexStart">
      </el-table-column>
      <el-table-column
        fixed
        label="文件列表"
        type="expand"
        width="60">
        <template slot-scope="scope">
          <el-table :data="scope.row.eventLogList" border style="width: 100%">
            <el-table-column align="center" label="文件序号" type="index" width="60"></el-table-column>
            <el-table-column align="center" prop="eventTimeStr" label="成文时间" width="180"></el-table-column>
            <el-table-column align="center" prop="nameDec" label="姓名" width="100"></el-table-column>
            <el-table-column align="center" prop="idcardDec" label="身份证" width="200"></el-table-column>
            <el-table-column align="center" prop="concatAddress" label="乡镇/村社" width="200"></el-table-column>
            <el-table-column
              align="center"
              label="附件"
              width="600">
              <template slot-scope="scope">
                <div class="picPopover"
                     v-if="scope.row.idcardFrontPic">
                  <span style="float: top">身份证正面:</span>
                  <div style="float: top">
                    <el-popover
                      placement="bottom"
                      trigger="hover">
                      <img slot="reference" :src="'http://socialsecurity.oss-cn-beijing.aliyuncs.com/' + scope.row.idcardFrontPic" height="50px" width="50px" class="head_pic"/>
                      <img :src="'http://socialsecurity.oss-cn-beijing.aliyuncs.com/' + scope.row.idcardFrontPic" height="100%" width="100%" class="head_pic"/>
                    </el-popover>
                  </div>
                </div>
                <div class="picPopover"
                     v-if="scope.row.idcardBackPic">
                  <span style="float: top">身份证背面:</span>
                  <div style="float: top">
                    <el-popover
                      placement="bottom"
                      trigger="hover">
                      <img slot="reference" :src="'http://socialsecurity.oss-cn-beijing.aliyuncs.com/' + scope.row.idcardBackPic" height="50px" width="50px" class="head_pic"/>
                      <img :src="'http://socialsecurity.oss-cn-beijing.aliyuncs.com/' + scope.row.idcardBackPic" height="100%" width="100%" class="head_pic"/>
                    </el-popover>
                  </div>
                </div>
                <div class="picPopover"
                     v-if="scope.row.bankPic">
                  <span style="float: top">银行卡:</span>
                  <div style="float: top">
                    <el-popover
                      placement="bottom"
                      trigger="hover">
                      <img slot="reference" :src="'http://socialsecurity.oss-cn-beijing.aliyuncs.com/' + scope.row.bankPic" height="50px" width="50px" class="head_pic"/>
                      <img :src="'http://socialsecurity.oss-cn-beijing.aliyuncs.com/' + scope.row.bankPic" height="100%" width="100%" class="head_pic"/>
                    </el-popover>
                  </div>
                </div>
                <div class="picPopover"
                     v-if="scope.row.specialPhotoPic">
                  <span style="float: top">特殊证明:</span>
                  <div style="float: top">
                    <el-popover
                      placement="bottom"
                      trigger="hover">
                      <img slot="reference" :src="'http://socialsecurity.oss-cn-beijing.aliyuncs.com/' + scope.row.specialPhotoPic" height="50px" width="50px" class="head_pic"/>
                      <img :src="'http://socialsecurity.oss-cn-beijing.aliyuncs.com/' + scope.row.specialPhotoPic" height="100%" width="100%" class="head_pic"/>
                    </el-popover>
                  </div>
                </div>
                <div class="picPopover"
                     v-if="scope.row.bookPic">
                  <span style="float: top">户口簿:</span>
                  <div style="float: top">
                    <el-popover
                      placement="bottom"
                      trigger="hover">
                      <img slot="reference" :src="'http://socialsecurity.oss-cn-beijing.aliyuncs.com/' + scope.row.bookPic" height="50px" width="50px" class="head_pic"/>
                      <img :src="'http://socialsecurity.oss-cn-beijing.aliyuncs.com/' + scope.row.bookPic" height="100%" width="100%" class="head_pic"/>
                    </el-popover>
                  </div>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="eventSign"
        label="业务类型"
        :formatter="getEventType"
        width="150">
      </el-table-column>
      <el-table-column
        align="center"
        prop="year"
        label="年度"
        width="70">
      </el-table-column>
      <el-table-column
        align="center"
        prop="title"
        label="正题名"
        width="330">
      </el-table-column>
      <el-table-column
        align="center"
        prop="startTimeStr"
        label="起时间"
        width="120">
      </el-table-column>
      <el-table-column
        align="center"
        prop="endTimeStr"
        label="止时间"
        width="120">
      </el-table-column>
      <el-table-column
        align="center"
        prop="pages"
        label="页数"
        width="60">
      </el-table-column>
      <el-table-column
        align="center"
        prop="files"
        label="件数"
        width="60">
      </el-table-column>
      <el-table-column
        align="center"
        prop="fileType"
        label="档案类别"
        width="100">
      </el-table-column>
      <el-table-column
        align="center"
        prop="secondaryCategory"
        label="二级类目"
        width="250">
      </el-table-column>
      <el-table-column
        align="center"
        prop="categoryType"
        label="类别代码"
        width="60">
      </el-table-column>
      <el-table-column
        align="center"
        prop="businessType"
        label="业务类别"
        width="250">
      </el-table-column>
      <el-table-column
        align="center"
        fixed="right"
        label="操作"
        width="200">
        <template slot-scope="scope">
          <el-input
            onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
            v-model="scope.row.fileNumber"
            style="float: left;width: 63%"
            placeholder="输入案卷号"
            clearable
            size="mini"></el-input>
          <el-button
            style="float: left;margin-left: 10px"
            type="primary"
            size="mini"
            plain
            @click="fileArchive(scope.row)">
            归档
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="pone"
      :page-size="pageSize"
      :page-sizes="[10, 50, 100]"
      @size-change="handleSizeChange"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totals"
      :current-page.sync="pageNum"
      @current-change="current_change">
    </el-pagination>
  </div>
</template>
<script>
  import CryptoJS from 'crypto-js'

  import {Loading} from 'element-ui';

  export default {
    data() {
      return {
        tableData: [],
        loading: false,
        totals: 0,
        pageNum: 1,
        pageSize: 10,
        indexStart: 1,
      }
    },
    methods: {
      current_change(pageNum) {
        this.pageNum = pageNum;
        this.indexStart = (pageNum - 1) * this.pageSize + 1;
        const data = {
          pageNum: pageNum,
          pageSize: this.pageSize,
        };
        this.search(data);
      },
      search(data) {
        this.loading = true;
        this.$api.getlist.selectExpectArchive(data)
          .then((response) => {
            if (response.code === 200) {
              for (const i in response.data.content) {
                for (const j in response.data.content[i].eventLogList) {
                  response.data.content[i].eventLogList[j].nameDec = this.$options.methods.decryptParam(response.data.content[i].eventLogList[j].name);
                  response.data.content[i].eventLogList[j].idcardDec = this.$options.methods.decryptParam(response.data.content[i].eventLogList[j].idcard);
                }
              }
              this.tableData = response.data.content;
              this.totals = response.data.totalSize;
            }
          })
          .catch((response) => {
          });
        this.loading = false;
      },
      handleSizeChange(pageSize) {
        this.pageSize = pageSize;
        this.pageNum = 1;
        this.indexStart = 1;
        const data = {
          pageNum: 1,
          pageSize: pageSize,
        };
        this.search(data);
      },
      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();
      },
      decryptByDES(ciphertext) {
        var keyHex = CryptoJS.enc.Utf8.parse("KkweFace95271124");
        var decrypted = CryptoJS.DES.decrypt({
          ciphertext: CryptoJS.enc.Base64.parse(ciphertext)
        }, keyHex, {
          mode: CryptoJS.mode.ECB,
          padding: CryptoJS.pad.Pkcs7
        });
        return decrypted.toString(CryptoJS.enc.Utf8);
      },
      decryptCellValue(row, column, cellValue) {
        this.decryptParam(cellValue);
      },
      decryptParam(param) {
        if (param === null || param === "") return null;
        return this.decrypt(param);
      },
      fileArchive(archive) {
        if (archive.fileNumber === null || archive.fileNumber === "" || archive.fileNumber < 0) {
          this.$message({
            showClose: true,
            message: "请输入案卷号",
            type: 'warning',
            duration: 3000
          });
          return;
        }
        this.$confirm('该 ' + archive.title + ' 将归档为案卷号: ' + archive.fileNumber + ' 的档案, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true;
          const archives = [archive];
          this.fileArchives(archives);
        }).catch(() => {
          this.$message({
            showClose: true,
            type: 'info',
            message: '已取消归档',
            duration: 3000
          });
        });

      },
      fileArchives(archives) {
        this.loading = true;
        this.$api.getlist.fileArchives(archives)
          .then((response) => {
            if (response.code === 200) {
              this.$message({
                showClose: true,
                message: response.data,
                type: 'success',
                duration: 10000
              });
            } else {
              this.$message({
                showClose: true,
                message: response.message,
                type: 'error',
                duration: 10000
              });
            }
            this.reload();
            this.loading = false;
          })
          .catch((response) => {
            this.$message({
              showClose: true,
              message: response.message,
              type: 'error',
              duration: 10000
            });
            this.loading = false;
          });
      },
      reload() {
        const data = {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          eventType: this.eventType,
          eventTypeDetail: this.eventTypeDetail,
        };
        this.search(data);
      },
      getEventType(row, column, cellValue) {
        switch (cellValue) {
          case "1" : return "参保登记";
          case "3" : return "待遇申请";
          case "4" : return "参保注销";
          case "5" : return "补缴保费";
          case "6" : return "升档改办";
          case "7" : return "关系转移";
          case "2-1" : return "信息变更/档次变更";
          case "2-2" : return "信息变更/银行卡变更";
          case "2-3" : return "信息变更/手机号变更";
          case "2-4" : return "信息变更/参保身份变更";
          case "2-5" : return "信息变更/户籍地址变更";
          case "2-6" : return "信息变更/姓名变更";
          case "2-7" : return "信息变更/身份证变更";
          default : return null;
        }
      },
    },
    created() {
      this.loading = true;
      const data = {
        pageNum: 1,
        pageSize: this.pageSize
      };
      this.$api.getlist.selectExpectArchive(data)
        .then((response) => {
          if (response.code === 200) {
            for (const i in response.data.content) {
              for (const j in response.data.content[i].eventLogList) {
                response.data.content[i].eventLogList[j].nameDec = this.$options.methods.decryptParam(response.data.content[i].eventLogList[j].name);
                response.data.content[i].eventLogList[j].idcardDec = this.$options.methods.decryptParam(response.data.content[i].eventLogList[j].idcard);
              }
            }
            this.tableData = response.data.content;
            this.totals = response.data.totalSize;
            console.log(this.tableData);
          }
        })
        .catch((response) => {
        });
      this.loading = false;
    }
  }
</script>
<style scoped>
  .pone {
    margin-top: 20px;
    margin-bottom: 20px;
  }

  .picPopover {
    float: left;
    margin-left: 20px;
  }

  .archive-expect {
    height: 100%;
    overflow-y: scroll;
  }
</style>
