<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-form ref="searchFrom" :model="searchFrom" label-width="100px">
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="受理公安机关">
                    <el-input v-model="searchFrom.name"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="受理时间">
                    <el-date-picker
                      v-model="searchFrom.beginDate"
                      placeholder="请选择"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      type="date"
                      style="width: 100%"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="至">
                    <el-date-picker
                      v-model="searchFrom.endDate"
                      placeholder="请选择"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      type="date"
                      style="width: 100%"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24" class="one_2txt">
                <el-col :span="24" class="btn">
                  <el-button type="primary" size="mini" @click="search()">查询</el-button>
                </el-col>
              </el-col>
            </el-form>
          </el-col>
        </el-col>
        <el-col :span="24" class="thr">
          <el-col :span="24" v-if="show == '1'">
            <data-table :fields="fields" :opera="opera" :data="list" :usePage="false" @view="toview"> </data-table>
          </el-col>
          <el-col :span="24" v-else-if="show == '2'">
            <data-table :fields="fields" :opera="twoOpera" :data="twoList" :usePage="false">
              <template slot="btn">
                <el-button type="primary" size="mini" @click="back()">返回</el-button>
              </template>
            </data-table>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: baoan_statis } = createNamespacedHelpers('baoan_statis');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      // 页面显示
      show: '1',
      // 查询表单
      searchFrom: {},
      // 分局
      list: [],
      fields: [
        { label: '受理公安机关', model: 'name' },
        { label: '已受理数', model: 'yishouli' },
        { label: '采集人像数', model: 'renxiangcaiji' },
        { label: '采集指纹数', model: 'zhiwencaiji' },
        { label: '注销人员数', model: 'zhuxiao' },
      ],
      opera: [{ label: '详情', method: 'view' }],
      // 派出所
      twoList: [],
      twoOpera: [],
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...baoan_statis(['thrQuery']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      if (this.show == '1') {
        info.type == 'two';
        const condition = _.cloneDeep(this.searchFrom);
        let res = await this.thrQuery({ type: 'two', ...condition, ...this.searchFrom, ...this.info });
        if (this.$checkRes(res)) {
          this.$set(this, `list`, res.data);
        }
      } else if (this.show == '2') {
        const condition = _.cloneDeep(this.searchFrom);
        let res = await this.thrQuery({ ...condition, ...this.searchFrom, ...this.info });
        if (this.$checkRes(res)) {
          this.$set(this, `twoList`, res.data);
        }
      }
    },
    // 详情
    async toview({ data }) {
      let res = await this.thrQuery({ branch_id: data.id });
      if (this.$checkRes(res)) {
        this.$set(this, `twoList`, res.data);
        this.show = '2';
      }
    },
    // 返回
    back() {
      this.show = '1';
      this.search();
    },
  },
  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: 0;
        }
        /deep/.el-date-editor.el-input,
        .el-date-editor.el-input__inner {
          width: 100%;
        }
        /deep/.el-select {
          width: 100%;
        }
        .btn {
          text-align: right;
          padding: 5px 5px;
        }
      }
    }
  }
  .thr {
    margin: 10px 0 0 0;
  }
}
</style>
