<template>
    <global-page
        :padding="24"
        title="布置工作详情"
        :showNavRight="arrangeWorkExtendList.length > 1"
        navRightType="icon"
        :showFooterBtn="!!assignWorkStore.getDetailsFooterBtn"
        :footerBtnText="assignWorkStore.getDetailsFooterBtn?.name"
        @handleRightClick="handleRightClick"
        @handleFooterClick="handleFooterClick"
    >
        <view class="details" v-if="details">
            <view class="details-header">
                <view class="details-header-title">{{ getParamNameByValue('LayoutWorkType', details.workType) }}详情</view>
                <view class="details-header-top">
                    <custom-state :value="details.state == 1 ? 'OPEN' : 'CLOSE'" :size="48"></custom-state>
                    <view class="right">
                        <global-field label="提出人:" :value="details.presenter"></global-field>
                    </view>
                </view>
                <view class="details-header-center">
                    <view class="right">
                        <text>{{ details.seat }}</text>
                        <text class="txt">{{ getParamNameByValue('LayoutWorkType', details.workType) }}</text>
                    </view>
                </view>
                <view class="details-header-footer">
                    <view class="left">
                        <global-icon icon="safe"></global-icon>
                        <text class="txt">反馈情况</text>
                    </view>
                    <view class="right">{{ useGetDictByValue('aw_feedbackOpts', details.feedback) }}</view>
                </view>
            </view>
            <view class="details-body">
                <view class="details-body-content">
                    {{ details.taskDescribe }}
                </view>
                <view class="details-body-file">
                    <global-upload :fileList="details.taskFileVoList" :showUpload="false"></global-upload>
                </view>
            </view>
            <view class="details-footer">
                <global-field label="开始日期:" :value="timeStampFormat(details.startTime, { format: 'YYYY/MM/DD' })"></global-field>
                <global-field label="完成日期:" :value="timeStampFormat(details.feedbackTime, { format: 'YYYY/MM/DD' })"></global-field>
            </view>
        </view>
        <template v-if="arrangeWorkExtend">
            <card-details title="工作反馈" :showEmpty="arrangeWorkExtend.feedbackTime == '0'">
                <card-details-item title="问题分析" :content="arrangeWorkExtend.problem"></card-details-item>
                <card-details-item title="解决措施" label="工作目标" :content="arrangeWorkExtend.workTarget"></card-details-item>
                <template v-for="(item, index) in assignWorkStore.getDecompose" :key="index">
                    <card-details-item
                        :label="assignWorkStore.getDecompose.length > 1 && index > 0 ? '分解计划' + (index + 1) : '分解计划'"
                        :content="item.plan"
                    >
                        <card-details-footer
                            rightLabel="完成时限:"
                            :rightValue="timeStampFormat(item.time, { format: 'YYYY/MM/DD' }) || '-'"
                        ></card-details-footer>
                    </card-details-item>
                </template>
                <card-details-item label="当前进展" :content="arrangeWorkExtend.current">
                    <global-upload :fileList="arrangeWorkExtend.fileVoList" :showUpload="false"></global-upload>
                </card-details-item>
                <card-details-item>
                    <card-details-footer leftLabel="基地/部门批准领导:" :leftValue="arrangeWorkExtend.baseApprovalLeader"></card-details-footer>
                    <card-details-footer leftLabel="MCD批准领导:" :leftValue="arrangeWorkExtend.mcdApprovalLeader"></card-details-footer>
                </card-details-item>
                <card-details-item label="批复附件" :borderBottom="false">
                    <global-upload :fileList="arrangeWorkExtend.approvalFileVoList" :showUpload="false"></global-upload>
                    <card-details-footer
                        leftLabel="后续措施反馈:"
                        :leftValue="arrangeWorkExtend.followUpFeedback == '1' ? '是' : '否'"
                        rightLabel="计划完成时间:"
                        :rightValue="
                            arrangeWorkExtend.followUpFeedback == '1' ? timeStampFormat(arrangeWorkExtend.pcTime, { format: 'YYYY/MM/DD' }) : '-'
                        "
                    ></card-details-footer>
                    <card-details-footer
                        leftLabel="工作反馈状态:"
                        :leftValue="useGetDictByValue('aw_feedbackState', arrangeWorkExtend.feedbackState)"
                        rightLabel="反馈人:"
                        :rightValue="arrangeWorkExtend.feedbackUser || '-'"
                    ></card-details-footer>
                    <card-details-footer
                        leftLabel="反馈时间:"
                        :leftValue="timeStampFormat(arrangeWorkExtend.feedbackTime) || '-'"
                    ></card-details-footer>
                </card-details-item>
            </card-details>
            <card-details title="领导批示" :showEmpty="arrangeWorkExtend.approvalTime == '0'">
                <card-details-item
                    title="领导批示意见"
                    :content="useGetDictByValue('aw_leaderState', arrangeWorkExtend.leaderApprovalComments)"
                ></card-details-item>
                <card-details-item title="批示要点" :content="arrangeWorkExtend.approvalContent"></card-details-item>
                <card-details-footer
                    leftLabel="批示人:"
                    :leftValue="arrangeWorkExtend.approvalUser || '-'"
                    rightLabel="批示时间:"
                    :rightValue="timeStampFormat(arrangeWorkExtend.approvalTime) || '-'"
                ></card-details-footer>
            </card-details>
            <card-details
                title="跟踪反馈"
                :showEmpty="arrangeWorkExtend.gzFeedbackTime == '0'"
                v-if="arrangeWorkExtend.feedbackTime && arrangeWorkExtend.approvalTime && arrangeWorkExtend.leaderApprovalComments != 1"
            >
                <card-details-item title="跟踪反馈" :content="arrangeWorkExtend.gzFeedbackContent"></card-details-item>
                <card-details-footer
                    leftLabel="反馈人:"
                    :leftValue="arrangeWorkExtend.gzFeedbackUser"
                    rightLabel="反馈时间:"
                    :rightValue="timeStampFormat(arrangeWorkExtend.gzFeedbackTime)"
                ></card-details-footer>
            </card-details>
            <card-details
                title="跟踪批示"
                :showEmpty="arrangeWorkExtend.gzApprovalTime == '0'"
                v-if="arrangeWorkExtend.approvalTime && arrangeWorkExtend.gzFeedbackTime && arrangeWorkExtend.leaderApprovalComments != 1"
            >
                <card-details-item
                    title="领导批示意见"
                    :content="useGetDictByValue('aw_leaderState', arrangeWorkExtend.gzApprovalComments)"
                ></card-details-item>
                <card-details-item title="批示要点" :content="arrangeWorkExtend.gzApprovalContent"></card-details-item>
                <card-details-footer
                    leftLabel="批示人:"
                    :leftValue="arrangeWorkExtend.gzApprovalUser || '-'"
                    rightLabel="批示时间:"
                    :rightValue="timeStampFormat(arrangeWorkExtend.gzApprovalTime) || '-'"
                ></card-details-footer>
            </card-details>
            <card-details
                title="后续措施反馈"
                :showEmpty="arrangeWorkExtend.followUpFeedbackTime == '0'"
                v-if="arrangeWorkExtend.followUpFeedback == '1'"
            >
                <card-details-item :borderBottom="false" title="反馈内容" :content="arrangeWorkExtend.followUpFeedbackContent"></card-details-item>
                <card-details-item
                    :borderBottom="false"
                    title="应用分类"
                    :content="getParamNameByValue('ApplicationType', arrangeWorkExtend.appType)"
                ></card-details-item>
                <card-details-item label="验证材料">
                    <global-upload :fileList="arrangeWorkExtend.followUpFeedbackFileVoList" :showUpload="false"></global-upload>
                    <card-details-footer
                        leftLabel="反馈人:"
                        :leftValue="arrangeWorkExtend.followUpFeedbackUser || '-'"
                        rightLabel="反馈时间:"
                        :rightValue="timeStampFormat(arrangeWorkExtend.followUpFeedbackTime) || '-'"
                    ></card-details-footer>
                </card-details-item>
            </card-details>
            <card-details title="工作验证" :showEmpty="arrangeWorkExtend.eventType == ''" v-if="assignWorkStore.isCreateUser">
                <card-details-item title="跟踪要点" :content="arrangeWorkExtend.trackingPoints"></card-details-item>
                <card-details-item label="批复附件">
                    <global-upload :fileList="arrangeWorkExtend.validateFileVoList" :showUpload="false"></global-upload>
                    <card-details-footer
                        leftLabel="事件类型:"
                        :leftValue="getParamNameByValue('LayoutEventType', arrangeWorkExtend.eventType)"
                        rightLabel="重复/同类事件:"
                        :rightValue="useGetDictByValue('aw_validateType', arrangeWorkExtend.validateType)"
                    ></card-details-footer>
                </card-details-item>
                <card-details-item :borderBottom="false">
                    <view class="mocp-color-danger-6" style="font-size: 30rpx">
                        {{ useGetDictByValue('aw_feedbackState', arrangeWorkExtend.validateState) }}
                    </view>
                    <card-details-footer
                        v-if="arrangeWorkExtend.validateState == '2'"
                        leftLabel="关闭人:"
                        :leftValue="arrangeWorkExtend.validateCloseUser"
                        rightLabel="关闭时间:"
                        :rightValue="timeStampFormat(arrangeWorkExtend.validateCloseTime)"
                    ></card-details-footer>
                </card-details-item>
            </card-details>
        </template>
    </global-page>
    <!-- 责任单位弹出层 -->
    <company-popup ref="companyPopupRef"></company-popup>
