<template>
	<view class='center'>
		<view style="background: linear-gradient( 180deg, #1FCA7C 0%, #F2F2F2 100%);height: 550rpx;">
			<u-navbar :autoBack="true" title="常用电话" placeholder="true" bgColor="transparent" leftIconColor="#FFF"
				:title-style="{color: '#FFF'}">
			</u-navbar>
			<view class=" mlr-25 mt-30 ">
				<input
					style="height: 72rpx; text-align: center;border:1rpx solid #F2F2F2; border-radius:36rpx;color: #fff;"
					placeholder="搜索" placeholder-style="color:#fff" @input="search" />
			</view>
		</view>
		<view class="overflow-y mlr-25"
			style="background: white;border-top-left-radius: 20rpx;border-top-right-radius: 20rpx;margin-top: -250rpx;">
			<scroll-view scroll-y style="height: 100%;">
				<view class="mar-20">
					<view v-for="(item, index) in filteredList(searchKey)" :key="index">
						<view class="flex" style="border:1rpx solid #20CA7D;">
							<view class="flex vh-center ptb-20 fs-24" style="flex: 1;border-right:1rpx solid #1FCA7C;">
								{{item.name}}
							</view>
							<view class="flex vh-center fs-28" style="flex: 1;border-right:1rpx solid #1FCA7C;">
								{{item.phone}}
							</view>
							<view class="flex vh-center" style="flex: 1;" @click="onZd(index)">
								<!-- <view class="flex-column vh-center" style="flex: 1;">
									<image v-if="index==0" class="w-30 h-30" src="/pagesMain/static/icon_cydh_qxzd.png">
									</image>
									<image v-else class="w-30 h-30" src="/pagesMain/static/icon_cydh_zd.png"></image>
									<text style="color: #999999;font-size: 18rpx;">{{index==0?"取消置顶":"置顶"}}</text>
								</view> -->
								<view class="flex-column vh-center ml-30" style="flex: 1;" @click="onBd(item.phone)">
									<image class="w-30 h-30" src="/pagesMain/static/icon_cydh_dh.png"></image>
									<text style="color: #999999;font-size: 18rpx;">一键拨打</text>
								</view>
							</view>
						</view>

					</view>

				</view>


			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				searchKey: '',
			};
		},
		onLoad(e) {

		},
		onShow() {
			this.listAll()
		},
		methods: {
			onZd(index) {
				if (index == 0) {
					this.$wskj.toast("取消置顶")
				} else {
					this.$wskj.toast("置顶")
				}

			},
			search(event) {
				this.searchKey = event.detail.value
				console.log(this.filteredList(this.searchKey))
			},
			filteredList(e) {
				return e == '' ? this.list : this.list.filter(item => {
					// 筛选条件：名称包含关键词（忽略大小写）
					return item.name.includes(e)
				})
			},
			listAll() {
				const params = {
					url: '/api/commonPhone/listAll',
					loadingTip: '',
					method: 'GET',
					data: {}
				}
				this.$request(params).then(res => {
					console.log(res.data)
					this.list = res.data
				})
			},
			onBd(phone) {
				this.$wskj.onCall(phone)
			}
		},
	};
</script>

<style scoped>
	.center {
		height: 100vh;
		display: flex;
		flex-direction: column;
		background: #F2F2F2;
	}
</style>