<!-- 用户编辑弹窗 -->
<template>
    <ele-modal
        :width="`80%`"
        :visible="visible"
        :confirm-loading="loading"
        :maxable="maxAble"
        title="派单详情"
        :body-style="{ paddingBottom: '8px', background: '#f3f3f3' }"
        @update:visible="updateVisible"
        :maskClosable="false"
        :footer="null"
        @ok="save"
    >
        <a-collapse v-model:activeKey="activeKey" accordion v-if="visible">
            <a-collapse-panel
                :header="`标地:${info.address}(审核状态:${WORKSHEET_AUDIT_STATUS_LIST[info.auditStatus]},当前状态:${WORKSHEET_STATUS_LIST[info.status]})`"
                v-for="(info, index) in list" :key="index.toString()">
                <a-card>
                    <a-descriptions title="人员信息">
                        <a-descriptions-item :label="`审核人${auditIndex + 1}`" v-for="(audit, auditIndex) in info.auditList"
                                             :key="auditIndex">{{ audit.nickname }}({{ audit.auditStatus === 1 ? "审核通过" : (audit.auditStatus === 2 ? "审核不通过" : "未审核")
                          }})
                        </a-descriptions-item>
                        <a-descriptions-item label="资料员">{{ info.documentUser?.nickname }}({{ info.documentDoneTime ? `完成时间:${dayjs(info.documentDoneTime).format("YYYY-MM-DD HH:mm:ss")}` : "待完成"
                            }})
                        </a-descriptions-item>
                        <a-descriptions-item label="资产管理员">{{ info.assetUser?.nickname }}({{ info.assetDoneTime ? `完成时间:${dayjs(info.assetDoneTime).format('YYYY-MM-DD HH:mm:ss')}` : '待完成' }})
                        </a-descriptions-item>
                        <a-descriptions-item label="维保人员">{{ info.fixUser?.nickname }}({{ info.fixDoneTime ? `完成时间:${dayjs(info.fixDoneTime).format('YYYY-MM-DD HH:mm:ss')}` : "待完成"
                          }})
                        </a-descriptions-item>
                        <a-descriptions-item label="生产主管">{{ info.productionMangerUser?.nickname }}
                        </a-descriptions-item>
                        <a-descriptions-item label="班组组长">{{ info.classManagerUser?.nickname }}({{ info.status >= 4 ? '已到场' : '待完成' }})
                        </a-descriptions-item>
                        <a-descriptions-item label="车辆调度员">{{ info.carDispatchUser?.nickname }}
                        </a-descriptions-item>
                    </a-descriptions>
                </a-card>
                <a-card>
                    <a-descriptions title="项目信息">
                        <a-descriptions-item label="派单类型">{{ WORKSHEET_WORK_TYPE[info.detail.workType] }}
                        </a-descriptions-item>
                        <a-descriptions-item label="项目名称">{{ info.projectName }}</a-descriptions-item>
                        <!--                        <a-descriptions-item label="项目地址">{{ info.projectRegion + info.projectAddress }}-->
                        <!--                        </a-descriptions-item>-->
                        <a-descriptions-item label="计划进场时间">{{ info.planInDate }}</a-descriptions-item>
                        <a-descriptions-item label="到货时间">{{ info.receiveDate }}</a-descriptions-item>
                        <a-descriptions-item label="项目联系人电话"> {{ info.contactPhone }}</a-descriptions-item>
                    </a-descriptions>
                </a-card>
                <a-card>
                    <a-descriptions title="设备信息">
                        <a-descriptions-item label="设备名称">{{ info.detail?.equipmentName }}</a-descriptions-item>
                        <a-descriptions-item label="作业类型">{{ WORKSHEET_TYPE[info.detail?.workType] }}
                        </a-descriptions-item>
                        <a-descriptions-item label="设备型号">{{ info.detail?.model }}</a-descriptions-item>
                        <a-descriptions-item label="出厂编号">{{ info.detail?.factoryNo }}</a-descriptions-item>
                        <a-descriptions-item label="设备厂家">{{ info.detail.equipment.manufactor }}
                        </a-descriptions-item>
                        <a-descriptions-item label="安装臂长">{{ info.detail?.setupLength }}</a-descriptions-item>
                        <a-descriptions-item label="年份要求"> {{ info.detail?.yearRequest }}</a-descriptions-item>
                        <a-descriptions-item label="初始安装高度">{{ info.detail?.setupHeight }}米</a-descriptions-item>
                        <a-descriptions-item label="最终安装高度">{{ info.detail?.finalSetupHeight }}米
                        </a-descriptions-item>
                        <a-descriptions-item label="是否需要油漆">{{ TRUE_OR_FALSE[info.detail?.needPaint] }}
                        </a-descriptions-item>
                        <a-descriptions-item label="是否确认道路通畅">{{ TRUE_OR_FALSE[info.detail?.confirmRoad] }}
                        </a-descriptions-item>
                        <a-descriptions-item label="是否确认电箱到位">{{ TRUE_OR_FALSE[info.detail?.confirmElectric] }}
                        </a-descriptions-item>
                        <a-descriptions-item label="是否确认基础预埋时间满足">
                            {{ TRUE_OR_FALSE[info.detail?.confirmHasTime] }}
                        </a-descriptions-item>
                        <a-descriptions-item label="是否确认安装资料完善"> {{ TRUE_OR_FALSE[info.detail?.confirmProfile]
                            }}
                        </a-descriptions-item>
                    </a-descriptions>
                </a-card>
                <a-card>
                    <a-descriptions title="派单信息">
                        <a-descriptions-item label="作业人员">{{ info.detail?.sysWorkerList }}</a-descriptions-item>
                        <a-descriptions-item label="外调人员">{{ info.detail?.outComeWorkerList }}</a-descriptions-item>
                        <a-descriptions-item label="人员类型">
                            {{ (info.detail) ? WORKER_TYPE[info.detail?.workerType] : "" }}
                        </a-descriptions-item>
                        <a-descriptions-item label="班组负责人">{{ info.classManagerUser?.nickname }}
                        </a-descriptions-item>
                        <a-descriptions-item label="现场负责人">{{ info.detail?.localeManager }}</a-descriptions-item>
                        <!--                        <a-descriptions-item label="司机"> {{ info.detail?.driver }}</a-descriptions-item>-->
                        <!--                        <a-descriptions-item label="车牌">{{ info.detail?.carPlate }}</a-descriptions-item>-->
                        <a-descriptions-item label="派单说明">{{ info.detail?.intro }}</a-descriptions-item>
                        <a-descriptions-item label="备注信息">{{ info.detail?.remark }}</a-descriptions-item>
                    </a-descriptions>
                    <a-descriptions title="资料图片" v-if="info.detail && info.detail?.photos">
                        <a-descriptions-item>
                            <a-image-preview-group>
                                <a-image style="margin-right: 1rem"
                                         :width="45"
                                         v-for="(item, index) in info.detail?.photos.split(',')"
                                         :key="index"
                                         :src="item"
                                />
                            </a-image-preview-group>
                        </a-descriptions-item>
                    </a-descriptions>
                    <!--                    <a-card title="配件信息">-->
                    <!--                        <a-descriptions v-for="(item, index) in parts" :key="index" :title="item.title">-->
                    <!--                            <a-descriptions-item v-for="(part, partIndex) in item.children" :key="partIndex"-->
                    <!--                                                 :label="part.partsTitle">-->
                    <!--                                x{{ part.num }}-->
                    <!--                            </a-descriptions-item>-->
                    <!--                        </a-descriptions>-->
                    <!--                    </a-card>-->
                </a-card>
                <a-card>
                    <a-descriptions title="安装信息">
                        <a-descriptions-item label="最高安装高度">{{ info.setUp?.maxSetUpHeight }}米
                        </a-descriptions-item>
                        <a-descriptions-item label="安装高度">{{ info.setUp?.setUpHeight }}米</a-descriptions-item>
                        <a-descriptions-item label="附着高度">{{ info.setUp?.clingHeight }}米</a-descriptions-item>
                        <a-descriptions-item label="大臂长度">{{ info.setUp?.bigArmLength }}米</a-descriptions-item>
                        <a-descriptions-item label="平衡长度">{{ info.setUp?.balanceLength }}米</a-descriptions-item>
                        <a-descriptions-item label="计划安装附墙数"> {{ info.setUp?.planSetUpCling }}
                        </a-descriptions-item>
                    </a-descriptions>
                </a-card>
                <a-card>
                    <a-descriptions title="车辆信息">
                        <a-descriptions-item :label="item.carPlate" v-for="(item, index) in info.carDispatchList"
                                             :key="index">{{ item.name }}({{ item.phone }})
                        </a-descriptions-item>
                    </a-descriptions>
                </a-card>
                <a-card title="到场核验信息">
                    <a-descriptions title="资料图片" v-if="info.check && info.check?.photos">
                        <a-descriptions-item>
                            <a-image-preview-group>
                                <a-image style="margin-right: 1rem"
                                         :width="45"
                                         v-for="(item, index) in info.check?.photos.split(',')"
                                         :key="index"
                                         :src="item"
                                />
                            </a-image-preview-group>
                        </a-descriptions-item>
                    </a-descriptions>
                    <a-descriptions title="核验信息">
                        <a-descriptions-item label="现场定位">{{ info.check?.address }}</a-descriptions-item>
                        <a-descriptions-item label="实际到场时间">{{ info.check?.checkTime }}</a-descriptions-item>
                        <a-descriptions-item label="核验人">{{ info.check?.nickname }}</a-descriptions-item>
                    </a-descriptions>
                </a-card>
            </a-collapse-panel>
        </a-collapse>
    </ele-modal>
