<script setup>
import XSelect from "../../../../../components/XSelect/index.vue";
import {reactive, ref, watch} from "vue";
import Api from "../../../../../api/index.js";
import {Message} from "@arco-design/web-vue";

const emits = defineEmits(['success']);
const visible = ref(false);
const detail = reactive({});
const {id} = defineProps({
    id: {
        type: Number,
        default: null,
    }
});

watch(
    () => visible.value,
    (val) => {
        if (val) Api.admin.businessDetail(id).then(({data}) => {
            Object.assign(detail, data);
        });
    }
)

const getState = async () => {
    return {
        data: [
            {
                id: 0,
                name: '禁用'
            },
            {
                id: 1,
                name: '可用'
            },
        ]
    }
}

const success = async () => {
    const {msg} = await Api.admin.businessEdit(detail);
    Message.success(msg);
    emits('success');
}
</script>

<template>
    <a-link :hoverable="false" @click="visible=true">编辑</a-link>

    <a-modal
        @ok="success"
        ok-text="确定修改"
        title="编辑"
        title-align="start"
        v-model:visible="visible">
        <a-form layout="vertical">
            <a-form-item label="ID">
                <a-input :model-value="detail.uid" disabled placeholder="ID"></a-input>
            </a-form-item>
            <a-form-item label="昵称">
                <a-input :model-value="detail.nickname" disabled placeholder="昵称"></a-input>
            </a-form-item>
            <a-form-item label="头像">
                <div class="flex flex-wrap gap-[12px]">
                    <a-image
                        width="62px"
                        height="62px"
                        :src="detail.avatar">
                    </a-image>
                </div>
            </a-form-item>
            <a-form-item label="手机号">
                <a-input v-model:model-value="detail.mobile" placeholder="手机号"></a-input>
            </a-form-item>
            <a-form-item label="微信号">
                <a-input v-model:model-value="detail.wechat" placeholder="微信号"></a-input>
            </a-form-item>
            <a-form-item label="状态">
                <x-select v-model:model-value="detail.status" :api="getState" init></x-select>
            </a-form-item>
            <a-form-item label="邀请人">
                <a-input v-model:model-value="detail.puid" placeholder="邀请人"></a-input>
            </a-form-item>
            <a-form-item label="入驻日期">
                <a-input :model-value="detail.createtime" disabled placeholder="入驻日期"></a-input>
            </a-form-item>
        </a-form>
    </a-modal>
</template>

<style scoped lang="scss">

</style>
