<template>
	<view class="container">
		<!-- #ifdef APP -->
		<view class="backArrow">
			<text class="iconfont icon-youjiantou zuojiantou" style="left: 5rpx;" @click="goBack()"></text>
			<text style="font-size: 30rpx;">提现记录</text>
		</view>
		<!-- #endif -->
		<view class="content">
			<view style="flex: 1;">
				<view class="totalBox" :style="{justifyContent:showTotal?'space-between':'flex-end'}">
					<view class="left"  v-if="showTotal">
						<text class="totalTxt">总金额：</text>
						<text class="totalNum">￥{{dataObj.totalAmount}}</text>
						<view class="des">
						(不包含已拒绝记录)
						</view>
					</view>
					<view class="right" >
						<multi-select-dropdown 
							:options="statusOptions"
							:value="selectedStatus"
							labelKey="label"
							valueKey="value"
							placeholder="提现状态"
							@change="handleStatusChange"
						>
							<template #trigger="{ selectedItems }">
								<text class="filterTxt">{{selectedTxt}}</text>
							  <text class="iconfont icon-shaixuan"></text>
							</template>
						</multi-select-dropdown>
					</view>
				</view>
				<view class="recordBox" v-if="dataObj.withdrawalVOList.length>0">
					<view class="itemBox" v-for="item in dataObj.withdrawalVOList" :key="item.id">
						<view class="left">
							<text v-if="item.paidMethod == 2" class="iconfont icon-zhifubao2"></text>
							<text v-if="item.paidMethod == 1" class="iconfont icon-weixin"></text>
						</view>
						<view class="right">
							<view class="top">
								<text class="tixian">提现时间：<text>{{item.exchangeDate}}</text> </text>
								<text class="money">￥{{item.exchangeAmount}}</text>
							</view>
							<view class="bottom" :style="{justifyContent:item.status=='0'?'flex-end':'space-between'}">
								<text v-show="item.status=='1'" class="daozhang">到账时间：<text>{{item.paidDate}}</text> </text>
								<view v-show="item.status=='3'" class="daozhang ">拒绝理由：<text class="refuse-reason">{{item.reviewMessage}}</text> </view>
								<text class="pay" >
								{{
									item.status=='0'?'审核中'
									:item.status=='1'?'已到账'
									:item.status=='3'?'已拒绝':'--'
								}}
								</text>
							</view>
						</view>
					</view>
				</view>
				<view class="empty" v-else>
					暂无数据
				</view>
			</view>
			<view class="btnBottom" @click="gotoKefu">
				<view class="myBtn">
					咨询客服
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import dataHandling from "@/util/dataHandling";
	import api from "@/api/api";
	import { initJssdkShare, setWechatShare } from '@/util/fiveshare';
	import {companyInfo} from "@/environments/environment";
	import MultiSelectDropdown from '@/components/commonPopup/MultiSelectDropdown.vue'
	export default {
		components: {
		    MultiSelectDropdown
		  },
		data() {
			return {
				dataObj:{withdrawalVOList:[],totalAmount:'0.00'},
				statusOptions: [
					{ label: '全部', value: '-1' },
					{ label: '审核中', value: '0' },
					{ label: '已到账', value: '1' },
					{ label: '已拒绝', value: '3' }
				],
				selectedStatus: [],
				selectedTxt:'提现状态',
				showTotal:true
			}
		},
		
		onLoad(options){
		},
		onShow() {
			// #ifdef H5
			initJssdkShare(() => {
			  setWechatShare();
			}, window.location.href);
			// #endif
			this.selectedStatus = []
			this.selectedTxt = '提现状态'
			this.showTotal = true
			this.getWithdrawalList()
			
		},
		methods: {
			
			// 获取团队数据
			getWithdrawalList() {
				const status = this.selectedStatus.length === 0 || this.selectedStatus.includes('-1') 
				        ? [] 
				        : this.selectedStatus
				api.withdrawalList({
					userId: uni.getStorageSync('cffp_userId'),
					status: status
				}).then(res =>{
					if(res['message']=='ok'){
						this.dataObj = res.data
						if(this.dataObj.withdrawalVOList){
							this.dataObj.withdrawalVOList.forEach(item=>{
								if(item.exchangeDate){
									item.exchangeDate = dataHandling.dateFormat2(item.exchangeDate)
								}
								if(item.paidDate){
									item.paidDate = dataHandling.dateFormat2(item.paidDate)
								}
								
							})
						}
					}else {
						uni.showToast({
							title: res['message'],
							duration: 2000,
							icon: 'none'					
						})
					}
				})
			},
			
			goBack(){
				uni.navigateBack({
					delta: 1  
				});
			},
			// 获取状态显示文本
			    getStatusText(selectedItems) {
			      if (selectedItems.length === 0 || selectedItems.includes('-1')) {
			        return '全部'
			      }
			      return this.statusOptions
			        .filter(item => selectedItems.includes(item.value))
			        .map(item => item.label)
			        .join('、')
			    },
			    // 状态变化处理 确定按钮
			    handleStatusChange(status) {
				  this.selectedTxt = this.getStatusText(status)
			      this.selectedStatus = status
				  if(status.length==1&&status.includes('3')){
					  this.showTotal = false
				  }else{
					  this.showTotal = true
				  }
			      this.getWithdrawalList()
			    },
				gotoKefu(){
					// #ifdef MP-WEIXIN
					dataHandling.pocessTracking(
					  '咨询客服',
					  `用户咨询客服`,
					  '点击',
					  2,
					  '我的',
					  'pages/personalCenter/personalCenter'
					)
					uni.openCustomerServiceChat({
					  extInfo: {
						url: 'https://work.weixin.qq.com/kfid/kfc08c55f4170e7fc9e'
					  },
					  corpId: 'ww43cac1cf9dd6a3d0', // 客服会话按钮打开后，在微信客服会话按钮处理的事件类型
					  showMessageCard: true,
					  sendMessageTitle: (uni.getStorageSync('hoservice_mobileNo')?(uni.getStorageSync('hoservice_mobileNo')+"，") :"" ) + "进入个人中心-->咨询客服",
					  sendMessagePath: `/pages/index/mySelf.html`,
					  //sendMessageImg: cardItem.value['list'][0]['itemImg']
					});
					// #endif
					// #ifndef MP-WEIXIN
					dataHandling.pocessTracking(
					  '咨询客服',
					  `用户咨询客服`,
					  '点击',
					  2,
					  '我的',
					  'pages/personalCenter/personalCenter'
					)
					window.open('https://work.weixin.qq.com/kfid/kfc08c55f4170e7fc9e')
					// #endif
				}
		},
		
	}
