<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 :class="'primary-color'">
				        {{ 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 userInfo = uni.getStorageSync('userInfo')
			if (!userInfo) {
				console.log('havent userInfo')
				uni.showModal({
					content: '艺术家账户过期,请重新登录！',
					showCancel: false,
					success() {
						//没有缓存则跳转登录页面
						uni.reLaunch({
							url: '/pages/login/login'
						});
					}
				});
			} else {
				this.userInfo = userInfo;
				console.log('have userInfo')
			}
			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() {
				let that = this;
				const res = await getWithdrawList({
					pageSize: that.pageSize,
					pageNum: that.pageNum,
					creatorId: that.userInfo.id
				})
				console.log('res', res)
				if (res.data.code === 200) {
					that.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" scoped>
.container {
  width: 670rpx;
  margin: 20rpx auto;

  ::v-deep .uni-list {
    background: $uni-bg-base-color !important;
    margin-bottom: 20rpx;
    border-radius: 24rpx;
    overflow: hidden;
  }

  ::v-deep .uni-list-item {
    background: $uni-bg-base-color !important;
  }

  ::v-deep .uni-list--border-top {
    display: none !important;
  }
  ::v-deep .uni-list--border-bottom {
    display: none !important;
  }

  ::v-deep .uni-list-item__content-title {
    color: $uni-white !important;
  }

  ::v-deep .uni-list-item__content-note {
    color: $uni-secondary-color !important;
  }

}
.box {
  display: flex;
  padding-right: 16rpx;
  flex: 1;
  color: $uni-secondary-color;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;

  .primary-color {
    color: $uni-primary;
  }
}
.box-bot {
  display: flex;
  margin-top: 10rpx;
}
.box-bot view {
  border-radius: 6rpx;
  color: $uni-secondary-color;
  border: 2rpx solid $uni-primary;
  padding: 4rpx 10rpx;
  margin-right: 10rpx;
  font-size: 24rpx;
}

</style>
