<template>
  <section class="screen wallet-list">
    <flat-list
      @fetch="fetch"
      ref="list"
      :security-size="20"
    >

      <template v-slot:item="{item,index}">
        <layout-wallet
          :key="'layout-wallet-'+index"
          :item="item"
        ></layout-wallet>
      </template>

    </flat-list>
  </section>

</template>

<script>
import {
  FlatList
} from '$components';
import props from '../props';
import layoutWallet from '$layout/layout-wallet';
import { DateFormat } from '$utils/tool/date';
import {FlatListReload} from "$components/flat-list/const";
export default {
  name: "wallet-list",
  components:{
    FlatList,
    layoutWallet
  },

  watch:{

    '$store.getters.money':function (newValue,oldValue) {
      let diff = newValue - oldValue;
      if (diff === 0) return;
      let updateOtherType = diff >= 0 ? '1':'2';
      if ((this.type === '0' || this.type === updateOtherType ) && this.moneyType === '1') {
        return this.$refs.list && this.$refs.list.reload(FlatListReload.reload);
      }
    },

    '$store.getters.integral':function (newValue,oldValue) {
      let diff = newValue - oldValue;
      if (diff === 0) return;
      let updateOtherType = diff >= 0 ? '1':'2';
      if ((this.type === '0' || this.type === updateOtherType ) && this.moneyType === '2') {
        return this.$refs.list && this.$refs.list.reload(FlatListReload.reload);
      }
    },


  },

  methods:{
    fetch(obj){
      return this.$request({
        url:'hxuser/get_wallet_log_list',
        data:{
          money_type: this.moneyType,
          change_type: this.type
        },
        page:obj.data,
        token:true
      }).then((data)=>{
        return obj.success((data.data || []).map((item)=>{

          item.change_value = item.change_value.toString();
          if (parseFloat(item.change_value) > 0 && item.change_value.indexOf('+') < 0) {
            item.change_value ='+'+item.change_value;
          }

          item.add_time_format = DateFormat(item.add_time,'YYYY-MM-DD hh:mm')
          return item;
        }));
      }).catch(obj.fail);
    }
  },

  props
}
</script>

<style scoped lang="scss" src="../style.scss"></style>