
<style scoped>
.user-panel {
  margin: 10px auto;
}
</style>
<template>
  <el-dialog
    :visible.sync="showDialog"
    :title="title"
    :modal-append-to-body="false"
    style="text-align: left"
    @close="closeDialog"
    :close-on-click-modal="false"
  >
    <div class="user-panel" v-loading="loading">
      <el-form
        ref="form"
        :model="formModel"
        :rules="ruleValidate"
        :label-width="'100px'"
      >
        <el-form-item label="" prop="id">
          <el-input
            v-model="formModel.id"
            placeholder="请输入"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="商户id" prop="merchantId">
          <el-input
            v-model="formModel.merchantId"
            placeholder="请输入商户id"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="申请提现金额" prop="applyWithdrawalAmount">
          <el-input
            v-model="formModel.applyWithdrawalAmount"
            placeholder="请输入申请提现金额"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="申请时间" prop="applyTime">
          <el-input
            v-model="formModel.applyTime"
            placeholder="请输入申请时间"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态（0：申请中，1：同意，2：拒绝）" prop="status">
          <el-input
            v-model="formModel.status"
            placeholder="请输入状态（0：申请中，1：同意，2：拒绝）"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="审核时间" prop="examineTime">
          <el-input
            v-model="formModel.examineTime"
            placeholder="请输入审核时间"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="审核人" prop="examineBy">
          <el-input
            v-model="formModel.examineBy"
            placeholder="请输入审核人"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="formModel.remark"
            placeholder="请输入备注"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="提现编号" prop="withdrawalNo">
          <el-input
            v-model="formModel.withdrawalNo"
            placeholder="请输入提现编号"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="创建人" prop="createBy">
          <el-input
            v-model="formModel.createBy"
            placeholder="请输入创建人"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          <el-input
            v-model="formModel.createTime"
            placeholder="请输入创建时间"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="更新人" prop="updateBy">
          <el-input
            v-model="formModel.updateBy"
            placeholder="请输入更新人"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="更新时间" prop="updateTime">
          <el-input
            v-model="formModel.updateTime"
            placeholder="请输入更新时间"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="是否删除" prop="delFlag">
          <el-input
            v-model="formModel.delFlag"
            placeholder="请输入是否删除"
            style="width: 300px"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="handleSubmit" :loading="submitting"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
import Constant from "@/constant";
import withdrawalRecordApi from "@/api/merchant/withdrawalRecord";

export default {
  props: ["businessKey", "title"],
  data() {
    return {
      formModel: {},
      ruleValidate: {
        id: [{ required: true, message: "不能为空", trigger: "blur" }],
        merchantId: [
          { required: true, message: "商户id不能为空", trigger: "blur" },
        ],
        applyWithdrawalAmount: [
          { required: true, message: "申请提现金额不能为空", trigger: "blur" },
        ],
        applyTime: [
          { required: true, message: "申请时间不能为空", trigger: "blur" },
        ],
        status: [
          {
            required: true,
            message: "状态（0：申请中，1：同意，2：拒绝）不能为空",
            trigger: "blur",
          },
        ],
        examineTime: [
          { required: true, message: "审核时间不能为空", trigger: "blur" },
        ],
        examineBy: [
          { required: true, message: "审核人不能为空", trigger: "blur" },
        ],
        remark: [{ required: true, message: "备注不能为空", trigger: "blur" }],
        withdrawalNo: [
          { required: true, message: "提现编号不能为空", trigger: "blur" },
        ],
        createBy: [
          { required: true, message: "创建人不能为空", trigger: "blur" },
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" },
        ],
        updateBy: [
          { required: true, message: "更新人不能为空", trigger: "blur" },
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" },
        ],
        delFlag: [
          { required: true, message: "是否删除不能为空", trigger: "blur" },
        ],
      },
      showDialog: true,
      loading: false,
      submitting: false,
    };
  },
  methods: {
    closeDialog() {
      this.$emit("close", false);
    },
    handleSubmit() {
      var self = this;

      this.$refs["form"].validate((valid) => {
        if (valid) {
          (function () {
            var id = self.formModel.id;

            if (id == null || id.length == 0) {
              return withdrawalRecordApi.add(self.formModel);
            } else {
              return withdrawalRecordApi.update(self.formModel);
            }
          })().then(function (response) {
            var jsonData = response.data;

            if (jsonData.result) {
              self.$message({
                message: "保存成功!",
                type: "success",
              });

              self.$emit("close", true);
            } else {
              self.$message({
                message: jsonData.message + "",
                type: "warning",
              });

              self.$emit("close", false);
            }
          });
        }
      });
    },
  },
  mounted: function () {
    var self = this;

    (function () {
      if (self.businessKey.length == 0) {
        return withdrawalRecordApi.create();
      } else {
        return withdrawalRecordApi.edit(self.businessKey);
      }
    })()
      .then((response) => {
        var jsonData = response.data;
        self.loading = false;

        if (jsonData.result) {
          self.formModel = jsonData.data;
        } else {
          self.$message.error(jsonData.message + "");
        }
      })
      .catch((error) => {
        self.$message.error(error + "");
      });
  },
};
</script>