<template>
  <div class="cmain">
    <div class="bos">
      <div class="lab">
        <div class="bsg"></div>
        <div class="tit">提现账户信息</div>
      </div>
      <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" disabled>
            <template slot="append">账户余额：{{ company.money }}</template>
          </el-input>
        </el-form-item>
      </el-form>
      <el-form-item label="申请人">
        <el-input v-model="company.bankAccount" disabled />
      </el-form-item>
    </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>
export default {
  data() {
    return {
      company: {},
      form: {},
      rules: {
        money: [{ required: true, message: '提现金额不能为空', trigger: 'blur' }]
      }
    };
  },
  props: {
    param: {
      type: Object,
      default: () => {
        return {};
      }
    },
    layerid: {
      type: String
    }
  },
  mounted() {
    if (this.param.id) {
      this.ajax({ url: '/work/out/detail/' + this.param.id }).then((response) => {
        this.form = response.data;
        this.company = response.data.company;
      });
    }
  },
  methods: {
    submitForm(state) {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.$prompt(state == 1 ? '确认提现' + this.form.money + '元到 ' + this.company.companyName + ' 银行账户? 该操作不可撤销！' : '确认无效提现', {
            type: 'warning',
            showInput: state == 1 ? false : true,
            inputType: 'textarea',
            inputPlaceholder: '无效原因',
            inputValidator: (value) => {
              if (!value && state == 2) {
                return '请输入无效原因';
              }
            }
          }).then(({ value }) => {
            this.post({ url: '/work/out/edit', data: { id: this.form.id, state: state, msg: value } }).then((response) => {
              this.$modal.msgSuccess('操作成功');
              this.$layer.close(this.layerid);
              this.$parent.getList();
            });
          });
        }
      });
    }
  }
};
</script>
