<template>
	<div>
		<div class="analysis-cell" @tap="toggleShow" :class="{ 'active': item.show }" :style="activeCellStyleStr">
			<div class="shop-title" :class="'theme-' + provinceCode">
				<span> {{ (i > 8 ? i + 1 : '0' + (i + 1)) + ' ' + item.SHOPNAME }}</span>
				<p>
					<span v-show="item.UNACCOUNT_SIGN">￥</span>
					<span class="cell-price" :style="priceStyleStr">{{
						item.UNACCOUNT_SIGN
							? $util.fmoney(item.CASHPAY_TOTAL, 2) : '无结账信息' }}</span>
					<image src="/static/images/effective/true.png" mode="aspectFit" class="" v-if='item.SHOWDEAL_SIGN'>
					</image>
					<!-- <text class="uni-icon uni-icon-checkmarkempty"  v-if='item.SHOWDEAL_SIGN'></text> -->

				</p>
			</div>
			<p v-if="item.detail.length > 0" style="line-height: 1.2;">
				<span v-for="(child, index) in item.detail" :key="index" class="atribute-tag">{{ child }} </span>
			</p>
		</div>
		<div class="analysis-detail" v-show="item.show">
			<div class="detail-unit" v-for="(unit, o) in item.ShopEndAccountList" :key="o">
				<div class="uni-inline-flex">
					<span class="detail-title">结账时间：</span>
					<div style="flex: 1;text-align: left;">
						<div style="font-size: 24rpx;">起 {{ unit.ENDACCOUNT_STARTDATE }}</div>
						<div style="font-size: 24rpx;">止 {{ unit.ENDACCOUNT_DATE }}</div>
					</div>
					<span style="color:#EE7941;margin-right:50rpx;padding-top: 20rpx;font-size: 24rpx;">{{
						getHour(unit.ENDACCOUNT_STARTDATE, unit.ENDACCOUNT_DATE) }}小时</span>
				</div>
				<block v-if="unit.DESCRIPTION_DATE">

					<div class="detail-title">日结校验：{{ unit.DESCRIPTION_DATE }}</div>
					<p><span class="detail-title">{{ unit.DESCRIPTION_STAFF }}：</span><span style="font-size: 24rpx;">{{
						unit.DIFFERENCE_REASON
					}}</span>
					</p>
				</block>
				<block v-if="unit.APPROVE_DATE">
					<div><span class="detail-title">日结审核：{{ unit.APPROVE_DATE }}</span></div>
					<p><span class="detail-title" style="font-size: 24rpx;">{{ unit.APPROVE_STAFF }}：</span><span
							style="font-size: 24rpx;">{{
								unit.APPROVED_INFO }}</span>
					</p>
				</block>
				<div>
					<p class="detail-short-info" v-show="unit.FACTAMOUNT_SALE">单品报表：<text
							class="uni-icon uni-icon-checkmarkempty"></text></p>
					<p class="detail-short-info" v-show="unit.FACTAMOUNT_CIGARETTE">香烟数据：<span
							class="uni-icon uni-icon-checkmarkempty"></span></p>
				</div>
				<div><span class="detail-title detail-short-info" style="font-size: 24rpx;">稽核次数：{{ unit.CHECK_COUNT }}
						次</span><span class="detail-short-info" style="font-size: 24rpx;">长短款额：{{
							$util.fmoney(unit.DIFFERENT_PRICE) }} 元</span></div>
				<div>
					<span class="detail-title detail-short-info" style="font-size: 24rpx;">现金缴款：{{
						$util.fmoney(unit.CASHPAY_DOWNLORD) }} 元</span>
					<span class="detail-short-info" style="font-size: 24rpx;">移动支付：{{ $util.fmoney(unit.MOBILEPAYMENT)
						}} 元</span>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
export default {
	props: {
		item: {
			type: Object,
			required: true
		},
		i: {
			type: Number,
			required: true
		},
		provinceCode: {
			type: String,
			default: '530000' // 默认使用云南的配色
		}
	},
	data() {
		return {


		}
	},
	computed: {
		// 根据省份代码获取主题色
		themeColors() {
			const themes = {
				'330200': { // 宁波
					primary: '#1890FF',
					secondary: '#69C0FF'
				},
				'340000': { // 安徽
					primary: '#748ED6',
					secondary: '#91A7E3'
				},
				'500000': { // 重庆
					primary: '#FA541C',
					secondary: '#FF7A45'
				},
				'510000': { // 四川
					primary: '#FA8C16',
					secondary: '#FFA940'
				},
				'520000': { // 贵州
					primary: '#52C41A',
					secondary: '#73D13D'
				},
				'530000': { // 云南（默认色）
					primary: '#27B25F',
					secondary: '#4CCC7F'
				},
				'630000': { // 青海
					primary: '#13C2C2',
					secondary: '#36CFC9'
				},
				'734100': { // 海南
					primary: '#E91E63',
					secondary: '#F06292'
				}
			}
			return themes[this.provinceCode] || themes['530000']
		},

		// 动态样式字符串（小程序兼容）
		activeCellStyleStr() {
			if (!this.item.show) return ''
			return `border: 2rpx solid ${this.themeColors.primary}; box-shadow: 0 4px 20px rgba(${this.hexToRgb(this.themeColors.primary)}, 0.15);`
		},

		// 价格样式字符串
		priceStyleStr() {
			const paddingRight = !this.item.UNACCOUNT_SIGN ? '0' : '0'
			const fontSize = !this.item.UNACCOUNT_SIGN ? '24rpx' : '24rpx'
			return `padding-right: ${paddingRight}; font-size: ${fontSize}; color: ${this.themeColors.primary};`
		}
	},
	methods: {
		getHour(start, end) {
			return parseInt((new Date(end) - new Date(start)) / (1000 * 3600))
		},

		toggleShow() {
			this.$emit('toggleShow', this.i)
		},

		// 将十六进制颜色转换为RGB
		hexToRgb(hex) {
			const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
			return result ?
				`${parseInt(result[1], 16)}, ${parseInt(result[2], 16)}, ${parseInt(result[3], 16)}` :
				'39, 178, 95'; // 默认绿色的RGB
		}
	}
}
</script>

