<!--
 * @Author: XuanJi
 * @Date: 2024-05-20 15:42:30
 * @LastEditors: XuanJi
 * @LastEditTime: 2024-05-22 17:52:15
 * @Message: 角色认证界面
-->
<template>
    <view class="authentication">
        <view class="authentication-cont">
            <kirin-form v-if="current == 0" ref="form" :list="list" labelPosition="top"></kirin-form>
            <kirin-form v-else-if="current == 1" ref="form" :list="list" labelPosition="top"></kirin-form>
        </view>
    </view>
</template>

<script>
import { authenticationFormList } from "./constant";
import formBasicMixin from "@/utils/form-basic-mixin.js";
import { getAffairInfo } from "@/config/http.js";

export default {
    mixins: [formBasicMixin],
    data() {
        return {
            list: [],
            infoList: [],
            authenticationFormList,
            current: 0,
        };
    },
    async onLoad() {
        await this.initDictList("sex,supplierType");
        this.initFormData();
    },
    methods: {
        async initFormData() {
            if (this.vuex_userInfo.attr.affairType == "SupplierJoin" && this.vuex_userInfo.attr.auditState == 1) {
                this.current = 1;
                const resData = await getAffairInfo(this.vuex_userInfo.attr.affairId);
                const data = resData.data;
                this.list = [...this.authenticationFormList];
                this.list.map(item => {
                    item.canEdit = item.required = false;
                    item.rv = item.sv = data[item.code];
                });
            } else if (
                (this.vuex_userInfo.attr.affairType == "UserJoinOrg" &&
                    [1, 2].includes(this.vuex_userInfo.attr.auditState)) ||
                ([0].includes(this.vuex_userInfo.attr.auditState) &&
                    this.vuex_userInfo.attr.BusinessRole == "orgMember")
            ) {
                this.current = 0;
                const { OrgUnit } = this.vuex_userInfo.attr;
                this.infoList = [
                    {
                        type: "input",
                        label: "组织名称",
                        code: "orgName",
                        sv: OrgUnit.name,
                        rv: OrgUnit.name,
                        canShow: true,
                        canEdit: false,
                    },
                    {
                        type: "input",
                        label: "用户名称",
                        code: "name",
                        sv: null,
                        rv: null,
                        canShow: true,
                        canEdit: true,
                        required: true,
                    },
                    {
                        type: "input",
                        label: "联系方式",
                        code: "phone",
                        sv: null,
                        rv: null,
                        canShow: true,
                        canEdit: true,
                        required: true,
                    },
                ];
                let resData, data;
                this.list = [...this.infoList];
                if (this.vuex_userInfo.attr.auditState !== 0) {
                    resData = await getAffairInfo(this.vuex_userInfo.attr.affairId);
                    data = resData.data;
                    this.list.map(item => {
                        item.canEdit = item.required = false;
                        item.rv = item.sv = data[item.code];
                    });
                } else {
                    this.list.map(item => {
                        item.canEdit = item.required = false;
                        if (this.vuex_userInfo[item.code]) {
                            item.rv = item.sv = this.vuex_userInfo[item.code];
                        }
                    });
                }
            }
        },
    },
};
</script>

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