<template>
  <div>
    <div class="yhzl-wrapper">
      <div class="header">
        <div class="bottom">
          <el-tabs class="yhzlbox" v-model="activeTab" type="card" @tab-click="onTabClick">
            <el-tab-pane :label="item.label" :name="item.value" v-for="(item, i) in tabs" :key="i" />
          </el-tabs>
        </div>
      </div>
      <!-- 风险评价 -->
      <fxpj v-if="activeTab === 'bspjindex'" :orgCodeIds="orgCodeIds" :planid="props.planid" :btnshow="props.btnshow"
        :initPage="props.initPage" :listQuery="listQuery" @close="Close">
      </fxpj>
    </div>
    <!-- 评价小组成员分工清单 -->
    <listEvaluationteams v-if="activeTab === 'listEvaluationteams'" :planid="props.planid" :parentstatus="parentstatus"
      @close="Close">
    </listEvaluationteams>
  </div>
</template>
<script setup>
// 引入
import { defineProps, watch, onMounted, getCurrentInstance, defineEmits, ref, computed } from 'vue'
import { getApi } from "@/api/tobAcco_api.js";
import listEvaluationteams from './listEvaluationteams.vue';
import fxpj from './fxpj.vue';
const emits = defineEmits(["close"]);
/**登陆人id */
const tableHeight = ref()
const props = defineProps({
  btnshow: {
    default: true,
    type: Boolean
  },
  initPage: Object,
  title: String,
  planid: {
    type: String,
    default: null
  },
  orgCodeId: {
    type: String,
    default: null
  },
  rowstatus: {
    type: String,
    default: null
  }
});
const deptlist = ref([])
const shsm = ref(null)
/** 左边部门状态 */
const zbbmzt = ref(1)//左边部门状态
const total = ref(0)
const status = ref(2)
const zzlx = ref(null);
const proms = ref({
})
const listQuery = ref({})
const listpage = ref({
  pageCurrent: 1,
  pageSize: 10,
  planid: props.planid
})
const tableData1 = ref([])
const tableData2 = ref([])
const infoList = ref([])
const idlist = ref({
  planid: props.planid,
})
const orgCodeIds = ref(null)
const parentstatus = ref(null)
onMounted(() => {
  proms.value.planid = props.planid
  orgCodeIds.value = props.orgCodeId
  tabHeightFn();
  getpageDate()
  // setAuthObj()
})
//辨识评价-页面数据详情
function getpageDate () {
  // orgcode:只有评价小组登录才传orgcode
  getApi({ planid: props.planid }, '/mosty-jcgl/dangerPlanlist/bspj/showSjInfo').then(res => {
    tableData1.value = res.list
    let arr = tableData1.value.filter(item => {
      return (item.orangePointCount + item.redPointCount + item.yellowPointCount
        + item.bluePointCount) > 0
    })
    let arr2 = tableData1.value.filter(item => {
      return item.stage == '21'
    })
    if (arr.length > 0) {
      handlexg(arr[0])
    } else if (arr2.length > 0) {
      handlexg(arr2[0])
    }
    infoList.value = res.list.map(item => {
      return { entityCode: item.entityCode, entityName: item.entityName, id: item.id, usernames: item.teamUsernames, userids: item.teamUserids }
    })
    deptlist.value = res.list.map(item => {
      return { value: item.entityCode, label: item.entityName }
    })
    shsm.value = res.shsm ? res.shsm : null
    // status.value = res.entity.status
    listQuery.value = res.entity;
    proms.value.identifyEntityId = res.entity.id;
    idlist.value.identifyEntityId = res.entity.id;
    parentstatus.value = res.entity.stage
    //     10-部门辨识中
    // 20-分公司辨识中 21-分公司汇总评价中
    // 30-整体任务辨识中 31-省、市公司分管领导审核中 32- 省、市公司主管领导审核中  33-完成
    if (['30', '31', '32'].includes(res.entity.stage)) {
      status.value = 3
    } else if (res.entity.stage == '33') {
      status.value = 4
    }
  })
}
//查看
function handlexg (row) {
  listpage.value.depcode = row.entityCode;
  zbbmzt.value = row.stage
  getpjxqTab()
  // if (['XGS','SZGS','SGS'].includes(props.initPage.type)) {
  //   listpage.value.depcode = row.entityCode;
  //   getpjxqTab()
  // }
  //  else {
  //   listpage.value.countycode = row.entityCode;
  //   listpage.value.spfag = row.spfag;
  //   getpjxqTab()
  // }

}

//   辨识评价 - 查询各个单位的辨识情况
function getpjxqTab () {
  tableData2.value = []
  getApi(listpage.value, '/mosty-jcgl/dangerPlanlist/bspj/getBmbsListByDeptId').then(async (res) => {
    total.value = res.total
    const results = []
    for (const item of res?.records) {

      try {
        let params = {
          // identifyOrgId: listpage.value.depcode,
          bmbsid: item.id,
        }
        const authRes = await getApi(params, '/mosty-jcgl/tbDangerIdentifyEvaluateMember/checkEvaluatePermission')
        results.push({
          ...item,
          isHadBtnAuth: authRes || false
        })
      } catch (error) {
        results.push({
          ...item,
          isHadBtnAuth: false
        })
      }
    }
    tableData2.value = results
  })
}
// 方法
const tabHeightFn = () => {
  tableHeight.value =
    window.innerHeight - 100 - 57 - 60 + 'px'
}
//返回
function Close () {
  emits("close");
}
const tabs = ref([{
  label: '评价小组成员分工清单',
  value: 'listEvaluationteams'
}, {
  label: '风险评价',
  value: 'bspjindex'
},
])
const activeTab = ref("listEvaluationteams")
const onTabClick = e => {
  const tabName = e.props.name
  activeTab.value = tabName
}

</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>
