<!--
 * @Author: PoJun
 * @Date: 2023-09-28 10:38:11
 * @LastEditors: PoJun
 * @LastEditTime: 2024-01-05 11:09:42
 * @Message: 个人信息
-->
<template>
    <view class="my-info">
        <uv-skeletons
            :loading="skeletonLoading"
            :skeleton="[
                {
                    type: 'line',
                    num: 10,
                    gap: '0',
                    style: 'height: 32px;marginTop:36rpx',
                },
            ]"
        >
            <kirin-form v-if="!skeletonLoading" ref="form" :list="list"></kirin-form>
            <view class="uv-m-t-30">
                <uv-button type="primary" text="确定" @click="save"></uv-button>
            </view>
        </uv-skeletons>
    </view>
</template>

<script>
import { editPersonInfo } from "@/config/http.js";
import { myInfoFormList } from "./constant";
import formBasicMixin from "@/utils/form-basic-mixin.js";
export default {
    mixins: [formBasicMixin],
    data() {
        return {
            skeletonLoading: true,
            list: [],
        };
    },
    async onLoad() {
        await this.initDictList("sex");
        this.initFormData();
    },
    methods: {
        async save() {
            const formData = this.$refs.form.getFormData();
            if (!formData) {
                return;
            }
            uni.showLoading({ mask: true });
            await editPersonInfo(formData);
            try {
                await this.$store.dispatch("UPDATELOGININFO");
                uni.$uv.toast("信息修改成功");
            } finally {
                uni.hideLoading();
            }
        },
        initFormData() {
            this.list = JSON.parse(JSON.stringify(myInfoFormList));
            this.list.forEach(item => {
                // 这里的数据本身没有显示值和存储值的说法,
                const val = this.vuex_userInfo[item.code];
                item.rv = item.sv = val;
                if (["sex", "birthday", "phone"].includes(item.code)) {
                    item.canShow = item.canEdit = this.vuex_userInfo.attr.BusinessRole == "orgMember";
                    if (item.code == "sex") {
                        if (val || val == 0) {
                            item.sv = val == 0 ? "男" : "女";
                        } else {
                            item.sv = val;
                        }
                    }
                }
            });
            console.log(this.list);

            uni.$uv.sleep(300).then(() => {
                this.skeletonLoading = false;
            });
        },
    },
};
</script>

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