<template>
  <el-dialog title="企业信息查询" :visible.sync="open"   width="800px"   append-to-body>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="登记部门" prop="deptId" v-show="deptShow">
        <el-select v-model="queryParams.deptId" filterable placeholder="请选择部门" clearable>
          <el-option
            v-for="dict in allDeptList"
            :key="dict.deptId"
            :label="dict.deptName"
            :value="dict.deptId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="社会信用代码" prop="enterpriseCode">
        <el-input
          v-model="queryParams.enterpriseCode"
          placeholder="请输入社会信用代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="enterpriseName">
        <el-input
          v-model="queryParams.enterpriseName"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="行业" prop="enterpriseType">
        <el-select v-model="queryParams.enterpriseType" placeholder="请选择行业" clearable>
          <el-option
            v-for="dict in dict.type.enterprise_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="企业现状" prop="enterpriseStatus">
        <el-select v-model="queryParams.enterpriseStatus" placeholder="请选择行业" clearable>
          <el-option
            v-for="dict in statusOptions"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="ehsEnterpriseList" highlight-current-row
              @current-change="handleCurrentChange" >
     <!-- <el-table-column type="selection" width="55" align="center" />-->
     <!-- <el-table-column label="" align="center" prop="enterpriseId" />-->
      <el-table-column label="登记部门" align="center" prop="deptName"  v-if="this.$store.state.user.parentId==0"/>
      <el-table-column label="社会信用代码" align="center" prop="enterpriseCode" />
      <el-table-column label="名称" align="center" prop="enterpriseName" />
      <el-table-column label="行业" align="center" prop="enterpriseType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.enterprise_type" :value="scope.row.enterpriseType"/>
        </template>
      </el-table-column>
      <el-table-column label="企业现状" align="center" prop="enterpriseStatus">
        <template slot-scope="scope">
          <span> {{ (scope.row.enterpriseStatus !=null && scope.row.enterpriseStatus != "") ? statusOptions[scope.row.enterpriseStatus].label:""}}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产经营地址" align="center" prop="enterpriseAddr" />
      <el-table-column label="企业负责人" align="center" prop="enterpriseLeader" />
      <el-table-column label="企业负责人电话" align="center" prop="leaderTel" />
      <el-table-column label="注册资本" align="center" prop="registeredCapital" />
      <el-table-column label="证照上核定的业务范围" align="center" prop="businessScope" />
      <el-table-column label="实际从事的业务范围" align="center" prop="businessProjects" />
      <el-table-column label="企业现状" align="center" prop="enterpriseStatus" />
      <el-table-column label="分管安全副职姓名" align="center" prop="safetyManagerName" />
      <el-table-column label="分管安全副职电话" align="center" prop="safetyManagerTel" />
      <el-table-column label="备注" align="center" prop="remark" />

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listEhsEnterprise, getEhsEnterprise, delEhsEnterprise, addEhsEnterprise, updateEhsEnterprise } from "@/api/ehs/ehsEnterprise";
import {listAllDept } from "@/api/system/dept";
export default {
  name: "enterpriseSelect",
  dicts: ['enterprise_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业基本信息表格数据
      ehsEnterpriseList: [],
      //是否显示部门列表查询条件
      deptShow: false,
      //所有部门列表字典
      allDeptList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      currRow:{},//当前选中的行
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enterpriseCode: null,
        enterpriseName: null,
        enterpriseType: null,
        enterpriseAddr: null,
        enterpriseLeader: null,
        leaderTel: null,
        registeredCapital: null,
        businessScope: null,
        businessProjects: null,
        enterpriseStatus: null,
        safetyManagerName: null,
        safetyManagerTel: null,
        deptId: null,
        createUserId: null,
        updateUserId: null
      },
      statusOptions: [{
        value: '0',
        label: '停业',
      }, {
        value: '1',
        label: '正常经营',
      }],
      editShow:true,//删除编辑按钮是否显示
      curDeptId:-1,//当前部门
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getListAllDept();
    this.deptShow = this.$store.state.user.parentId==0 ?true :false;
    this.curDeptId = this.$store.state.user.deptId;
  },
  methods: {
    /** 查询企业基本信息列表 */
    getList() {
      this.loading = true;
      listEhsEnterprise(this.queryParams).then(response => {
        this.ehsEnterpriseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 单位信息列表 */
    getListAllDept() {
      console.log(this.$store.state.user.deptId);
      this.loading = true;
      listAllDept().then(response => {
        this.allDeptList = response.data;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        enterpriseId: null,
        enterpriseCode: null,
        enterpriseName: null,
        enterpriseType: null,
        enterpriseAddr: null,
        enterpriseLeader: null,
        leaderTel: null,
        registeredCapital: null,
        businessScope: null,
        businessProjects: null,
        enterpriseStatus: null,
        safetyManagerName: null,
        safetyManagerTel: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        deptId: null,
        createUserId: null,
        updateUserId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //  选中数据
    handleCurrentChange(row) {

      this.currRow = row;
    },
    openDialog() {
      this.open = true;
    },
    submitForm() {
      // console.log(this.currRow);
     // this.$emit("currEnterpriseInfo", this.currRow);
      this.$emit("selectInfo",this.currRow);
      this.open = false;
    }

  }
};
</script>
