<template>
	<view >
		<view v-if="$isNotEmpty(channel)" @click="channelShow=true" class="channel " style="width: 100%;">
			<view class="left">
				<view class="center">
					<image :src="channel.channelLogo?channel.channelLogo:'/static/icon/channel.png'" mode=""></image>
				</view>
				<view class="content">
					<text>{{channel.channelName}}</text>
					<text style="font-weight: 300;">优先使用该渠道积分支付</text>
				</view>
			</view>
			<view class="right">
				<text class="cuIcon-unfold"></text>
			</view>
		</view>
		
		<u-popup :closeable="true" v-model="channelShow" mode="bottom" height="65%">
			<view class="popup-content">
				<view class="">
					<view style="border-bottom: 1rpx solid #eee;" class="fixed center text-bold text-lg padding-bottom-40">
						请选择优先使用的渠道积分
					</view>
					<view @click="check(item)" v-for="(item,index) in channelList" :key="index" class="channel-item">
						<image :src="item.channelLogo?item.channelLogo:'/static/icon/channel.png'" mode=""></image>
						<text class="margin-left-10">{{item.channelName}}（剩余 ￥ {{item.available}}）</text>
						<text v-if="channel.channelId==item.channelId" class="cuIcon-check checked"></text>
					</view>
				</view>
				<view class="center">
					<view @click="confirm" class="cu-btn radius channelbtn">
						确认
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		name:"channel-list",
		data() {
			return {
				//渠道积分
				channel:{},
				channelList:[],
				channelShow:false,
			};
		},
		created() {
			this.getUserPonint()
		},
		methods:{
			//获取用户渠道积分
			getUserPonint(){
				if (this.$isEmpty(this.vuex_userId)) {
					return
				}
				let params={
					userId:this.vuex_userId || '-1'
				}
				this.$api.userChannelPoint.list(params).then(res=>{
					if (this.$isNotEmpty(res.data.records)) {
						this.channelList=res.data.records
						this.channel=this.channelList[0]
						this.$u.vuex('vuex_channel',this.channel)
					}
				})
			},
			confirm(){
				this.channelShow=false
				this.$u.vuex('vuex_channel',this.channel)
				this.$emit('click',this.channel)
			},
			check(item){
				this.channel=item
			}
		}
	}
</script>

<style lang="scss">
	.channel{
		display: flex;
		justify-content: space-between;
		margin-top: 10rpx;
		padding:20rpx 40rpx;
		background-color: #FFFFFF;
		
		.left{
			display: flex;
			image{
				width: 60rpx;
				height: 60rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
			view{
				display: flex;
				flex-direction: column;
			}
			
			.content{
				margin-left: 16rpx;
				
				text:first-child{
					font-size: 32rpx;
					margin-bottom: 10rpx;
				}
				
				text:last-child{
					font-size: 28rpx;
					color: #989898;
				}
			}
		}
		
		.right{
			display: flex;
			justify-content: center;
			align-items: center;
		}
		
	}
	
	.popup-content{
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		padding: 40rpx 0;
		height: 100%;
		
		.channelbtn{
			background-color: #18b566;
			color: #FFFFFF;
			padding: 38rpx 180rpx;
		}
		
		.channel-item{
			position: relative;
			display: flex;
			padding: 30rpx;
			border-bottom: 1rpx solid #eee;
			image{
				width: 40rpx;
				height: 40rpx;
				margin-right: 10rpx;
			}
			
			.checked{
				color: #18b566;
				font-size: 34rpx;
				position: absolute;
				font-weight: 800;
				right: 40rpx;
				bottom: 30rpx;
			}
			
		}
	}
</style>
