<template>
  <ns-view-list-table ref="mainRef" v-bind="config">
    <template #bodyCell="{ record, column }">
      <template v-if="column.dataIndex === 'executionTime'">
        {{ getData(record) }}
      </template>
    </template>
  </ns-view-list-table>
  <NsModalFrom ref="modalFormRef" v-bind="nsModalFormConfig" />
</template>
<script lang="ts" setup>
  import { tableConfig } from './config';
  import { ref, onMounted } from 'vue';
  import NsModalFrom from '/@/components/ns-modal-form.vue';
  import { planToAddApi } from '/@/api/planToAdd';
  //页面 创建
  const orgId = ref('');
  const projectId = ref('');
  const result = JSON.parse(sessionStorage.getItem('ORGID')!);
  orgId.value = result;
  const results = JSON.parse(sessionStorage.getItem('/hx-ai-intelligent/')!);
  projectId.value = results.projectId;
  const mainRef = ref(null);
  const modalFormRef = ref(null);
  const getData = (record: any) => {
    return record.startTime
      ? record.startTime.substring(0, 10) + ' - ' + record.endTime.substring(0, 10)
      : '未配置时间';
  };
  const nsModalFormConfig = ref({
    api: planToAddApi.updPlan,
    data: {},
    title: '编辑',
    schemas: [
      { field: 'id', component: 'NsInput', show: false },
      { field: 'orgId', component: 'NsInput', show: false },
      {
        field: 'createTime',
        label: '执行时间',
        component: 'NsRangePicker',
        allowClear: true,
        fieldMap: ['startTime', 'endTime'],
        componentProps: {
          valueFormat: 'YYYY-MM-DD',
          placeholder: ['开始日期', '结束日期'],
        },
        rules: [
          {
            required: true,
            message: '请选择执行时间',
          },
        ],
      },
    ],
    extraModalConfig: {
      bodyStyle: { paddingBottom: 0 },
    },
    success: (data: any) => {
      console.log(data, '数据');
      mainRef.value?.nsTableRef.reload();
    },
  });
  //创建页面调用方法
  onMounted(() => {});
  const config = tableConfig(
    orgId.value,
    projectId.value,
    mainRef,
    nsModalFormConfig,
    modalFormRef,
  );

  defineOptions({
    name: 'LedgerIndex', // 与页面路由name一致缓存才可生效
  });
</script>
<style lang="less" scoped>
  :deep(.ns-table-search),
  :deep(.ns-part-tree),
  :deep(.ns-table-main) {
    box-shadow: @ns-content-box-shadow;
  }
</style>
