<template>
  <div>
      <div class="btnBox">
        <!-- 市公司安全部门人员&&stage为30 -->
                <el-popconfirm v-if='sgsaqry&&isSbshow' confirm-button-text="是"
                  cancel-button-text="否" icon-color="red" title="确定要上报红橙风险?" @confirm="cahngesb">
                  <template #reference>
                <el-button type="primary"  >
                <span>上报红橙风险</span>
                 </el-button>
                  </template>
                </el-popconfirm>
        <el-button type="primary" @click="Close">
          <el-icon>
            <ArrowLeft />
          </el-icon>
          <span>返回</span>
        </el-button>
      </div>
   
    <!-- 表格 -->
    <div class="box-a">
      <div>
        <div style="display: flex;justify-content: space-between;">
          <div style="width: 40%;height:calc(100vh - 200px);">
            <MOSTY.Table :table-columns="tableColumn" :tableData="tableData1" :tableloading="tableloading"
              :isSelect="false" :isSort="false" style="width: 100%;" :actionsW='150'>
                     <template #redPointCount="{ row }">
               <span :style="{ color: row.redPointCount>0?'#e80000':'black' }">{{row.redPointCount}}</span>
              </template>
               <template #orangePointCount="{ row }">
               <span :style="{ color: row.orangePointCount>0?'#ff8040':'black' }">{{row.orangePointCount}}</span>
              </template>
                    <template #stage="{ row }">
                <dict-tag :options="GZ_D_ENT_STAGE" :value="row.stage" :tag="false" />
              </template>
              <template #actions="{ row }">
                 <el-popconfirm v-if="row.stage == '30'&&sgsaqry" confirm-button-text="是"
                  cancel-button-text="否" icon-color="red" title="确定要驳回?" @confirm="handleth(row)">
                  <template #reference>
                    <span class="operedit" size="small">驳回</span>
                  </template>
                </el-popconfirm>
                <span class="operesee" v-if="['30','31'].includes(row.stage)" @click="handlexg(row)">查看</span>
                <span v-else>--</span>
              </template>
            </MOSTY.Table>
          </div>
          <div style="flex: 1;margin-left: 10px;margin-right:10px">
            <div style="height: calc(100vh - 249px)">
  <el-table ref="mulRefs" stripe :data="tableData2" style="width: 100%;height:100%;"
              @selection-change="handleSelectionChange" height="100%" border>
              <el-table-column label="风险单位" property="riskcell">
              </el-table-column>
              <el-table-column label="辨识区域" property="objname" show-overflow-tooltip>
              </el-table-column>
              <el-table-column label="风险等级" property="risklevel" width='150'>
                <template #default="{ row }">
                  <span v-if="row.risklevel == '4'" class="fxdjspan reds">重大风险</span>
                  <span v-else-if="row.risklevel == '3'" class="fxdjspan orgs">较大风险</span>
                  <span v-else-if="row.risklevel == '2'" class="fxdjspan blus">一般风险</span>
                  <span v-else-if="row.risklevel == '1'" class="fxdjspan gres">低风险</span>
                  <span v-else>待定</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" width='250'>
                <template #default="{ row }">
                     <span class="operesee" @click="handlepj(row,'xq')"><el-icon>
                      <Compass />
                    </el-icon>详情</span>
                </template>
              </el-table-column>
            </el-table>
            <div class="fenye" >
              <el-pagination class="pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="listpage.pageCurrent" :page-sizes="[2, 5, 10, 20]" :page-size="listpage.pageSize"
                layout="total, prev, pager, next, sizes, jumper" :total="total"></el-pagination>
            </div>
            </div>
          
          </div>
        </div>
      </div>

    </div>


    <!-- 评价 -->
    <div v-if="showpjpage" class="dialog-box">
            <Bsxqinfo @close="changepjclose" :idlist="idlist" :saveBtnShow="false" :type="'bm'"
        :identifyEntityId="null"  :listpage='listpage'/>
    </div>
  </div>
</template>

<script setup>
// 引入
import { defineProps, watch, onMounted, getCurrentInstance, defineEmits, ref } from 'vue'
import * as MOSTY from "@/components/MyComponents/index";
import { ElMessage } from "element-plus";
import { getApi, deleteApi, putApi, postApi } from "@/api/tobAcco_api.js";
import { filterqx } from "@/utils/auth.js"
import Bsxqinfo from './bsxqinfo.vue';
const emits = defineEmits(["close"]);
const { proxy } = getCurrentInstance();
const { GZ_D_ENT_STAGE } = proxy.$dict("GZ_D_ENT_STAGE");
const showpjpage = ref(false)
const sgsaqry=ref(filterqx("isgs") == "1"&&filterqx("isaqbm") == "1")// 市公司安全部门人员
const props = defineProps({
  btnshow: {
    default: true,
    type: Boolean
  },
  initPage: Object,
  title: String,
  planid: {
    type: String,
    default: null
  }
});
const tjtype=ref('pj')
const total = ref(0)
const isSbshow = ref(false)
const proms = ref({
})
const listpage = ref({
  pageCurrent: 1,
  pageSize: 10,
  planid: props.planid
})
const tableData1 = ref([])
const tableData2 = ref([])
const tableloading = ref(false)
const tableColumn = ref([
  {
    title: "分公司",
    prop: "entityName",
    sortable: true
  },
  {
    title: "红色风险",
    prop: "redPointCount",
     slot: true
  },
  {
    title: "橙色风险",
    prop: "orangePointCount",
     slot: true
  },
    {
    title: "状态",
    prop: "stage",
      slot: true
  },
  {
    title: "操作",
    prop: "actions",
    slot: true
  }
])
const idlist = ref({
  planid: props.planid,
})
onMounted(() => {
  proms.value.planid = props.planid
  getpageDate()
})

