<template>
  <el-dialog
    append-to-body
    custom-class="center-dialog"
    :title="title"
    top="0vh"
    :visible.sync="dialogFormVisible"
    width="500px"
    @close="close"
  >
    <el-form ref="form" label-width="80px" :model="form" :rules="rules">
      <el-form-item
        v-if="false"
        :label="__('发票单号')"
        prop="order_invoice_id"
      >
        <el-input
          v-model="form.order_invoice_id"
          :placeholder="__('发票单号')"
        />
      </el-form-item>
      <el-form-item :label="__('发票单号')" prop="invoice_number">
        <el-input v-model="form.invoice_number" :placeholder="__('发票单号')" />
      </el-form-item>
      <el-form-item :label="__('开票时间')" prop="invoice_date">
        <el-date-picker
          v-model="form.invoice_date"
          clearable
          format="yyyy-MM-dd HH:mm:ss"
          :placeholder="__('开票时间')"
          :style="{ width: '100%' }"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
        />
      </el-form-item>
      <el-form-item :label="__('开票状态')" prop="invoice_status">
        <el-switch
          v-model="form.invoice_status"

          active-text=""
          :active-value="1"

          inactive-text=""
          :inactive-value="0"
        />
      </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 { doEdits } from '@/api/order/invoice'

  export default {
    name: 'AddProductCommentReplyEdit',
    data() {
      return {
        form: {
          order_invoice_id: '',
          invoice_number: '',
          activity_starttime: '',
          invoice_status: '',
        },
        rules: {},
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {},
    mounted() {
      this.rules = {
        invoice_number: [
          { required: true, trigger: 'blur', message: this.__('发票单号') },
        ],
      }
    },
    methods: {
      __,
      showEdit(row) {
        this.form = Object.assign({}, row)
        this.dialogFormVisible = true
      },
      close() {
        this.dialogFormVisible = false
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg, status } = await doEdits(this.form)
            if (200 == status) {
              this.$baseMessage(msg, 'success')
            } else {
              this.$baseMessage(msg, 'error')
            }
            this.$emit('fetch-data')
            this.close()
          } else {
            return false
          }
        })
      },
    },
  }
</script>
