<template>
  <div class="app-container">
    <GetPos
      :dialogVisible.sync="dialogVisible"
      device="pipe"
      @close="dialogVisible=false"
      @getPath="getPath"
      :pipePath="this.coordinateslist"
    />

    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="97px">
      <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="fRelationObjectType">
        <el-select v-model="queryParams.fRelationObjectType" placeholder="请选择关联对象类型" clearable size="small">
          <el-option
            v-for="dict in fRelationObjectTypeOptions"
            :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-table v-loading="loading" :data="processList" @selection-change="handleSelectionChange">
      <el-table-column label="项目名称" align="center" prop="fProjectName" />
      <el-table-column label="燃气企业" align="center" prop="enterpriseName" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="关联对象类型" align="center" prop="fRelationObjectType" :formatter="fRelationObjectTypeFormat" />
      <el-table-column label="年度" align="center" prop="fYear">
        <template slot-scope="scope">
          <span v-if="scope.row.fYear != null">{{ scope.row.fYear }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="项目开始时间" align="center" prop="fStartTime" width="150">
        <template slot-scope="scope">
          <span v-if="scope.row.fStartTime != null">{{ scope.row.fStartTime }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="项目结束时间" align="center" prop="fEndTime" width="150">
        <template slot-scope="scope">
          <span v-if="scope.row.fEndTime != null">{{ scope.row.fEndTime }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="联系人" align="center" prop="fConcatPerson">
        <template slot-scope="scope">
          <span v-if="scope.row.fConcatPerson != null">{{ scope.row.fConcatPerson }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="联系电话" align="center" prop="fConcatTel">
        <template slot-scope="scope">
          <span v-if="scope.row.fConcatTel != null">{{ scope.row.fConcatTel }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column :label="fUploadTypeLable" align="center" prop="fUploadType" :formatter="uploadStateFormat">
      </el-table-column>
      <el-table-column :label="fUploadTimeLable" align="center" prop="fUploadTime" width="150" :formatter="uploadTimeFormat">
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="checkProgress(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"
    />

    <ProgressList ref="progressList"/>

  </div>
</template>

<script>
import { listProcess, getProcess, delProcess, addProcess, updateProcess, exportProcess,reportPipeOldPlanProcess,entReportPipeOldPlanProcess } from "@/api/oldpipesystem/process";
import{getInfo} from "@/api/login"
import { enterpriseLists } from "@/api/regulation/info";
import { getDefaultCountyList } from "@/api/area/county";
import GetPos from '@/components/GetPos';
import ProgressList from "./components/ProgressList";


"/";
export default {
  name: "Progress",
  components: {
    GetPos,
    ProgressList
  },
  data() {
    return {
      dialogVisible:false,
      //地图管径回显数据
      coordinateslist: null,
      enterpriseName:"",
      user:{},
      isDisabledEnterprise: false,
      enterprises: [],
      countyInfo: [],
      fUploadTypeLable: "",
      fUploadTimeLable: "",
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      fProjectNames: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 老旧管网改造计划表格数据
      processList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 关联对象类型
      fRelationObjectTypeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fProjectName: null,
        fRelationObjectType: null,
        fConcatPerson: null,
        fConcatTel: null,
        fFundsDisbursementProgress: null,
        fUploadType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fProjectName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" }
        ],
        fRelationObjectType: [
          { required: true, message: "请选择关联对象", trigger: "change" }
        ],
        fConcatTel: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: '手机号格式有误！',
            trigger: 'blur'
          }
        ],
      }
    };
  },
  created() {
    this.getuserInfo();
    this.getDicts("t_relation_object_type").then(response => {
      this.fRelationObjectTypeOptions = response.data;
    });
    this.getEnterpriseLists();
    this.getCountyInfo();
  },
  methods: {
    //获取县级
    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.fRegion);
      return info?info.fName:"-";
    },
    getuserInfo(){
      getInfo().then(response => {
        console.log(response);
        this.user = response.user.roles[0]
        this.getList();
      });
    },
    //所属单位
    getEnterpriseLists(){
      const param = {};
        enterpriseLists(param).then(response => {
          this.enterprises = response.rows;
      });
    },
    beyondEnterpriseFormat(row){
      let info = this.enterprises.find(item => item.enterpriseId == row.beyondEnterpriseId);
      return info?info.enterpriseName:"-";
    },
    /** 查询老旧管网改造计划列表 */
    getList() {
      this.loading = true;
      // 企业查自己的数据
      if (this.user.roleId == 5) {
        this.queryParams.fEnterpriseId = this.$store.state.user.enterpriseId
        this.queryParams.entUploadState = this.queryParams.fUploadType;
      }
      // 政府如果按照状态查的话，是查的 govUploadState
      if (this.user.roleId == 3) {
        this.queryParams.govUploadState = this.queryParams.fUploadType;
      }
      listProcess(this.queryParams).then(response => {
        this.processList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 关联对象类型
    fRelationObjectTypeFormat(row, column) {
      return this.selectDictLabel(this.fRelationObjectTypeOptions, row.fRelationObjectType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    //判断 上报是否需要显示，上报分为企业上报 和 政府端上报
    judgeUploadIsShow(row) {

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

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

      // 政府端 上报状态 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;

    },
    //上报状态动态展示
    uploadStateFormat(row, column) {
      //角色 1 超级管理员  5 企业
      let roleId = this.user.roleId;
      if (roleId == 5) {
        this.fUploadTypeLable = "上报状态"
        if (row.fUploadType == '0') {
          return "未上报"
        } else{
          return "已上报"
        }
      } else {
        this.fUploadTypeLable = "上报省厅状态"
        if (row.govUploadState == '0') {
          return "未上报"
        } else{
          return "已上报"
        }
      }
    },
    //上报时间动态展示
    uploadTimeFormat(row, column) {
      //角色 1 超级管理员  5 企业
      let roleId = this.user.roleId;
      if (roleId == 5) {
        this.fUploadTimeLable = "上报时间"
        return row.fUploadTime;
      } else {
        this.fUploadTimeLable = "上报省厅时间"
        return row.govUploadTime;
      }

    },
    // 表单重置
    reset() {
      this.form = {
        fOldPlanProcessId: null,
        fUuid: null,
        fEntUuid: null,
        fRegion: null,
        fProjectName: null,
        fRelationObjectType: null,
        fYear: null,
        fStartTime: null,
        fEndTime: null,
        fTotalInvestment: null,
        fCreateTime: null,
        fUpdateTime: null,
        fSubjectImplementation: null,
        fConcatPerson: null,
        fConcatTel: null,
        fConstructionContent: null,
        fActualFinishTime: null,
        fReconstructionProgress: null,
        fFundsDisbursementProgress: null,
        fUploadType: null,
        fUploadTime: 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.fOldPlanProcessId);
      this.fProjectNames = selection.map(item => item.fProjectName);
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 查看进度 */
    checkProgress(row) {
      console.log("row.serialNumber111111111",row.serialNumber)
      this.$refs.progressList.getList(row.serialNumber);
    },
    /**管道信息 选择管道提交数据方法*/
    getPath(e){
      // for (let i=0;i<e.length;i++){
      //   console.log(e[i])
      //   coordinates.push(e[i])
      // }
      var a = '['
      for (var i in e) {
        if (i == e.length - 1) {
          a += '[' + e[i].toString()+']'
        } else {
          a += '[' + e[i].toString()+'],'
        }
      }
      a += ']'
      this.form.coordinates=a;
    },
    /** 管道打开方法*/
    MapdialogFun(){
      this.dialogVisible=true;
    }
  }
};
</script>
<style>
/* 自定义输入框样式 */
.left-aligned-input .el-input__inner{
  text-align: left;
  padding-left: 5px; /* 根据需要调整内边距 */
}
</style>
