<template>
  <div class="cmain">
    <div class="bos">
      <el-form ref="platform" disabled :model="platform" label-width="120px">
        <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-item label="服务公司名称">
          <el-input v-model="platform.serviceCompany" />
        </el-form-item>
        <el-form-item label="开户行">
          <el-input v-model="platform.bankName" />
        </el-form-item>
        <el-form-item label="充值到账">
          <el-input v-model="platform.bankAccount" />
        </el-form-item>
      </el-form>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="充值金额" prop="money">
          <el-input type="number" v-model="form.money" placeholder="请输入充值金额" clearable>
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="充值凭证" prop="certificate">
          <ImageUpload v-model="form.certificate" :isShowTip="false" :limit="1"></ImageUpload>
          <span class="tips">例如：付款或者转账截图</span>
        </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 {
        platform: {},
        form: {},
        rules: {
          money: [{ required: true, message: '充值金额不能为空', trigger: 'blur' }],
          certificate: [{ required: true, message: '充值凭证不能为空', trigger: 'blur' }]
        }
      };
    },
    props: {
      param: {
        type: Object,
        default: () => {
          return {};
        }
      },
      layerid: {
        type: String
      }
    },
    mounted() {
      this.ajax({ url: '/work/platform/detail' }).then((response) => {
        this.platform = response.data;
      });
      if (this.param.id) {
        this.ajax({ url: '/work/recharge/detail/' + this.param.id }).then((response) => {
          this.form = response.data;
        });
      }
    },
    methods: {
      submitForm() {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            if (this.form.id) {
              this.ajax({ method: 'post', url: '/work/recharge/edit', data: this.form }).then((response) => {
                this.$modal.msgSuccess('修改成功');
                this.$layer.close(this.layerid);
                this.$parent.getList();
              });
            } else {
              this.ajax({ method: 'post', url: '/work/recharge/add', data: this.form }).then((response) => {
                this.$modal.msgSuccess('提交成功');
                this.$layer.close(this.layerid);
                this.$parent.getList();
              });
            }
          }
        });
      }
    }
  };
</script>
