<template>
  <!-- #ifdef H5 -->
  <zj-page-layout
    :hasFooter="false"
    :isScroll="true"
    :refresherTriggered="refresherTriggered"
    @refresherrefresh="refresherrefresh"
    @scrolltolower="scrolltolower">
    <view class="list-container">
      <block v-for="(item, index) in dataList" :key='index'>
        <view class="item" @tap="toDetail(item)">
          <view class="left">
            <view class="row">订单编号：{{item.orderId}}</view>
						<view class="row">订单类型：{{ ["商城分销订单", "延保分销订单"][item.flag - 1] }}</view>
            <view class="row">订单金额：¥{{item.payment | numToFixed}}</view>
            <view class="row">支付时间：{{item.payTime}}</view>
          </view>
          <view class="right">
            <view class="state wait" v-if="item.status == 'ING'">待结算</view>
            <view class="state over" v-if="item.status == 'OVER'">已结算</view>
            <view class="state cancel" v-if="item.status == 'CANCEL'">已取消</view>
            <view class="price" v-if="item.status !== 'CANCEL'">+{{item.amount | numToFixed}}</view>
            <view class="price" v-else></view>
          </view>
        </view>
      </block>
    </view>
    <Loading :loadStatus="loadStatus" :dataList="dataList" />
  </zj-page-layout>
  <!-- #endif -->
  <!-- #ifndef H5 -->
  <web-view :src="webViewHref(`/packageMine/pages/profit/return`, pam,crossPagePam)" @message="crossPage.$listener"></web-view>
  <!-- #endif -->
</template>

<script>
  // #ifdef H5
	export default {
		data() {
			return {
				dataList: [], // 收益列表
				pageNum: 1,
        loadStatus: 0,
        refresherTriggered: false,
			}
		},

		onLoad() {
			this.getList();
		},

		methods: {
			// 获取列表
			getList() {
				this.$api.get('/user/profit/list', {
          pageNum: this.pageNum,
          pageSize: 10,
          userId: this.$store.state.user.userId,
          status: 'CANCEL'
				}).then(res => {
					this.loadStatus = 0;
					let list = res.data.records;
					if (list.length < 10) {
					  this.loadStatus = 2;
					}
					this.dataList = this.dataList.concat(list);
				}).catch(() => {
          this.loadStatus = 2;
        }).finally(res => {
          this.refresherTriggered = false;
        })
			},

      // 滚动到底部
      scrolltolower(e) {
        if (this.loadStatus === 0) {
          this.pageNum++;
          this.getList();
        }
      },

      // 触发下拉刷新
      refresherrefresh(e) {
        this.refresherTriggered = true;
        this.refreshList();
      },

      refreshList() {
        this.dataList = [];
        this.pageNum = 1;
        this.getList();
      },

			toDetail(item) {
				this.$navToPage({
					url: [
            '/packageMine/pages/profit/detail?orderId=' + item.orderId + '&orderRefundId=' + item.orderRefundId,
            '/packageMine/pages/profit/ybdetail?orderId=' + item.orderId + '&orderRefundId=' + item.orderRefundId
          ][item.flag - 1]
				})
			},
		}
	}
  // #endif
  // #ifndef H5
  export default {
    data() {
      return {
        pam: {},
      }
    },

    onLoad(pam) {
      this.pam = pam;
    },
  }
  // #endif
</script>

<style lang="scss">
	.list-container {
		padding: 20rpx;
		.item {
			display: flex;
			justify-content: space-between;
			margin-bottom: 20rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 20rpx;
			.left {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.row {
					font-size: 28rpx;
					color: #666666;
          margin-top: 12rpx;
          &:first-child {
            margin-top: 0;
          }
				}
			}
			.right {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				align-items: flex-end;
				.state {
					font-size: 28rpx;
					&.wait {
						color: #FE781F;
					}
					&.over {
						color: #3F9EFF;
					}
					&.cancel {
						color: #999999;
					}
				}
				.price {
					font-size: 32rpx;
					color: #333333;
				}
			}
		}
	}
</style>
