<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="12">
                  <el-form-item label="服务对象名称">
                    <el-input v-model="searchFrom.name"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="服务对象类型">
                    <el-select v-model="searchFrom.type" clearable placeholder="请选择" style="width: 100%">
                      <el-option v-for="(i, index) in service_typeList" :label="i" :value="i" :key="index"> </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="公司归属地管辖单位">
                    <el-select v-model="searchFrom.tube_company" clearable placeholder="请选择">
                      <el-option v-for="(item, index) in tube_companyList" :key="index" :label="item.name" :value="item.name"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="合同开始时间">
                    <el-date-picker
                      v-model="searchFrom['start@contract_startdate']"
                      placeholder="请选择"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      type="date"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="至">
                    <el-date-picker
                      v-model="searchFrom['end@contract_startdate']"
                      placeholder="请选择"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      type="date"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="是否重点单位">
                    <el-select v-model="searchFrom.key_address" clearable placeholder="请选择" style="width: 100%">
                      <el-option label="是" value="是"> </el-option>
                      <el-option label="否" value="否"> </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="合同终止时间">
                    <el-date-picker
                      v-model="searchFrom['start@contract_enddate']"
                      placeholder="请选择"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      type="date"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="至">
                    <el-date-picker v-model="searchFrom['end@contract_enddate']" placeholder="请选择" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="是否娱乐场所">
                    <el-select v-model="searchFrom.recreation_address" clearable placeholder="请选择" style="width: 100%">
                      <el-option label="是" value="是"> </el-option>
                      <el-option label="否" value="否"> </el-option>
                    </el-select>
                  </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"></info-1>
    </el-dialog>
  </div>
</template>

<script>
const { service_type } = require('@common/src/layout/deploy/dict');
import info1 from './infomation/info-4.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: company_service_object } = createNamespacedHelpers('company_service_object');
const { mapActions: police_department } = createNamespacedHelpers('police_department');
export default {
  name: 'index',
  props: {},
  components: { info1 },
  data: function () {
    return {
      // 查询
      searchFrom: {},
      // 列表
      fields: [
        { label: '服务对象名称', model: 'name' },
        { label: '服务对象类型', model: 'type' },
        { label: '公司归属地管辖单位', model: 'tube_company' },
        { label: '服务单位联系人', model: 'contact' },
        { label: '联系电话', model: 'phone' },
        { label: '合同开始时间', model: 'contract_startdate' },
        { label: '合同结束时间', model: 'contract_enddate' },
        { label: '娱乐场所', model: 'recreation_address' },
        { label: '重点单位', model: 'key_address' },
        { label: '所在分局', model: 'where_branch' },
      ],
      opera: [{ label: '详情', method: 'view' }],
      list: [],
      total: 0,

      // 详情
      twoShow: false,
      info: {},
      // 部门列表
      tube_companyList: [],
      service_typeList: service_type,
    };
  },
  created() {
    this.searchOther();
    this.search();
  },
  methods: {
    ...company_service_object(['query', 'fetch', 'create', 'update']),
    ...police_department({ deptQuery: 'query' }),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      info.company_id = this.$route.query.id;
      info.status = '0';
      console.log(skip);
      console.log('1');
      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, `info`, data);
      this.twoShow = true;
    },
    // 关闭详情
    twoClose() {
      this.twoShow = false;
    },
    // 查询管辖单位
    async searchOther() {
      let res = await this.deptQuery();
      if (this.$checkRes(res)) {
        this.$set(this, `tube_companyList`, res.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 {
    .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;
        }
      }
    }
  }
}
/deep/.el-dialog__body {
  padding: 10px;
}
</style>
