<template>
    <div>
        <MOSTY.PageTree :pageTitle="props.zbFrom.title" :isShowLeftTree="false" :searchType="'01'" @getDeptId="getDeptId">
            <template #serach>
                <el-divider />
                <div class="btnBox">
                    <el-button style="margin-left: 40px;" @click="handleClose" type="primary">
                        <span>关闭</span>
                    </el-button>
                </div>
            </template>
            <template #table>
                <section style="height: calc(100vh - 266px);">
                    <MOSTY.Table :table-columns="tableColumn" :tableData="tableData" :tableloading="tableloading"
                        :isSelect="false" :isSort="true" @SortChange="SortChange" style="width: 100%;">
                        <template #qdzt="{ row }">
                            <dict-tag :options="D_BZ_SF" :value="row.qdzt" :tag="false" />
                        </template>
                        <template #qdsj="{ row }">
                            <span>{{ row.qdsj ? row.qdsj : '--' }}</span>
                        </template>
                        <template #zbqk="{ row }">
                            <span>{{ row.zbqk ? row.zbqk : '--' }}</span>
                        </template>

                    </MOSTY.Table>
                </section>


            </template>
        </MOSTY.PageTree>
    </div>
</template>

<script setup>
// 引入
import {
    ref,
    onMounted,
    defineProps,
    defineEmits,
    getCurrentInstance
} from "vue";
import { getItem } from "@/utils/storage";
import { timeValidate, weekValidate } from "@/utils/tools.js";
import { getApi, postApi, putApi } from "@/api/tobAcco_api.js";
import { ElMessage } from "element-plus";
import * as MOSTY from "@/components/MyComponents/index";
// import Edit from "./components/edit.vue";
const { proxy } = getCurrentInstance();
const { D_BZ_SF } = proxy.$dict("D_BZ_SF");
const tableloading = ref(false);
const emits = defineEmits(["changeclose"]);
const saveloading = ref(false);
const props = defineProps({
    zbFrom: Object,
    xqobj: Object,
    row: {
        type: Object,
        default: () => {
            return {}
        }
    },
});
const tableData = ref([])
const tableColumn = ref([
    {
        title: "所属部门",
        prop: "deptname",
        sortable: true
    },
    {
        title: "值班人员姓名",
        prop: "username",
        sortable: true
    },

])
//获取详情
onMounted(() => {
    let content = props.row?.content|| '';
    if(typeof content === 'string') {
        let contentArr = content.split('(')
        let dept = contentArr[0] || '';
        
        let user = contentArr[1] && contentArr[1].split(')')[0] || ''
        let users = user.split(',')
        tableData.value = users.filter(useName => useName).map(useName=>{
            return {
                username: useName,
                deptname: dept

            }
        })
    }
});
// 关闭
const handleClose = () => {

    emits("changeclose", false);
};

function saveFrom(obj, url) {
    saveloading.value = true
    postApi(obj, url).then(res => {
        ElMessage.success("提交成功");
        let params = {
            id: props.Fromobj.rwid,
            sfyd: "1",
            clzt: "02"
        };
        postApi(params, "/mosty-jcgl/rw/updateRw")
            .then((res) => {
                emits("changeclose", false);
            });
    }).finally(() => {
        saveloading.value = false
    })
}
</script>

<style lang="scss" scoped>
.btnBox {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 12px;
}
</style>
