<template>
  <BasePage>
    <div class="transfer">
      <div class="top">
        <div class="tit">
          被赠送人账号
        </div>
        <input v-model="cellphone" type="text" maxlength="11" @blur="checkExists" placeholder="请输入被赠送人手机号">
        <hr>
        <span class="errorinfo">{{ errorInfo }}</span>
      </div>

      <!-- <div class="type_box">
        <div class="title">
          <b>互转类型</b>
        </div>

        <van-radio-group v-model="checked" icon-size="3.47vw" checked-color="#22a56e">
          <van-radio name="balance" label-position="left">
            <img src="/img/balance-i1.png" alt="">
            <p>
              转余额
              <span>（剩余：265444.00）</span>
            </p>
          </van-radio>
          <van-radio name="2" label-position="left">
            <img src="/img/balance-i1.png" alt="">
            <p>
              转余额 
              <span>（剩余：265444.00）</span>
            </p>
          </van-radio>
        </van-radio-group>

      </div> -->

      <div class="quota_box">
        <div class="title">
          <b>赠送金额</b>
          <span class="r" @click="showTerm = true">
            <van-icon name="info-o" />
            赠送说明
          </span>
        </div>
        <!-- <input v-model="amount" type="number" placeholder="请输入转账数额"> -->
        <b class="nums">500.00</b>
        <hr>
      </div>

      <div class="com_btn">
        <van-button type="primary" color="#ea3e23" round @click="toTransfer">确认赠送</van-button>
      </div>
    </div>
  </BasePage>

  <van-action-sheet v-model:show="showTerm" safe-area-inset-bottom :title="`${this.$route.meta.title}说明`" closeable
    style="min-height: 50%; padding: 0px 10px 10px 10px">
    <div class="w100 html" v-html="$datadic.getContent('code_hykzssm')" />
  </van-action-sheet>
</template>

<script>
export default {
  name: 'WalletTransfer',
  mounted() {
    this.me = this.$ls.get('cellphone');
    // $(".van-stepper__input").val("");
    // this.me = window.localStorage.getItem("member_username");
    // Promise.all([this.$MemberAPI.Post('GetWallet')])
    //   .then(data => {
    //     this.wallet = data[0];

    //   }).catch(err => {
    //     this.$showFailToast("获取钱包信息失败:" + err.message);
    //   });
  },
  // watch: {
  //     password(val, old) {
  //         if (val.length === 6) {
  //             this.showKeyboard = false;
  //             this.data.PayPassword = val;
  //             this.$MemberAPI.Post('WalletTransfer', {
  //                 TransferType: 'Balance',
  //                 Member: this.data.id,
  //                 Amount: this.data.Amount,
  //             }).then((data) => {
  //                 this.$showToast({ type: "success", message: "兑换积分转出成功" });
  //                 setTimeout(() => {
  //                     window.location.reload();
  //                 }, 500);
  //             })
  //                 .catch((error) => {
  //                     this.$showToast({
  //                         type: "fail",
  //                         message: "兑换积分转出失败：" + error,
  //                     });
  //                     this.errorInfo = "密码错误";
  //                     this.showKeyboard = true;
  //                     setTimeout(() => {
  //                         this.password = "";
  //                     }, 500);
  //                 });
  //         }
  //     },
  // },
  data() {
    return {
      amount: 500.00,
      checked: 'balance',
      checkedCH: "余额",
      showTerm: false,
      left: 0,
      loading: false,
      toUser: { NickName: null },
      error: false,
      // password: "",
      // show: false,
      // showKeyboard: false,
      data: {},
      wallet: {},
      errorInfo: "",
      me: "",
      cellphone: "",
      showmeerror: false,
      amount: null,
    };
  },
  methods: {
    checkExists() {
      // if (!this.userName) {
      //   this.error = false;
      //   this.showmeerror = false;
      //   return;
      // }
      this.errorInfo = "";
      if (this.cellphone.length < 11) {
        this.errorInfo = "请输入11位手机号";
        this.error = true;
        return;
      }
      if (this.cellphone === this.me) {
        this.errorInfo = "无法转账给自己!";
        this.error = true;
        return;
      }

      this.$get('/v1/client/DUsersClient/check', { cellphone: this.cellphone }).then((data) => {
        // this.toUser = data;
        // this.error = !data.id;
        // console.log(data);

        if (data.status === 404) {
          this.errorInfo = "此账号不存在，无法转账，请重新输入！";
          this.error = true;
        } else {
          this.errorInfo = "";
          this.error = false;
        }

      }).catch(err => {
        this.errorInfo = err.message;
        this.error = true;
        this.$showFailToast(err.message)
      })
    },
    toMoney(val) {
      return numberConverter.formatNum(val, 0, "+", 2);
    },
    toTransfer() {
      setTimeout(() => {
        if (this.error) {
          this.$showFailToast("请先修正错误信息");
          return;
        }

        this.$showConfirmDialog({
          title: '确认赠送？',
        }).then(() => {
          this.$post('/v1/client/DUserxiaofeiquansClient', {
            "cellphone": this.cellphone,
            "amount": 500,
          }).then(data => {
            if (data.status === 200) {
              this.$showSuccessToast('赠卡成功！')
              this.$navigate('CertificateRecord')
            }
          }).catch(err => {
            this.$showFailToast(err.message);
          })
        })
      }, 500);


    },
  },
};
</script>
