<!--
 * @Author: PoJun
 * @Date: 2023-09-28 10:38:11
 * @LastEditors: PoJun
 * @LastEditTime: 2024-04-27 22:10:30
 * @Message: 供应商详情页面
-->
<template>
    <view class="supplier-detail">
        <uv-navbar :border="false" :autoBack="true" bgColor="transparent" :placeholder="false"></uv-navbar>
        <uv-swiper :list="getImages(item.image)" height="400" indicator circular></uv-swiper>
        <view class="supplier-detail-cont">
            <uv-cell-group :border="false">
                <uv-cell title="名称" :value="item.name" :border="false" :cellStyle="{ padding: '15px' }"></uv-cell>
                <uv-cell title="评分" :value="item.mark" :border="false" :cellStyle="{ padding: '15px' }"></uv-cell>
                <uv-cell
                    title="联系人"
                    :value="item.personName"
                    :border="false"
                    :cellStyle="{ padding: '15px' }"
                ></uv-cell>
                <uv-cell
                    title="联系方式"
                    :value="item.phone"
                    :border="false"
                    :cellStyle="{ padding: '15px' }"
                ></uv-cell>
                <uv-cell
                    title="供应商类型"
                    :value="item.type"
                    :border="false"
                    :cellStyle="{ padding: '15px' }"
                ></uv-cell>
                <uv-cell
                    title="公司地址"
                    :value="item.address"
                    :border="false"
                    :cellStyle="{ padding: '15px' }"
                ></uv-cell>
                <uv-cell
                    title="公司简介"
                    :value="item.intro"
                    :border="false"
                    :cellStyle="{ padding: '15px' }"
                ></uv-cell>
				<uv-cell
				    title="产品"
				    :value="item.product"
				    :border="false"
				    :cellStyle="{ padding: '15px' }"
				></uv-cell>
				<uv-cell
				    title="优势产品"
				    :value="item.superiorProduct"
				    :border="false"
				    :cellStyle="{ padding: '15px' }"
				></uv-cell>
                <uv-cell title="营业执照" :border="false" :cellStyle="{ padding: '15px' }">
                    <uv-album
                        v-if="item.businessLicense"
                        slot="value"
                        :urls="getImages(item.businessLicense)"
                    ></uv-album>
                </uv-cell>
                <uv-cell title="权威证书" :border="false" :cellStyle="{ padding: '15px' }">
                    <uv-album v-if="item.certificates" slot="value" :urls="getImages(item.certificates)"></uv-album>
                </uv-cell>
                <uv-cell
                    v-if="showBtn"
                    title="评分申述"
                    :isLink="true"
                    arrow-direction="right"
                    url="/subpkg/home/representations"
                    :border="false"
                    :cellStyle="{ padding: '15px' }"
                ></uv-cell>

                <uv-cell
                    v-if="showBtn"
                    title="修改供应商信息"
                    :isLink="true"
                    arrow-direction="right"
                    url="/subpkg/home/editInfo"
                    :border="false"
                    :cellStyle="{ padding: '15px' }"
                ></uv-cell>
            </uv-cell-group>
        </view>
    </view>
</template>

<script>
import { getSupplierInfo, getMySupplierInfo } from "@/config/http.js";

export default {
    data() {
        return {
            list: [],
            item: {},
            showBtn: false,
        };
    },
    methods: {
        async initPage(id) {
            const res = id ? await getSupplierInfo(id) : await getMySupplierInfo();
            this.item = Object.assign({}, res);
        },
        getImageUrl(id) {
            return process.env.VUE_APP_BASE_API + `/files/${id}/show_image`;
        },
    },
    computed: {
        getImages() {
            return ids => {
                if (!ids) {
                    return [];
                }
                if (typeof ids === "string") {
                    ids = [ids];
                }
                if (ids.length == 0) {
                    return [];
                }
                console.log(ids.map(v => this.getImageUrl(v)));
                return ids.map(v => this.getImageUrl(v));
            };
        },
    },
    onLoad(e) {
        this.showBtn = e.id ? false : true;
        this.initPage(e.id);
    },
    onReady() {
        uni.$on("refreshSupplierDetail", () => {
            this.initPage();
        });
    },
    beforeDestroy() {
        uni.$off("refreshSupplierDetail");
    },
};
</script>

<style lang="scss">
page {
    background-color: $uv-bg-color;
}
.supplier-detail {
    &-cont {
        margin: 0 25rpx -75rpx;
        background-color: #fff;
        border-radius: 14rpx;
        overflow: hidden;
        z-index: 9;
        position: relative;
        bottom: 100rpx;
    }
}
</style>
