<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="统一社会信用代码" prop="fBizCode">
        <el-input
          v-model="queryParams.fBizCode"
          placeholder="请输入统一社会信用代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业名称" prop="fCompanyName">
        <el-input
          v-model="queryParams.fCompanyName"
          placeholder="请输入企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="fCreateTime">
        <el-date-picker clearable size="small"
                        v-model="queryParams.fCreateTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择创建时间">
        </el-date-picker>
      </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"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="inforList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="所属区县名称" align="center" prop="fDistrictName" />
      <el-table-column label="统一社会信用代码" align="center" prop="fBizCode" />
      <el-table-column label="企业名称" align="center" prop="fCompanyName" />
      <el-table-column label="管道燃气许可证号" align="center" prop="fPipelineCertCode" />
      <el-table-column label="年度" align="center" prop="fYear" />
      <el-table-column label="创建时间" align="center" prop="fCreateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fCreateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <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-view"
            @click="handleView(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.isReport == '0'"
            @click="report(scope.row)"
          >上报</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="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="200px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属市名称" prop="fCityName">
              <el-input v-model="form.fCityName" placeholder="请输入所属市名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属区县名称" prop="fDistrictName">
              <el-input v-model="form.fDistrictName" placeholder="请输入所属区县名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="统一社会信用代码" prop="fBizCode">
              <el-input v-model="form.fBizCode" placeholder="请输入统一社会信用代码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业名称" prop="fCompanyName">
              <el-input v-model="form.fCompanyName" placeholder="请输入企业名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="管道燃气许可证号" prop="fPipelineCertCode">
              <el-input v-model="form.fPipelineCertCode" placeholder="请输入管道燃气许可证号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="管道燃气企业经营状况" prop="fPipelineComp">
              <el-input v-model="form.fPipelineComp" placeholder="请输入管道燃气企业经营状况" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="燃气汽车加气站企业许可证号" prop="fStationCertCode">
              <el-input v-model="form.fStationCertCode" placeholder="请输入燃气汽车加气站企业许可证号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="燃气汽车加气站经营状况" prop="fStationComp">
              <el-input v-model="form.fStationComp" placeholder="请输入燃气汽车加气站经营状况" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="其他经营类企业许可证号" prop="fOtherCertCode">
              <el-input v-model="form.fOtherCertCode" placeholder="请输入其他经营类企业许可证号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="其他经营类企业经营情况" prop="fOtherComp">
              <el-input v-model="form.fOtherComp" placeholder="请输入其他经营类企业经营情况" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="企业主要负责人数量" prop="fResponsibleCount">
              <el-input v-model="form.fResponsibleCount" placeholder="请输入企业主要负责人数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="安全生产管理人数量" prop="fManagementCount">
              <el-input v-model="form.fManagementCount" placeholder="请输入安全生产管理人数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="运行、维护和抢修人数量" prop="fMaintenanceCount">
              <el-input v-model="form.fMaintenanceCount" placeholder="请输入运行、维护和抢修人数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业主要负责人持证数量" prop="fResponsibleCertCount">
              <el-input v-model="form.fResponsibleCertCount" placeholder="请输入企业主要负责人持证数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="安全生产管理人持证数量" prop="fManagementCertCount">
              <el-input v-model="form.fManagementCertCount" placeholder="请输入安全生产管理人持证数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="运行、维护和抢修人支持数量" prop="fMaintenanceCertCount">
              <el-input v-model="form.fMaintenanceCertCount" placeholder="请输入运行、维护和抢修人支持数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="门站数量" prop="fStationCount">
              <el-input v-model="form.fStationCount" placeholder="请输入门站数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="燃气储配站数量" prop="fStorageStationCount">
              <el-input v-model="form.fStorageStationCount" placeholder="请输入燃气储配站数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="气化站数量" prop="fGasificationStationCount">
              <el-input v-model="form.fGasificationStationCount" placeholder="请输入气化站数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="混气站数量" prop="fMixingStationCount">
              <el-input v-model="form.fMixingStationCount" placeholder="请输入混气站数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="加气站数量" prop="fGasStationCount">
              <el-input v-model="form.fGasStationCount" placeholder="请输入加气站数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="灌装站数量" prop="fFillingStationCount">
              <el-input v-model="form.fFillingStationCount" placeholder="请输入灌装站数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="供应站数量" prop="fSupplyStationCount">
              <el-input v-model="form.fSupplyStationCount" placeholder="请输入供应站数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="调压站数量" prop="fPressureStationCount">
              <el-input v-model="form.fPressureStationCount" placeholder="请输入调压站数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="其他站数量" prop="fOtherStationCount">
              <el-input v-model="form.fOtherStationCount" placeholder="请输入其他站数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年度" prop="fYear">
              <el-date-picker clearable size="small"
                              v-model="form.fYear"
                              type="year"
                              value-format="yyyy"
                              placeholder="选择年度">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </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>

    <!-- 查看详情对话框 -->
    <el-dialog title="详情" :visible.sync="viewOpen" width="1200px" append-to-body>
      <el-form label-width="200px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属市名称">
              <span>{{ viewForm.fCityName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属区县名称">
              <span>{{ viewForm.fDistrictName }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="统一社会信用代码">
              <span>{{ viewForm.fBizCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业名称">
              <span>{{ viewForm.fCompanyName }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="管道燃气许可证号">
              <span>{{ viewForm.fPipelineCertCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="管道燃气企业经营状况">
              <span>{{ viewForm.fPipelineComp }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="燃气汽车加气站企业许可证号">
              <span>{{ viewForm.fStationCertCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="燃气汽车加气站经营状况">
              <span>{{ viewForm.fStationComp }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="其他经营类企业许可证号">
              <span>{{ viewForm.fOtherCertCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="其他经营类企业经营情况">
              <span>{{ viewForm.fOtherComp }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="企业主要负责人数量">
              <span>{{ viewForm.fResponsibleCount }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="安全生产管理人数量">
              <span>{{ viewForm.fManagementCount }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="运行、维护和抢修人数量">
              <span>{{ viewForm.fMaintenanceCount }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业主要负责人持证数量">
              <span>{{ viewForm.fResponsibleCertCount }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="安全生产管理人持证数量">
              <span>{{ viewForm.fManagementCertCount }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="运行、维护和抢修人支持数量">
              <span>{{ viewForm.fMaintenanceCertCount }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="门站数量">
              <span>{{ viewForm.fStationCount }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="燃气储配站数量">
              <span>{{ viewForm.fStorageStationCount }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="气化站数量">
              <span>{{ viewForm.fGasificationStationCount }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="混气站数量">
              <span>{{ viewForm.fMixingStationCount }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="加气站数量">
              <span>{{ viewForm.fGasStationCount }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="灌装站数量">
              <span>{{ viewForm.fFillingStationCount }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="供应站数量">
              <span>{{ viewForm.fSupplyStationCount }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="调压站数量">
              <span>{{ viewForm.fPressureStationCount }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="其他站数量">
              <span>{{ viewForm.fOtherStationCount }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年度">
              <span>{{ viewForm.fYear }}</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="viewOpen = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfor, getInfor, delInfor, addInfor, updateInfor, exportInfor } from "@/api/regulation/infor";
import {updateTask} from "@/api/inspectionWork/workTask";
export default {
  name: "Infor",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 年度行业指标汇总 - 燃气企业基本情况信息表格数据
      inforList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示详情弹出层
      viewOpen: false,
      // 详情表单数据
      viewForm: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fCityName: null,
        fDistrictName: null,
        fBizCode: null,
        fCompanyName: null,
        fPipelineCertCode: null,
        fPipelineComp: null,
        fStationCertCode: null,
        fStationComp: null,
        fOtherCertCode: null,
        fOtherComp: null,
        fResponsibleCount: null,
        fManagementCount: null,
        fMaintenanceCount: null,
        fResponsibleCertCount: null,
        fManagementCertCount: null,
        fMaintenanceCertCount: null,
        fStationCount: null,
        fStorageStationCount: null,
        fGasificationStationCount: null,
        fMixingStationCount: null,
        fGasStationCount: null,
        fFillingStationCount: null,
        fSupplyStationCount: null,
        fPressureStationCount: null,
        fOtherStationCount: null,
        fCreateTime: null,
        fUpdateTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fCityName: [
          { required: true, message: "所属市名称不能为空", trigger: "blur" }
        ],
        fDistrictName: [
          { required: true, message: "所属区县名称不能为空", trigger: "blur" }
        ],
        fBizCode: [
          { required: true, message: "统一社会信用代码不能为空", trigger: "blur" }
        ],
        fCompanyName: [
          { required: true, message: "企业名称不能为空", trigger: "blur" }
        ],
        fResponsibleCount: [
          { required: true, message: "企业主要负责人数量不能为空", trigger: "blur" }
        ],
        fManagementCount: [
          { required: true, message: "安全生产管理人数量不能为空", trigger: "blur" }
        ],
        fMaintenanceCount: [
          { required: true, message: "运行、维护和抢修人数量不能为空", trigger: "blur" }
        ],
        fResponsibleCertCount: [
          { required: true, message: "企业主要负责人持证数量不能为空", trigger: "blur" }
        ],
        fManagementCertCount: [
          { required: true, message: "安全生产管理人持证数量不能为空", trigger: "blur" }
        ],
        fMaintenanceCertCount: [
          { required: true, message: "运行、维护和抢修人支持数量不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询年度行业指标汇总 - 燃气企业基本情况信息列表 */
    getList() {
      this.loading = true;
      listInfor(this.queryParams).then(response => {
        this.inforList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fEnterpriseId: null,
        fCityName: null,
        fDistrictName: null,
        fBizCode: null,
        fCompanyName: null,
        fPipelineCertCode: null,
        fPipelineComp: null,
        fStationCertCode: null,
        fStationComp: null,
        fOtherCertCode: null,
        fOtherComp: null,
        fResponsibleCount: null,
        fManagementCount: null,
        fMaintenanceCount: null,
        fResponsibleCertCount: null,
        fManagementCertCount: null,
        fMaintenanceCertCount: null,
        fStationCount: null,
        fStorageStationCount: null,
        fGasificationStationCount: null,
        fMixingStationCount: null,
        fGasStationCount: null,
        fFillingStationCount: null,
        fSupplyStationCount: null,
        fPressureStationCount: null,
        fOtherStationCount: null,
        fCreateTime: null,
        fUpdateTime: 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.fEnterpriseId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加年度行业指标汇总";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
     const fEnterpriseId = row.fEnterpriseId || this.ids
      getInfor(fEnterpriseId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改年度行业指标汇总";
      });
    },
    /** 详情按钮操作 */
    handleView(row) {
     const fEnterpriseId = row.fEnterpriseId;
      getInfor(fEnterpriseId).then(response => {
        this.viewForm = response.data;
        this.viewOpen = true;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fEnterpriseId != null) {
            updateInfor(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfor(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
     const fEnterpriseIds = row.fEnterpriseId || this.ids;
      this.$confirm('是否确认删除年度行业指标汇总 - 燃气企业基本情况信息编号为"' + fEnterpriseIds + '"的数据项？', "警告", {
       confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delInfor(fEnterpriseIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {});
    },
    report(row){
      this.$confirm('是否确认上报年度行业指标汇总编号为"' + row.fEnterpriseId + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return updateInfor({fEnterpriseId:row.fEnterpriseId,isReport:"1"});
      }).then(() => {
        this.getList();
        this.msgSuccess("上报成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
     const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有年度行业指标汇总 - 燃气企业基本情况信息数据项？', "警告", {
       confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportInfor(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};

</script>