</template>

<script setup>
import { ref } from 'vue'
import CardDetails from './components/card-details.vue'
import CardDetailsItem from './components/card-details-item.vue'
import CardDetailsFooter from './components/card-details-footer.vue'
import CompanyPopup from './components/company-popup.vue'
import useAssignWorkStore from 'mocp/store/assign-work'
import { storeToRefs } from 'pinia'
import { onLoad } from '@dcloudio/uni-app'
import { timeStampFormat } from 'mocp/utils/tool'
import { useGetDictByValue } from 'mocp/hooks/use-dict/useDict'
import { getParamNameByValue } from 'mocp/hooks/use-params/useParams'

const query = defineProps(['id'])
const assignWorkStore = useAssignWorkStore()
const { details, arrangeWorkExtendList, arrangeWorkExtend } = storeToRefs(assignWorkStore)
onLoad(async () => {
    assignWorkStore.setState('id', query.id)
    uni.showLoading({
        title: '加载中...',
        mask: true
    })
    await assignWorkStore.getArrangeWorkDetail()
    if (arrangeWorkExtendList.value.length > 1) {
        await assignWorkStore.getEnetOrgTree()
    }
    uni.hideLoading()
})
//责任公司弹框
const companyPopupRef = ref()
const handleRightClick = () => {
    companyPopupRef.value?.open()
}
//新增
const handleFooterClick = () => {
    uni.$mocpJump.navigateTo(assignWorkStore.getDetailsFooterBtn?.path)
}
</script>
<style lang="scss" scoped>
@import './constants/details.scss';
</style>
