
<template>
    <div class="detail-popup">
        <popup ref="popupRef" title="施工计划详情" :async="true" width="80%" @confirm="handleSubmit" @close="handleClose">
            <el-form ref="formRef" :model="formData" label-width="120px">

                <el-row>
                    <el-col :span="12">
                        <el-form-item label="项目名称">
                            {{ formData.project_name }}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="项目编码">
                            {{ formData.project_code }}
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="计划开始日期">
                            {{ formData.plan_start_date }}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="计划结束日期">
                            {{ formData.plan_end_date }}
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="工序步骤号">
                            {{ formData.process_step_no }}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="工序步骤">
                            {{ formData.process_step }}
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="图例说明">
                            <div v-if="formData.file && formData.file.length > 0"> <img :src="item.uri"
                                    v-for="item in formData.file" style="width:200px" /></div>
                            <div v-else>暂无文件</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="质量控制点">
                            {{ formData.quality_control_points }}
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="班组长">
                            {{ formData.project_member_name }}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="施工人员">
                            {{ formData.work_user }}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="施工内容">
                            {{ formData.work_content }}
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="作业量">
                            {{ formData.workload }}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="单位">
                            {{ formData.unit }}
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="单价">
                            {{ formData.price }}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="金额">
                            {{ formData.amount }}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="完工作业量">
                            {{ formData.done_workload }}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="剩余作业量">
                            {{ formData.residue_workload }}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="进度(%)">
                            {{ formData.completion_degree }}
                        </el-form-item>
                    </el-col>

                </el-row>

                <div style="margin:10px 0">施工汇报</div>
                <div>
                    <el-table :data="buildreportsList">

                        <el-table-column label="施工汇报单号" prop="report_code" show-overflow-tooltip />
                        <el-table-column label="填报人" prop="add_user_name" show-overflow-tooltip />
                        <el-table-column label="填报日期" prop="create_time" show-overflow-tooltip />
                        <el-table-column label="现场照片" prop="process_step_no">
                            <template #default="{ row }">

                                <div v-if="row.scene_file && row.scene_file.length > 0">
                                    <!--                                     
                                    <material-picker
                                        v-model="row.scene_file" /> -->

                                    <img v-for="item in row.scene_file" :src="item" style="width:50px">

                                    <!-- {{ row.scene_file }} -->
                                </div>
                                <div v-else>暂无文件</div>
                            </template>
                        </el-table-column>
                        <el-table-column label="今日完工量" prop="report_workload" show-overflow-tooltip />
                        <el-table-column label="单价" prop="price" show-overflow-tooltip />
                        <el-table-column label="金额" prop="report_amount" show-overflow-tooltip />
                        <el-table-column label="备注" prop="remark" show-overflow-tooltip />


                    </el-table>
                </div>
                <div class="flex justify-end mt-4">

                    <el-pagination v-model:current-page="pager1.page" v-model:page-size="pager1.size"
                        :page-sizes="[10, 20, 30, 40]" layout="total, sizes, prev, pager, next, jumper" :total="totalnum1"
                        @size-change="handleSizeChange1" @current-change="handleCurrentChange1" />

                </div>
                <div style="margin:10px 0">人工明细</div>
                <div>
                    <el-table :data="buildpersonsList">

                        <el-table-column label="施工汇报单号" prop="report_code" show-overflow-tooltip />
                        <el-table-column label="日期" prop="report_date" show-overflow-tooltip />
                        <el-table-column label="姓名" prop="user_name" show-overflow-tooltip />
                        <el-table-column label="身份证号" prop="user_idcard" show-overflow-tooltip />
                        <el-table-column label="工种" prop="user_work_type" show-overflow-tooltip />
                        <el-table-column label="今日完工量" prop="work_num" show-overflow-tooltip />

                        <el-table-column label="单价" prop="price" show-overflow-tooltip />
                        <el-table-column label="金额" prop="amount" show-overflow-tooltip />
                        <el-table-column label="备注" prop="remark" show-overflow-tooltip />

                    </el-table>
                </div>
                <div class="flex justify-end mt-4">
                    <el-pagination v-model:current-page="pager.page" v-model:page-size="pager.size"
                        :page-sizes="[10, 20, 30, 40]" layout="total, sizes, prev, pager, next, jumper" :total="totalnum"
                        @size-change="handleSizeChange" @current-change="handleCurrentChange" />
                </div>
            </el-form>
        </popup>
    </div>
</template>

<script lang="ts" setup name="customdetail">
import { usePaging } from '@/hooks/usePaging'
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiCustomDetail } from '@/api/custom'
import { buildreportsDetail, buildpersonsDetail } from '@/api/build/build_plan'
import { timeFormat } from '@/utils/util'
import { buildreportLists } from "@/api/build/build_report.ts"
import { buildreportDetaillists } from "@/api/build/build_report_detail.ts"


import type { PropType } from 'vue'
defineProps({
    dictData: {
        type: Object as PropType<Record<string, any[]>>,
        default: () => ({})
    }
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const buildpersonsList = ref([])
const buildreportsList = ref([])
const datas = reactive({
    provinceOptions: [],
    cityOptions: [],
    areaOptions: [],
});
const totalnum = ref(0)
const totalnum1 = ref(0)
const pager = reactive({
    page: 1,
    size: 10,
})
const pager1 = reactive({
    page: 1,
    size: 10,
})
// 查询条件
const queryParams = reactive({
    plan_id: '',

})
//获取人员明细
const buildpersons = async (id: any) => {
    const data = await buildreportDetaillists({
        plan_id: id,
        page_no: pager1.page,
        page_size: pager1.size,
    })
    buildpersonsList.value = data.lists
    totalnum1.value = data.count
}


const handleSizeChange = (val: number) => {
    // console.log(`${val} items per page`)
    pager.size = val
    buildreports(formData.id)
}
const handleCurrentChange = (val: number) => {
    // console.log(`current page: ${val}`)
    pager.page = val
    buildreports(formData.id)
}
const handleSizeChange1 = (val: number) => {
    // console.log(`${val} items per page`)
    pager1.size = val
    buildpersons(formData.id)
}
const handleCurrentChange1 = (val: number) => {
    // console.log(`current page: ${val}`)
    pager1.page = val
    buildpersons(formData.id)
}
//获取施工汇报明细
const buildreports = async (id: any) => {
    const data = await buildreportLists({
        plan_id: id,
        page_no: pager.page,
        page_size: pager.size,
    })
    buildreportsList.value = data.lists
    totalnum.value = data.count
}

// 表单数据
const formData = reactive({

})

const getLists = (e) => {
    console.log(e)
}


// 获取详情
const setFormData = async (data: Record<any, any>) => {
    Object.assign(formData, data)

    buildpersons(data.id)
    buildreports(data.id)
}

const getDetail = async (row: Record<string, any>) => {
    const data = await apiCustomDetail({
        id: row.id
    })
    setFormData(data)
}


// 提交按钮
const handleSubmit = async () => {
    popupRef.value?.close()

}

//打开弹窗
const open = () => {
    console.log('1111111')
    popupRef.value?.open()
}

// 关闭回调
const handleClose = () => {
    emit('close')
}








defineExpose({
    open,
    setFormData,
    getDetail
})
</script>
<style lang="scss" scoped>
.tit {
    font-size: 1.2em;
    margin-bottom: 10px;
}

:deep(.my-label) {
    width: 150px;
}
</style>