</template>

<script lang="ts" setup>
import { ref, reactive, watch } from "vue";
import { Form } from "ant-design-vue";
import { useThemeStore } from "@/store/modules/theme";
import { storeToRefs } from "pinia";
import { getWorksheet, getWorksheetByWordType } from "@/api/tower/worksheet";
import {
    Worksheet,
    WORKSHEET_AUDIT_STATUS_LIST,
    WORKSHEET_STATUS_LIST,
    WORKSHEET_WORK_TYPE
} from "@/api/tower/worksheet/model";
import dayjs from "dayjs";

const useForm = Form.useForm;
// 是否开启响应式布局
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);

const props = defineProps<{
    // 弹窗是否打开
    visible: boolean;
    // 修改回显的数据
    data?: Worksheet | null;
    workType: number;
}>();

// 是否显示最大化切换按钮
const maxAble = ref(true);

const active = ref(2);

const emit = defineEmits<{
    (e: "done"): void;
    (e: "update:visible", visible: boolean): void;
}>();

// 请求状态
const loading = ref(true);

const activeKey = ref<string[]>();

/* 更新visible */
const updateVisible = (value: boolean) => {
    emit("update:visible", value);
};

const WORKSHEET_TYPE = ["安装单", "加高单", "拆卸单"];
const TRUE_OR_FALSE = ["否", "是"];
const WORKER_TYPE = ["自有", "外派"];

const list = ref<Worksheet[]>([]);

const parts = ref<any>([]);

const getDetail = () => {
    const projectId = props.data?.projectId;
    list.value = [];
    getWorksheetByWordType(projectId, props.workType).then((data) => {
        list.value = data;
        // for (let key in data) info[key] = data[key];
        // parts.value = [];
        // if (info.parts) {
        //     const parentIdIdList = [];
        //     info.parts.forEach((item: any) => {
        //         if (parentIdIdList.indexOf(item.parentId) === -1) {
        //             parentIdIdList.push(item.parentId);
        //             parts.value.push({
        //                 title: item.parentPartsTitle,
        //                 parentId: item.parentId,
        //                 children: []
        //             });
        //         }
        //     });
        //     info.parts.forEach(item => {
        //         parts.value.forEach((parent, index) => {
        //             if (item.parentId === parent.parentId) parts.value[index].children.push(item);
        //         });
        //     });
        // }
    });
};

/* 保存编辑 */
const save = () => {
};

watch(
    () => props.visible,
    (visible) => {
        if (visible) {
            if (props.data) {
                loading.value = false;
                getDetail();
            }
        }
    }
);
</script>

