<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="130px">
      <el-form-item label="项目编码" prop="fProjectCode">
        <el-input
          v-model="queryParams.fProjectCode"
          placeholder="请输入项目编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="施工工程项目名称" prop="fProjectName">
        <el-input
          v-model="queryParams.fProjectName"
          placeholder="请输入施工工程项目名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="管道压力等级分类" prop="fPipePress">
        <el-select v-model="queryParams.fPipePress" placeholder="请选择管道压力等级分类" clearable size="small">
          <el-option
            v-for="dict in fPipePressOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      
      <el-form-item label="上报状态" prop="fUploadType">
        <el-select v-model="queryParams.fUploadType" placeholder="请选择上报状态" clearable size="small">
          <el-option label="未上报" value="0" />
          <el-option label="已上报" value="1" />
        </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-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-if="user.roleId==5"
        >新增</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-if="user.roleId==5"
        >修改</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-if="user.roleId==5"
        >删除</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 label="项目编码" align="center" prop="fProjectCode" />
      <!-- <el-table-column label="外部工程编码" align="center" prop="fProjectNo" /> -->
      <el-table-column label="燃气企业" align="center" prop="companyInfoName" :show-overflow-tooltip="true"/>
      <el-table-column label="施工工程项目名称" align="center" prop="fProjectName" />
      <el-table-column label="开工时间" align="center" prop="fConstructionStart" />
      <el-table-column label="计划竣工时间" align="center" prop="fConstructionEnd" />
      <el-table-column label="所属县级行政区" align="center" prop="fDistrictId" :formatter="beyondCountyFormat"/>
      <el-table-column label="涉气施工点位属性" align="center" prop="fConstructionPointType" >
        <template slot-scope="scope">
          <span v-if="scope.row.fConstructionPointType == '1'">城镇</span>
          <span v-else-if="scope.row.fConstructionPointType == '2'">农村</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="管道压力等级分类" align="center" prop="fPipePress" :formatter="fPipePressFormat" />
      <el-table-column :label="uploadStateLabel" align="center" prop="uploadState" :formatter="uploadStateFormat" />
      <el-table-column :label="uploadTimeLabel" align="center" prop="uploadTime" :formatter="uploadTimeFormat" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="210">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="handleDetail(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-if="user.roleId==5&&scope.row.entUploadState==0"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-if="user.roleId==5&&scope.row.entUploadState==0"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleReport(scope.row)"
            v-if="judgeUploadIsShow((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="1000px" append-to-body destroy-on-close :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">
        <el-row class="el-row-table">
          <el-col :span="12">
            <el-form-item label="燃气企业" prop="fCompanyInfoId"> 
              <el-input v-model="enterpriseName" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="外部工程编码" prop="fProjectNo">
              <el-input v-model="form.fProjectNo" placeholder="请输入外部工程编码" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="施工工程项目名称" prop="fProjectName">
              <el-input v-model="form.fProjectName" placeholder="请输入施工工程项目名称" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="开工时间" prop="fConstructionStart">
              <el-date-picker
                style="width: 100%"
                v-model="form.fConstructionStart"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择开工时间">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="计划竣工时间" prop="fConstructionEnd">
              <el-date-picker
                style="width: 100%"
                v-model="form.fConstructionEnd"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择计划竣工时间">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="项目位置描述" prop="fAddress">
              <el-input v-model="form.fAddress" placeholder="请输入项目位置描述" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="所属县级行政区" prop="fDistrictId">
              <el-select
                v-model="form.fDistrictId"
                placeholder="请选择县级行政区"
                style="width: 100%"
              >
                <el-option
                  v-for="county in countyInfo"
                  :key="county.fId"
                  :label="county.fName.trim()"
                  :value="county.fId"
                />
              </el-select>
              <!-- <el-input type="Number" v-model="form.fDistrictId" placeholder="请输入所属县级行政区" /> -->
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="经纬度坐标" prop="fConstructionLongitude">
              <el-col :span="9">
                <el-input v-model="form.fConstructionLongitude" placeholder="请输入经度"/>
              </el-col>
              <el-col :span="9" style="margin-left: 13px">
                <el-input v-model="form.fConstructionLatitude" placeholder="请输入纬度"/>
              </el-col>
              <el-col :span="4" style="margin-left: 30px">
                <el-button type="primary" plain @click="MapdialogFun">选择经纬度</el-button>
              </el-col>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="涉气施工点位位置属性" prop="fConstructionPointType">
              <el-select style="width: 100%" v-model="form.fConstructionPointType" placeholder="请选择涉气施工点位位置属性">
                <el-option label="城镇" value="1" />
                <el-option label="农村" value="2" />
              </el-select>
            </el-form-item>
          </el-col> 

          <el-col :span="12">
            <el-form-item label="管道压力等级分类" prop="fPipePress">
              <el-select style="width: 100%" v-model="form.fPipePress" placeholder="请选择管道压力等级分类">
                <el-option
                  v-for="dict in fPipePressOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="施工是否主动报备" prop="fReportFlag">
              <el-select style="width: 100%" v-model="form.fReportFlag" placeholder="请选择施工是否主动报备">
                <el-option label="是" value=1 />
                <el-option label="否" value=0 />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="施工状态">
              <el-select style="width: 100%" v-model="form.fConstructionStatus" placeholder="请选择施工状态">
                <el-option label="未开工" value='1' />
                <el-option label="正在施工" value='2' />
                <el-option label="已完工" value='3' />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="建设单位名称" prop="fBuildDepartment">
              <el-input v-model="form.fBuildDepartment" placeholder="请输入建设单位名称" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="建设单位项目负责人姓名" prop="fProjectLeader">
              <el-input v-model="form.fProjectLeader" placeholder="请输入建设单位项目负责人姓名" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item :rules="[{
                pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                message: '手机号格式有误！',
                trigger: 'blur'
              }]"
              label="建设单位项目负责人电话"
              prop="fProjectLeaderPhone"
            >
              <el-input :maxlength="11" v-model="form.fProjectLeaderPhone" placeholder="请输入建设单位项目负责人电话" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="所属行业" prop="fIndustry">
              <el-input v-model="form.fIndustry" placeholder="请输入所属行业" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="行业安全监管部门名称" prop="fDepartmentName">
              <el-input v-model="form.fDepartmentName" placeholder="请输入行业安全监管部门名称" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="施工单位名称" prop="fConstructDepartment">
              <el-input v-model="form.fConstructDepartment" placeholder="请输入施工单位名称" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="施工单位项目负责人姓名" prop="fBuildProjectLeaderName">
              <el-input v-model="form.fBuildProjectLeaderName" placeholder="请输入施工单位项目负责人姓名" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item
              :rules="[{
                pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                message: '手机号格式有误！',
                trigger: 'blur'
              }]"
              label="施工单位项目负责人电话"
              prop="fBuildProjectLeaderPhone"
            >
              <el-input :maxlength="11" v-model="form.fBuildProjectLeaderPhone" placeholder="请输入施工单位项目负责人电话" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="施工单位技术负责人姓名" prop="fTechnicalLeaderName">
              <el-input v-model="form.fTechnicalLeaderName" placeholder="请输入施工单位技术负责人姓名" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item
              :rules="[{
                pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                message: '手机号格式有误！',
                trigger: 'blur'
              }]"
              label="施工单位技术负责人电话"
              prop="fTechnicalLeaderPhone"
            >
              <el-input :maxlength="11" v-model="form.fTechnicalLeaderPhone" placeholder="请输入施工单位技术负责人电话" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="监理单位名称" prop="fSupervisionUnitName">
              <el-input v-model="form.fSupervisionUnitName" placeholder="请输入监理单位名称" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="监理单位总监理工程师姓名" prop="fChiefEngineerName">
              <el-input v-model="form.fChiefEngineerName" placeholder="请输入监理单位总监理工程师姓名" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item
              :rules="[{
                pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                message: '手机号格式有误！',
                trigger: 'blur'
              }]"
              label="监理单位总监理工程师电话"
              prop="fChiefEngineerPhone"
            >
              <el-input :maxlength="11" v-model="form.fChiefEngineerPhone" placeholder="请输入监理单位总监理工程师电话" />
            </el-form-item>
          </el-col>


          <el-col :span="12">
            <el-form-item label="施工点位巡线员编码" prop="fPatrolSafetyOfficerNo">
              <el-input v-model="form.fPatrolSafetyOfficerNo" placeholder="请输入施工点位巡线员编码" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="施工点位巡线员姓名" prop="fPartrolSafetyOfficerName">
              <el-input v-model="form.fPartrolSafetyOfficerName" placeholder="请输入施工点位巡线员姓名" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item
              :rules="[{
                pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                message: '手机号格式有误！',
                trigger: 'blur'
              }]"
              label="施工点位巡线员电话"
              prop="fPatrolSafetyOfficerPhone"
            >
              <el-input :maxlength="11" v-model="form.fPatrolSafetyOfficerPhone" placeholder="请输入施工点位巡线员电话" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="驻村安全员编码" prop="fResidentSafetyOfficerNo">
              <el-input v-model="form.fResidentSafetyOfficerNo" placeholder="请输入驻村安全员编码" />
            </el-form-item>
          </el-col>


          <el-col :span="12">
            <el-form-item label="驻村安全员姓名" prop="fResidentSafetyOfficerName">
              <el-input v-model="form.fResidentSafetyOfficerName" placeholder="请输入驻村安全员姓名" />
            </el-form-item>
          </el-col>


          <el-col :span="12">
            <el-form-item
              :rules="[{
                pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                message: '手机号格式有误！',
                trigger: 'blur'
              }]"
              label="驻村安全员电话"
              prop="fResidentSafetyOfficerPhone"
            >
              <el-input :maxlength="11" v-model="form.fResidentSafetyOfficerPhone" placeholder="请输入驻村安全员电话" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="燃气企业旁站人员编码" prop="fGasCompanyStationNo">
              <el-input v-model="form.fGasCompanyStationNo" placeholder="请输入燃气企业旁站人员编码" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="燃气企业旁站人员姓名" prop="fGasCompanyStationName">
              <el-input v-model="form.fGasCompanyStationName" placeholder="请输入燃气企业旁站人员姓名" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item
              :rules="[{
                pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                message: '手机号格式有误！',
                trigger: 'blur'
              }]"
              label="燃气企业旁站人员电话"
              prop="fGasCompanyStationPhone"
            >
              <el-input :maxlength="11" v-model="form.fGasCompanyStationPhone" placeholder="请输入燃气企业旁站人员电话" />
            </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>

    <GetPos
      :dialogVisible.sync="dialogTableVisibles"
      device=""
      :devicePos="devicePos"
      @close="dialogcancelFun"
      @getPath="getPath"
    />

    <!-- 详情 -->
    <DetailInfo ref="detail"/>

  </div>