<style lang="scss" scoped>
.analysis-cell {
	background-color: #fff;
	border-radius: 16rpx;
	margin-bottom: 16rpx;
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
	padding: 16rpx 16rpx 8rpx;
	display: flex;
	flex-direction: column;
	transition: all 0.3s ease;
	position: relative;

	&.active {
		// 边框和阴影由动态样式控制
	}
}

.analysis-cell .shop-title {
	display: flex;
	justify-content: space-between;
	position: relative;
	font-size: 24rpx;
	font-weight: 600;
	align-items: flex-start;

	span {
		color: #333;
		flex: 1;
	}

	p {
		display: flex;
		align-items: center;
		flex-shrink: 0;
	}
}

.analysis-cell .shop-title:before {
	content: '';
	position: absolute;
	width: 24rpx;
	height: 24rpx;
	border-radius: 50%;
	left: -40rpx;
	top: 4rpx;
	background: #e0e0e0;
	border: 3rpx solid #fff;
	box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
	transition: all 0.3s ease;
}

// 主题色状态指示点样式
.analysis-cell.active .shop-title.theme-330200:before {
	background: #1890FF;
	box-shadow: 0 2rpx 12rpx rgba(24, 144, 255, 0.3);
}

.analysis-cell.active .shop-title.theme-340000:before {
	background: #748ED6;
	box-shadow: 0 2rpx 12rpx rgba(116, 142, 214, 0.3);
}

.analysis-cell.active .shop-title.theme-500000:before {
	background: #FA541C;
	box-shadow: 0 2rpx 12rpx rgba(250, 84, 28, 0.3);
}

.analysis-cell.active .shop-title.theme-510000:before {
	background: #FA8C16;
	box-shadow: 0 2rpx 12rpx rgba(250, 140, 22, 0.3);
}

.analysis-cell.active .shop-title.theme-520000:before {
	background: #52C41A;
	box-shadow: 0 2rpx 12rpx rgba(82, 196, 26, 0.3);
}

.analysis-cell.active .shop-title.theme-530000:before {
	background: #27B25F;
	box-shadow: 0 2rpx 12rpx rgba(39, 178, 95, 0.3);
}

.analysis-cell.active .shop-title.theme-630000:before {
	background: #13C2C2;
	box-shadow: 0 2rpx 12rpx rgba(19, 194, 194, 0.3);
}

.analysis-cell.active .shop-title.theme-734100:before {
	background: #E91E63;
	box-shadow: 0 2rpx 12rpx rgba(233, 30, 99, 0.3);
}

.shop-title image {
	width: 32rpx;
	height: 32rpx;
	margin-left: 12rpx;
	border-radius: 4rpx;
}

.analysis-cell .cell-price {
	// 颜色由动态样式控制
	font-family: 'PingFang SC', sans-serif;
	font-size: 24rpx;
	font-weight: 700;
}

.atribute-tag {
	display: inline-block;
	background: linear-gradient(135deg, #ff9f43, #ff8c42);
	color: #fff;
	padding: 4rpx 12rpx;
	margin: 4rpx 8rpx 4rpx 0;
	border-radius: 20rpx;
	font-size: 20rpx;
	font-weight: 500;
	box-shadow: 0 2rpx 8rpx rgba(255, 159, 67, 0.2);
}

.analysis-detail {
	background-color: #f8f9fa;
	border-radius: 12rpx;
	position: relative;
	overflow: hidden;
	// margin-top: 16rpx;
	border: 1rpx solid #f0f0f0;
}

.analysis-detail span,
.analysis-detail view {
	color: #333;
	font-size: 26rpx;
}

.uni-icon-checkmarkempty,
.analysis-detail span.uni-icon-checkmarkempty {
	color: #2ed573;
	font-size: 32rpx;
	font-weight: 600;
}

.analysis-detail::before {
	content: '';
	width: 0;
	height: 0;
	border-left: 12rpx solid transparent;
	border-right: 12rpx solid transparent;
	border-bottom: 16rpx solid #f8f9fa;
	position: absolute;
	top: -16rpx;
	left: 32rpx;
}

.analysis-detail .detail-unit {
	background-color: #fff;
	padding: 24rpx;
	border-radius: 8rpx;
	// margin: 16rpx;
	box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);

	&:first-child {
		// margin-top: 24rpx;
	}

	&:last-child {
		margin-bottom: 24rpx;
	}
}

.analysis-detail .detail-unit>div {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	margin-bottom: 16rpx;

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

.analysis-detail .detail-unit>p {
	margin-bottom: 16rpx;

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

.analysis-detail span {
	display: inline-block;
	vertical-align: middle;
	line-height: 1.4;
}

.analysis-detail .detail-title {
	min-width: 140rpx;
	color: #666;
	font-weight: 500;
	font-size: 24rpx;
}

.analysis-detail .detail-short-info {
	width: 50%;
	color: #333;
	font-size: 24rpx;

	&:first-child {
		padding-right: 16rpx;
	}
}

.uni-inline-flex {
	span:last-child {
		color: #ff9f43;
		font-weight: 600;
		font-size: 28rpx;
	}
}
</style>
