<template>
	<store-page-layout title="门店管理" :show-back="true">
		<view class="page">
			<view class="filter-panel">
				<input class="filter-input" v-model="filters.name" placeholder="诊所名称" />
				<input class="filter-input" v-model="filters.shouzimu" placeholder="拼音首字母" />
				<input class="filter-input" v-model="filters.mobile" placeholder="联系人手机号" />
				<view class="filter-btn" @click="reload">查询</view>
			</view>

			<view v-if="loading" class="empty">加载中...</view>
			<view v-else-if="!list.length" class="empty">暂无门店</view>

			<view
				v-for="item in list"
				:key="item.id"
				class="card"
				hover-class="card-hover"
				@click="goDetail(item)"
			>
				<view class="card-head">
					<text class="name">{{ item.name }}</text>
					<text class="type-tag">{{ clinicTypeText(item.clinic_type) }}</text>
				</view>
				<text class="addr">{{ item.position || '暂无地址' }}</text>
				<view class="meta-row">
					<text>ID {{ item.id }}</text>
					<text v-if="item.mobile">电话 {{ item.mobile }}</text>
				</view>
				<view class="tag-row">
					<text class="mini-tag" :class="{ on: Number(item.salesperson_see_price) === 1 }">推广员可见价格</text>
					<text class="mini-tag" :class="{ on: Number(item.is_shipping_free) === 1 }">包邮</text>
					<text v-if="Number(item.bank_card_report_status) === 0" class="mini-tag warn">需报备银行卡</text>
					<text v-else-if="item.bank_card_report_status_text" class="mini-tag bank">{{ item.bank_card_report_status_text }}</text>
				</view>
			</view>
		</view>
	</store-page-layout>
</template>

<script>
import StorePageLayout from '@/subPackages/sub_platform_admin/components/store-page-layout.vue';
import { getPlatformStoreList } from '@/api/platformStore.js';

const ROOT = '/subPackages/sub_platform_admin/store';

export default {
	components: { StorePageLayout },
	data() {
		return {
			filters: { name: '', shouzimu: '', mobile: '' },
			list: [],
			loading: false,
		};
	},
	onShow() {
		this.reload();
	},
	methods: {
		clinicTypeText(type) {
			if (Number(type) === 1) return '西医诊所';
			if (Number(type) === 2) return '中医诊所';
			return '未设置';
		},
		async reload() {
			this.loading = true;
			try {
				const wrap = await getPlatformStoreList({
					page: 1,
					pageSize: 50,
					...this.filters,
				});
				const data = wrap && wrap.ok ? wrap.data : null;
				if (data && Array.isArray(data.items)) {
					this.list = data.items;
				} else if (Array.isArray(data)) {
					this.list = data;
				} else {
					this.list = [];
				}
			} finally {
				this.loading = false;
			}
		},
		goDetail(item) {
			uni.navigateTo({ url: `${ROOT}/detail?id=${item.id}` });
		},
	},
};
</script>

<style lang="scss" scoped>
.page { padding: 24rpx; }
.filter-panel { display: flex; flex-wrap: wrap; gap: 12rpx; margin-bottom: 20rpx; }
.filter-input {
	flex: 1; min-width: 200rpx; background: #fff; border-radius: 12rpx;
	padding: 16rpx 20rpx; font-size: 26rpx;
}
.filter-btn {
	background: #6ACDBB; color: #fff; padding: 16rpx 32rpx; border-radius: 12rpx; font-size: 26rpx;
}
.empty { text-align: center; color: #999; padding: 80rpx 0; }
.card {
	background: #fff; border-radius: 20rpx; padding: 28rpx; margin-bottom: 20rpx;
	box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.04);
}
.card-hover { opacity: 0.92; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8rpx; }
.name { font-size: 30rpx; font-weight: 600; flex: 1; }
.type-tag { font-size: 22rpx; color: #6ACDBB; background: #f0fbf8; padding: 4rpx 12rpx; border-radius: 8rpx; }
.addr { font-size: 24rpx; color: #666; display: block; margin-bottom: 12rpx; }
.meta-row { display: flex; justify-content: space-between; font-size: 22rpx; color: #999; margin-bottom: 12rpx; }
.tag-row { display: flex; gap: 12rpx; flex-wrap: wrap; }
.mini-tag { font-size: 22rpx; color: #999; background: #f5f5f5; padding: 4rpx 12rpx; border-radius: 8rpx; }
.mini-tag.on { color: #22C55E; background: #F0FDF4; }
.mini-tag.warn { color: #D97706; background: #FEF3C7; }
.mini-tag.bank { color: #3B82F6; background: #EFF6FF; }
</style>