</template>

<script>
import { listInfor, getInfor, delInfor, addInfor, updateInfor, exportInfor, reportConGasProInfo,entReportConGasProInfo } from "@/api/thirdbuild/project";
import GetPos from '@/components/GetPos';
import{getInfo} from "@/api/login"
import DetailInfo from "./components/DetailInfo";
import { enterpriseLists } from "@/api/regulation/info";
import { getDefaultCountyList } from "@/api/area/county";
export default {
  name: "Infor",
  components: {
    GetPos,
    DetailInfo
  },
  data() {
    return {
      uploadStateLabel:"",
      uploadTimeLabel:"",
      enterpriseName:"",
      enterprises: [],
      user:{},
      countyInfo: [],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      fProjectNames: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 涉气第三方施工项目档案表格数据
      inforList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 管道压力等级分类
      fPipePressOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fProjectCode: null,
        fProjectNo: null,
        fProjectName: null,
        fPipePress: null,
        fCompanyInfoId: null,
        fUploadType:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fProjectCode: [
          { required: true, message: "项目编码，6位县级行政区划编码+4位年+4位顺序码不能为空", trigger: "blur" }
        ],
        fProjectNo: [
          { required: true, message: "外部工程编码，工程项目在市级平台或燃气企业系统中的自有编号不能为空", trigger: "blur" }
        ],
        fProjectName: [
          { required: true, message: "施工工程项目名称不能为空", trigger: "blur" }
        ],
        fConstructionStart: [
          { required: true, message: "开工时间不能为空", trigger: "blur" }
        ],
        fConstructionEnd: [
          { required: true, message: "计划竣工时间不能为空", trigger: "blur" }
        ],
        fAddress: [
          { required: true, message: "项目位置描述不能为空", trigger: "blur" }
        ],
        fDistrictId: [
          { required: true, message: "所属县级行政区不能为空", trigger: "blur" }
        ],
        fPipePress: [
          { required: true, message: "管道压力等级分类", trigger: "change" }
        ],
        fBuildDepartment: [
          { required: true, message: "建设单位名称不能为空", trigger: "blur" }
        ],
        fIndustry: [
          { required: true, message: "所属行业不能为空", trigger: "blur" }
        ],
        fConstructDepartment: [
          { required: true, message: "施工单位名称不能为空", trigger: "blur" }
        ],
        fCompanyInfoId: [
          { required: true, message: "燃气企业编码不能为空", trigger: "blur" }
        ],
      },
      dialogTableVisibles: false,
      devicePos: []
    };
  },
  created() {
    this.getuserInfo();
    this.getCountyInfo();
    this.getEnterpriseLists();
    this.getDicts("t_pipe_press").then(response => {
      this.fPipePressOptions = response.data;
    });
  },
  methods: {
    //所属单位
    getEnterpriseLists(){
      const param = {}; 
        enterpriseLists(param).then(response => {
          if (response.rows.length>1){ 
            this.enterprises = response.rows;
            this.enterpriseName = response.rows[0].enterpriseName; 
        }else { 
          this.enterprises = response.rows;
          this.enterpriseName = response.rows[0].enterpriseName; 
        }
      }); 
    },
    //获取县级
    getCountyInfo(){
      getDefaultCountyList().then(res =>{
        if(res.code == 200 && res.data){
        this.countyInfo =  res.data;
      }
    })
    },
    beyondCountyFormat(row){
      let info = this.countyInfo.find(item => item.fId == row.fDistrictId);
      return info?info.fName:"-";
    },
    /** 查询涉气第三方施工项目档案列表 */
    getList() {
      this.loading = true; 
      // 企业查自己的数据
      if (this.user.roleId == 5) {
        this.queryParams.fCompanyInfoId = this.$store.state.user.enterpriseId 
        this.queryParams.entUploadState = this.queryParams.fUploadType;
      }
      // 政府如果按照状态查的话，是查的 govUploadState
      if (this.user.roleId == 3) {
        this.queryParams.govUploadState = this.queryParams.fUploadType;
      } 
      listInfor(this.queryParams).then(response => {
        this.inforList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 管道压力等级分类
    fPipePressFormat(row, column) {
      return this.selectDictLabel(this.fPipePressOptions, row.fPipePress);
    },
    //上报状态动态展示
    uploadStateFormat(row, column) { 
      //角色 1 超级管理员  5 企业
      let roleId = this.user.roleId;
      if (roleId == 5) {
        this.uploadStateLabel = "上报状态"
        if (row.entUploadState == '0') {
          return "未上报"
        } else{
          return "已上报"
        } 
      } else { 
        this.uploadStateLabel = "上报省厅状态"
        if (row.govUploadState == '0') {
          return "未上报"
        } else{
          return "已上报"
        } 
      } 
    },
    //上报时间动态展示
    uploadTimeFormat(row, column) {
      //角色 1 超级管理员  5 企业
      let roleId = this.user.roleId;
      if (roleId == 5) {
        this.uploadTimeLabel = "上报时间"
        return row.entUploadTime;
      } else {
        this.uploadTimeLabel = "上报省厅时间"
        return row.govUploadTime;
      }

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fConGasProInforId: null,
        fProjectCode: null,
        fProjectNo: null,
        fProjectName: null,
        fConstructionStart: null,
        fConstructionEnd: null,
        fAddress: null,
        fDistrictId: null,
        fConstructionLongitude: null,
        fConstructionLatitude: null,
        fConstructionPointType: null,
        fVillageId: null,
        fPipePress: null,
        fReportFlag: null,
        fConstructionStatus: null,
        fBuildDepartment: null,
        fProjectLeader: null,
        fProjectLeaderPhone: null,
        fIndustry: null,
        fDepartmentName: null,
        fConstructDepartment: null,
        fBuildProjectLeaderName: null,
        fBuildProjectLeaderPhone: null,
        fTechnicalLeaderName: null,
        fTechnicalLeaderPhone: null,
        fSupervisionUnitName: null,
        fChiefEngineerName: null,
        fChiefEngineerPhone: null,
        fCompanyInfoId: null,
        fPatrolSafetyOfficerNo: null,
        fPartrolSafetyOfficerName: null,
        fPatrolSafetyOfficerPhone: null,
        fResidentSafetyOfficerNo: null,
        fResidentSafetyOfficerName: null,
        fResidentSafetyOfficerPhone: null,
        fGasCompanyStationNo: null,
        fGasCompanyStationName: null,
        fGasCompanyStationPhone: null,
        fRemark: 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.fConGasProInforId);
      this.fProjectNames = selection.map(item => item.fProjectName);
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加涉气第三方施工项目档案";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fConGasProInforId = row.fConGasProInforId || this.ids
      getInfor(fConGasProInforId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改涉气第三方施工项目档案";
      });
    },
    //判断 上报是否需要显示，上报分为企业上报 和 政府端上报
    judgeUploadIsShow(row) { 

      //角色 1 超级管理员  5 企业
      let roleId = this.user.roleId;

      // 企业端 上报状态 0-未上报，1-已上报
      let entUploadState = row.entUploadState;

      // 政府端 上报状态 0-未上报，1-已上报
      let govUploadState = row.govUploadState;

      // 如果政府端都已经上报，那就不能显示了。
      if(govUploadState === '1') {
        return false;
      }

      // 如果企业端上报了，则企业端就不能显示了，政府端和 超级管理员能显示
      if(entUploadState === '1' && govUploadState === '0') {
        if (roleId === 5) {
          return false;
        } else {
          return true;
        }
      }

      // 别的情况，都显示
      return true;

    },
    getuserInfo(){
      getInfo().then(response => {
        this.user = response.user.roles[0]
        this.getList();
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.form.fCompanyInfoId=this.enterprises[0].enterpriseId;
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fConGasProInforId != 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 fConGasProInforIds = row.fConGasProInforId || this.ids;
      const fProjectNames = row.fProjectName || this.fProjectNames;
      this.$confirm('是否确认删除涉气第三方施工项目档案名称为"' + fProjectNames + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfor(fConGasProInforIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有涉气第三方施工项目档案数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          
          // 企业查自己的数据
          if (this.user.roleId == 5) {
            this.queryParams.fCompanyInfoId = this.$store.state.user.enterpriseId 
            this.queryParams.entUploadState = this.queryParams.fUploadType;
          }
          // 政府如果按照状态查的话，是查的 govUploadState
          if (this.user.roleId == 3) {
            this.queryParams.govUploadState = this.queryParams.fUploadType;
          } 
          return exportInfor(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },
    /**
     * 经纬度坐标方法
     */
    MapdialogFun() {
      this.dialogTableVisibles = true;
    },
    /**
     * 经纬度 选择
     * @param res
     */
    getPath(res){
      //确认选择经纬度
      this.form.fConstructionLongitude = res[0];
      this.form.fConstructionLatitude = res[1];
    },
    /**
     * 地图关闭方法
     */
    dialogcancelFun() {
      this.dialogTableVisibles = false;
    },
    //详情
    handleDetail(row){
      this.$refs.detail.getDetailInfo(row.fConGasProInforId);
    },
    /** 上报按钮操作 */
    handleReport(row) {

      // 如果是 超级管理员 或这企业，并且 企业端上报状态为0
      if ((this.user.roleId == 5 || this.user.roleId == 1) && row.entUploadState == '0') {
        this.$confirm('是否确认上报涉气第三方施工项目档案名称为"' + row.fProjectName + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
            return entReportConGasProInfo({fConGasProInforId : row.fConGasProInforId});
        }).then(() => {
          this.getList();
          this.msgSuccess("上报成功");
        }).catch(() => {});
      } 
    
      // 如果是 超级管理员 或这政府，并且 政府端上报状态为0
      if ((this.user.roleId == 3 || this.user.roleId == 1) && row.govUploadState == '0') {
        this.$confirm('是否确认上报涉气第三方施工项目档案名称为"' + row.fProjectName + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return reportConGasProInfo({fConGasProInforId : row.fConGasProInforId});
        }).then(() => {
          this.getList();
          this.msgSuccess("上报成功");
        }).catch(() => {});
      }
    },
  }
};
</script>
