<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-input v-model="searchFrom.phone"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" 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="two">
          <data-table @query="search" :fields="fields" :opera="opera" :data="list" :total="total" @view="toView"> </data-table>
        </el-col>
      </el-col>
    </el-row>
    <el-dialog title="信息详细信息" :visible.sync="show" width="50%" :before-close="close" :close-on-click-modal="false">
      <el-form :model="form" ref="form" label-width="120px">
        <el-form-item label="企业类型" prop="purpose">
          <el-input v-model="form.purpose" placeholder="请输入账号名称"></el-input>
        </el-form-item>
        <el-form-item label="账号名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入账号名称"></el-input>
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" readonly></el-input>
        </el-form-item>
        <el-form-item label="电子邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入电子邮箱"></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: company_base } = createNamespacedHelpers('company_base');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      // 查询
      searchFrom: {},
      // 列表
      fields: [
        { label: '账号用途', model: 'purpose' },
        { label: '账号名称', model: 'name' },
        { label: '联系电话', model: 'phone' },
        { label: '安全邮箱', model: 'email' },
      ],
      opera: [{ label: '详情', method: 'view' }],
      list: [],
      total: 0,
      // 信息详情
      show: false,
      form: {},
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...company_base(['query', 'update']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      let res = await this.query({ skip, limit, ...this.searchFrom, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 查看详情
    toView({ data }) {
      this.$set(this, `form`, data);
      this.show = true;
    },
    // 取消添加
    close() {
      this.form = {};
      this.show = false;
      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;
        }
      }
    }
  }
}
</style>
