<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="140px">
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="保安服务区域名称">
                    <el-input v-model="searchFrom.service_name"></el-input>
                  </el-form-item>
                </el-col>
                <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.card"></el-input>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="保安服务区域省市县">
                    <el-input v-model="searchFrom.onhouse_city"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="16" 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 class="twoDialog" title="信息详情" :visible.sync="twoShow" width="60%" :before-close="twoClose" :close-on-click-modal="false">
      <info-1 :info="info" :fileList="fileList"></info-1>
    </el-dialog>
  </div>
</template>

<script>
import info1 from './parts/info-1.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: company_service_area } = createNamespacedHelpers('company_service_area');
const { mapActions: digital_files } = createNamespacedHelpers('digital_files');
export default {
  name: 'index',
  props: {},
  components: { info1 },
  data: function () {
    return {
      // 查询
      searchFrom: {},
      // 列表
      fields: [
        { label: '保安服务区域名称', model: 'service_name' },
        { label: '保安服无区域详址', model: 'address_detailed' },
        { label: '保安负责人姓名', model: 'name' },
        { label: '保安负责人身份证号', model: 'card' },
        { label: '保安服务联系电话', model: 'phone' },
      ],
      opera: [{ label: '详情', method: 'view' }],
      list: [],
      total: 0,
      // 信息详情
      twoShow: false,
      info: {},
      fileList: [],
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...company_service_area(['query', 'delete', 'fetch']),
    ...digital_files({ fileQuery: 'query', fileCreate: 'create' }),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const condition = _.cloneDeep(this.searchFrom);
      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);
      }
    },

    // 详情
    async toView({ data }) {
      let res = await this.fileQuery({ main_id: data.id });
      if (this.$checkRes(res)) {
        this.$set(this, `fileList`, res.data);
        this.$set(this, `info`, data);
        this.twoShow = true;
      }
    },
    // 关闭详情
    twoClose() {
      this.twoShow = false;
    },
  },
  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>
