<template>
  <div>
    <div>
     
      <el-input v-model="listQuery.search"
                placeholder="组织名称/工厂编号"
                style="width: 300px;"
                class="filter-item"
                @keyup.enter.native="handleFilter" />
      <el-button class="filter-item"
                 type="primary"
                 icon="el-icon-search"
                 @click="handleFilter">搜索</el-button>
      <el-button class="filter-item"
                 style="margin-left: 10px;"
                 type="primary"
                 icon="el-icon-refresh-left"
                 @click="resetFilter">刷新重置</el-button>
    </div>
    <el-table v-loading="listLoading"
              :data="enterpriseList.results"
             style="width: 100%;margin-bottom: 20px"
             row-key="id"
             border
             default-expand-all
             max-height="400"
             :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
             @row-dblclick="handleChose2"
             >
      <el-table-column fixed="left" type="index" width="50" />
      <el-table-column fixed="left" width="150" label="组织查询码">
        <template slot-scope="scope">
          {{ scope.row.query_code }}
        </template>
      </el-table-column>
     
      <el-table-column width="150" label="工厂编号">
        <template slot-scope="scope">
          {{ scope.row.code }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="组织名称">
        <template slot-scope="scope">
          {{scope.row.name  }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="英文名">
        <template slot-scope="scope">
          {{ scope.row.ename }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="法人">
        <template slot-scope="scope">
          {{ scope.row.legal }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="机构类型">
        <template slot-scope="scope" v-if="scope.row.type">
          {{ scope.row.type.name }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="组织员工数">
        <template slot-scope="scope">
          {{ scope.row.person_count }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="建厂时间">
        <template slot-scope="scope">
          {{ scope.row.build_time }}
        </template>
      </el-table-column>

      <el-table-column width="150" label="经济行业">
        <template slot-scope="scope" v-if="scope.row.economy_class">
          {{ scope.row.economy_class.name }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="经营范围">
        <template slot-scope="scope">
          {{ scope.row.business_type }}
        </template>
      </el-table-column>

      <el-table-column width="150" label="组织机构代码">
        <template slot-scope="scope">
          {{ scope.row.credit_code }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="注册资本">
        <template slot-scope="scope">
          {{ scope.row.gassets }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="县/区">
        <template slot-scope="scope">
          {{ scope.row.region_code }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="常用联系人">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="常用联系人电话">
        <template slot-scope="scope">
          {{ scope.row.linkman1_tel }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="常用联系人手机">
        <template slot-scope="scope">
          {{ scope.row.linkman1_mobile }}
        </template>
      </el-table-column>
      <el-table-column width="150" label="常用联系人职务">
        <template slot-scope="scope">
          {{ scope.row.linkman1_duty }}
        </template>
      </el-table-column>

      <el-table-column align="center" fixed="right" label="操作" width="100px">
        <template slot-scope="scope">
          <el-button type="primary"
                     size="small"
                     @click="handleChose(scope)">选中</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="enterpriseList.count>0"
                :total="enterpriseList.count"
                :page.sync="listQuery.page"
                :limit.sync="listQuery.page_size"
                @pagination="getList" />
  </div>
</template>
<script>
import { getEnterpriseList,deleteEnterprise } from "@/api/enterprise"
import Pagination from "@/components/Pagination"
  import checkPermission from '@/utils/permission'
    import { genTree } from "@/utils";
export default {
  name:'Enterprisechose',
  components: { Pagination },
  data() {
    return {
      enterpriseList: {count:0},
      listLoading: true,
      listQuery: {
        page: 1,
        page_size: 20
      },
     
    };
  },
  created() {
    this.getList();
  },
  methods: {
    checkPermission,
    getList() {
      this.listLoading = true;
      getEnterpriseList(this.listQuery).then(response => {
        if (response.data) {
          this.enterpriseList = response.data
        }
        this.listLoading = false
      });
    },
    resetFilter() {
      this.listQuery = {
        page: 1,
        page_size: 20
      }
      this.getList()
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleChose(scope) {
      this.$emit('handleChose',scope.row);
    },
    handleChose2(row, column, event){
      this.$emit('handleChose',row);
    }
  },
  
};
</script>
