<template>
    <div class="hc-task-form">
        <!-- 基础表单 -->
        <hc-card-item>
            <el-form ref="baseFormRef" :model="baseForm" :rules="baseFormRules" label-position="left" label-width="auto">
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="计量期：">
                            <el-select v-model="baseForm.contractPeriodId" placeholder="选择计量期" disabled block>
                                <el-option v-for="item in periods" :key="item.id" :label="item.periodNumber" :value="item.id" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="业务日期：">
                            <el-date-picker v-model="baseForm.businessDate" class="block" format="YYYY-MM-DD" type="date" value-format="YYYY-MM-DD" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="计量金额：">
                            <el-input v-model="baseForm.meterMoney" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="预付款总额：">
                            <el-input v-model="baseForm.meterMoney1" placeholder="开工预付款总额" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="申请依据：">
                            <el-input v-model="baseForm.calculateFormula" :autosize="{ minRows: 4, maxRows: 8 }" type="textarea" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </hc-card-item>
        <!-- 附件列表 -->
        <hc-card-item class="mt-3" title="附件列表">
            <template #extra>
                <span class="text-[13px] text-orange font-400">可上传 图片(png、jpg、jpeg)、Excel(xls、xlsx)、PDF、Word(doc、docx)文件</span>
            </template>
            <el-form :model="baseForm" label-position="left" label-width="auto">
                <el-form-item label="上传附件">
                    <hc-form-upload type="list" :src="baseForm.fileList" :h-props="uploadFormProps" @upload="attachmentUpload" @change="attachmentUploadChange" />
                </el-form-item>
            </el-form>
        </hc-card-item>
        <!-- 文件上传组件 -->
        <hc-upload-file ref="uploadFileRef" :echo-params="uploadFileParams" :options="uploadFileOptions" @success="uploadFileSuccess" />
    </div>
</template>

<script setup>
import { getArrValue } from 'js-fast-way'
import { onMounted, ref, watch } from 'vue'
import { getHeader } from 'hc-vue3-ui'

import mainApi from '~api/tasks/hc-data'

const props = defineProps({
    isEdit: {
        type: Boolean,
        default: true,
    },
    type: {
        type: [String, Number],
        default: '',
    },
})

//双向绑定
// eslint-disable-next-line no-undef
const rowInfo = defineModel('modelValue', {
    default: () => ({}),
})

//监听可否编辑
const isEdits = ref(props.isEdit)
watch(() => props.isEdit, (val) => {
    isEdits.value = val
}, { immediate: true, deep: true })

//监听类型
const isType = ref(props.type)
watch(() => props.type, (val) => {
    isType.value = val
}, { immediate: true, deep: true })

//监听数据
watch(() => rowInfo, (val) => {
    setTaskInfo(val.value)
}, { deep: true })

//渲染完成
onMounted(() => {
    setTaskInfo(rowInfo.value)
})

//设置任务信息
const taskInfo = ref({})
const setTaskInfo = async (info) => {
    taskInfo.value = info
    getStartWorkPeriod(info.contractId).then()
}

//获取开工计量期列表
const periods = ref([])
const getStartWorkPeriod = async (cid) => {
    if (cid === '') return
    const { data } = await mainApi.getMeterPeriod({
        contractId: cid,
        type: 2,
    })
    periods.value = getArrValue(data)
}

//基础表单
const baseFormRef = ref(null)
const baseForm = ref({ fileList: [] })
const baseFormRules = {}

const uploadFormProps = ref({})

const attachmentUpload = () => {

}

const attachmentUploadChange = () => {

}

//文件上传
const uploadFileRef = ref(null)
const uploadFileParams = ref({})
const uploadFileOptions = ref({})
const uploadFileSuccess = () => {

}
</script>

<style lang="scss" scoped>
.hc-task-form {

}
</style>
