<template>
  <div id="service">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <el-col :span="24" class="title">{{ title }}</el-col>
          <el-col :span="24" class="form">
            <el-form ref="searchForm" :model="searchForm" label-width="140px">
              <el-col :span="8" class="one_1">
                <el-form-item label="服务对象名称">
                  <el-input v-model="searchForm.name"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="服务对象类型">
                  <el-select v-model="searchForm.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 :span="8" class="one_1">
                <el-form-item label="公司归属地管辖单位">
                  <el-select v-model="searchForm.tube_company" clearable placeholder="请选择" style="width: 100%">
                    <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" class="one_1">
                <el-form-item label="合同开始时间">
                  <el-date-picker
                    v-model="searchForm['start@contract_startdate']"
                    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" class="one_1">
                <el-form-item label="至">
                  <el-date-picker
                    v-model="searchForm['end@contract_startdate']"
                    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" class="one_1">
                <el-form-item label="是否重点单位">
                  <el-select v-model="searchForm.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" class="one_1">
                <el-form-item label="合同终止时间">
                  <el-date-picker
                    v-model="searchForm['start@contract_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 :span="8" class="one_1">
                <el-form-item label="至">
                  <el-date-picker
                    v-model="searchForm['end@contract_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 :span="8" class="one_1">
                <el-form-item label="是否娱乐场所">
                  <el-select v-model="searchForm.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="24" class="btn">
                <el-button type="primary" size="mini" @click="search()">查询</el-button>
              </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="title" :close-on-click-modal="false" :visible.sync="dialog" center :destroy-on-close="true" @closed="toClose">
      <el-form ref="info" :model="info" label-width="auto">
        <el-col :span="12">
          <el-form-item label="服务对象名称" prop="name">
            <el-input v-model="info.name" placeholder="请输入服务对象名称" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="服务对象类型" prop="type">
            <el-input v-model="info.type" placeholder="请输入服务对象类型" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="保安服务类型" prop="baoan_sevicetype">
            <el-input v-model="info.baoan_sevicetype" placeholder="请输入服务对象类型" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="详细地址" prop="service_address">
            <el-input v-model="info.service_address" placeholder="请输入详细地址" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="保安公司所属县市区" prop="household">
            <el-input v-model="info.household" placeholder="请输入保安公司所属县市区" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公司归属地管辖单位" prop="tube_company">
            <el-input v-model="info.tube_company" placeholder="请输入公司归属地管辖单位" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="服务单位联系人" prop="contact">
            <el-input v-model="info.contact" placeholder="请输入服务单位联系人" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系电话" prop="phone">
            <el-input v-model="info.phone" placeholder="请输入联系电话" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="合同开始时间" prop="contract_startdate">
            <el-input v-model="info.contract_startdate" placeholder="请输入合同开始时间" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="合同终止时间" prop="contract_enddate">
            <el-input v-model="info.contract_enddate" placeholder="请输入合同终止时间" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否重点单位" prop="key_address">
            <el-input v-model="info.key_address" placeholder="请输入是否重点单位" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否娱乐场所" prop="recreation_address">
            <el-input v-model="info.recreation_address" placeholder="请输入是否娱乐场所" readonly></el-input>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
const { service_type } = require('@common/src/layout/deploy/dict');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions } = createNamespacedHelpers('company_service_object');
const { mapActions: police_department } = createNamespacedHelpers('police_department');
const _ = require('lodash');
export default {
  name: 'service',
  props: {
    title: { type: String },
  },
  components: {},
  data: function () {
    return {
      // 查询
      searchForm: {},
      list: [],
      total: 0,
      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' }],
      // 弹框
      dialog: false,
      // 详情
      info: {},
      // 部门列表
      tube_companyList: [],
      service_typeList: service_type,
    };
  },
  async created() {
    await this.searchOther();
    if (this.id) await this.search();
  },
  methods: {
    ...mapActions(['query', 'fetch', 'create', 'update']),
    ...police_department({ deptQuery: 'query' }),
    async search({ skip, limit = 10 } = {}) {
      const condition = _.cloneDeep(this.searchForm);
      const res = await this.query({ skip, limit, ...condition, company_id: this.id });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 查看详情
    async toView({ data }) {
      let res = await this.fetch({ id: data.id });
      if (this.$checkRes(res)) {
        this.$set(this, `info`, res.data);
        this.$set(this, `dialog`, true);
      }
    },
    // 关闭弹框
    toClose() {
      this.$set(this, `dialog`, false);
    },
    // 查询管辖单位
    async searchOther() {
      let res = await this.deptQuery();
      if (this.$checkRes(res)) {
        this.$set(this, `tube_companyList`, res.data);
      }
    },
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.one {
  .title {
    font-weight: bold;
    font-size: 18px;
    padding: 10px 0;
    border-bottom: 1px solid #cccccc;
    margin: 0 0 10px 0;
  }
  .form {
    .one_1 {
      padding: 0 10px;
      /deep/.el-form-item {
        margin: 0;
      }
    }
    .btn {
      text-align: right;
      margin: 10px 0 0 0;
      padding: 0 10px;
    }
  }
}
/deep/.el-dialog__body {
  max-height: 430px;
  overflow: auto;
}
.dialog {
  .btn {
    text-align: center;
  }
}
</style>
