<script setup>
import api from '../api'

const formRef = ref(null)

const formData = ref({})

const rules = {}

onMounted(() => {
  get_config()
})

const get_config = async () => {
  const res = await api.getSignConfig()
  formData.value = res.data.data[0]
}

const ok = () => {
  formRef.value?.validate(async (errors) => {
    if (!errors) {
      try {
        // const data = {
        //   Gift: formData.value.gift,
        //   Sign: formData.value.sign,
        //   WeekSign: formData.value.weekSign,
        //   MonthSign: formData.value.monthSign,
        //   WarningNumber: formData.value.warningNumber,
        // }
        await api.setSignConfig(formData.value)
        $message.success('保存成功')
      } catch (e) {
        $message.error(e.msg)
      }
    }
  })
}
</script>

<template>
  <CommonPage show-footer :title="$route.title">
    <n-form ref="formRef" :model="formData" :rules="rules">
      <n-grid :cols="24" :x-gap="24">
        <n-form-item-gi :span="24" label="注册赠送" path="Gift">
          <n-input-number v-model:value="formData.Gift" :step="100" />
        </n-form-item-gi>
        <n-form-item-gi :span="24" label="每日赠送" path="Sign">
          <n-input-number v-model:value="formData.Sign" :step="100" />
        </n-form-item-gi>
        <n-form-item-gi :span="24" label="每周赠送" path="WeekSign">
          <n-input-number v-model:value="formData.WeekSign" :step="100" />
        </n-form-item-gi>
        <n-form-item-gi :span="24" label="每月赠送" path="MonthSign">
          <n-input-number v-model:value="formData.MonthSign" :step="100" />
        </n-form-item-gi>
        <n-form-item-gi :span="24" label="下注预警（豆子）" path="WarningNumber">
          <n-input-number v-model:value="formData.WarningNumber" :step="100" />
        </n-form-item-gi>
        <n-form-item-gi :span="12">
          <n-button v-perms="['/admin/gift/setting/edit']" type="primary" @click="ok">
            保存
          </n-button>
        </n-form-item-gi>
      </n-grid>
    </n-form>
  </CommonPage>
</template>

<style scoped lang="scss"></style>
