<template>
  <div class="mod-seckill-shopWalletLog">
    <div class="trading-record">
      <div class="blue"></div>
      <span class="record-txt">店铺余额</span>
    </div>

    <!-- 店铺余额栏 -->
    <div class="balance-wrapper">
      <div class="balance-item">
        <div class="balance-item-title">
          <span class="title-tips">可用店铺余额(元)</span>
          <el-tooltip
            class="item"
            effect="dark"
            content="用户确认收货后，增加可用店铺余额，可用于店铺提现"
            placement="right"
          >
            <i class="el-icon-question"></i>
          </el-tooltip>
        </div>
        <div class="balance-show">
          <span class="balance-num">{{shopWallet.settledAmount}}</span>
          <!-- <span class="stress-btn">充值</span> -->
          <span class="weak-btn" @click="applyWithdrawCash">提现</span>
        </div>
      </div>

      <div class="balance-item">
        <div class="balance-item-title">
          <span class="title-tips">待结算(元)</span>
          <el-tooltip
            class="item"
            effect="dark"
            content="用户购买商品之后，等待用户确认收货，将会变成可用店铺余额"
            placement="right"
          >
            <i class="el-icon-question"></i>
          </el-tooltip>
        </div>
        <div class="balance-show">
          <span class="balance-num">{{shopWallet.unsettledAmount}}</span>
        </div>
      </div>

      <div class="balance-item">
        <div class="balance-item-title">
          <span class="title-tips">不可用余额(元)</span>
          <el-tooltip
            class="item"
            effect="dark"
            content="商城进行提现申请的时候，将会把余额冻结，增加不可用余额"
            placement="right"
          >
            <i class="el-icon-question"></i>
          </el-tooltip>
        </div>
        <div class="balance-show">
          <span class="balance-num">{{shopWallet.freezeAmount}}</span>
        </div>
      </div>

      <div class="balance-item">
        <div class="balance-item-title">
          <span class="title-tips">总结算金额(元)</span>
          <el-tooltip
            class="item"
            effect="dark"
            content="用户确认收货的所有金额，当用户发生退款的时候，总结算金额会减少"
            placement="right"
          >
            <i class="el-icon-question"></i>
          </el-tooltip>
        </div>
        <div class="balance-show">
          <span class="balance-num">{{shopWallet.totalSettledAmount}}</span>
        </div>
      </div>
    </div>

    <div class="trading-record clearfix">
      <div class="blue"></div>
      <span class="record-txt">最近交易记录</span>
      <!-- <span class="all-record blue-font">全部交易记录</span> -->
    </div>
    <avue-crud
      ref="crud"
      :page="page"
      :data="dataList"
      :table-loading="dataListLoading"
      :option="tableOption"
      @search-change="searchChange"
      @on-load="getDataList"
      @refresh-change="refreshChange"
    ></avue-crud>

    <cashWithdrawal v-if="isCashWithdrawal" ref="cashWithdrawal" @refreshDataList="refreshChange"></cashWithdrawal>
  </div>
</template>

<script>
import { tableOption } from '@/crud/shop/shopWalletLog'
import cashWithdrawal from './cashWithdrawal'
export default {
  data () {
    return {
      dataList: [],
      shopWallet: {},
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      searchForm: {}, // 搜索
      dataListLoading: false,
      tableOption: tableOption,
      isCashWithdrawal: false  // 提现弹框
    }
  },
  components: {
    cashWithdrawal
  },
  created () {
    this.getShopWalletInfo()
  },
  methods: {
    getShopWalletInfo () {
      this.$http({
        url: this.$http.adornUrl('/shop/shopWallet/info'),
        method: 'get',
        params: this.$http.adornParams()
      }).then(({ data }) => {
        this.shopWallet = data
      })
    },
    getDataList (page) {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/shop/shopWalletLog/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign(
            {
              current: page == null ? this.page.currentPage : page.currentPage,
              size: page == null ? this.page.pageSize : page.pageSize
            },
            this.searchForm
          )
        )
      }).then(({ data }) => {
        this.dataList = data.records
        this.page.total = data.total
        this.dataListLoading = false
      })
    },
    /**
     * 刷新回调
     */
    refreshChange () {
      this.isCashWithdrawal = false
      this.page = this.$refs.crud.$refs.tablePage.defaultPage
      this.getDataList(this.page)
    },
    searchChange (params) {
      this.searchForm = params
      this.getDataList(this.page)
    },
    // 提现
    applyWithdrawCash () {
      console.log(this.isCashWithdrawal)
      this.isCashWithdrawal = !this.isCashWithdrawal
      console.log(this.isCashWithdrawal)
      this.$nextTick(() => {
        this.$refs.cashWithdrawal.init()
      })
    }
  }
}
</script>
<style lang="scss">
.mod-seckill-shopWalletLog {
  .trading-record {
    display: block;
    background: #f7f8fa;
    margin: 10px 0;
    padding: 10px 20px;
  }
  .all-record {
    float: right;
  }
  .record-txt {
    vertical-align: middle;
    font-weight: bold;
  }
  .blue {
    display: inline-block;
    width: 3px;
    height: 1em;
    background: #02a1e9;
    vertical-align: middle;
    margin-right: 2px;
  }
  .balance-wrapper {
    display: flex;
    background: #f5f5f5;
    padding: 30px 30px;
    margin-bottom: 20px;
    justify-content: space-between;
  }
  .balance-item {
    display: inline-block;
  }
  .balance-item-title {
    padding-bottom: 25px;
  }
  .title-tips {
    vertical-align: middle;
  }
  .blue-font {
    color: #02a1e9;
    padding-left: 5px;
    cursor: pointer;
    vertical-align: middle;
  }
  .balance-show {
    text-align: left;
  }
  .balance-num {
    font-size: 28px;
    vertical-align: middle;
    margin-right: 30px;
  }
  .stress-btn,
  .weak-btn {
    font-size: 15px;
    padding: 6px 15px;
    border-radius: 3px;
    vertical-align: middle;
    border: 1px solid #02a1e9;
    cursor: pointer;
  }
  .stress-btn {
    color: #fff;
    background: #02a1e9;
    margin-right: 10px;
  }
  .weak-btn {
    color: #02a1e9;
  }
  .clearfix::after {
    display: block;
    content: "";
    visibility: hidden;
    height: 0;
    clear: both;
  }
}
</style>

