<template>
<view id="cashRecord">
    <view class="isList" v-if="dataList&&dataList[0]&& !dataList[0].length  && init">
        暂无提现记录!!!
    </view>
    <view v-for="(items, idx) in dataList" :key="idx">
        <view class="cashRecord-item" v-for="(item, index) in dataList[idx]" :key="index">
            <view class="record-area record-title">
                <span class="recordnum">提现工单号:{{item.cash_no}}</span>
                <span class="recordtxt">{{statusList[item.status]}}</span>
            </view>
            <view class="record-area record-count">
                <span class="recorddate">{{item.created_at}}</span>
                <span class="recordmon">-￥{{item.amount/100}}</span>
            </view>
        </view>
    </view>

</view>
</template>
<script>
import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';

export default {
  data() {
    return {
      dataList: [],
      meta: '',
      page: 1,
      init: false,
      statusList: ["待审核", "待打款", "已打款", "提现申请已拒绝"],
      show: false
    };
  },

  onReachBottom() {
    var hasMore = this.meta.pagination.total_pages > this.meta.pagination.current_page;

    if (hasMore) {
      this.setData({
        show: true
      });
      var page = this.meta.pagination.current_page + 1;
      this.getRecordList(page);
    } else {
      wx.showToast({
        image: '../../../static/error.png',
        title: '再拉也没有啦'
      });
    }
  },

  onLoad(e) {
    this.getRecordList(1);
  },

  components: {},
  props: {},
  methods: {
    //获取数据提现记录列表
    getRecordList(page = 1) {
      var token = this.$cookieStorage.get('user_token');
      this.$http.get({
        api: 'api/distribution/cash/list',
        header: {
          Authorization: token
        },
        data: {
          page: page
        }
      }).then(res => {
        if (res.statusCode == 200) {
          res = res.data;

          if (res.status) {
            this.setData({
              [`dataList.${page - 1}`]: res.data,
              meta: res.meta,
              init: true
            });
          }
        } else {
          wx.showModal({
            content: '请求失败，请稍后重试',
            showCancel: false
          });
        }
      });
    },

    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  },
  computed: {},
  watch: {}
};
</script>
<style rel="stylesheet/less" lang="less">
    @import "cashRecord";
</style>