<template>
  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column :label="t('FactoryModeling.AutocodeRule.partTableIdColumn')" align="center" prop="id" />
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTablePartIndexColumn')"
        align="center"
        prop="partIndex"
      />
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTablePartTypeColumn')"
        align="center"
        prop="partType"
      >
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.ERP_AUTOCODE_PARTTYPE" :value="scope.row.partType" />
        </template>
      </el-table-column>
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTablePartCodeColumn')"
        align="center"
        prop="partCode"
      />
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTablePartNameColumn')"
        align="center"
        prop="partName"
      />
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTablePartLengthColumn')"
        align="center"
        prop="partLength"
      />
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTableDatetimeFormatColumn')"
        align="center"
        prop="datetimeFormat"
      />
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTableInputCharacterColumn')"
        align="center"
        prop="inputCharacter"
      />
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTableFixCharacterColumn')"
        align="center"
        prop="fixCharacter"
      />
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTableSeriaStartNoColumn')"
        align="center"
        prop="seriaStartNo"
      />
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTableSeriaStepColumn')"
        align="center"
        prop="seriaStep"
      />
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTableSeriaNowNoColumn')"
        align="center"
        prop="seriaNowNo"
      />
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTableCycleFlagColumn')"
        align="center"
        prop="cycleFlag"
      >
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.ERP_AUTOCODE_IS_PADDING" :value="scope.row.cycleFlag" />
        </template>
      </el-table-column>
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTableCycleMethodColumn')"
        align="center"
        prop="cycleMethod"
      >
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.ERP_AUTOCODE_CYCLEMETHOD" :value="scope.row.cycleMethod" />
        </template>
      </el-table-column>
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTableRemarkColumn')"
        align="center"
        prop="remark"
      />
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTableIsEnableColumn')"
        align="center"
        prop="isEnable"
      >
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.isEnable" />
        </template>
      </el-table-column>
      <el-table-column
        :label="t('FactoryModeling.AutocodeRule.partTableCreateTimeColumn')"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
    </el-table>
  </ContentWrap>
</template>
<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import { AutocodeRuleApi } from '@/api/erp/autocode'

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

const props = defineProps<{
  ruleId?: number // 规则ID（主表的关联字段）
}>()
const loading = ref(false) // 列表的加载中
const list = ref([]) // 列表的数据

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    list.value = await AutocodeRuleApi.getAutocodePartListByRuleId(props.ruleId)
  } finally {
    loading.value = false
  }
}

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

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