<template>
  <!-- 积分变更对话框 -->
  <el-dialog
    :title="$t('wu-shang-pin-shou-kuan')"
    :visible.sync="showDialog"
    class="common-dialog"
    width="700px"
    @close="close"
    destroy-on-close
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('shou-kuan-jin-e')" prop="amount">
            <el-input
              v-model="form.amount"
              :placeholder="$t('qing-shu-ru-shou-kuan-jin-e')"
              style="width: 200px"
              maxlength="150"
            />
            <div class="form-tips">( {{ $t('dan-wei') }} : {{ $t('yuan') }} )</div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item class="recharge-item" :label="$t('bei-zhu-xin-xi')" prop="remark">
            <el-input
              v-model="form.remark"
              type="textarea"
              rows="3"
              :placeholder="$t('qing-shu-ru-bei-zhu-xin-xi')"
              maxlength="255"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" class="main-button" @click="submitForm">
        {{ $t('que-ding-shou-kuan') }}
      </el-button>
      <el-button @click="close">{{ $t('qu-xiao') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'noGoodsCashier',
  props: {
    showDialog: {
      type: [Boolean],
      default: () => false,
    },
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 表单参数
      form: { amount: '', remark: '' },
      // 表单校验
      rules: {
        amount: [
          { required: true, message: this.$t('jin-e-bu-neng-wei-kong'), trigger: 'blur' },
          {
            pattern: /^[0-9]{1,10}$/,
            message: this.$t('qing-shu-ru-1-10-wei-shu-zi'),
            trigger: 'blur',
          },
        ],
      },
    }
  },
  watch: {
    showDialog(value) {
      if (value) {
        this.form.amount = ''
        this.form.remark = ''
      }
    },
  },
  methods: {
    // 取消按钮
    close() {
      this.$emit('closeDialog', 'openNoGoodsCashierDialog')
    },
    // 重置表单
    reset() {
      this.form.amount = ''
      this.form.remark = ''
    },
    // 提交按钮
    submitForm: function () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.$emit('submit', this.form)
        }
      })
    },
  },
}
</script>
