<template>
  <div class="cmain">
    <div class="bos">
      <el-form ref="user" disabled :model="user" label-width="120px">
        <el-form-item label="用户姓名">
          <span class="pon" @click="info()">{{ user.name }}</span>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="user.phone" />
        </el-form-item>
        <el-form-item label="提现方式">
          <el-input :value="form.way == 0 ? '提现到银行卡' : '提现到微信'" />
        </el-form-item>
        <div v-if="form.way == 0">
          <el-form-item label="开户行">
            <el-input v-model="user.bankName" />
          </el-form-item>
          <el-form-item label="银行卡号">
            <el-input v-model="user.bankAccount" />
          </el-form-item>
        </div>
      </el-form>
      <el-form ref="form" disabled :model="form" :rules="rules" label-width="120px">
        <el-form-item label="提现金额(元)" prop="money">
          <el-input type="number" v-model="form.money" />
        </el-form-item>
        <el-form-item label="手续费(元)">
          <el-input v-model="form.serviceMoney" />
        </el-form-item>
        <el-form-item label="提现费率(%)">
          <el-input v-model="form.rate" />
        </el-form-item>
        <el-form-item label="实际到账(元)">
          <el-input :value="(form.money - form.serviceMoney).toFixed(2)" />
        </el-form-item>
        <div class="opp" v-if="form.updateTime">
          <span>操作人：{{ form.updateBy }}，</span>
          <span>操作时间：{{ form.updateTime }}</span>
        </div>
      </el-form>
      <el-alert title="提现成功" type="success" show-icon class="cg" v-if="form.state === 1"></el-alert>
      <el-alert title="提现驳回,已退款到用户余额" :description="form.msg" type="error" show-icon class="cg" v-if="form.state === 2" :closable="false"></el-alert>
    </div>
    <div class="mfooter" v-if="!param.detail">
      <el-button type="primary" @click="submitForm(1)">确认转账</el-button>
      <el-button type="danger" @click="submitForm(2)">不通过(退款)</el-button>
      <el-button @click="$layer.close(layerid)">取 消</el-button>
    </div>
  </div>
</template>

<script>
import info from '@/views/work/user/edit';
export default {
  data() {
    return {
      user: {},
      form: {},
      rules: {}
    };
  },
  props: {
    param: {
      type: Object,
      default: () => {
        return {};
      }
    },
    layerid: {
      type: String
    }
  },
  mounted() {
    if (this.param.id) {
      this.ajax({ url: '/work/pay/detail/' + this.param.id }).then((response) => {
        this.form = response.data.pay;
        this.user = response.data.user;
      });
    }
  },
  methods: {
    info() {
      this.iframe({ obj: info, param: { id: this.user.id, detail: true }, title: '用户详情', width: '55%', height: '65%' });
    },
    submitForm(state) {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.$prompt(state == 1 ? '确认已转账到 ' + this.user.bankAccount + ' 银行账户? 该操作不可撤销！' : '确认驳回提现(退款)', {
            type: 'warning',
            showInput: state == 1 ? false : true,
            inputType: 'textarea',
            inputPlaceholder: '提现不通过原因',
            inputValidator: (value) => {
              if (!value && state == 2) {
                return '请输入驳回原因';
              }
            }
          }).then(({ value }) => {
            this.post({ url: '/work/pay/audit', data: { id: this.form.id, state: state, msg: value } }).then((response) => {
              this.$modal.msgSuccess('操作成功');
              this.$layer.close(this.layerid);
              this.$parent.getList();
            });
          });
        }
      });
    }
  }
};
</script>
