<template>
    <div class="page">
        <NavBar backgroundBox="#FFFFFF" :showIcon="true" :showTitle="true" title="企业信息"></NavBar>
        <view class="image-wrap">
            <image v-if="formData.licensePath" :src="evn.APP_IMAGE_BASE_API + formData.licensePath" mode="" />
            <view>注：接受拍摄复印件，黑白复印需要加盖公章，大小不超过10M</view>
        </view>
        <view class="content-wrap">
            <view class="item">
                <view class="label"> 企业全称 </view>
                <view class="content">
                    {{ formData.name }}
                </view>
            </view>
            <view class="item">
                <view class="label"> 信用代码 </view>
                <view class="content">
                    {{ formData.creditCode }}
                </view>
            </view>
            <!-- <view class="item">
                <view class="label"> 有效期 </view>
                <view class="content">
                    <wd-radio-group v-model="radio" shape="dot" inline>
                        <wd-radio :value="1">长期</wd-radio>
                        <wd-radio :value="2">具体时间</wd-radio>
                    </wd-radio-group>
                </view>
            </view>
            <view class="item">
                <view class="label"> 日期 </view>
                <wd-calendar
                    v-model="formData.licenseValidityPeriod"
                    :disabled="radio == 1"
                    :min-date="new Date().getTime()"
                    :max-date="new Date('2059/01/01').getTime()"
                    use-default-slot
                >
                    <view :class="`content ${radio == 1 ? 'disabled' : ''}`">
                        {{
                            (formData.licenseValidityPeriod && dayjs(formData.licenseValidityPeriod).format("YYYY-MM-DD")) ||
                            "请选择"
                        }}
                    </view>
                </wd-calendar>
            </view> -->
        </view>

        <view class="btn-wrap">
            <button class="bottom-btn" @tap="submit">提交</button>
        </view>
        <!-- 申请错误 -->
        <!-- <van-popup show="{{ showSubmitError }}" custom-style="border-radius:12rpx">
           
        </van-popup> -->
        <wd-overlay :show="show" @click="show = false">
            <view class="popup-wrapper">
                <view class="block" @click.stop="">
                    <view class="sumbit-error">
                        <image src="@/static/image/icon/delete2.png" @tap="show = false" />
                        <view class="title">企业已存在</view>
                        <view class="info">
                            您在注册的<text>“{{ name }}”</text>已在乐业观山湖认证，请核对企业名称是否正确
                        </view>
                        <view class="btn flex-between" @tap="navigateTo('/pages/user/businessLicense/fillIn')">
                            <view class="text">
                                <view class="t1">修改公司名称</view>
                                <view class="t2">这不是我的企业</view>
                            </view>
                            <view class="arrow"></view>
                        </view>
                        <view
                            class="btn flex-between"
                            @tap="navigateTo(`/pages/user/businessLicense/appeal?name=${name}&id=${id}`)"
                        >
                            <view class="text">
                                <view class="t1">申述资质被冒用</view>
                                <view class="t2">确定没有注册过乐业观山湖</view>
                            </view>
                            <view class="arrow"></view>
                        </view>
                    </view>
                </view>
            </view>
        </wd-overlay>
    </div>
</template>

<script setup>
import evn from "@/utils/config";
import { useDefineStore } from "./store";
import { ref } from "vue";
import dayjs from "dayjs";
import { registerCompanyApi } from "@/api/user";
const { formData, setFormDataKey } = useDefineStore();
const show = ref(false);
// console.log(formData);
const id = ref("");
const name = ref("");
const radio = ref(1);
const navigateTo = url => {
    uni.navigateTo({
        url
    });
};
const submit = () => {
    const params = { ...formData };
    if (radio.value == 1) {
        params.licenseValidityPeriod = "2099-12-31";
    }
    registerCompanyApi(params).then(res => {
        if (res.code == 200) {
            // 被占用
            if (res.data) {
                name.value = res.data.name;
                id.value = res.data.id;
                show.value = true;
            } else {
                // 正常
                uni.showToast({
                    title: "提交成功",
                    icon: "none"
                });
                uni.switchTab({
                    url: "/pages/user/index"
                });
            }
        } else {
            uni.showToast({
                title: res.message,
                icon: "error"
            });
        }
    });
};
</script>

<style lang="scss" scoped>
.page {
    display: flex;
    flex-direction: column;
    height: 100%;
}
.image-wrap {
    padding: 32rpx;
    border-bottom: 16rpx solid #f3f4f8;
    image {
        width: 686rpx;
        height: 381.56rpx;
        border-radius: 12rpx;
    }
    view {
        margin-top: 36rpx;
        font-size: 24rpx;
        line-height: 36rpx;
        color: #a3a7b3;
    }
}
.content-wrap {
    flex: 1;
    padding: 0 32rpx;
    .item {
        display: flex;
        padding: 32rpx 0;
        border-bottom: 2rpx solid #f3f4f8;
        .label {
            flex: 0 0 184rpx;
            font-size: 24rpx;
            line-height: 36rpx;
            color: #77818f;
        }
        .content {
            font-size: 28rpx;
            line-height: 36rpx;
            color: #1b2026;
            .van-radio-group {
                display: flex;
                gap: 30rpx;
            }
        }
        .disabled {
            color: #cccccc;
        }
    }
}
.btn-wrap {
    padding: 16rpx 0;
    border-top: 2rpx solid rgb(31 35 41 / 15%);
}
.popup-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    .sumbit-error {
        position: relative;
        box-sizing: border-box;
        width: 600rpx;
        padding: 0 32rpx 32rpx;
        background-color: #ffffff;
        border-radius: 10rpx;
        image {
            position: absolute;
            top: 20rpx;
            right: 20rpx;
            width: 30rpx;
            height: 30rpx;
        }
        .title {
            padding: 32rpx 0;
            font-size: 36rpx;
            font-weight: 600;
            line-height: 54rpx;
            color: #1b2026;
            text-align: center;
        }
        .info {
            font-family: "PingFang SC";
            font-size: 24rpx;
            line-height: 48rpx;
            text {
                color: #1f86ff;
            }
        }
        .btn {
            padding: 24rpx;
            padding-right: 36rpx;
            margin-top: 32rpx;
            border: 2rpx solid #dfe1e5;
            border-radius: 8rpx;
            .t1 {
                font-size: 28rpx;
                font-weight: 500;
                line-height: 36rpx;
                color: #1b2026;
            }
            .t2 {
                margin-top: 8rpx;
                font-size: 24rpx;
                line-height: 36rpx;
                color: #a3a7b3;
            }
            .arrow {
                border-color: #77818f;
            }
        }
    }
}
</style>
