<template>
  <div class="page-box" style="position: relative;">
    <el-form
      ref="FormUserLikeTravelNotes"
      :model="formData"
      :size="layoutStore.defaultFormItemSize"
      label-width="120px"
      label-position="right"
      @submit.prevent
    >
      <filter-box :item-width="350" @search="refreshFormUserLikeTravelNotes()" @reset="resetFormUserLikeTravelNotes">
        <el-form-item label="用户id">
          <user-select
            class="filter-item"
            v-model="formFilter.userIdFilter"
            placeholder=""
            :disabled="false"
          />
        </el-form-item>
      </filter-box>
    </el-form>
    <table-box
      ref="tourUserLikeTravelNotes"
      class="page-table"
      :data="tourUserLikeTravelNotesWidgetDataList"
      :size="layoutStore.defaultFormItemSize"
      :row-config="{isCurrent: false, isHover: true}"
      :seq-config="{startIndex: ((tourUserLikeTravelNotesWidgetCurrentPage - 1) * tourUserLikeTravelNotesWidgetPageSize)}"
      :sort-config="{remote: true}"
      :hasExtend="false"
      @sort-change="tourUserLikeTravelNotesWidget.onSortChange"
      @refresh="tourUserLikeTravelNotesWidget.refreshTable()"
    >
      <vxe-column title="序号" type="seq" :index="tourUserLikeTravelNotesWidget.getTableIndex" :width="80" />
      <vxe-column title="用户id" field="userId" />
      <vxe-column title="游记id" field="travelNotesId" />
      <vxe-column title="创建用户" field="createUserId" />
      <vxe-column title="操作" fixed="right">
        <template v-slot="scope">
          <el-button
            link
            type="primary"
            :size="layoutStore.defaultFormItemSize"
            @click.stop="onDeleteClick(scope.row)"
            :disabled="!checkPermCodeExist('FormUserLikeTravelNotes:FormUserLikeTravelNotes:delete')"
          >
            删除
          </el-button>
        </template>
      </vxe-column>
      <template slot="empty">
        <div class="table-empty unified-font">
          <img src="@/assets/img/empty.png">
          <span>暂无数据</span>
        </div>
      </template>
      <!-- 分页 -->
      <template #pagination>
        <el-row type="flex" justify="end" style="margin-top: 10px;">
          <el-pagination
            :total="tourUserLikeTravelNotesWidgetTotalCount"
            :current-page="tourUserLikeTravelNotesWidgetCurrentPage"
            :page-size="tourUserLikeTravelNotesWidgetPageSize"
            :page-sizes="[10, 20, 50, 100]"
            layout="total, prev, pager, next, sizes"
            @current-change="tourUserLikeTravelNotesWidget.onCurrentPageChange"
            @size-change="tourUserLikeTravelNotesWidget.onPageSizeChange">
          </el-pagination>
        </el-row>
      </template>
    </table-box>
    <label v-if="subPage" class="page-close-box" @click="onCancel()">
      <img src="@/assets/img/back2.png" alt="">
    </label>
  </div>
</template>

<script lang="ts">
export default {
  name: 'FormUserLikeTravelNotes',
};
</script>

<script setup lang="ts">
import { VxeColumn, VxeTable } from 'vxe-table';
import { ANY_OBJECT } from '@/types/generic';
import { DictData, DictionaryBase } from '@/common/staticDict/types';
import { ElMessage, ElMessageBox, UploadFile } from 'element-plus';
import { useRoute, useRouter } from 'vue-router';
import { useCommon } from '@/common/hooks/useCommon';
import { useLayoutStore, useStaticDictStore } from '@/store';
import { useDownload } from '@/common/hooks/useDownload';
import { useDropdown } from '@/common/hooks/useDropdown';
import { DropdownOptions, ListData } from '@/common/types/list';
import { useTable } from '@/common/hooks/useTable';
import { TableOptions } from '@/common/types/pagination';
import { useUpload } from '@/common/hooks/useUpload';
import { useUploadWidget } from '@/common/hooks/useUploadWidget';
import { DictionaryController } from '@/api/system';
import { treeDataTranslate, findItemFromList, findTreeNodePath, findTreeNode } from '@/common/utils';
import { TourUserLikeTravelNotesData } from '@/api/generated/tourUserLikeTravelNotesController';
import { TourUserLikeTravelNotesController } from '@/api/generated';

