<template>
	<view>
		<view class="flbtn" style="padding-top: 20rpx;">
			<view class="flex">
				<u-checkbox-group @change="checkboxChange">
					<u-checkbox checked activeColor="#FF7700" shape="circle" v-for="(item, index) in checkboxList1"
						:key="index" :label="item.name" :name="item.name">

					</u-checkbox>
				</u-checkbox-group>
				<view class="lit-666 bold" style="padding-top: 4rpx;">
					可用消费补贴卡余额抵扣<text style="color: #EB4141;">￥{{newPrice/100}}</text>
				</view>
			</view>
			<view class="lit-666" style="font-weight: 400;padding-top: 4rpx;">
				余额：￥{{amount/100}}
			</view>
		</view>
		<u-gap height="10rpx"></u-gap>
		<view class="lit-666" style="padding-left: 44rpx;" v-if="amount < newPrice">
			您余额不足，实际可抵扣<text style="color: #EB4141;">￥{{amount <= 0?'0':(amount) / 100}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		name: "card-checked",
		props: {
			price: {
				type: [String, Number],
				default: 0
			},
			// percent:{
			// 	type:[Number,String],
			// 	default:0
			// },
			// store_id:{
			// 	type:[String,Number],
			// 	default:0
			// }

		},
		data() {
			return {
				checkboxList1: [{
					name: '',
				}],
				checked: '',
				amount: -1,
				newPrice: 0,
				// price:0,
				// percent:0
			};
		},
		watch: {
			price: {
				immediate: true,
				async handler(newVul, oldVul) {
					if(this.amount <= -1){
						await this.getWallet()
					}
					// console.log(newVul,this.amount, '执行监听器');
					// console.log(newVul, 'new')
					this.newPrice = Math.floor(newVul);
					let _p = (this.newPrice > this.amount ? this.amount : this.newPrice) /
						100 //this['amount'] * this['percent'];
					this.$emit('GitData', _p)
					// this.price = Math.floor(val*this.percent)
					// console.log(val,'价格')
				}

			},
		},
		// mounted() {
		// 	// console.log(this['price'], 'pricepriceprice');
		// 	// this.getWallet();
		// 	// this.getPercent();
		// },
		methods: {
			async getWallet() {
				let self = this;
				// console.log('执行');
				let _m = await self.$store.dispatch('card/userConWallet');
				self['amount'] = _m['amount'] ;
				// self['amount'] = 10;
			},
			// getPercent(){
			// 	this.$store.dispatch('api/storeDeductionProp',{
			// 		store_id : this.store_id
			// 	}).then(res => {
			// 		this.percent = res
			// 	})
			// },
			checkboxChange(e) {
				console.log(e,'123');
				this.$emit('checked', (e.length > 0 ? true : false))
				// return this.checked
			},
			GetP() {
				console.log(this.newPrice, 'new price')
				let _p = (this.newPrice > this.amount ? this.amount : this.newPrice) /
					100 //this['amount'] * this['percent'];
				// console.log(_p,'p')
				return _p;
			}
		}


	}
</script>

<style>

</style>
