<template>
    <view class="bg-[#FAFAFE]">
        <view class="bg-white px-[32rpx]">
            <TForm ref="tForm" :model="form" errorType="toast">
                <TFormItem prop="studentName">
                    <TInputField
                        v-model="form.studentName"
                        label="客户姓名"
                        placeholder=""
                        inputAlign="left"
                        readonly
                        :required="false"
                        :labelWidth="120"
                    />
                </TFormItem>
                <TFormItem prop="phone">
                    <TInputField
                        v-model="form.phone"
                        label="电话"
                        placeholder=""
                        inputAlign="left"
                        readonly
                        :required="false"
                        :labelWidth="120"
                    />
                </TFormItem>
                <TFormItem prop="basicInformation">
                    <TTextareaField
                        v-model="form.basicInformation"
                        label="基本情况"
                        placeholder=""
                        autoHeight
                        disabled
                        :required="false"
                        :labelWidth="120"
                    />
                </TFormItem>
                <TFormItem prop="telemarketingTeacherName">
                    <TInputField
                        v-model="form.telemarketingTeacherName"
                        label="电销老师"
                        placeholder=""
                        inputAlign="left"
                        readonly
                        :required="false"
                        :labelWidth="120"
                    />
                </TFormItem>
                <TFormItem prop="followUpTime">
                    <TInputField
                        v-model="form.followUpTime"
                        label="跟进时间"
                        placeholder=""
                        inputAlign="left"
                        readonly
                        :required="false"
                        :labelWidth="120"
                    />
                </TFormItem>
                <TFormItem prop="recruitTeacherName">
                    <TInputField
                        v-model="form.recruitTeacherName"
                        label="招生老师"
                        placeholder=""
                        inputAlign="left"
                        readonly
                        :required="false"
                        :labelWidth="120"
                    />
                </TFormItem>
                <TFormItem prop="state">
                    <TInputField
                        v-model="parseStatusText"
                        label="状态"
                        placeholder=""
                        inputAlign="left"
                        readonly
                        :required="false"
                        :labelWidth="120"
                    />
                </TFormItem>
                <TFormItem prop="isConversion">
                    <TSwitchField
                        v-model="form.isConversion"
                        label="是否转化成功"
                        :labelWidth="120"
                        disabled
                        :required="false"
                    />
                </TFormItem>
                <TFormItem prop="remark">
                    <TTextareaField
                        v-model="form.remark"
                        label="备注"
                        placeholder=""
                        autoHeight
                        disabled
                        :required="false"
                        :labelWidth="120"
                    />
                </TFormItem>
                <TFormItem prop="accomplishTime">
                    <TTextareaField
                        v-model="form.accomplishTime"
                        label="成交时间"
                        placeholder=""
                        autoHeight
                        disabled
                        :required="false"
                        :labelWidth="120"
                    />
                </TFormItem>
            </TForm>
        </view>
    </view>
</template>

<script setup lang="ts">
import { onLoad } from '@dcloudio/uni-app'
import { ref, computed } from 'vue'
import { useClueDetail } from '@/hooks/useCommon'
import { optionsMap } from '@/config/options'

const { fetchClueDetail, clueDetailInfo } = useClueDetail()

const id = ref('')

const tForm = ref()
const form = ref({
    id: '',
    recruitTeacherName: '',
    studentName: '',
    phone: '',
    basicInformation: '',
    state: null,
    isConversion: 0,
    remark: '',
    accomplishTime: '',
    followUpTime: '',
    telemarketingTeacherName: ''
})
const parseStatusText = computed(
    () => optionsMap.stateOptions.find(item => item.value == form.value.state)?.label
)

onLoad(async option => {
    if (option?.id) {
        id.value = option.id
        await fetchClueDetail(id.value)
        setFormData()
    }
})
const setFormData = () => {
    for (const key in clueDetailInfo.value) {
        if (
            Object.prototype.hasOwnProperty.call(form.value, key) &&
            clueDetailInfo.value[key] != null &&
            clueDetailInfo.value[key] != undefined
        ) {
            form.value[key] = clueDetailInfo.value[key]
        }
    }
    console.log(form.value)
}
</script>

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