</script>

<style lang="scss" scoped>
	.container{
		display: flex;
		flex-direction: column;
		.backArrow{
			box-sizing: border-box;
			display: flex;
			height: 100rpx;
			justify-content: space-between;
			align-items: center;
			position: relative;
			width: 100%;
			margin-bottom: 10rpx;
			text:nth-child(2){
				width: 100%;
				text-align: center;
				position: absolute;
			}
		}
		.content{
			flex: 1;
			display: flex;
			flex-direction: column;
			background-color: #fff;
			.totalBox{
				background-color: #fff;
				padding: 30rpx 20rpx;
				display: flex;
				justify-content: space-between;
				.left{
					.totalTxt{
						font-size: 30rpx;
						font-weight: 600;
						color: #383838;
					}
					.totalNum{
						font-size: 30rpx;
						color: #FF705D;
					}
					.des{
						color: rgba(187, 189, 193, 1);
						font-size: 26rpx;
						margin-top: 5rpx;
					}
				}
				.right{
					.filterTxt, .icon-shaixuan{
						font-size: 28rpx;
						color: #383838;
					}
					.filterTxt {
					    font-size: 28rpx;
					    color: #383838;
					    margin-right: 5rpx;
					    max-width: 300rpx;
					    overflow: hidden;
					    text-overflow: ellipsis;
					    white-space: nowrap;
					    display: inline-block;
					  }
					.icon-shaixuan{
						margin-left: 5rpx;
						font-size: 32rpx;
					}
				}
				
			}
			.recordBox{
				padding: 10rpx;
				box-sizing: border-box;
				.itemBox{
					box-sizing: border-box;
					width: 100%;
					padding: 20rpx;
					background-color: #fff;
					border-radius: 10rpx;
					display: flex;
					justify-content: flex-start;
					margin-top: 20rpx;
					box-shadow: 0rpx 12rpx 24rpx  rgba(12, 57, 193, 0.05);
					.left{
						width: 50rpx;
						margin-right: 10rpx;
						background: #F7F8F9;
						padding: 20rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						border-radius: 10rpx;
						.icon-zhifubao2{
							color: #00A1E8;
							font-size: 40rpx;
						}
						.icon-weixin{
							color: #41C740;
							font-size: 40rpx;
						}
					}
					.right{
						width: calc(100% - 50rpx);
						.top,.bottom{
							width: 100%;
							display: flex;
							align-items: center;
							justify-content: space-between;
						}
						.top{
							.tixian{
								font-size: 28rpx;
								color: #383838;
							}
							.money{
								font-size: 30rpx;
								color: #FF705D;
							}
						}
						.bottom{
							margin-top: 3rpx;
							.daozhang{
								color: rgba(187, 189, 193, 1);
								font-size: 26rpx;
								display: flex;
								align-items: center;
								.refuse-reason {
									width: 350rpx; /* 根据需要调整 */
									display: inline-block; /* 或者 block */
									overflow: hidden;
									text-overflow: ellipsis;
									white-space: nowrap !important;
									flex-shrink: 1; /* 允许缩小 */
								}
							}
							
							.pay{
								color: #2A36AD;
								font-size: 28rpx;
								flex-shrink: 0; /* 禁止缩小 */
							}
						}
					}
				}
				// .itemBox:last-child{
				// 	margin-top: 0rpx;
				// }
			}
			.empty{
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				color:#666;
				font-size: 28rpx;
				margin-top: 50rpx;
			}
			.btnBottom{
				width: 100%;
				padding-bottom: 40rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				.myBtn{
					background: rgba(32, 38, 155, 1);
					font-size: 30rpx;
					color: #fff;
					text-align: center;
					padding: 20rpx 100rpx;
					border-radius: 80rpx;
					
				}
				
			}
		}
		
	}
</style>