<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <el-col :span="24" class="one_1"> 保安员信息导入 </el-col>
          <el-col :span="24" class="one_2">
            <el-button type="primary" size="mini" @click="getTemplate">保安员信息导入格式文件下载</el-button>
            <el-button type="primary" size="mini" @click="getTemplates">保安员入职信息导入格式文件下载</el-button>
          </el-col>
        </el-col>
        <el-col :span="24" class="two">
          <el-col :span="24" class="two_1">
            <el-form ref="form" :model="form" label-width="120px">
              <el-form-item label="保安员信息文件">
                <s-upload :limit="1" :data="form.uri" type="uri" listType="" :url="uri" @upload="uplSuc" @delete="uplDel"></s-upload>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" size="mini" @click="onSubmit">提交导入</el-button>
              </el-form-item>
            </el-form>
          </el-col>
          <el-col :span="24" class="two_1">
            <el-form ref="twoFrom" :model="twoFrom" label-width="120px">
              <el-form-item label="保安员入职信息文件">
                <s-upload :limit="1" :data="twoFrom.uri" type="uri" listType="" :url="uri" @upload="twouplSuc" @delete="twouplDel"></s-upload>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" size="mini" @click="twoSubmit">提交导入</el-button>
              </el-form-item>
            </el-form>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: import_file } = createNamespacedHelpers('import_file');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      form: {},
      uri: '/files/baoan/examAchieve/upload',
      twoFrom: {},
    };
  },
  async created() {},
  methods: {
    ...import_file(['securityGuard', 'guardWork']),
    // 提交导入
    async onSubmit() {
      let data = this.form;
      let res = await this.securityGuard(data);
      if (this.$checkRes(res)) {
        this.$message({ type: `success`, message: `操作成功` });
        this.form = {};
      }
    },
    // 上传图片
    uplSuc({ type, data }) {
      this.$set(this.form, `${type}`, data.uri);
    },
    uplDel({ type }) {
      this.$set(this.form, `${type}`, null);
    },
    // 提交导入
    async twoSubmit() {
      let data = this.twoFrom;
      let res = await this.guardWork(data);
      if (this.$checkRes(res)) {
        this.$message({ type: `success`, message: `操作成功` });
        this.form = {};
      }
    },
    twouplSuc({ type, data }) {
      this.$set(this.twoFrom, `${type}`, data.uri);
    },
    twouplDel({ type }) {
      this.$set(this.twoFrom, `${type}`, null);
    },
    // 导入格式文件下载
    getTemplate() {
      window.open(`${process.env.VUE_APP_HOST}/${process.env.VUE_APP_ROUTER}/保安员信息导入文件模板.xlsx`, '_blank');
    },
    getTemplates() {
      window.open(`${process.env.VUE_APP_HOST}/${process.env.VUE_APP_ROUTER}/保安员入职信息导入文件模板.xlsx`, '_blank');
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .one {
    .one_1 {
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #ccc;
      margin: 0 0 10px 0;
      font-size: 18px;
      font-weight: bold;
    }
    .one_2 {
      .one_2txt {
        border: 1px solid #ccc;
        /deep/.el-form-item {
          margin: 10px 0;
        }
        /deep/.el-date-editor.el-input,
        .el-date-editor.el-input__inner {
          width: 100%;
        }
        /deep/.el-select {
          width: 100%;
        }
        .btn {
          text-align: center;
          padding: 5px 5px;
        }
      }
    }
  }
  .two {
    .two_1 {
      border: 1px solid #ccc;
      margin: 10px 0;
    }
  }
}
</style>
