<script setup lang="ts">
import { uploadProps } from 'wot-design-uni/components/wd-upload/types'
import { BASE_URL, StaticUrl } from '@/config'

const props = defineProps(uploadProps)
const emit = defineEmits(['update:value'])
const { token } = storeToRefs(useUserStore())
const fileSubmitList = computed({
  get() {
    console.log(props.fileList, ' props.fileList')

    return props.fileList
  },
  set(val) {
    const fileData = val.map((item) => {
      return {
        url: JSON.parse(String(item.response)).data.url,
      }
    })
    emit('update:value', fileData)
  },
})
</script>

<template>
  <wd-upload
    v-bind="props" v-model:file-list="fileSubmitList" image-mode="aspectFill"
    :action="`${BASE_URL}/smqjh-system/api/v1/files`" :header="{
      authorization: token,
    }"
  >
    <view class="h120rpx w120rpx flex items-center justify-center rounded-32rpx bg-white">
      <image :src="`${StaticUrl}/upload.png`" class="h40rpx w40rpx" />
    </view>
  </wd-upload>
</template>