//辨识评价-页面数据详情
function getpageDate() {
  // orgcode:只有评价小组登录才传orgcode
  getApi({ planid: props.planid }, '/mosty-jcgl/dangerPlanlist/bspj/showDwList').then(res => {
        isSbshow.value=false
    tableData1.value = res
   let arr= tableData1.value.filter(item=>{
      return (item.orangePointCount + item.redPointCount)>0
    })
    let arr2=tableData1.value.filter(it=>{
      return it.stage=='30'
    })
if(arr2.length>0){
    isSbshow.value=true
  }

   if(arr.length>0){
    handlexg(arr[0])
   }else if(arr2.length>0){
  handlexg(arr2[0])
   }

    
  })
}



//评价
function handlepj(row,type) {
  idlist.value.bmbsid = row.id
 tjtype.value=type
  showpjpage.value = true
}
//关闭汇总
function changepjclose(val) {
  showpjpage.value = false;
  listpage.value=val
  // getpageDate();
     getpjxqTab()
}

//查看
function handlexg(row) {
    listpage.value.countycode = row.entityCode;
    listpage.value.spfag = row.spfag;
    getpjxqTab()
}
//   辨识评价 - 查询各个单位的辨识情况
function getpjxqTab() {
    getApi(listpage.value, '/mosty-jcgl/dangerPlanlist/bspj/getOrgBsList').then(res => {
      tableData2.value = res.records
      total.value = res.total
    })

}
//驳回
function handleth(row) {
  postApi({ }, `/mosty-jcgl/dangerPlanlist/bspj/sgsBack/${row.id}`).then(res => {
    ElMessage.success("驳回成功");
    getpageDate()
  })
}
//市公司上报红橙风险
function cahngesb() {
    postApi({ }, `/mosty-jcgl/dangerPlanlist/bspj/sgsTjsh/${props.planid}`).then(res => {
    ElMessage.success("提交成功");
    getpageDate()
  })
}
//返回
function Close() {
  emits("close");
}
//分页
const handleSizeChange = (currentSize) => {
  listpage.value.pageSize = currentSize;
  getpjxqTab()
};
const handleCurrentChange = (currentPage) => {
  listpage.value.pageCurrent = currentPage;
  getpjxqTab()
};
</script>

<style lang="scss" scoped>
.titleBox {
  border: none;
  height: 152px;
  display: flex;
  justify-content: center;
  position: relative;
  z-index: 2;
}

.el-form-item__label {
  padding: 12px 12px 0 0 !important;
}

.stebox {
  width: 90%;
  display: flex;
  justify-content: center;
  position: relative;
  align-items: center;
  margin: o auto;
}

.left {
  width: 70%;
}

.el-select {
  width: 150px;
}

.btnBox {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin: 10px;
}

.bs-title {
  color: red;
  margin: 10px;
}

.leftbox {
  width: 30%;
  margin-right: 40px;
}

.tabBox2 {
  width: 65%;
}

.fil-bbox {
  display: flex;

  .font {
    color: #000;
    font-size: 16px;
    font-weight: 600;
    margin: 10px;

    .labs {
      color: #999494;
    }
  }
}

.operates {
  cursor: pointer;
  color: yellowgreen !important;
  display: inline-block;
  width: 40px;
  height: 23px;
  border: 1px solid #000;
  margin: 0 5px;
  background-color: #fff;
}

.operated {
  cursor: pointer;
  color: #fff !important;
  display: inline-block;
  width: 40px;
  height: 23px;
  border: 1px solid #000;
  margin: 0 5px;
  background-color: #f11515;
}

.redfont {
  color: rgb(245, 34, 34) !important;
}

.box-big {
  display: flex;
  margin-top: 10px;

  .fix-box {
    display: flex;
    margin-right: 30px;
  }
}

.el-textarea {
  --el-input-placeholder-color: #4c4e52 !important;
}

.btnpas {
  display: inline-block;
  padding: 5px 10px;
  color: #fff !important;
  margin-right: 4px;
  background-color: var(--el-color-primary);
  border-radius: 5px;
  cursor: pointer;
}

.fxdjspan {
  display: inline-block !important;
  width: 100px;
  text-align: center;
  padding: 5px 0;
  border-radius: 5px;
  color: #fff !important;
}

.reds {
  background-color: #e80000;
}

.orgs {
  background-color: #ff8040;
}

.blus {
  background-color: #e2d101;
}

.gres {
  background-color: #0080ff;
}
</style>