<template>
  <div class="app-container">
    <el-form :model="form" ref="formRef" @submit.prevent>
      <el-row class="mb10">
        <el-col :lg="24">
          <el-form-item>
            <UploadImage ref="uploadRef" v-model="form.homeImage" :limit="1" :fileSize="15" style="width: 100px" :data="{ storeType: 2 }">
              <template #icon>
                <div class="upload-wrap">
                  <el-icon class="avatar-uploader-icon"><plus /></el-icon>
                  <div>首页宣传图片</div>
                </div>
              </template>
            </UploadImage>
          </el-form-item>
        </el-col>
        <el-col :lg="24">
          <el-form-item>
            <UploadImage ref="uploadRef" v-model="form.extend" :limit="1" :fileSize="15" style="width: 100px" :data="{ storeType: 2 }">
              <template #icon>
                <div class="upload-wrap">
                  <el-icon class="avatar-uploader-icon"><plus /></el-icon>
                  <div>首页礼品图片</div>
                </div>
              </template>
            </UploadImage>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="btn-wrap">
      <el-button type="success" @click="handlePublish">保存</el-button>
    </div>
  </div>
</template>

<script setup name="mp_settings">
import useSettingsStore from '@/store/modules/settings'
import { getGiftConfig, updateGiftConfig } from '@/api/business/giftconfig.js'
const settingsStore = useSettingsStore()
const { proxy } = getCurrentInstance()
const formRef = ref()
const uploadRef = ref()

const form = reactive({
  homeImage: '',
  extend: '',
  extend1: '',
  id: 0
})

/** 提交按钮 */
async function handlePublish() {
  await updateGiftConfig(form)
  proxy.$modal.msgSuccess('保存成功')
}

function getList() {
  getGiftConfig(0).then((res) => {
    const { code, data } = res
    if (code == 200) {
      console.log(data)
      form.homeImage = data.homeImage ?? ''
      form.id = data.id
      form.extend = data.extend
    }
  })
}
getList()
</script>

<style scoped>
.app-container {
  position: relative;
}

.upload-wrap {
  display: flex;
  align-items: center;
  flex-direction: column;
  color: #ccc;
}

.btn-wrap {
  z-index: 10;
  width: 100%;
  background: #fff;
  padding: 3px 20px;
  display: flex;
  align-items: center;
  position: fixed;
  bottom: var(--base-footer-height);
}
</style>
