<template>
	<view class="main">
		<view class="one">客服电话</view>
		<view class="two">
			<text>{{config.phone||'暂无联系电话'}}</text>
			<button class="button" type="primary" size="mini" @tap="toCopy(config.phone)">复制</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				config: {}
			}
		},
		onLoad: async function(e) {
			const that = this;
			that.searchConfig();
		},
		methods: {
			searchConfig() {
				const that = this;
				try {
					const res = uni.getStorageSync('config');
					if (res) that.$set(that, `config`, res);
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			// 复制
			toCopy(context) {
				uni.setClipboardData({
					data: context, //被复制的内容
					success: () => { //复制成功的回调函数
						uni.showToast({
							title: '复制成功'
						})
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		padding: 2vw;
		text-align: center;
		font-size: var(--font18Size);
		font-weight: bold;

		.two {
			display: flex;
			align-items: center;
			justify-content: center;

			.button {
				margin: 10px;
				font-size: var(--font12Size);
				background-color: var(--f3CColor);
			}
		}
	}
</style>