<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="统一社会信用代码" prop="unifiedSocialCreditCode">
        <el-input
            v-model="queryParams.unifiedSocialCreditCode"
            placeholder="请输入统一社会信用代码"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="enterprisesList" height="650" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="企业名称" align="center" prop="enterpriseName" width="260" />
      <el-table-column label="统一社会信用代码" align="center" prop="unifiedSocialCreditCode" width="200" />
      <el-table-column label="行政许可得分" align="center" prop="administrativeLicense" />
      <el-table-column label="行政处罚得分" align="center" prop="administrativePenalty" />
      <el-table-column label="行政确认得分" align="center" prop="administrativeConfirmation" />
      <el-table-column label="行政监督得分" align="center" prop="administrativeSupervision" />
      <el-table-column label="环保信用评价得分" align="center" prop="environmentalCreditEvaluationNotification" />
      <el-table-column label="纳税信用得分" align="center" prop="enterpriseTaxClassificationInfo" />
      <el-table-column label="行政强制信息得分" align="center" prop="administrativeCompulsionInformation" />
      <el-table-column label="行政裁决信息得分" align="center" prop="administrativeSanctionInfo" />
      <el-table-column label="列入经营异常名录得分" align="center" prop="abnormalBusinessList" />
      <el-table-column label="抽查信息得分" align="center" prop="spotCheck" />
      <el-table-column label="破产信息得分" align="center" prop="bankruptcyInformation" />
      <el-table-column label="海关信用得分" align="center" prop="customsCreditRating" />
      <el-table-column label="法院判决信息得分" align="center" prop="judgmentDocumentJudgmentInformation" />
      <el-table-column label="失信被执行人信息得分" align="center" prop="dishonestExecutor" />
      <el-table-column label="营业执照信息得分" align="center" prop="businessLicenseInformation" />
      <el-table-column label="所属行业类型信息" align="center" prop="industryType" />
      <el-table-column label="科技研发得分" align="center" prop="enterpriseTechnologyRndSummary" />
      <el-table-column label="认证高新技术企业得分" align="center" prop="certifiedTechnologyEnterprise" />
      <el-table-column label="“专精特新”企业得分" align="center" prop="newEnterpriseRecognitionDetails" />
      <el-table-column label="科技型中小企业得分" align="center" prop="technologyEnterprises" />
      <el-table-column label="变更信息得分" align="center" prop="changeRecordInformation" />
      <el-table-column label="股东及出资信息得分" align="center" prop="shareholderInformation" />
      <el-table-column label="分支机构信息得分" align="center" prop="branchOfficeInformation" />
      <el-table-column label="股权出质登记信息得分" align="center" prop="equityPledgeInformation" />
      <el-table-column label="海关注册信息得分" align="center" prop="customsRegistrationInformation" />
      <el-table-column label="软件著作权得分" align="center" prop="softwareCopyrightInformation" />
      <el-table-column label="商标得分" align="center" prop="enterpriseTrademarkInformation" />
      <el-table-column label="专利得分" align="center" prop="patentInformation" />
      <el-table-column label="社保得分" align="center" prop="enterpriseSocialSecurityInfo" />
      <el-table-column label="社保欠缴得分" align="center" prop="enterpriseTaxArrearsInfo1" />
      <el-table-column label="非正常纳税户得分" align="center" prop="abnormalTaxInformation" />
      <el-table-column label="纳税欠税得分" align="center" prop="enterpriseTaxArrearsInfo2" />
      <el-table-column label="公积金汇总得分" align="center" prop="accumulationFundSummary" />
      <el-table-column label="水费信息得分" align="center" prop="industrialParkWaterUsageDetail" />
      <el-table-column label="电费信息得分" align="center" prop="enterpriseElectricityFeeInfo" />
      <el-table-column label="企业名下房产抵押信息" align="center" prop="propertyMortgage" />
      <el-table-column label="企业产值得分" align="center" prop="annualOutputValueInfo" />
    </el-table>
    <div style="position: fixed;bottom: 20px;right: 10px;">
      <el-pagination
          :page-sizes="[10, 20, 30, 50]"
          v-model:page-size = "queryParams.pageSize"
          v-model:current-page = "queryParams.pageNum"
          layout="total, sizes, prev, pager, next, jumper"
          @current-change="getList"
          :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script setup name="Enterprises">
import { listEnterprises, getEnterprises, delEnterprises, addEnterprises, updateEnterprises } from "@/api/basicData/enterprises2";
import {likeQueryMethod} from "../../../utils/likeQueryMethod";

const { proxy } = getCurrentInstance();

const enterprisesList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 20,
    enterpriseName: null,
    unifiedSocialCreditCode: '',
    enterpriseLeader: null,
    contactPhone: null,
  },
  rules: {
    enterpriseName: [
      { required: true, message: "企业名称不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询高新区企业（119家）列表 */
function getList() {
  loading.value = true;
  let toServerObj = {
    pageNum: queryParams.value.pageNum,
    pageSize: queryParams.value.pageSize,
    unifiedSocialCreditCode:queryParams.value.unifiedSocialCreditCode
  }
  listEnterprises(toServerObj).then(response => {
    enterprisesList.value = response.data.result;
    total.value = response.data.totalSize;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    enterpriseName: null,
    unifiedSocialCreditCode: '',
    enterpriseLeader: null,
    contactPhone: null,
    createTime: null,
    updateTime: null
  };
  proxy.resetForm("enterprisesRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加高新区企业（119家）";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const id = row.id || ids.value
  getEnterprises(id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改高新区企业（119家）";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["enterprisesRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateEnterprises(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addEnterprises(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除高新区企业（119家）编号为"' + ids + '"的数据项？').then(function() {
    return delEnterprises(ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('basicData/enterprises/export', {
    ...queryParams.value
  }, `enterprises_${new Date().getTime()}.xlsx`)
}

getList();
</script>
