<template>
	<view class="consumption">
		<view class="consumption-header">
			<view class="consumption-header-text">
				<view class="consumption-header-text-neishi" @click="topgi">
					<view class="consumption-header-text-icon">
						<image src="https://cdn.bjtdba.com/vod/image/2022-08-11/20220811133828415.png" mode="widthFix">
						</image>
					</view>
				</view>
				<view class="consumption-header-text-title">
					我的消费分
				</view>
			</view>
		</view>
		<view class="consumption-list">
			<view class="consumption-list-yi">
				<view class="consumption-list-yi-top">
					已结算消费分
				</view>
				<view class="consumption-list-yi-bot">
					{{list.settlement==undefined?0:list.settlement}}
				</view>
			</view>
			<view class="consumption-list-yi">
				<view class="consumption-list-yi-top">
					预估消费分
				</view>
				<view class="consumption-list-yi-bot">
					{{list.predict==undefined?0:list.predict}}
				</view>
			</view>
			<view class="consumption-list-yi">
				<view class="consumption-list-yi-top">
					已释放消费分
				</view>
				<view class="consumption-list-yi-bot">
					{{list.release==undefined?0:list.release}}
				</view>
			</view>
		</view>
		<view class="consumption-xi" @click="consumptionbreakdown">
			<view class="consumption-xi-left">
				消费分明细
			</view>
			<view class="consumption-xi-icon">
				<image src="https://cdn.bjtdba.com/vod/image/2022-08-11/20220811110111315.png" mode="widthFix"></image>
			</view>
		</view>
		<view class="consumption-guiz" @click="consumptionrule">
			<view class="consumption-guiz-icon">
				<image src="https://cdn.bjtdba.com/vod/image/2022-08-11/20220811150537359.png" mode="widthFix"></image>
			</view>
			<view class="">
				规则
			</view>
		</view>
		<view class="consumption-wenan">
			说明：开通消费分后，商户返利比例设置最低2%，不可低于2%，请谨慎设置开通消费分，此过程不可逆。
		</view>
		<view class="consumption-buttom" @click="kaitong" v-if="list.consumptionScore==1?false:true">
			开通消费分
		</view>

		<view class="kiss" v-if="ispan">
			<view class="bottomss">
				<view class="top">
					是否要开通消费分功能？
				</view>
				<view class="cv">
					<view class="sss" @click="women(1)">
						取消
					</view>
					<view class="sdfg">

					</view>
					<view class="sss" style="color: #1F7CFF;" @click="women(2)">
						确认
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		merchantConsumption,
		updateConsumptionScore
	} from '@/commit/shop.js'

	export default {
		data() {
			return {
				ispan: false,
				mer_id: '',
				list: []
			}
		},
		onLoad() {
			let selectmerchant = uni.getStorageSync('selectmerchant')
			this.mer_id = selectmerchant.merId
			this.merchantConsumption()
		},
		methods: {
			merchantConsumption() {
				uni.showLoading({
					title: '加载中',
				});
				merchantConsumption({
					mer_id: this.mer_id
				}).then(res => {
					if (res.data.status == 200) {
						this.list = res.data.data
						uni.hideLoading();
					}
				}, fail => {
					console.log(fail)
					uni.hideLoading();
				})
			},
			consumptionbreakdown() {
				uni.redirectTo({
					url: "consumptionbreakdown"
				})
			},
			consumptionrule() {
				uni.navigateTo({
					url:"/pages/index/bottombat?url=" + 'https://vod.bjtdba.com/agreement/17'
				})
			},
			kaitong() {
				this.ispan = true
			},
			women(e) {
				if (e == 1) {
					this.ispan = false
				} else {
					// 开通消费分接口
					updateConsumptionScore({
						mer_id: this.mer_id
					}).then(res => {
						if (res.data.status == 200) {
							uni.showToast({
								title: res.data.message,
								icon: 'success',
							})
							this.list.consumptionScore = 1
							this.ispan = false
						}
					}, fail => {
						console.log(fail)
					})
				}
			},
			topgi() {
				uni.switchTab({
					url: "/pages/cashier/index"
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #F7F8FC;
	}
</style>
<style lang="scss" scoped>
	.kiss {
		width: 100%;
		height: 100%;
		background: transparent;
		background: rgba(0, 0, 0, 0.5);
		position: fixed;
		margin: auto;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		z-index: 12;
		display: flex;
		justify-content: center;
		align-items: center;

		.bottomss {
			width: 560rpx;
			height: 290rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.top {
				width: 100%;
				height: 191rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				border-bottom: 1rpx solid #E5E5E5;
			}

			.cv {
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 36rpx;
				font-weight: 400;
				color: #333333;

				.sss {
					width: 280rpx;
					height: 100%;
					display: flex;
					justify-content: center;
					align-items: center;
				}

				.sdfg {
					height: 99rpx;
					width: 1rpx;
					background-color: #E5E5E5;
				}
			}
		}
	}

	.consumption {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;

		.consumption-header {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 111;
			width: 100%;
			height: 176rpx;
			background: #FFFFFF;
			display: flex;
			justify-content: center;

			.consumption-header-text {
				width: 686rpx;
				font-size: 36rpx;
				font-weight: 500;
				color: #333333;
				display: flex;
				margin-top: 107rpx;
				align-items: center;

				.consumption-header-text-neishi {
					width: 45rpx;
					height: 45rpx;
					margin-right: 17rpx;

					.consumption-header-text-icon {
						width: 36rpx;
						height: 36rpx;
						margin-top: 2rpx;

						image {
							width: 100%;
							height: 100%;
						}
					}
				}
			}
		}

		.consumption-list {
			width: 686rpx;
			height: 166rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			margin: 202rpx 0 26rpx 0;
			display: flex;
			justify-content: space-around;
			align-items: center;

			.consumption-list-yi {
				height: 92rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				align-items: center;
				color: #333333;

				.consumption-list-yi-top {
					font-size: 26rpx;
					font-weight: 400;

				}

				.consumption-list-yi-bot {
					font-size: 40rpx;
					font-weight: bold;
				}
			}
		}

		.consumption-xi {
			width: 686rpx;
			height: 118rpx;
			background: #FFFFFF;
			border-radius: 8rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 30rpx;
			font-weight: 400;
			color: #333333;

			.consumption-xi-left {
				margin-left: 32rpx;
			}

			.consumption-xi-icon {
				width: 20rpx;
				height: 20rpx;
				margin-right: 32rpx;
				line-height: 20rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.consumption-guiz {
			width: 686rpx;
			display: flex;
			justify-content: flex-end;
			align-items: center;
			margin-top: 26rpx;
			font-size: 26rpx;
			font-weight: 400;
			color: #333333;

			.consumption-guiz-icon {
				width: 20rpx;
				height: 20rpx;
				margin-right: 5rpx;
				line-height: 20rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.consumption-wenan {
			width: 686rpx;
			margin-top: 743rpx;
			font-size: 26rpx;
			font-weight: 400;
			color: #999999;
		}

		.consumption-buttom {
			width: 686rpx;
			height: 98rpx;
			background: #1F7CFF;
			border-radius: 8rpx;
			position: fixed;
			bottom: 94rpx;
			text-align: center;
			line-height: 98rpx;
			font-size: 36rpx;
			font-weight: 400;
			color: #FFFFFF;
		}
	}
</style>
