<template>
  <el-dialog
    append-to-body
    :title="title"
    :visible.sync="dialogFormVisible"
    width="30%"
    @close="close"
  >
    <el-form ref="form" label-position="left" label-width="100px" :model="form">
      <el-form-item :label="__('商品审核')" prop="product_verify_id">
        <el-radio-group v-model="form.product_verify_id">
          <el-radio
            v-for="(item, index) in product_verify_idOptions"
            :key="index"
            :disabled="item.disabled"
            :label="item.value"
          >
            {{ item.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        v-if="form.product_verify_id === 3000"
        :label="__('审核失败原因')"
        prop="product_verify_remark"
      >
        <el-input
          v-model="form.product_verify_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 { verify } from '@/api/product/base'

  export default {
    name: 'ReviewEdit',
    components: {},
    data() {
      return {
        form: {},
        dialogFormVisible: false,
        title: this.__('商品审核'),
        layout: 'total, sizes, prev, pager, next, jumper',
        product_verify_idOptions: [
          {
            label: this.__('审核通过'),
            value: 3001,
          },
          {
            label: this.__('审核未通过'),
            value: 3000,
          },
        ],
      }
    },
    created() {},
    methods: {
      __,
      showTable(row) {
        this.form = {
          product_verify_id: 3001,
          product_id: row.product_id,
        }
        this.dialogFormVisible = true
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg, status } = await verify(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.dialogFormVisible = false
        this.form = { product_verify_id: 3001 }
        this.$refs['form'].resetFields()
      },
    },
  }
</script>
