<template>
	<view class="container">
		<uni-list 
		border-full 
		v-for="(item,index) in withdrawList" :key="index"
		>
			<uni-list-item 
			showArrow 
			clickable 
			:title="'订单号:'+item.orderId"
			:note="item.createTime+'&'+item.channel+'&'+item.status" 
			:rightText="'￥'+item.amt"
				@click="targetToDetail(item.orderId)">
				<template v-slot:body>
				  <view class="box">
				    <view class="uni-list-item__content-title">{{
				      item.createTime 
				    }}</view>
				    <view class="box-bot">
				      <view>
				        {{ setChannel(item.channel) }}
				      </view>
				      <view style="color: #4d6aff">
				        {{ setStatus(item.status)}}
				      </view>
				    </view>
				  </view>
				</template>
				</uni-list-item>
		</uni-list>
		<view class="ivOver" v-if="flag">-----已经到底啦-----</view>
	</view>
</template>

<script>
	import {
		getWithdrawList
	} from '@/api/userInfo.js'
	export default {
		data() {
			return {
				withdrawList: [],
				pageSize: 10,
				pageNum: 1,
				userInfo: {},
				flag: false
			}
		},
		created() {
			const userInfoSync = uni.getStorageSync('userInfo')
			this.userInfo = userInfoSync
			this.getWithdrawList();
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.pageNum = 1
			this.withdrawList = []
			this.getWithdrawList()
			uni.stopPullDownRefresh()
		},
		// 上划加载更多
		onReachBottom() {
			if (this.withdrawList.length > this.pageSize*this.pageNum-1) {
				this.flag = false;
				this.pageNum += 1
				this.getWithdrawList();
			}else{
				this.flag = true;
			}
		},
		methods: {
			// 查询提现记录列表
			async getWithdrawList() {
				const res = await getWithdrawList({
					pageSize: this.pageSize,
					pageNum: this.pageNum,
					creatorId: this.userInfo.id
				})
				console.log('res', res)
				if (res.data.code === 200) {
					this.withdrawList.push(...res.data.rows)
				} else {
					uni.showModal({
						content: '提现记录列表数据加载失败！',
						showCancel: false
					});
				}
			},

			targetToDetail(orderId) {
				console.log('orderId', orderId)
				if (orderId) {
					uni.navigateTo({
						url: 'withdrawDetail?orderId=' + orderId,
					});
				}
			},
			setChannel(data){
				if (data == "0") {
				  return "微信";
				} else if (data == "1") {
				  return "银行卡";
				} else if (data == "2") {
				  return "支付宝";
				}
			},
			setStatus(data){
				if (data == "0") {
				  return "待审核";
				} else if (data == "1") {
				  return "提现中";
				} else if (data == "2") {
				  return "提现成功";
				} else if(data == "3"){
				  return "提现失败";
				}else if(data == "4"){
				  return "审核拒绝";
				}
			}
		}
	}
</script>

<style lang="scss">
	.uni-list-item__icon-img {
	  border-radius: 8px;
	}
	.ivOver{
		width: 100%;
		height:50px;
		line-height: 50px;
		text-align: center;
		background: #fff;
		font-size: 20rpx;
	}
	.box {
	  display: flex;
	  padding-right: 8px;
	  flex: 1;
	  color: #3b4144;
	  flex-direction: column;
	  justify-content: center;
	  overflow: hidden;
	}
	.box-bot {
	  display: flex;
	  margin-top: 5px;
	}
	.box-bot view {
	  border-radius: 3px;
	  border: 1px solid #4d6aff;
	  padding: 2px 5px;
	  margin-right: 5px;
	  font-size: 12px;
	}
	.uni-list-item__content-title {
	  font-size: 14px;
	  color: #3b4144;
	  overflow: hidden;
	}
</style>
