<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-__enterpriseinfo}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <div>
          <el-form-item label="区域">
            <el-cascader v-model="ids" :options="options" :props="{ checkStrictly: true }" clearable>
            </el-cascader>
          </el-form-item>
        </div>
        <el-form-item label="公司名称"><el-input v-model="dataForm.enterpriseName" placeholder="请输入" clearable></el-input></el-form-item>
        <el-form-item label="联系人手机号"><el-input v-model="dataForm.mobile" placeholder="请输入" clearable></el-input></el-form-item>
        <el-form-item label="统一社会信用代码"><el-input v-model="dataForm.uniformSocialCreditCode" placeholder="请输入" clearable></el-input></el-form-item>
        <el-form-item label="法人姓名"><el-input v-model="dataForm.legalPerson" placeholder="请输入" clearable></el-input></el-form-item>

        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('epdc:enterpriseinfo:export')" type="primary" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="realName" label="姓名" header-align="center" align="center"></el-table-column>
        <el-table-column prop="sex" label="性别" width="60" header-align="center" align="center" :formatter="showFlagFormat"></el-table-column>
        <el-table-column prop="mobile" label="手机号" width="110" header-align="center" align="center"></el-table-column>
        <el-table-column prop="enterpriseName" min-width="250" label="企业全称" show-overflow-tooltip header-align="center" align="left"></el-table-column>
        <el-table-column prop="uniformSocialCreditCode" width="200" label="统一社会信用代码" header-align="center" align="left"></el-table-column>
        <el-table-column prop="legalPerson" label="企业法人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="enterpriseAddress" label="企业地址" min-width="300" show-overflow-tooltip header-align="center" align="left"></el-table-column>
        <el-table-column prop="industry" label="所属行业" header-align="center" align="center"></el-table-column>
        <el-table-column prop="businessScope" label="经营范围" min-width="200" show-overflow-tooltip header-align="center" align="left"></el-table-column>
        <el-table-column prop="registeredCapital" label="注册资金(万元)" header-align="center" align="center"></el-table-column>
        <el-table-column prop="employedPopulation" label="从业人数" header-align="center" align="center"></el-table-column>
        <el-table-column prop="allDeptNames" label="所属网格" min-width="400" show-overflow-tooltip header-align="center" align="left"></el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './enterpriseinfo-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/custom/enterpriseinfo/page',
        getDataListIsPage: true,
        deleteURL: '/custom/enterpriseinfo',
        deleteIsBatch: true,
        exportURL: '/custom/enterpriseinfo/export'
      },
      dataForm: {
        enterpriseName: '',
        mobile: '',
        uniformSocialCreditCode: '',
        legalPerson: ''
      },
      ids: [],
      options: []
    }
  },
  components: {
    AddOrUpdate
  },
  created: function () {
    this.getOptions()
  },
  watch: {
    'ids': function (val) {
      if (val.length === 0) {
        this.dataForm.streetId = ''
        this.dataForm.communityId = ''
        this.dataForm.gridId = ''
      }
      if (val.length === 1) {
        this.dataForm.streetId = this.ids[0]
        this.dataForm.communityId = ''
        this.dataForm.gridId = ''
      }
      if (val.length === 2) {
        this.dataForm.streetId = this.ids[0]
        this.dataForm.communityId = this.ids[1]
        this.dataForm.gridId = ''
      }
      if (val.length === 3) {
        this.dataForm.streetId = this.ids[0]
        this.dataForm.communityId = this.ids[1]
        this.dataForm.gridId = this.ids[2]
      }
    }
  },
  methods: {
    getOptions () {
      this.$http.get(`/sys/dept/party/getDeptTreeForEpiDemic`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.options = res.data.options
      }).catch(() => {})
    },
    showFlagFormat (row, column) {
      if (row.sex === '0') {
        return '女'
      } else {
        return '男'
      }
    }
  }
}
</script>
