<!--
 * @Author: PoJun
 * @Date: 2023-09-28 10:38:11
 * @LastEditors: PoJun
 * @LastEditTime: 2024-05-08 19:25:51
 * @Message: 修改供应商信息界面
-->
<template>
    <view class="authentication">
        <view class="authentication-cont">
            <kirin-form ref="dataFrom" :list="list"></kirin-form>
            <view class="uv-m-t-30">
                <uv-button type="primary" text="确定" @click="save"></uv-button>
            </view>
        </view>
    </view>
</template>

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

export default {
    data() {
        return {
            list: [],
        };
    },
    async onLoad() {
        this.initPage();
    },
    methods: {
        async initPage() {
            const res = await getMySupplierInfo();
            this.list = [
                {
                    type: "input",
                    label: "名称",
                    code: "name",
                    sv: res.name,
                    rv: res.name,
                    canShow: true,
                    canEdit: true,
                },
                {
                    type: "input",
                    label: "联系电话",
                    code: "phone",
                    sv: res.phone,
                    rv: res.phone,
                    canShow: true,
                    canEdit: true,
                },
                {
                    type: "input",
                    label: "地址",
                    code: "address",
                    sv: res.address,
                    rv: res.address,
                    canShow: true,
                    canEdit: true,
                },
                {
                    type: "input",
                    label: "企业简介",
                    code: "intro",
                    sv: res.intro,
                    rv: res.intro,
                    canShow: true,
                    canEdit: true,
                },
                {
                    type: "products",
                    label: "产品分类",
                    code: "product",
                    sv: null,
                    rv: res.product ? res.product : [],
                    canShow: true,
                    canEdit: true,
                    required: false,
                },
                {
                    type: "input",
                    label: "优势产品",
                    code: "superiorProduct",
                    sv: res.superiorProduct,
                    rv: res.superiorProduct,
                    canShow: true,
                    canEdit: true,
                    required: false,
                },
                {
                    type: "images",
                    label: "形象图片",
                    code: "imageStr",
                    sv: res.image ? res.image.join(",") : "",
                    rv: res.image ? res.image.join(",") : "",
                    canShow: true,
                    canEdit: true,
                    required: false,
                    maxCount: 5,
                    width: "80px",
                    height: "80px",
                    required: false,
                    uploadText: "上传图片",
                },

                {
                    type: "images",
                    label: "营业执照",
                    code: "businessLicense",
                    sv: res.businessLicense,
                    rv: res.businessLicense,
                    canShow: true,
                    canEdit: true,
                    maxCount: 1,
                    width: "80px",
                    height: "80px",
                    uploadText: "上传图片",
                },
                {
                    type: "images",
                    label: "权威证书",
                    code: "certificatesStr",
                    sv: res.certificates ? res.certificates.join(",") : "",
                    rv: res.certificates ? res.certificates.join(",") : "",
                    canShow: true,
                    canEdit: true,
                    maxCount: 5,
                    width: "80px",
                    height: "80px",
                    uploadText: "上传图片",
                },
            ];
        },
        async save() {
            const formData = this.$refs.dataFrom.getFormData();
            if (!formData) {
                return;
            }
            uni.showLoading({ mask: true });
            await editSelfInfo(formData);
            try {
                uni.$uv.route({ type: "back" });
                uni.$emit("refreshSupplierDetail");
            } finally {
                uni.hideLoading();
            }
        },
    },
};
</script>

<style lang="scss">
.authentication {
    &-cont {
        padding: 25rpx;
    }
}
</style>
