<template>
	<view class="city-page">
		<view class="city-list" v-if="recordList.length">
			<view class="city-card" v-for="item in recordList" :key="item.id">
				<view class="card-head">
					<text class="center-name">{{ item.cityName }}-{{ item.operationCenterName }}</text>
					<text class="status-tag" :class="item.status==0?'pending':item.status==1?'opened':'rejected'">
						{{ item.status==0?'审核中':item.status==1?'已开通':'审核驳回' }}
					</text>
				</view>
				<view class="card-divider"></view>
				<view class="card-body">
					<view class="meta-row">
						<text class="meta-label">开通原因</text>
						<text class="meta-value">{{ item.applyReason || '暂无' }}</text>
					</view>
					<view class="meta-row">
						<text class="meta-label">开通时间</text>
						<text class="meta-value">{{ item.actualApprovalTime }}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="empty" v-else>暂无城市记录</view>

		
		<view class="footer-bar">
			<view class="submit-btn" @click="goApply">开通新城市</view>
		</view>
	</view>
</template>

<script>
import { MOCK_CITY_RECORDS, CITY_STATUS_MAP } from './mock.js'
import { getCityList } from '@/api/workbench.js'
export default {
	data() {
		return {
			recordList: [],
		}
	},
	onShow() {
		this.loadList()
	},
	methods: {
		loadList() {
			this.recordList = [...MOCK_CITY_RECORDS]
			//接口就绪后替换
			getCityList({
				merchantId: uni.getStorageSync('userId'),
			}).then(res => {
				console.log(res)
				if (res.data.code == 200) {
					this.recordList = res.data.data
				}
			})
		},
		
		goApply() {
			uni.navigateTo({ url: '/workbench/city/apply' })
		},
	},
}
</script>

<style lang="scss" scoped>
.city-page {
	min-height: 100vh;
	background: #f5f5f5;
	padding: 24rpx 24rpx 140rpx;
	box-sizing: border-box;
}

.city-list {
	display: flex;
	flex-direction: column;
	gap: 20rpx;
}

.city-card {
	background: #fff;
	border-radius: 16rpx;
	padding: 32rpx;
}

.card-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.center-name {
	flex: 1;
	font-size: 32rpx;
	color: #333;
	font-weight: 600;
	line-height: 1.4;
	padding-right: 16rpx;
}

.status-tag {
	flex-shrink: 0;
	font-size: 22rpx;
	padding: 6rpx 16rpx;
	border-radius: 8rpx;
	line-height: 1.4;

	&.opened {
		color: #1db870;
		background: #e8faf0;
	}

	&.pending {
		color: #ff8800;
		background: #fff4e6;
	}

	&.rejected {
		color: #ff4d4f;
		background: #fff0f0;
	}
}

.card-divider {
	height: 1rpx;
	background: #f0f0f0;
	margin: 24rpx 0;
}

.card-body {
	display: flex;
	flex-direction: column;
	gap: 16rpx;
}

.meta-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.meta-label {
	font-size: 26rpx;
	color: #999;
	flex-shrink: 0;
}

.meta-value {
	flex: 1;
	text-align: right;
	font-size: 26rpx;
	color: #333;
	margin-left: 24rpx;
}

.empty {
	text-align: center;
	padding: 120rpx 0;
	font-size: 28rpx;
	color: #999;
}

.footer-bar {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	padding: 20rpx 32rpx;
	padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
}
.submit-btn {
	margin: 0 auto;
	width: 654rpx;
	height: 88rpx;
	line-height: 88rpx;
	text-align: center;
	font-weight: 500;
	font-size: 32rpx;
	color: #FFFFFF;
	background: #333335;
	border-radius: 60rpx 60rpx 60rpx 60rpx;
}
</style>
