<template>
  <el-dialog
    custom-class="center-dialog"
    :title="title"
    top="0vh"
    :visible.sync="dialogFormVisible"
    width="500px"
    @close="close"
  >
    <el-form
      ref="form"
      label-width="100px"
      :model="form"
      :rules="rules"
      size="medium"
    >
      <el-form-item label-width="0" prop="withdraw_invoice_no">
        <el-input
          v-model="form.withdraw_invoice_no"
          clearable
          :placeholder="__('请输入发票号')"
          :style="{ width: '100%' }"
        />
      </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 { translateTitle as __ } from '@/utils/i18n'
  import { doUpdateInvoiceNo } from '@/api/consume/withdraw'
  import { renderTime } from '@/utils/date'

  export default {
    name: 'ConsumeWithdrawInvoiceno',
    data() {
      return {
        form: {
          withdraw_invoice_no: '',
        },
        rules: {
          withdraw_invoice_no: [
            {
              required: true,
              message: '',
              trigger: 'change',
            },
          ],
        },
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {
      this.title = this.__('发票号采集')
      this.rules.withdraw_invoice_no[0].message = this.__('请输入发票号')
    },
    methods: {
      __,
      showEdit(row) {
        this.title = this.__('发票号采集')
        this.form = {
          withdraw_id: row.withdraw_id,
          withdraw_invoice_no: row.withdraw_invoice_no,
        }
        this.dialogFormVisible = true
      },
      close() {
        this.form = {}
        this.$refs['form'].resetFields()
        this.dialogFormVisible = false
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg, status } = await doUpdateInvoiceNo(this.form)
            if (200 == status) {
              this.$baseMessage(msg, 'success')
            } else {
              this.$baseMessage(msg, 'error')
            }
            this.$emit('fetch-data')
            this.close()
          } else {
            return false
          }
        })
      },
    },
  }
</script>
