<template>
  <div class="w-full h-full bg-white p-4">
    <p class="font-bold text-lg leading-10 border-b-2">订单文件管理</p>
    <el-form class="pt-4" :inline="true" :model="formState">
      <el-form-item label="原始文件地址">
        <el-input v-model="formState.filePath" placeholder="" clearable />
      </el-form-item>
      <el-form-item label="标注文件地址">
        <el-input v-model="formState.mergeFilePath" placeholder="" clearable />
      </el-form-item>

      <el-form-item>
        <el-button type="default" @click="onReset">重置</el-button>
        <el-button type="primary" @click="onQuery">查询</el-button>
      </el-form-item>
    </el-form>

    <div class="">
      <vxe-toolbar>
        <template #buttons>
          <el-button type="danger" @click="removeRows">删除</el-button>
        </template>
      </vxe-toolbar>
      <vxe-table
        ref="xTable"
        size="small"
        min-height="460"
        border
        :loading="loading"
        :data="tableData"
      >
        <vxe-column type="checkbox" width="50"></vxe-column>
        <!-- <vxe-column field="orderFileId" title="文件id" width="200"></vxe-column> -->
        <vxe-column field="customerId_dictText" title="客户名称" width="200"></vxe-column>
        <vxe-column field="filePath" title="原始文件地址"></vxe-column>
        <vxe-column field="mergeFilePath" title="标注文件地址"></vxe-column>
        <vxe-column field="action" title="操作" width="140">
          <template #default="{row}">
            <el-button type="primary" text size="small" @click="toDetail(row)">查看</el-button>
            <el-button type="primary" text size="small" @click="toDetail2(row)">查看新</el-button>
          </template>
        </vxe-column>
      </vxe-table>

      <vxe-pager
        size="small"
        background
        v-model:current-page="formState.currentPage"
        v-model:page-size="formState.pageSize"
        :total="formState.total"
        @page-change="onQuery"
        :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'Sizes', 'FullJump', 'Total']"
      >
      </vxe-pager>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, reactive, ref } from 'vue'
import { getOrderFilePage, deleteOrderFiles } from '@/api/order'
import { ElMessage } from 'element-plus'
import type { VxeTableInstance } from 'vxe-table'
import { useRouter } from 'vue-router';


const router = useRouter()
const loading = ref(false)
const formState = reactive({
  filePath: '',
  mergeFilePath: '',
  currentPage: 1,
  pageSize: 10,
  total: 0,
  column: 'orderFileId',
  order: 'desc'
})

const xTable = ref<VxeTableInstance>()

const tableData = ref([])

const removeRows = async () => {
  const list = xTable.value?.getCheckboxRecords()
  if (list?.length) {
    const ids = list.map(v => v.orderFileId).join(',')
    await deleteOrderFiles(ids)
    ElMessage.success('删除成功')
    onQuery()
  }
}

const toDetail = (row: any) => {
  router.push({
    path: '/online-excel',
    query: {
      fileId: row.orderFileId
    }
  })
}

const toDetail2 = (row: any) => {
  router.push({
    path: '/comment-excel',
    query: {
      fileId: row.orderFileId
    }
  })
}
const onReset = () => {}
const onQuery = async () => {
  loading.value = true
  try {
    const { data } = await getOrderFilePage(formState)
    tableData.value = data.result.records
    formState.total = +data.result.total
  } catch {}
  loading.value = false
}

onMounted(() => {
  onQuery()
})
</script>
<style lang="scss" scoped></style>
