<!--
 * @Author: PoJun
 * @Date: 2024-01-03 16:13:54
 * @LastEditors: PoJun
 * @LastEditTime: 2024-05-08 20:37:11
 * @Message: Nothing
-->
<template>
    <view class="flow-detail">
        <uv-skeletons
            :loading="skeletonLoading"
            :skeleton="[
                {
                    type: 'line',
                    num: 10,
                    gap: '0',
                    style: 'height: 32px;marginTop:36rpx',
                },
            ]"
        >
            <kirin-form :list="list" labelWidth="80"></kirin-form>
            <view class="uv-m-t-30" v-if="tabType == 'todo'">
                <uv-row gutter="15">
                    <uv-col span="6">
                        <uv-button type="primary" :plain="true" text="拒绝" @click="refuse"></uv-button>
                    </uv-col>
                    <uv-col span="6">
                        <uv-button type="primary" text="同意" @click="agree"></uv-button>
                    </uv-col>
                </uv-row>
            </view>
        </uv-skeletons>
    </view>
</template>

<script>
import { getAffairSelfInfo, refuseAffairs, agreeAffairs } from "@/config/http.js";
import formBasicMixin from "@/utils/form-basic-mixin.js";
import { authenticationFormList } from "../setting/constant";
export default {
    mixins: [formBasicMixin],
    data() {
        return {
            list: [],
            tabType: "todo",
            id: "",
            skeletonLoading: true,
            detailItem: null,
            authenticationFormList,
        };
    },
    methods: {
        async initPage(id) {
            const data = await getAffairSelfInfo(id);
            this.detailItem = data;
            const type = data.type;
            if (type == "UserJoinOrg") {
                this.list = [
                    {
                        type: "textarea",
                        label: "标题",
                        code: "title",
                        sv: data.title,
                        rv: data.title,
                        canShow: true,
                        labelWidth: 80,
                    },
                    {
                        type: "input",
                        label: "审核类型",
                        code: "type",
                        sv: "人员加入组织",
                        rv: "人员加入组织",
                        canShow: true,
                        labelWidth: 80,
                    },
                    {
                        type: "input",
                        label: "名称",
                        code: "name",
                        sv: data?.data.name,
                        rv: data?.data.name,
                        canShow: true,
                        labelWidth: 80,
                    },
                    {
                        type: "input",
                        label: "联系方式",
                        code: "phone",
                        sv: data?.data.phone,
                        rv: data?.data.phone,
                        canShow: true,
                        labelWidth: 80,
                    },
                ];
            } else {
                this.list = authenticationFormList.map(item => {
                    item.sv = item.rv = data?.data[item.code];
                    item.canEdit = false;
                    return item;
                });
                this.list.unshift(
                    {
                        type: "textarea",
                        label: "标题",
                        code: "title",
                        sv: data.title,
                        rv: data.title,
                        canShow: true,
                        labelWidth: 80,
                    },
                    {
                        type: "input",
                        label: "审核类型",
                        code: "type",
                        sv: "申请加入供应商",
                        rv: "申请加入供应商",
                        canShow: true,
                        labelWidth: 80,
                    }
                );
            }

            if (data.result != undefined && data.result != null) {
                this.list.push({
                    type: "input",
                    label: "审核结果",
                    code: "result",
                    sv: data.result == 1 ? "已通过" : "已拒绝",
                    rv: data.result == 1 ? "已通过" : "已拒绝",
                    canShow: true,
                    labelWidth: 80,
                });
            }
            uni.$uv.sleep(200).then(() => {
                this.skeletonLoading = false;
            });
        },
        async refuse() {
            uni.showLoading({ mask: true });
            await refuseAffairs(this.id);
            this.doback();
        },
        async agree() {
            uni.showLoading({ mask: true });
            await agreeAffairs(this.id, this.detailItem.data);
            this.doback();
        },
        doback() {
            try {
                uni.$uv.route({ type: "back" });
                uni.$emit("refreshFlowList");
            } finally {
                uni.hideLoading();
            }
        },
    },
    async onLoad(e) {
        await this.initDictList("supplierType");
        this.tabType = e?.tabType;
        this.id = e?.id;
        this.initPage(e.id);
    },
};
</script>

<style lang="scss">
.flow-detail {
    padding: 0 25rpx;
}
</style>
