<template>
  <!-- #ifdef H5 -->
  <view>
    <zj-page-layout
      :isScroll="true"
      :refresherTriggered="refresherTriggered"
      @refresherrefresh="refresherrefresh"
      @scrolltolower="scrolltolower">
      <template slot="header">
        <view class="date-container" @tap="isShowDatePicker = true">
          <view class="box">
            <u-icon name="calendar" size="22"></u-icon>
            <view class="value" v-if="startDate">{{startDate}}</view>
            <view class="placeholder" v-else>开始时间</view>
            <view class="text">至</view>
            <view class="value" v-if="endDate">{{endDate}}</view>
            <view class="placeholder" v-else>结束时间</view>
          </view>
        </view>
      </template>

      <view class="list-container">
        <view class="item" v-for="(item, index) in dataList" :key="index" @tap="toDetail(item)">
          <view class="top">
            <view class="left">{{item.type | typeFilter}}</view>
            <view class="right" @tap.stop="toRecord(item)">查看明细<text class="iconfont icon-jinru"></text></view>
          </view>
          <view class="row">
            <view class="label">银行卡号</view>
            <view class="value">{{item.bankNo}}</view>
          </view>
          <view class="row">
            <view class="label">发放时间</view>
            <view class="value">{{item.grantTime}}</view>
          </view>
          <view class="row">
            <view class="label">提现金额</view>
            <view class="value">¥{{item.amount | priceFilter}}</view>
          </view>
          <view class="row">
            <view class="label">结算状态</view>
            <view class="value orange">{{item.status | statusFilter}}</view>
          </view>
        </view>
      </view>
      <Loading :loadStatus="loadStatus" :dataList="dataList" />

    </zj-page-layout>

    <zj-dialog-dateRangePicker v-model="isShowDatePicker" @confirm="confirmDate"></zj-dialog-dateRangePicker>

  </view>
  <!-- #endif -->

  <!-- #ifndef H5 -->
  <web-view :src="webViewHref(`/packageMine/pages/salesProfit/withdraw/list`, pam, crossPagePam)" @message="crossPage.$listener"></web-view>
  <!-- #endif -->
</template>

<script>
  // #ifdef H5
	import zjDialogDateRangePicker from '@/components/zj-dialog/zj-dialog-dateRangePicker.vue';

  export default {
		components: {
			zjDialogDateRangePicker,
		},

    filters: {
      statusFilter(val) {
        const MAP = {
          0: '待发放',
          1: '已发放',
        }
        return MAP[val];
      },
      typeFilter(val) {
        const MAP = {
          1: '销售提现',
          2: '服务提现',
        }
        return MAP[val];
      },
    },

    data() {
      return {
				dataList: [],
				pageNum: 1,
				loadStatus: 0,
        refresherTriggered: false,
        isShowDatePicker: false,
        startDate: '',
        endDate: '',
      }
    },

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

    methods: {
      getList() {
      	this.loadStatus = 1;
      	this.$api.post('/withdrawal/list', {
          pageNum: this.pageNum,
          pageSize: 10,
          startTime: this.startDate ? this.startDate + ' 00:00:00' : '',
          endTime: this.endDate ? this.endDate + ' 23:59:59' : '',
      	}).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;
      	})
      },

      changeTab(e) {
      	this.tabCurrent = e.index;
      	this.status = e.value;
        this.refreshList();
      },

      changeSalesType(e) {
        this.salesTypeCurrent = e.index;
        this.salesType = e.value;
        this.refreshList();
      },

      // 选择日期
      confirmDate(item) {
      	let [start, end] = item;
      	if (start == '' || end == '') {
      		this.startDate = '';
      		this.endDate = '';
      		return;
      	}
      	this.startDate = start;
      	this.endDate = end;

      	this.refreshList();
      },

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

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

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

      toDetail(item) {
        this.$navToPage({
          url: `/packageMine/pages/salesProfit/withdraw/detail?id=${item.id}`
        })
      },

      toRecord(item) {
        this.$navToPage({
          url: `/packageMine/pages/salesProfit/withdraw/orderList?id=${item.id}`
        })
      }
    },
  }

  // #endif
  // #ifndef H5
  export default {
    data() {
      return {
        pam: {},
      }
    },
    onLoad(pam) {
      this.pam = pam;
    }
  }
  // #endif
</script>

<style lang="scss" scoped>
.date-container {
  background: #FFFFFF;
  padding: 0 20rpx 20rpx;
  .box {
    padding-left: 20rpx;
    border: 1px solid #eaeaea;
    border-radius: 8rpx;
    display: flex;
    align-items: center;
    height: 60rpx;
    .placeholder {
      flex: 1;
      text-align: center;
      font-size: 28rpx;
      color: $sec-font;
    }
    .value {
      flex: 1;
      text-align: center;
      font-size: 28rpx;
    }
    .text {
      font-size: 28rpx;
    }
  }
}

.list-container {
  padding: 0 20rpx;
  .item {
    @include zj-card;
    margin-top: 20rpx;
    padding: 30rpx;
    .top  {
      display: flex;
      align-items: center;
      justify-content: space-between;
      .left {
        font-weight: 500;
      }
      .right {
        color: $sec-font;
        font-size: 28rpx;
        .iconfont {
          font-size: 28rpx;
        }
      }
    }
    .row {
      display: flex;
      align-items: center;
      margin-top: 20rpx;
      &:first-child {
        margin-top: 0;
      }
      .label {
        font-size: 28rpx;
        color: $sec-font;
        margin-right: 20rpx;
      }
      .value {
        flex: 1;
        font-size: 28rpx;
        text {
          color: $minor-color;
        }
      }
      .status {
        margin-left: 30rpx;
        font-size: 28rpx;
      }
      .blue {
        color: $theme-color;
      }
      .green {
        color: $success-color;
      }
      .orange {
        color: $assist-color;
      }
    }
  }
}
</style>
