<route lang="yaml">
style:
  navigationBarBackgroundColor: '#fff'
  navigationBarTitleText: 推荐材料商
</route>

<script setup lang="ts">
import DataForm from '@/components/data-form.vue'
import { useUserStore } from '../../../store'
import { useToast } from 'wot-design-uni'
import { storeToRefs } from 'pinia'
import { createMaterialsReferrer } from '../../../core/libs/requests'

const { success, error } = useToast()
const userStore = useUserStore()
const { userInfo } = storeToRefs(userStore)
const form = ref<InstanceType<typeof DataForm>>()
const formData = ref({ referrerId: userInfo.value.userId, referrerName: userInfo.value.nickname })
const handleSubmit = async () => {
  const { valid } = await form.value.validate()
  if (valid) {
    console.log(formData.value)
    const { code, msg } = await createMaterialsReferrer(formData.value)
    code === 0 && success('提交成功')
    code !== 0 && error(msg)
  }
}
const schema = {
  materialsName: {
    type: 'TextField',
    label: '*材料商名称/品牌名称',
  },
  contactPerson: {
    type: 'TextField',
    label: '*对接人姓名',
  },
  contactPosition: {
    type: 'TextField',
    label: '*对接人职位',
  },
  contactPhone: {
    type: 'TextField',
    label: '*对接人电话',
  },
  submit: {
    type: 'Submit',
    label: '提交',
  },
}
onMounted(() => {})
</script>
<template>
  <div class="flex-grow p-3.5 bg-white">
    <DataForm
      ref="form"
      v-model="formData"
      :schema="schema"
      direction="vertical"
      @submit="handleSubmit"
    ></DataForm>
    <div
      class="w-[319px] h-[43px] text-center text-black/30 text-xs font-normal font-['PingFang SC'] leading-normal"
    >
      为满足筑巢荟设计师设计需求，各位设计师可向平台推荐优质服务材料商/施工队，平台优先进行洽谈和考核
    </div>
  </div>
</template>
