<template>
    <div class="edit-popup">
        <popup ref="popupRef" :title="popupTitle" :async="true" width="550px" confirmButtonText="" cancelButtonText=""
            @close="handleClose">
            <el-form ref="formRef" :model="formData" label-width="90px">
                <el-form-item label="入驻城市" prop="city_name">
                    <el-input v-model="formData.city_name" clearable disabled />
                </el-form-item>
                <!-- <el-form-item label="昵称" prop="nickname">
                    <el-input v-model="formData.nickname" clearable placeholder="请输入昵称" />
                </el-form-item> -->
                <el-form-item label="姓名" prop="username">
                    <el-input v-model="formData.username" clearable placeholder="请输入姓名" disabled />
                </el-form-item>
                <el-form-item label="电话" prop="mobile">
                    <el-input v-model="formData.mobile" clearable placeholder="请输入电话" disabled />
                </el-form-item>
                <el-form-item label="性别" prop="gender">
                    <el-select v-model="formData.gender[0]" clearable placeholder="请选择" disabled>
                        <el-option label="男" value="1"></el-option>
                        <el-option label="女" value="2"></el-option>
                    </el-select>
                </el-form-item>
                <!-- <el-form-item label="用户id" prop="user_id">
                    <el-input v-model="formData.user_id" clearable placeholder="请输入用户id" />
                </el-form-item> -->
                <el-form-item label="出生年月" prop="both">
                    <el-input v-model="formData.both" clearable placeholder="请输入出生年月" disabled />
                </el-form-item>
                <el-form-item label="身高" prop="height">
                    <el-input v-model="formData.height" clearable placeholder="请输入身高" disabled />
                </el-form-item>
                <el-form-item label="体重" prop="weight">
                    <el-input v-model="formData.weight" clearable placeholder="请输入体重" disabled />
                </el-form-item>
                <el-form-item label="个人头像照片" prop="avatar">
                    <el-image style="width: 100px; height: 100px" :src="formData.avatar" :zoom-rate="1.2" :max-scale="7"
                        :min-scale="0.2" :preview-src-list="[formData.avatar]" show-progress :initial-index="4"
                        fit="cover" />
                </el-form-item>
                <el-form-item label="健康证" prop="certificate"
                    v-if="formData.certificate.length > 0 && formData.certificate[0]">
                    <el-image style="width: 100px; height: 100px" :src="formData.certificate[0]" :zoom-rate="1.2"
                        :max-scale="7" :min-scale="0.2" :preview-src-list="[formData.certificate[0]]" show-progress
                        :initial-index="4" fit="cover" />
                </el-form-item>
                <el-form-item label="茶艺师资格证" prop="certificate"
                    v-if="formData.certificate.length > 0 && formData.certificate[1]">
                    <el-image style="width: 100px; height: 100px" :src="formData.certificate[1]" :zoom-rate="1.2"
                        :max-scale="7" :min-scale="0.2" :preview-src-list="[formData.certificate[1]]" show-progress
                        :initial-index="4" fit="cover" />
                </el-form-item>
                <!-- <el-form-item label="营业执照" prop="license_img">
                    <el-image style="width: 100px; height: 100px" :src="formData.license_img" :zoom-rate="1.2"
                        :max-scale="7" :min-scale="0.2" :preview-src-list="[formData.license_img]" show-progress
                        :initial-index="4" fit="cover" />
                    <material-picker v-model="formData.license_img" />
                </el-form-item> -->
                <el-form-item label="兴趣爱好" prop="hobby_introduce">
                    <editor class="flex-1" v-model="formData.hobby_introduce" :height="500" disabled />

                    <!-- <el-input v-model="formData.hobby_introduce" clearable placeholder="请输入兴趣爱好" /> -->
                </el-form-item>
                <el-form-item label="审核状态" prop="status">
                    <el-select v-model="formData.status" clearable placeholder="请选择" disabled>
                        <el-option label="未审核" :value="0"></el-option>
                        <el-option label="通过" :value="1"></el-option>
                        <el-option label="驳回" :value="2"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
        </popup>
    </div>
</template>

<script lang="ts" setup name="teamasterRealEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiTeamasterRealAdd, apiTeamasterRealEdit, apiTeamasterRealDetail } from '@/api/teamaster_real'
import { timeFormat, removeImageUrlPrefix } from '@/utils/util'
import type { PropType } from 'vue'
defineProps({
    dictData: {
        type: Object as PropType<Record<string, any[]>>,
        default: () => ({})
    }
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')


// 弹窗标题
const popupTitle = computed(() => {
    return mode.value == '茶艺师详情'
})

// 表单数据
const formData = reactive({
    id: '',
    city_id: '',
    city_name: '',
    nickname: '',
    username: '',
    mobile: '',
    gender: [],
    user_id: '',
    both: '',
    height: '',
    weight: '',
    avatar: '',
    information: '',
    certificate: [],
    license_img: '',
    hobby_introduce: '',
    status: '',
})



// 获取详情
const setFormData = async (data: Record<any, any>) => {
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            //@ts-ignore
            formData[key] = data[key]
        }
    }
    //@ts-ignore
    data.gender && (formData.gender = String(data.gender).split(","))
    //@ts-ignore
    formData.shenhe_time = timeFormat(formData.shenhe_time, 'yyyy-mm-dd hh:MM:ss')
    //@ts-ignore
    formData.bohui_time = timeFormat(formData.bohui_time, 'yyyy-mm-dd hh:MM:ss')
    //@ts-ignore
    formData.create_time = timeFormat(formData.create_time, 'yyyy-mm-dd hh:MM:ss')
}

const getDetail = async (row: Record<string, any>) => {
    const data = await apiTeamasterRealDetail({
        id: row.id
    })
    setFormData(data)
}

//打开弹窗
const open = (type = 'add') => {
    mode.value = type
    popupRef.value?.open()
}

// 关闭回调
const handleClose = () => {
    emit('close')
}



defineExpose({
    open,
    setFormData,
    getDetail
})
</script>