const router = useRouter();
const route = useRoute();
const layoutStore = useLayoutStore();
const { downloadFile } = useDownload();
const { getUploadHeaders, getUploadActionUrl, fileListToJson, parseUploadData, getPictureList } = useUpload();
const { 
  Delete,
  Search,
  Edit,
  Plus,
  Refresh,
  Picture,
  Dialog,
  mainContextHeight,
  clientHeight,
  checkPermCodeExist,
  parseParams,
  parseArrayParams,
  formatDateByStatsType,
  getDateRangeFilter,
} = useCommon();
// 静态字典
const { staticDict: StaticDict } = useStaticDictStore();

const props = withDefaults(
  defineProps<{
    subPage?: number | string | boolean;
  }>(),
  {
    subPage: 0,
  },
);

const formFilter = reactive({
  // 用户id
  userIdFilter: undefined,
});
const formFilterCopy = reactive({
  // 用户id
  userIdFilter: undefined,
});

const onCancel = () => {
  layoutStore.removeCachePage(route.name as string);
  route.meta.refreshParentCachedPage = true;
  router.go(-1);
};

const onResume = () => {
  refreshFormUserLikeTravelNotes();
};

/**
 * 表格组件数据获取函数，返回Promise
 */
const loadTourUserLikeTravelNotesWidgetData = (params: ANY_OBJECT) => {
  if (params == null) params = {};
  params = {
    ...params,
    tourUserLikeTravelNotesDtoFilter: {
      userId: formFilter.userIdFilter,
    }
  };
  return new Promise((resolve, reject) => {
    TourUserLikeTravelNotesController.list(params).then(res => {
      resolve({
        dataList: res.data.dataList,
        totalCount: res.data.totalCount
      });
    }).catch(e => {
      reject(e);
    });
  });
};
/**
 * 表格组件数据获取检测函数，返回true正常获取数据，返回false停止获取数据
 */
const loadTourUserLikeTravelNotesVerify = () => {
  formFilterCopy.userIdFilter = formFilter.userIdFilter;
  return true;
};
/**
 * 删除
 */
const onDeleteClick = (row?: TourUserLikeTravelNotesData) => {
  let params: ANY_OBJECT = {
    id: row?.id,
  };

  TourUserLikeTravelNotesController.delete(params).then(res => {
    ElMessage.success('删除成功');
    tourUserLikeTravelNotesWidget.refreshTable(false, 1);
  }).catch(e => {
    // TODO: 异常处理
    console.error(e);
  });
};
// 表格组件表格组件参数
const tourUserLikeTravelNotesOptions: TableOptions<TourUserLikeTravelNotesData> = {
  loadTableData: loadTourUserLikeTravelNotesWidgetData,
  verifyTableParameter: loadTourUserLikeTravelNotesVerify,
  paged: true,
  rowSelection: false,
  orderFieldName: 'userId',
  ascending: true,
};
// 表格组件表格组件
const tourUserLikeTravelNotes = ref();
const tourUserLikeTravelNotesWidget = useTable(tourUserLikeTravelNotesOptions);
const {
  dataList: tourUserLikeTravelNotesWidgetDataList,
  currentPage: tourUserLikeTravelNotesWidgetCurrentPage,
  pageSize: tourUserLikeTravelNotesWidgetPageSize,
  totalCount: tourUserLikeTravelNotesWidgetTotalCount,
} = tourUserLikeTravelNotesWidget;
const refreshFormUserLikeTravelNotes = () => {
  // 刷新段落
  tourUserLikeTravelNotesWidget.refreshTable();
};
/**
 * 重置过滤值
 */
const resetFormUserLikeTravelNotes = () => {
  formFilter.userIdFilter = undefined;
  formFilterCopy.userIdFilter = undefined;
  refreshFormUserLikeTravelNotes();
};
/**
 * 重置所有过滤值
 */
const resetFilter = () => {
  resetFormUserLikeTravelNotes();
};
const formInit = () => {
  refreshFormUserLikeTravelNotes();
};

onMounted(() => {
  formInit();
});
</script>