<!--  -->
<template>
    <div class="hc-page-box">
        <HcNewCard>
            <template #header>
                <div class="w-32">
                    <el-select v-model="searchForm.userName" placeholder="测量人" clearable filterable block @change="getTableData">
                        <el-option v-for="item in peopleType" :key="item" :label="item" :value="item" />
                    </el-select>
                </div>
                <div class="ml-3 w-42">
                    <el-select v-model="searchForm.backBreak" clearable block placeholder="是否超欠挖 " @change="getTableData">
                        <el-option v-for="item in tasksStatus" :key="item.value" :label="item.label" :value="item.value" />
                    </el-select>
                </div>
                <div class="ml-3 w-64">
                    <HcDatePicker :dates="betweenTime" clearable @change="betweenTimeUpdate" />
                </div>
            </template>
            <HcTable is-new :column="tableColumn" :datas="tableData">
                <template #backBreak="{ row }">
                    {{ tasksStatus.find(item => item.value == row.backBreak)?.label || row.backBreak }}
                </template>
                <template #action="{ row }">
                    <el-link type="primary" @click="viewSubmit(row)">查看详情</el-link>
                    <el-link type="warning" @click="changeRow(row)">编辑</el-link>
                </template>
            </HcTable>
            <template #action>
                <HcPages :pages="searchForm" @change="pageChange" />
            </template>
        </HcNewCard>
        <!-- 编辑 -->
        <cross-add v-model="editModal" :form-disabled="formDisabled" :row-id="rowId" @save="getTableData" />
    </div>
</template>

<script setup>
import { onMounted, ref, watch } from 'vue'

import crossApi from '~api/cross/cross'
import { useAppStore } from '~src/store'
import { getArrValue } from 'js-fast-way'
import crossAdd from './cross-add.vue'
import { getDictionaryData } from '~uti/tools'
const useAppState = useAppStore()
const projectId = ref(useAppState.getProjectId)
const contractId = ref(useAppState.contractId)

const tableColumn = [
    { key: 'deviceCode', name: '设备型号' },
    { key: 'createTime', name: '上传时间' },
    { key: 'nameOfProject', name: '工程名称' },
    { key: 'date', name: '测量时间' },
    { key: 'userName', name: '测量人' },
    { key: 'mileageNumber', name: '里程号' },
    { key: 'backBreak', name: '是否超欠挖' },
    { key: 'action', name: '操作', width:150 },
]
const tableData = ref([
  
])
//搜索表单
const searchForm = ref({
    current: 1, size: 20, total: 0, userName:'', backBreak:'', startTime:'', endTime:'',

})
onMounted(() => {
    getTableData()
    getPeopleType()
    getTasksStatusOptions()
   
})
const peopleType = ref([])
const getPeopleType = async () => {
     const { error, code, data } = await crossApi.getListUserName()
    //判断状态
 
    if (!error && code === 200) {
        peopleType.value = getArrValue(data)
       
    } else {
        peopleType.value = []
 
    }
}
const getTasksStatusOptions = async () => {
    tasksStatus.value = await getDictionaryData('q_profiler_back_break', true)
    tasksStatus.value.forEach(item => {
        item.value = String(item.value) 

    })
    

    
}
const tasksStatus = ref([
   
])
//日期时间被选择
const betweenTime = ref(null)
const betweenTimeUpdate = ({ val, arr }) => {
    betweenTime.value = arr
    searchForm.value.startTime = val['start']
    searchForm.value.endTime = val['end']
    getTableData()

}
//分页被点击
const pageChange = ({ current, size }) => {
    searchForm.value.current = current
    searchForm.value.size = size
    getTableData()
}
const tableLoading = ref(false)
const getTableData = async () => {
    tableLoading.value = true
    const { error, code, data } = await crossApi.queryListData({
        ...searchForm.value,
        projectId: projectId.value,
        contractId:contractId.value,

    })
    //判断状态
    tableLoading.value = false
    if (!error && code === 200) {
        tableData.value = getArrValue(data['records'])
        searchForm.value.total = data['total'] || 0
    } else {
        tableData.value = []
        searchForm.value.total = 0
    }
}

const editModal = ref(false)//提交整改
const rowId = ref(null)
const formDisabled = ref(false)
const changeRow = (row)=>{
    rowId.value = row['id']
    editModal.value = true
    formDisabled.value = false

}
//查看详情
const viewSubmit = async (row)=>{
      rowId.value = row['id']
    formDisabled.value = true
      editModal.value = true

}
</script>

<style lang='scss' scoped>
</style>