<template>
  <CommonPage show-footer :title="$route.title">
    <n-tabs type="line" animated>
      <n-tab-pane name="1" tab="用户协议">
        <Editor v-model:value-html="model.user" :height="550" />
      </n-tab-pane>
      <n-tab-pane name="2" tab="隐私政策">
        <Editor v-model:value-html="model.policy" :height="550" />
      </n-tab-pane>
      <n-tab-pane name="3" tab="积分使用规则">
        <Editor v-model:value-html="model.integral" :height="550" />
      </n-tab-pane>
    </n-tabs>
    <n-button v-perms="['/admin/edit/agreement']" mt-10 type="primary" @click="save">保存</n-button>
  </CommonPage>
</template>

<script setup>
import api from './api'
import Editor from '@/components/Editor.vue'

const model = ref({
  user: '',
  policy: '',
  integral: '',
})

onMounted(() => {
  get_agreement()
})

const get_agreement = async () => {
  const res = await api.getAgreement()
  model.value = res.data.data
}

const save = async () => {
  const res = await api.updateAgreement(model.value)
  $message.success(res.msg)
}
</script>

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