<template>
    <global-page
        :padding="24"
        :title="arrangeWorkExtend?.companyFullName"
        :showNavRight="arrangeWorkExtendList.length"
        navRightType="icon"
        showFooterBtn
        footerBtnText="领导批示"
        @handleRightClick="handleRightClick"
        @handleFooterClick="handleFooterClick"
    >
        <view class="details" v-if="details">
            <view class="details-header">
                <view class="details-header-title">{{ baseStore.getParamNameByValue('LayoutWorkType', details.workType) }}详情</view>
                <view class="details-header-top">
                    <view class="left">{{ details.state == 1 ? 'OPEN' : 'ClOSE' }}</view>
                    <view class="right">
                        <global-field label="提出人:" :value="details.presenter"></global-field>
                    </view>
                </view>
                <view class="details-header-center">
                    <view class="left">
                        <global-icon icon="mind-mapping"></global-icon>
                        <global-field class="txt" label="工作台编号:" :value="details.workbench || '-'"></global-field>
                    </view>
                    <view class="right">
                        <text>{{ details.seat }}</text>
                        <text class="txt">{{ baseStore.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('feedbackOpts', details.feedback) }}</view>
                </view>
            </view>
            <view class="details-body">
                <view class="details-body-content">
                    {{ details.taskDescribe }}
                </view>
                <view class="details-body-file">
                    <global-album :fileList="details.taskFileVoList"></global-album>
                </view>
            </view>
            <view class="details-footer">
                <global-field label="开始日期:" :value="timeStampFormat(details.startTime)"></global-field>
                <global-field label="完成日期:" :value="timeStampFormat(details.feedbackTime)"></global-field>
            </view>
        </view>
        <template v-if="arrangeWorkExtend">
            <card-details title="工作反馈">
                <template v-if="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 + 1) : '分解计划'"
                            :content="item.plan"
                        >
                            <card-details-footer rightLabel="完成时限:" :rightValue="timeStampFormat(item.time) || '-'"></card-details-footer>
                        </card-details-item>
                    </template>
                    <card-details-item label="当前进展" :content="arrangeWorkExtend.current">
                        <global-album :fileList="arrangeWorkExtend.fileVoList"></global-album>
                    </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-album :fileList="arrangeWorkExtend.approvalFileVoList"></global-album>
                        <card-details-footer
                            leftLabel="后续措施反馈:"
                            :leftValue="arrangeWorkExtend.followUpFeedback == '1' ? '是' : '否'"
                            rightLabel="计划完成时间:"
                            :rightValue="arrangeWorkExtend.followUpFeedback == '1' ? timeStampFormat(arrangeWorkExtend.pcTime) : '-'"
                        ></card-details-footer>
                        <card-details-footer
                            leftLabel="工作反馈状态:"
                            :leftValue="useGetDictByValue('feedbackState', arrangeWorkExtend.feedbackState)"
                            rightLabel="反馈人:"
                            :rightValue="arrangeWorkExtend.feedbackUser || '-'"
                        ></card-details-footer>
                        <card-details-footer
                            leftLabel="反馈时间:"
                            :leftValue="timeStampFormat(arrangeWorkExtend.feedbackTime) || '-'"
                        ></card-details-footer>
                    </card-details-item>
                </template>
                <view class="card-empty" v-else>
                    <global-empty></global-empty>
                </view>
            </card-details>
            <card-details title="领导批示">
                <template v-if="arrangeWorkExtend.approvalTime != 0">
                    <card-details-item
                        title="领导批示意见"
                        :content="useGetDictByValue('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>
                </template>
                <view class="card-empty" v-else>
                    <global-empty></global-empty>
                </view>
            </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, onUnload } from '@dcloudio/uni-app'
import useBaseStore from 'mocp/store/base'
import { timeStampFormat } from 'mocp/utils/tool'
import { useGetDictByValue } from 'mocp/hooks/use-dict/useDict'

const baseStore = useBaseStore()
const query = defineProps(['id'])
const assignWorkStore = useAssignWorkStore()
const { details, arrangeWorkExtendList, arrangeWorkExtend } = storeToRefs(assignWorkStore)
onLoad(() => {
    assignWorkStore.setState('id', query.id)
    assignWorkStore.getArrangeWorkDetail()
})
//责任公司弹框
const companyPopupRef = ref()
const handleRightClick = () => {
    companyPopupRef.value?.open()
}
//新增
const handleFooterClick = () => {
    uni.$mocpJump.navigateTo('/panel/assign-work/edit-approval')
}
onUnload(() => {
    assignWorkStore.$reset()
})
</script>
<style lang="scss" scoped>
@import './constants/details.scss';
</style>
