<template>
  <div class="cmain">
    <div class="bos">
      <el-steps :active="1" align-center class="cg">
        <el-step title="提现信息"></el-step>
        <el-step title="平台确认"></el-step>
        <el-step title="提现到账"></el-step>
      </el-steps>
      <el-form ref="company" :model="company" label-width="100px">
        <el-form-item label="开户行">
          <el-input v-model="company.bankName" disabled />
        </el-form-item>
        <el-form-item label="银行账户">
          <el-input v-model="company.bankAccount" disabled />
        </el-form-item>
      </el-form>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="提现金额" prop="money">
          <el-input type="number" v-model="form.money" placeholder="请输入充值金额" clearable>
            <template slot="append">账户余额：{{ company.money }}</template>
          </el-input>
        </el-form-item>
        <el-form-item label="手机号码">
          <el-input type="number" v-model="company.phone" disabled>
            <template slot="append">
              <span @click="getCode()" class="yzm">{{ msg }}</span>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item label="短信验证码" prop="code">
          <el-input type="number" v-model="form.code" />
        </el-form-item>
      </el-form>
    </div>
    <div class="mfooter">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="$layer.close(layerid)">取 消</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      msg: '获取验证码',
      time: 60,
      flag: true,
      company: {},
      form: {},
      rules: {
        money: [{ required: true, message: '提现金额不能为空', trigger: 'blur' }],
        code: [{ required: true, message: '验证码不能为空', trigger: 'blur' }]
      }
    };
  },
  props: {
    param: {
      type: Object,
      default: () => {
        return {};
      }
    },
    layerid: {
      type: String
    }
  },
  mounted() {
    this.ajax({ url: '/work/company/index' }).then((response) => {
      this.company = response.data;
    });
    if (this.param.id) {
      this.ajax({ url: '/work/out/detail/' + this.param.id }).then((response) => {
        this.form = response.data;
      });
    }
  },
  methods: {
    getCode() {
      if (!this.flag) {
        return;
      }
      this.$modal.msgSuccess('你的验证码是123456');
      //一分钟倒计时
      var countdown = setInterval(() => {
        this.time--;
        if (this.time == 0) {
          this.flag = true;
          this.msg = '获取短信';
          this.time = 60;
          clearInterval(countdown);
        } else {
          this.flag = false;
          this.msg = '重新获取(' + this.time + ')';
        }
      }, 1000);
    },
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.ajax({ method: 'post', url: '/work/out/add', data: this.form }).then((response) => {
            this.$modal.msgSuccess('申请成功');
            this.$layer.close(this.layerid);
            this.$parent.getList();
          });
        }
      });
    }
  }
};
</script>
