<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    width="500px"
    @close="close"
  >
    <el-form ref="form" label-width="80px" :model="form" :rules="rules">
      <el-form-item hidden :label="__('编号')" prop="duw_id">
        <el-input v-model="form.duw_id" :placeholder="__('编号')" />
      </el-form-item>
      <el-form-item :label="__('会员支付编号')" prop="user_id">
        <el-input v-model="form.user_id" :placeholder="__('会员支付编号')" />
      </el-form-item>
      <el-form-item :label="__('提现额度')" prop="duw_amount">
        <el-input v-model="form.duw_amount" :placeholder="__('提现额度')" />
      </el-form-item>
      <el-form-item :label="__('是否成功')" prop="duw_state">
        <el-input v-model="form.duw_state" :placeholder="__('是否成功')" />
      </el-form-item>
      <el-form-item :label="__('操作管理员')" prop="duw_user_id">
        <el-input v-model="form.duw_user_id" :placeholder="__('操作管理员')" />
      </el-form-item>
      <el-form-item :label="__('创建时间')" prop="duw_time">
        <el-input v-model="form.duw_time" :placeholder="__('创建时间')" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">{{ __('取消') }}</el-button>
      <el-button type="primary" @click="save">{{ __('确定') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { mapActions, mapGetters } from 'vuex'
  import { translateTitle as __ } from '@/utils/i18n'

  import { doEdit } from '@/api/distribution/user/withdraw'

  export default {
    name: 'DistributionUserWithdrawEdit',
    data() {
      return {
        form: {},
        rules: {},
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {},
    mounted() {
      this.form = {
        unit_name: '',
      }

      this.rules = {
        duw_id: [{ required: true, trigger: 'blur', message: this.__('编号') }],
        user_id: [
          { required: true, trigger: 'blur', message: this.__('会员支付编号') },
        ],
        duw_amount: [
          { required: true, trigger: 'blur', message: this.__('提现额度') },
        ],
        duw_state: [
          { required: true, trigger: 'blur', message: this.__('是否成功') },
        ],
        duw_user_id: [
          { required: true, trigger: 'blur', message: this.__('操作管理员') },
        ],
        duw_time: [
          { required: true, trigger: 'blur', message: this.__('创建时间') },
        ],
      }

      this.$forceUpdate()
    },
    methods: {
      __,
      showEdit(row) {
        if (!row) {
          this.title = this.__('添加')
        } else {
          this.title = this.__('编辑')
          this.form = Object.assign({}, row)
        }
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg } = await doEdit(this.form)
            this.$baseMessage(msg, 'success')
            this.$emit('fetch-data')
            this.close()
          } else {
            return false
          }
        })
      },
    },
  }
</script>
