<template>
  <Dialog :title="dialogTitle" width="80%" v-model="dialogVisible" center>
    <ContentWrap class="borderxx">
      <!-- 搜索工作栏 -->
      <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true" label-width="108px">
        <el-form-item label="项目编号" prop="code">
          <el-input v-model="queryParams.code" placeholder="请输入项目编号" clearable @keyup.enter="handleQuery" class="!w-240px" />
        </el-form-item>
        <el-form-item label="合同号" prop="contractNo">
          <el-input v-model="queryParams.contractNo" placeholder="请输入项目编号" clearable @keyup.enter="handleQuery" class="!w-240px" />
        </el-form-item>
        <el-form-item label="客户名称" prop="customerName">
          <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable @keyup.enter="handleQuery" class="!w-240px" />
        </el-form-item>
        <el-form-item>
          <el-button @click="handleQuery" type="primary">
            <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>
    <el-card class="hl-card">
      <!-- 列表 -->
      <ContentWrap>
        <el-table v-loading="loading" :data="tablelist" :stripe="true"  class="hl-table" @selection-change="handleSelectionChange"
         @row-click="clickRow" ref="multipleTable" selection
        >
          <el-table-column fixed type="selection" width="40" />
          <el-table-column fixed label="序号" type="index" width="60" />
          <el-table-column fixed label="名称" align="center" prop="name" min-width="220" />
          <el-table-column label="编号" align="center" prop="code" min-width="220" />
          <el-table-column label="编号" align="center" prop="code" min-width="220" />
          <el-table-column label="编号" align="center" prop="code" min-width="220" />
          <el-table-column label="编号" align="center" prop="code" min-width="220" />
          <el-table-column fixed="right" label="编号" align="center" prop="code" min-width="220" />
          <el-table-column fixed="right" label="编号" align="center" prop="code" min-width="220" />

        </el-table>

        <!-- 分页 -->
        <Pagination :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize" @pagination="getList" />
      </ContentWrap>
    </el-card>
    <template #footer>
      <el-button @click="dialogVisible=false" size="large">取 消</el-button>
      <el-button @click="submitForm" type="primary" size="large">确 定</el-button>

    </template>
  </Dialog>
</template>

<script setup lang="ts">
import { getIntDictOptions, getStrDictOptions, DICT_TYPE } from '@/utils/dict'
import { dateFormatter, dateFormatter2, formatDate } from '@/utils/formatTime'
import { ref } from 'vue'

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化
const router = useRouter()
const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题

const loading = ref(true) // 列表的加载中
const list = ref([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  contractNo: undefined,
  code: undefined,
  orderStatus: 32
})
const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    // const data = await ProjectOrderApi.getProjectOrderPage(queryParams)
    // list.value = data.list
    // total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

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

const tablelist = ref([
  {
    name: '合立000',
    code: 'heli000'
  },
  {
    name: '合立111',
    code: 'heli000'
  }
])
const multipleTable = ref<InstanceType<typeof ElTable>>()
const multipleSelection:any = ref([])
const handleSelectionChange = (val: []) => {
  if (val.length > 1) {
    multipleTable.value.clearSelection()
    multipleTable.value.toggleRowSelection(val.pop())
  } else {
    multipleSelection.value = val.pop()
  }
}
const clickRow = (row: any) => {
 if(row){
   multipleTable.value!.toggleRowSelection(row, undefined)
 }else{
  multipleTable.value!.clearSelection()
 }
}

/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
const submitForm = () => {
  if (multipleSelection.value.length === 0) {
    message.warning('请选择一条数据')
    return
  }
  dialogVisible.value = false
  // 发送操作成功的事件
  emit('success', multipleSelection.value)
}

/** 打开弹窗 */
const open = async () => {
  dialogTitle.value = t('common.selectText')
  dialogVisible.value = true
  handleQuery()
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>

