<template>
  <view>
    <view class="recharge_title">充值金额</view>
    <view>
      <view class="amount_area">
        <view
          class="amount string left"
          :class="amount == 5000 ? 'selected' : ''"
          @click="
            amount = 5000;
            other_amount = '';
          "
          >¥5000</view
        >
        <view
          class="amount string middle"
          :class="amount == 1000 ? 'selected' : ''"
          @click="
            amount = 1000;
            other_amount = '';
          "
          >¥1000</view
        >
        <view
          class="amount string"
          :class="amount == 800 ? 'selected' : ''"
          @click="
            amount = 800;
            other_amount = '';
          "
          >¥800</view
        >
      </view>
      <view class="amount_area">
        <view
          class="amount string left"
          :class="amount == 500 ? 'selected' : ''"
          @click="
            amount = 500;
            other_amount = '';
          "
          >¥500</view
        >
        <view
          class="amount string middle"
          :class="amount == 100 ? 'selected' : ''"
          @click="
            amount = 100;
            other_amount = '';
          "
          >¥100</view
        >
        <view class="amount">
          <input
            type="digit"
            placeholder="其它金额"
            class="other_amount"
            @click="amount = ''"
            v-model="other_amount"
          />
        </view>
      </view>

      <view class="confirm-btn">
        <button
          class="admin-button-com big blue"
          @click="wexinPayFn"
          formType="submit"
        >
          充值
        </button>
      </view>
    </view>
    <kd-entrance></kd-entrance>
  </view>
</template>
<script>
import AppWrapperEmpty from "@/components/app-wrapper-empty";
import { withdrawCashList } from "@/api/store";
import list from "@/mixins/list";
import wexinPay from "@/utils/pay/wxPay";
import { rechargeBalance } from "@/api/recharge";
export default {
  name: "recharge",
  components: {
    AppWrapperEmpty,
  },
  mixins: [list],
  data() {
    return {
      amount: "",
      other_amount: "",
    };
  },
  methods: {
    async init() {},
    // 微信支付
    wexinPayFn() {
      this._pay();
    },
    _pay() {
      if (this.other_amount > 0) {
        this.amount = this.other_amount;
      }
      if (!this.amount) {
        this.$msg("请选择充值金额");
        return false;
      }
      let params = { amount: this.amount };
      rechargeBalance(params).then((res) => {
        this.payCallData = res.data;
        if (res.code == 0) {
          this.$msg(res.msg);
          return false;
        }
        wexinPay(res.data, this.paySuccess, this.payFail);
      });
    },
    paySuccess() {
      this.$util.pageTo({
        url: "/pagesStore/me/rechargeSuccess",
        type: 2,
        query: {},
      });
    },
    payFail() {
    },
  },
  async onPullDownRefresh() {
    this.resetList();
    await this.init();
    uni.stopPullDownRefresh();
  },
  async onReachBottom() {
    if (!this.list.finished) {
      await this.init();
      uni.stopPullDownRefresh();
    } else {
      uni.stopPullDownRefresh();
    }
  },
};
</script>
<style lang="scss" scoped>
.recharge_title {
  font-weight: bold;
  font-size: 30rpx;
  margin: 30rpx 0 50rpx 0;
  padding: 0 0 0 28rpx;
}
.amount_area {
  display: block;
  width: 100%;
  height: 130rpx;
  margin: 35rpx 0 0 0;
  padding-left: 35rpx;
  .amount {
    border: 1rpx solid #f9f6ef;
    width: 23%;
    height: 120rpx;
    float: left;
    font-size: 25rpx;
    background-color: #f2f2f2;
    color: #666666;
    .other_amount {
      font-size: 25rpx;
      margin-top: 40rpx;
      text-align: center;
    }
  }
  .string {
    padding: 40rpx 0 0 45rpx;
  }
  .middle {
    margin: 0 90rpx 0 90rpx;
  }
  .selected {
    background-color: #0099ff;
    color: white;
  }
}
// 按钮
.confirm-btn {
  width: calc(100% - 60px);
  margin: 60px 30px 20px;
  .admin-button-com {
    width: 100%;
  }
}
</style>
