<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main animate__animated animate__backInRight">
        <el-col :span="24" class="one">
          <el-col :span="24" class="one_1"><span>涉案人员</span><span>(需要提供表格填写内容)</span></el-col>
          <el-col :span="24" class="one_2"><span></span></el-col>
        </el-col>
        <el-col :span="24" class="two">
          <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search" @edit="toEdit" @delete="toDel">
            <template #selfbtn>
              <el-button type="primary" size="mini" @click="toAdd">添加</el-button>
            </template>
          </data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions } = createNamespacedHelpers('involved');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      list: [],
      total: 0,
      opera: [
        { label: '修改', method: 'edit' },
        { label: '删除', method: 'delete', type: 'danger' },
      ],
      fields: [
        { label: '姓名', prop: 'name', filter: 'input' },
        { label: '曾用名', prop: 'beforename' },
        { label: '身份证号', prop: 'card', filter: 'input' },
        { label: '性别', prop: 'gender' },
        { label: '年龄', prop: 'age' },
        { label: '籍贯', prop: 'nativeaddr' },
        { label: '住址', prop: 'address' },
        { label: '工作单位', prop: 'unit' },
        { label: '职业', prop: 'work', filter: 'input' },
        { label: '社会关系', prop: 'sociology' },
        { label: '涉案信息', prop: 'involvedinfo' },
        { label: '备注', prop: 'remark' },
      ],
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...mapActions(['query', 'delete']),
    // 查询
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const condition = _.cloneDeep(this.searchForm);
      let res = await this.query({ skip, limit, ...condition, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 添加
    toAdd() {
      this.$router.push({ path: '/involved/detail' });
    },
    // 修改
    toEdit({ data }) {
      this.$router.push({ path: '/involved/detail', query: { id: data._id } });
    },
    // 删除
    async toDel({ data }) {
      let res = await this.delete(data._id);
      if (this.$checkRes(res)) {
        this.$message({ type: `success`, message: `刪除信息成功` });
        this.search();
      }
    },
    // 关闭
    toClose() {
      this.form = {};
      this.searchForm = {};
      this.dialog = { title: '信息管理', show: false, type: '1' };
      this.search();
    },
    // 多选
    handleSelect(data) {
      this.$set(this, `selected`, data);
    },
  },
  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 {
    margin: 0 0 10px 0;
    .one_1 {
      span:nth-child(1) {
        font-size: 20px;
        font-weight: 700;
        margin-right: 10px;
      }
      span:nth-child(2) {
        font-size: 14px;
        color: #979797;
      }
    }
    .one_2 {
      span:nth-child(1) {
        display: inline-block;
        color: #8baae7;
        font-size: 14px;
        margin-top: 10px;
      }
    }
  }
  .two {
    margin: 0 0 10px 0;
  }
}
</style>
