<!--
 * @Author: PoJun
 * @Date: 2024-01-03 16:13:54
 * @LastEditors: PoJun
 * @LastEditTime: 2024-01-04 17:33:34
 * @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";
export default {
    mixins: [formBasicMixin],
    data() {
        return {
            list: [
                {
                    type: "textarea",
                    label: "标题",
                    code: "title",
                    sv: null,
                    rv: null,
                    canShow: true,
                    labelWidth: 80,
                },
                {
                    type: "input",
                    label: "审核类型",
                    code: "type",
                    sv: null,
                    rv: null,
                    canShow: true,
                    labelWidth: 80,
                },
                {
                    type: "input",
                    label: "名称",
                    code: "name",
                    sv: null,
                    rv: null,
                    canShow: true,
                    labelWidth: 80,
                },
                {
                    type: "input",
                    label: "联系方式",
                    code: "phone",
                    sv: null,
                    rv: null,
                    canShow: true,
                    labelWidth: 80,
                },
                {
                    type: "input",
                    label: "审核结果",
                    code: "result",
                    sv: null,
                    rv: null,
                    canShow: true,
                    labelWidth: 80,
                },
            ],
            tabType: "todo",
            id: "",
            skeletonLoading: true,
            detailItem: null,
        };
    },
    methods: {
        async initPage(id) {
            const data = await getAffairSelfInfo(id);
            this.detailItem = data;
            this.list.forEach(item => {
                if (item.code == "title" || item.code == "type") {
                    item.sv = item.rv = data[item.code];
                }
                if (item.code == "phone" || item.code == "name") {
                    item.sv = item.rv = data?.data[item.code];
                }
                if (item.code == "result") {
                    if (data[item.code] != undefined && data[item.code] != null) {
                        item.sv = item.rv = data[item.code] == 1 ? "已通过" : "已拒绝";
                    }
                    if (this.tabType == "done") {
                        item.canShow = true;
                    } else {
                        item.canShow = false;
                    }
                }
            });
            uni.$uv.sleep(200).then(() => {
                this.skeletonLoading = false;
            });
        },
        async refuse() {
            await refuseAffairs(this.id);
            this.doback();
        },
        async agree() {
            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>
