<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true" label-width="120px">
      <el-form-item label="项目编号" prop="projectCode">
        <el-input
          v-model="queryParams.projectCode"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="生产计划单号" prop="planCode">
        <el-input
          v-model="queryParams.planCode"
          placeholder="请输入生产计划单号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="子项目编号" prop="projectOrderSubCode">
        <el-input
          v-model="queryParams.projectOrderSubCode"
          placeholder="请输入子项目编号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="子项目名称" prop="projectOrderSubName">
        <el-input
          v-model="queryParams.projectOrderSubName"
          placeholder="请输入子项目名称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="零件名称" prop="bomDetailName">
        <el-input
          v-model="queryParams.bomDetailName"
          placeholder="请输入零件名称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="任务负责人" prop="owner">
		    <UserSelect v-model="queryParams.owner"  @update:new-value="handleSelectedUser1" class="!w-265px"/>
		
	    </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 查 询</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重 置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column type="index" min-width="60" fixed label="序号" align="center" />
      <el-table-column label="项目编号" align="center" prop="projectCode"  width="180"/>
      <el-table-column label="项目名称" align="center" prop="projectName" width="120"/>
      <el-table-column label="生产计划单号" align="center" prop="planCode" />
      <el-table-column label="生产状态" align="center" prop="planStatus" width="110">
          <template #default="scope">
            <dict-tag :type="DICT_TYPE.HELI_PROJECT_PLAN_STATUS" :value="scope.row.planStatus" />
          </template>
        </el-table-column>
      <el-table-column label="子项目编号" align="center" prop="projectOrderSubCode" />
      <el-table-column label="子项目名称" align="center" prop="projectOrderSubName" width="120"/>
      <el-table-column label="零件名称" align="center" prop="bomDetailName" width="120"/>
      <el-table-column label="工序名称" align="center" prop="processName" width="110"/>
      <el-table-column label="总派工数量" align="center" prop="dispatchAmount" width="120"/>
      <el-table-column label="总报工时间" align="center" prop="reportAllHour" width="120"/>
      <el-table-column label="总预计工时" align="center" prop="reportPreviewHour" width="120"/>
      <el-table-column label="总报工数量" align="center" prop="reportAmount" width="120" />
      <el-table-column label="完成标志" align="center" prop="isover" width="110">
        <template #default="scope">
          <el-tag v-if="scope.row.isover==2">完成</el-tag>
          <el-tag v-else class="ml-2" type="danger">未完成</el-tag>
            <!-- <dict-tag :type="DICT_TYPE.HELI_YINGFU_MONEY" :value="scope.row.isover" /> -->
          </template>
      </el-table-column>
      <!-- <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openForm('update', scope.row.id)"
            v-hasPermi="['heli:track:update']"
          >
            编辑
          </el-button>
          <el-button
            link
            type="danger"
            @click="handleDelete(scope.row.id)"
            v-hasPermi="['heli:track:delete']"
          >
            删除
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <TrackForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts">
import download from '@/utils/download'
import * as TrackApi from '@/api/heli/track'
import TrackForm from './TrackForm.vue'
import {  DICT_TYPE } from '@/utils/dict'
	import UserSelect from '@/views/heli/hlvuestyle/userSelect.vue'
defineOptions({ name: 'Track' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  projectCode: undefined,
  projectId: undefined,
  planCode: undefined,
  planId: undefined,
  planStatus: undefined,
  projectOrderSubCode: undefined,
  projectOrderSubId: undefined,
  projectOrderSubName: undefined,
  bomDetailId: undefined,
  bomDetailName: undefined,
  processName: undefined,
  processId: undefined,
  dispatchAmount: undefined,
  reportAllHour: undefined,
  reportPreviewHour: undefined,
  reportAmount: undefined,
  isover: undefined,
  owner:undefined,
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await TrackApi.getTrackPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}
const handleSelectedUser1 = (newValue: any) => {
  queryParams.owner = newValue?.id
}
/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await TrackApi.deleteTrack(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await TrackApi.exportTrack(queryParams)
    download.excel(data, '生产进度跟踪.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>