<template>
  <el-dialog
    append-to-body
    :title="title"
    :visible.sync="dialogFormVisible"
    width="30%"
    @close="close"
  >
    <el-form ref="form" label-width="80px" :model="form">
      <el-form-item :label="__('违规原因')" prop="product_state_remark">
        <el-input
          v-model="form.product_state_remark"
          :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 { translateTitle as __ } from '@/utils/i18n'
  import { close } from '@/api/product/base'

  export default {
    name: 'OutOfStockTable',
    components: {},
    data() {
      return {
        form: {},
        dialogFormVisible: false,
        title: '',
        layout: 'total, sizes, prev, pager, next, jumper',
      }
    },
    created() {},
    methods: {
      __,
      showTable(row) {
        this.form.product_id = row.product_id
        this.dialogFormVisible = true
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg, status } = await close(this.form)
            if (200 == status) {
              this.$baseMessage(msg, 'success')
            } else {
              this.$baseMessage(msg, 'error')
            }
            this.$emit('fetch-data')
            this.close()
          } else {
            return false
          }
        })
      },
      close() {
        this.form = {}
        this.$refs['form'].resetFields()
        this.dialogFormVisible = false
      },
    },
  }
</script>
