<template>
	<view class="problem hover-scale">
		<view class="problem-content">
			<view class="header">
				<image class="header-logo" :src="getStaticImageUrl('/images/common_problem.png')" fit="contain" />
				<view class="header-content">
					<view class="header-title">常见问题</view>
					<view class="header-subject">聚焦商贸投资热点，回应企业民生关切</view>
					<button class="refresh" @tap="refresh">
						<view v-if="loading" class="refresh-loading">
							<uni-icons type="spinner-cycle" size="28rpx" color="#ffef7c" />
						</view>
						<uni-icons v-else type="refreshempty" size="24rpx" color="#ffef7c" />
						换一换
					</button>
				</view>
			</view>
			<view class="problem-list">
				<view class="problem-item" v-if="problems" v-for="(item, index) in problems" @tap="quickSend(item.questionContent)">{{ index + 1 }}.{{ item.questionContent }}</view>
			</view>
		</view>
		<image class="problem-image" fit="contain" :src="getStaticImageUrl('/images/bg011.png')" />
	</view>
</template>

<script>
import { RequestApi } from '@/api/requestApi';

export default {
	data() {
		return {
			loading: false,
			problems: [],
			search: {
				keyword: '',
				page: 1,
				size: 6
			}
		};
	},
	mounted() {
		this.getCommonQuestions();
	},
	methods: {
		getCommonQuestions() {
			this.loading = true;
			RequestApi.getCommonQuestionsRandom(this.search.keyword, this.search.page, this.search.size)
				.then((result) => {
					this.problems = result.records;
				})
				.finally(() => {
					this.loading = false;
				});
		},
		refresh() {
			this.getCommonQuestions();
		},
		quickSend(msg) {
			this.$emit('quickSend', msg)
		}
	}
};
</script>

<style scoped lang="scss">
@keyframes spin {
	0% {
		transform: rotate(0deg);
	}
	100% {
		transform: rotate(360deg);
	}
}

.problem {
	border-radius: 40rpx;
	position: relative;
	overflow: hidden;
	color: #ffffff;
	background: linear-gradient(180deg, #5a92f8, #2943d6);
	box-shadow: 0 8rpx 40rpx 0 rgba(52, 149, 239, 0.4);
	margin-bottom: 32rpx;

	.problem-content {
		position: relative;
		z-index: 2;
		padding: 48rpx 40rpx;

		.header {
			display: flex;
			align-items: center;
			margin-bottom: 48rpx;

			.header-logo {
				width: 68rpx;
				height: 68rpx;
				margin-right: 16rpx;
			}

			.header-content {
				width: calc(100% - 85rpx);
				position: relative;

				.header-title {
					font-size: 32rpx;
					font-weight: bold;
					margin-bottom: 10rpx;
					line-height: 28rpx;
					cursor: pointer;
				}

				.header-subject {
					font-size: 26rpx;
					font-weight: 400;
					line-height: 28rpx;
					cursor: pointer;
				}

				.refresh-loading {
					animation: spin 3s linear infinite;
				}

				.refresh {
					position: absolute;
					right: 0;
					top: 0;
					padding: 0;
					line-height: 24rpx;
					font-size: 24rpx;
					height: 24rpx;
					color: #ffef7c;
					background-color: transparent;
					border: 0;
					border-radius: 0;
					display: flex;
					align-items: center;

					.refresh-icon {
					}

					&:after,
					&::after {
						border: 0;
					}
				}
			}
		}

		.problem-list {
			.problem-item {
				font-size: 26rpx;
				line-height: 26rpx;
				margin-bottom: 24rpx;
				cursor: pointer;
        white-space: nowrap; /* 强制文本不换行 */
        overflow: hidden; /* 隐藏超出容器的内容 */
        text-overflow: ellipsis; /* 超出部分显示省略号 */

				&:last-child {
					margin-bottom: 0;
				}
			}
		}
	}

	.problem-image {
		position: absolute;
		width: 254rpx;
		height: 250rpx;
		bottom: 32rpx;
		right: 24rpx;
		z-index: 1;
		background-size: contain;
	}
}
</style>
