<!-- SpeechStance.vue -->
<template>
  <div class="speech-stance-container">
    <div class="speech-stance-grid">
      <div v-for="(item, index) in PersonRelation" :key="index" class="speech-stance-card">
        <div class="speech-stance-avatar-wrapper"  @click="handleClcikToCharacter(item.personId)">
          <img :src="item.personImage" alt="" class="speech-stance-avatar" />
        </div>
        <div class="speech-stance-text-content"  @click="handleClcikToCharacter(item.personId)">
          <div style="display: flex;      width: 683px;">
            <h3 class="speech-stance-name">{{ item.personName }}</h3>
            <p class="speech-stance-title">{{ item.positionTitle }}</p>
          </div>

          <p class="speech-stance-content" :title="item.remarks"><span class="speech-stance-text">{{ item.remarks }}</span></p>
        </div>
       
      </div>
    </div>
  </div>
</template>

<script setup>
// 导入数据
import { onMounted, ref,defineProps,watch } from "vue";
import speechStance from '../json/speechStance.json';
import {getPersonRelation} from "@/api/technologyFigures/technologyFigures"

import {  getPersonSummaryInfo } from "@/api/technologyFigures/technologyFigures";
import { useRouter } from "vue-router";
const router = useRouter();
const props = defineProps({
  fieldSelected: {
    type: String,
    default: "全部领域"
    },
    areaId: {
      type: String,
      default: 0
    }
});
// 跳转人物主页
const handleClcikToCharacter = async id => {
	const personTypeList = JSON.parse(window.sessionStorage.getItem("personTypeList"));
 
	let type = 0;
	let personTypeName = "";

	const params = {
		personId: id
	};
	try {
		const res = await getPersonSummaryInfo(params);
		console.log("人物全局信息", res);
		if (res.code === 200 && res.data) {
			const arr = personTypeList.filter(item => {
				return item.typeId === res.data.personType;
			});
			console.log("arr", arr);

			if (arr && arr.length > 0) {
				personTypeName = arr[0].typeName;
				console.log("personTypeName", personTypeName);

				if (personTypeName === "科技企业领袖") {
					type = 1;
				} else if (personTypeName === "国会议员") {
					type = 2;
				} else if (personTypeName === "智库研究人员") {
					type = 3;
				} else {
					personTypeName = "";
					ElMessage.warning("找不到当前人员的类型值！");
					return;
				}
				const route = router.resolve({
					path: "/characterPage",
					query: {
						type: type, // type=1为科技企业领袖，2为国会议员，3为智库研究人员
						personId: id
					}
				});
				window.open(route.href, "_blank");
			} else {
				personTypeName = "";
				ElMessage.warning("找不到当前人员的类型值！");
				return;
			}
		} else {
			ElMessage.warning("找不到当前人员的类型值！");
			return;
		}
	} catch (error) {}
};
const aId = ref();
const params = ref({});

watch(() => [props.fieldSelected, props.areaId], (val) => {
  const [fieldVal, areaVal] = val;
  aId.value = areaVal;
  if(fieldVal !== "全部领域"){
    params.value.industryId = areaVal;
  }else{
    params.value = {};
  }
  handlegetPersonRelationFn();
})


// 获取重要人物言论及立场
const PersonRelation = ref([]); 
const handlegetPersonRelationFn = async () => {
	
	try {
		const res = await getPersonRelation(params.value);
		console.log("重要人物言论及立场", res);
		if (res.code === 200) {
			PersonRelation.value = res.data;
		}
	} catch (error) {
    console.error("获取重要人物言论及立场失败:", error);
  }
};

onMounted(async () => {
	handlegetPersonRelationFn();
});

</script>

<style scoped>
.speech-stance-container {
  width: 1530px;
  margin: 15px 35px;
}

.speech-stance-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 28px 9px;
}

/* 响应式：小屏变一列 */
@media (max-width: 768px) {
  .speech-stance-grid {
    grid-template-columns: 1fr;
  }
}

.speech-stance-card {
  /* 容器 553 */
  width: 768px;
  height: 50px;
  display: flex;
}

.speech-stance-avatar-wrapper {
  flex-shrink: 0;
}

.speech-stance-avatar {
  /* 椭圆 141 */
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.speech-stance-text-content {
  width: 656px;
  flex: 1;
  margin-left: 13px;

}

.speech-stance-name {
  color: rgba(34, 41, 52, 1);
  margin: 0;
  font-family: Microsoft YaHei;
  font-size: 18px;
  font-weight: 700;
  line-height: 24px;
  letter-spacing: 0px;
  text-align: left;
}

.speech-stance-title {
  color: rgba(95, 101, 108, 1);
  margin: 0;
  margin-left: 12px;
  font-family: Microsoft YaHei;
  font-size: 16px;
  font-weight: 400;
  line-height: 24px;
  letter-spacing: 0px;
  text-align: left;
}

.speech-stance-content {
  color: rgba(95, 101, 108, 1);
  margin: 0;
  font-family: Microsoft YaHei;
  font-size: 16px;
  font-weight: 400;
  line-height: 30px;
  letter-spacing: 0px;
  text-align: left;
  /* 宽度保持不变，ellipsis 移至内部 span */
}

.speech-stance-text {
  display: inline-block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 24px;
  vertical-align: top;
}
</style>