<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单位名称" prop="unitName">
        <el-input
          v-model="queryParams.unitName"
          placeholder="请输入单位名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="组织机构代码" prop="orgCode">
        <el-input
          v-model="queryParams.orgCode"
          placeholder="请输入组织机构代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产经营地址" prop="runAddress">
        <el-input
          v-model="queryParams.runAddress"
          placeholder="请输入生产经营地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="注册地址" prop="regAddress">
        <el-input
          v-model="queryParams.regAddress"
          placeholder="请输入注册地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="监管分类大类" prop="regulationBigType">
        <el-select v-model="queryParams.regulationBigType" placeholder="请选择监管分类大类" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="监管分类小类" prop="regulationSmallType">
        <el-select v-model="queryParams.regulationSmallType" placeholder="请选择监管分类小类" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="省份代码" prop="provinceId">
        <el-input
          v-model="queryParams.provinceId"
          placeholder="请输入省份代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省份名称" prop="provinceName">
        <el-input
          v-model="queryParams.provinceName"
          placeholder="请输入省份名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市代码" prop="cityId">
        <el-input
          v-model="queryParams.cityId"
          placeholder="请输入城市代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市名称" prop="cityName">
        <el-input
          v-model="queryParams.cityName"
          placeholder="请输入城市名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区县代码" prop="countyId">
        <el-input
          v-model="queryParams.countyId"
          placeholder="请输入区县代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区县名称" prop="countyName">
        <el-input
          v-model="queryParams.countyName"
          placeholder="请输入区县名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属地区" prop="areaName">
        <el-input
          v-model="queryParams.areaName"
          placeholder="请输入所属地区"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属街道" prop="streetName">
        <el-input
          v-model="queryParams.streetName"
          placeholder="请输入所属街道"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经度" prop="longitude">
        <el-input
          v-model="queryParams.longitude"
          placeholder="请输入经度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="纬度" prop="latitude">
        <el-input
          v-model="queryParams.latitude"
          placeholder="请输入纬度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法定代表人" prop="legalPerson">
        <el-input
          v-model="queryParams.legalPerson"
          placeholder="请输入法定代表人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法定代表人手机" prop="legalPersonPhone">
        <el-input
          v-model="queryParams.legalPersonPhone"
          placeholder="请输入法定代表人手机"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法定代表人座机号码" prop="legalPersonTelephone">
        <el-input
          v-model="queryParams.legalPersonTelephone"
          placeholder="请输入法定代表人座机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人邮箱" prop="legalPersonEmail">
        <el-input
          v-model="queryParams.legalPersonEmail"
          placeholder="请输入法人邮箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否启用，0启用，1禁用" prop="isEnable">
        <el-input
          v-model="queryParams.isEnable"
          placeholder="请输入是否启用，0启用，1禁用"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人id" prop="createUserId">
        <el-input
          v-model="queryParams.createUserId"
          placeholder="请输入创建人id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新人id" prop="updateUserId">
        <el-input
          v-model="queryParams.updateUserId"
          placeholder="请输入更新人id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input
          v-model="queryParams.remarks"
          placeholder="请输入备注"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </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-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['enterprise:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['enterprise:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['enterprise:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['enterprise:info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="备注" align="center" prop="infoId" />
      <el-table-column label="单位名称" align="center" prop="unitName" />
      <el-table-column label="组织机构代码" align="center" prop="orgCode" />
      <el-table-column label="营业执照图片路径" align="center" prop="orgFilePath" />
      <el-table-column label="文件名称" align="center" prop="orgFileName" />
      <el-table-column label="生产经营地址" align="center" prop="runAddress" />
      <el-table-column label="注册地址" align="center" prop="regAddress" />
      <el-table-column label="监管分类大类" align="center" prop="regulationBigType" />
      <el-table-column label="监管分类小类" align="center" prop="regulationSmallType" />
      <el-table-column label="省份代码" align="center" prop="provinceId" />
      <el-table-column label="省份名称" align="center" prop="provinceName" />
      <el-table-column label="城市代码" align="center" prop="cityId" />
      <el-table-column label="城市名称" align="center" prop="cityName" />
      <el-table-column label="区县代码" align="center" prop="countyId" />
      <el-table-column label="区县名称" align="center" prop="countyName" />
      <el-table-column label="所属地区" align="center" prop="areaName" />
      <el-table-column label="所属街道" align="center" prop="streetName" />
      <el-table-column label="经度" align="center" prop="longitude" />
      <el-table-column label="纬度" align="center" prop="latitude" />
      <el-table-column label="法定代表人" align="center" prop="legalPerson" />
      <el-table-column label="法定代表人手机" align="center" prop="legalPersonPhone" />
      <el-table-column label="法定代表人座机号码" align="center" prop="legalPersonTelephone" />
      <el-table-column label="法人邮箱" align="center" prop="legalPersonEmail" />
      <el-table-column label="授权书" align="center" prop="authorizeFile" />
      <el-table-column label="授权书文件原名" align="center" prop="authorizeFileOriginalName" />
      <el-table-column label="厂区边界" align="center" prop="boundary" />
      <el-table-column label="是否启用，0启用，1禁用" align="center" prop="isEnable" />
      <el-table-column label="创建人id" align="center" prop="createUserId" />
      <el-table-column label="更新人id" align="center" prop="updateUserId" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['enterprise:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['enterprise:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改企业基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="单位名称" prop="unitName">
          <el-input v-model="form.unitName" placeholder="请输入单位名称" />
        </el-form-item>
        <el-form-item label="组织机构代码" prop="orgCode">
          <el-input v-model="form.orgCode" placeholder="请输入组织机构代码" />
        </el-form-item>
        <el-form-item label="营业执照图片路径" prop="orgFilePath">
          <el-input v-model="form.orgFilePath" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="文件名称" prop="orgFileName">
          <el-input v-model="form.orgFileName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="生产经营地址" prop="runAddress">
          <el-input v-model="form.runAddress" placeholder="请输入生产经营地址" />
        </el-form-item>
        <el-form-item label="注册地址" prop="regAddress">
          <el-input v-model="form.regAddress" placeholder="请输入注册地址" />
        </el-form-item>
        <el-form-item label="监管分类大类" prop="regulationBigType">
          <el-select v-model="form.regulationBigType" placeholder="请选择监管分类大类">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="监管分类小类" prop="regulationSmallType">
          <el-select v-model="form.regulationSmallType" placeholder="请选择监管分类小类">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="省份代码" prop="provinceId">
          <el-input v-model="form.provinceId" placeholder="请输入省份代码" />
        </el-form-item>
        <el-form-item label="省份名称" prop="provinceName">
          <el-input v-model="form.provinceName" placeholder="请输入省份名称" />
        </el-form-item>
        <el-form-item label="城市代码" prop="cityId">
          <el-input v-model="form.cityId" placeholder="请输入城市代码" />
        </el-form-item>
        <el-form-item label="城市名称" prop="cityName">
          <el-input v-model="form.cityName" placeholder="请输入城市名称" />
        </el-form-item>
        <el-form-item label="区县代码" prop="countyId">
          <el-input v-model="form.countyId" placeholder="请输入区县代码" />
        </el-form-item>
        <el-form-item label="区县名称" prop="countyName">
          <el-input v-model="form.countyName" placeholder="请输入区县名称" />
        </el-form-item>
        <el-form-item label="所属地区" prop="areaName">
          <el-input v-model="form.areaName" placeholder="请输入所属地区" />
        </el-form-item>
        <el-form-item label="所属街道" prop="streetName">
          <el-input v-model="form.streetName" placeholder="请输入所属街道" />
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="法定代表人" prop="legalPerson">
          <el-input v-model="form.legalPerson" placeholder="请输入法定代表人" />
        </el-form-item>
        <el-form-item label="法定代表人手机" prop="legalPersonPhone">
          <el-input v-model="form.legalPersonPhone" placeholder="请输入法定代表人手机" />
        </el-form-item>
        <el-form-item label="法定代表人座机号码" prop="legalPersonTelephone">
          <el-input v-model="form.legalPersonTelephone" placeholder="请输入法定代表人座机号码" />
        </el-form-item>
        <el-form-item label="法人邮箱" prop="legalPersonEmail">
          <el-input v-model="form.legalPersonEmail" placeholder="请输入法人邮箱" />
        </el-form-item>
        <el-form-item label="授权书">
          <fileUpload v-model="form.authorizeFile"/>
        </el-form-item>
        <el-form-item label="授权书文件原名" prop="authorizeFileOriginalName">
          <el-input v-model="form.authorizeFileOriginalName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="厂区边界" prop="boundary">
          <el-input v-model="form.boundary" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否启用，0启用，1禁用" prop="isEnable">
          <el-input v-model="form.isEnable" placeholder="请输入是否启用，0启用，1禁用" />
        </el-form-item>
        <el-form-item label="创建人id" prop="createUserId">
          <el-input v-model="form.createUserId" placeholder="请输入创建人id" />
        </el-form-item>
        <el-form-item label="更新人id" prop="updateUserId">
          <el-input v-model="form.updateUserId" placeholder="请输入更新人id" />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo } from "@/api/enterprise/info";
import FileUpload from '@/components/FileUpload';

export default {
  name: "Info",
  components: {
    FileUpload,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业基本信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        unitName: null,
        orgCode: null,
        orgFilePath: null,
        orgFileName: null,
        runAddress: null,
        regAddress: null,
        regulationBigType: null,
        regulationSmallType: null,
        provinceId: null,
        provinceName: null,
        cityId: null,
        cityName: null,
        countyId: null,
        countyName: null,
        areaName: null,
        streetName: null,
        longitude: null,
        latitude: null,
        legalPerson: null,
        legalPersonPhone: null,
        legalPersonTelephone: null,
        legalPersonEmail: null,
        authorizeFile: null,
        authorizeFileOriginalName: null,
        boundary: null,
        isEnable: null,
        createUserId: null,
        updateUserId: null,
        remarks: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询企业基本信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        infoId: null,
        unitName: null,
        orgCode: null,
        orgFilePath: null,
        orgFileName: null,
        runAddress: null,
        regAddress: null,
        regulationBigType: null,
        regulationSmallType: null,
        provinceId: null,
        provinceName: null,
        cityId: null,
        cityName: null,
        countyId: null,
        countyName: null,
        areaName: null,
        streetName: null,
        longitude: null,
        latitude: null,
        legalPerson: null,
        legalPersonPhone: null,
        legalPersonTelephone: null,
        legalPersonEmail: null,
        authorizeFile: null,
        authorizeFileOriginalName: null,
        boundary: null,
        isEnable: null,
        createUserId: null,
        updateUserId: null,
        updateTime: null,
        createTime: null,
        remarks: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.infoId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const infoId = row.infoId || this.ids
      getInfo(infoId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改企业基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.infoId != null) {
            updateInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const infoIds = row.infoId || this.ids;
      this.$confirm('是否确认删除企业基本信息编号为"' + infoIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(infoIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有企业基本信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
