<!-- <template>
  <div class="page-box" style="position: relative;">
    <el-form
      ref="formTourBrowseRecordsRef"
      :size="layoutStore.defaultFormItemSize"
      label-width="120px"
      label-position="right"
      @submit.prevent
    >
      <filter-box :item-width="350" @search="refreshFormTourBrowseRecords()" @reset="resetFormTourBrowseRecords">
        <el-form-item label="浏览者id">
          <el-input-number
            class="filter-item"
            v-model="formFilter.visitorIdFilter"
            placeholder=""
            :clearable="true"
            :step="1"
            :controls="true"
          />
        </el-form-item>
        <el-form-item label="浏览项目类型">
          <el-select
            class="filter-item"
            v-model="formFilter.itemTypeIdFilter"
            placeholder=""
            :clearable="true"
            :filterable="true"
            @visible-change="itemTypeIdFilterWidget.onVisibleChange"
          >
            <el-option
              v-for="item in itemTypeIdFilterWidgetDropdownList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
      </filter-box>
    </el-form>
    <table-box
      ref="formTourBrowseRecordsTable"
      class="page-table"
      :data="formTourBrowseRecordsTableWidgetDataList"
      :size="layoutStore.defaultFormItemSize"
      :row-config="{isCurrent: false, isHover: true}"
      :seq-config="{startIndex: ((formTourBrowseRecordsTableWidgetCurrentPage - 1) * formTourBrowseRecordsTableWidgetPageSize)}"
      :sort-config="{remote: true}"
      :hasExtend="true"
      @sort-change="formTourBrowseRecordsTableWidget.onSortChange"
      @refresh="formTourBrowseRecordsTableWidget.refreshTable()"
    >
      <template #operator>
        <el-button
          type="primary"
          :size="layoutStore.defaultFormItemSize"
          :disabled="!checkPermCodeExist('formTourBrowseRecords:formTourBrowseRecords:exportTourBrowseRecords')"
          @click="onExportTourBrowseRecordsClick()"
          >
          导出
        </el-button>
        <el-upload
          class="btn-import"
          :auto-upload="false"
          action=""
          :show-file-list="false"
          accept=".xls,.xlsx"
          style="display: inline-block;"
          :disabled="!checkPermCodeExist('formTourBrowseRecords:formTourBrowseRecords:importTourBrowseRecords')"
          :on-change="onImportTourBrowseRecordsClick"
        >
          <template #trigger>
            <el-button
              type="primary"
              :size="layoutStore.defaultFormItemSize"
              :disabled="!checkPermCodeExist('formTourBrowseRecords:formTourBrowseRecords:importTourBrowseRecords')"
            >
              导入
            </el-button>
          </template>
        </el-upload>
      </template>
      <vxe-column title="序号" type="seq" :index="formTourBrowseRecordsTableWidget.getTableIndex" :width="80" />
      <vxe-column title="浏览者id" field="visitorId" />
      <vxe-column title="项目id" field="itemId" />
      <vxe-column title="浏览项目类型" field="itemTypeIdDictMap.name" />
      <vxe-column title="操作" fixed="right">
        <template v-slot="scope">
          <el-button
            link
            type="primary"
            :size="layoutStore.defaultFormItemSize"
            @click.stop="onDeleteTourBrowseRecordsClick(scope.row)"
            :disabled="!checkPermCodeExist('formTourBrowseRecords:formTourBrowseRecords:deleteTourBrowseRecords')"
          >
            删除
          </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="formTourBrowseRecordsTableWidgetTotalCount"
            :current-page="formTourBrowseRecordsTableWidgetCurrentPage"
            :page-size="formTourBrowseRecordsTableWidgetPageSize"
            :page-sizes="[10, 20, 50, 100]"
            layout="total, prev, pager, next, sizes"
            @current-change="formTourBrowseRecordsTableWidget.onCurrentPageChange"
            @size-change="formTourBrowseRecordsTableWidget.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: 'formTourBrowseRecords',
};
</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, stringCase } from '@/common/utils';
import { TourBrowseRecordsData } from '@/api/generated/tourBrowseRecordsController';
import { TourBrowseRecordsController } 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
  visitorIdFilter: undefined,
  // 浏览项目类型
  itemTypeIdFilter: undefined,
});
const formFilterCopy = reactive({
  // 浏览者id
  visitorIdFilter: undefined,
  // 浏览项目类型
  itemTypeIdFilter: undefined,
});

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

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

/**
 * 表格组件数据获取函数，返回Promise
 */
const loadFormTourBrowseRecordsTableWidgetData = (params: ANY_OBJECT) => {
  if (params == null) params = {};
  params = {
    ...params,
    tourBrowseRecordsDtoFilter: {
      visitorId: formFilter.visitorIdFilter,
      itemTypeId: formFilter.itemTypeIdFilter,
    }
  };
  return new Promise((resolve, reject) => {
    TourBrowseRecordsController.list(params).then(res => {
      resolve({
        dataList: res.data.dataList,
        totalCount: res.data.totalCount
      });
    }).catch(e => {
      reject(e);
    });
  });
};
/**
 * 表格组件数据获取检测函数，返回true正常获取数据，返回false停止获取数据
 */
const loadFormTourBrowseRecordsTableVerify = () => {
  formFilterCopy.visitorIdFilter = formFilter.visitorIdFilter;
  formFilterCopy.itemTypeIdFilter = formFilter.itemTypeIdFilter;
  return true;
};
/**
 * 导出
 */
const onExportTourBrowseRecordsClick = (row?: TourBrowseRecordsData) => {
  let params: ANY_OBJECT = {
  };

  TourBrowseRecordsController.export(params, '表格组件.xlsx').then(res => {
    ElMessage.success('导出成功');
  }).catch(e => {
    ElMessage.error(e.errorMessage);
  });
};
/**
 * 导入
 */
const onImportTourBrowseRecordsClick = (file) => {
  let params: ANY_OBJECT = {
    importFile: file.raw,
    // 是否忽略表头
    skipHeader: false
  };

  TourBrowseRecordsController.import(params).then(res => {
    ElMessage.success('导入成功');
    formTourBrowseRecordsTableWidget.refreshTable();
  }).catch(e => {
    // TODO: 异常处理
    console.error(e);
  });
};
/**
 * 删除
 */
const onDeleteTourBrowseRecordsClick = (row?: TourBrowseRecordsData) => {
  let params: ANY_OBJECT = {
    id: row?.id,
  };

  ElMessageBox.confirm('是否删除此记录？').then(res => {
    TourBrowseRecordsController.delete(params).then(res => {
      ElMessage.success('删除成功');
      formTourBrowseRecordsTableWidget.refreshTable(false, 1);
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
  }).catch(e => {
    // TODO: 异常处理
    console.error(e);
  });
};
// 表格组件表格组件参数
const formTourBrowseRecordsTableOptions: TableOptions<TourBrowseRecordsData> = {
  loadTableData: loadFormTourBrowseRecordsTableWidgetData,
  verifyTableParameter: loadFormTourBrowseRecordsTableVerify,
  paged: true,
  rowSelection: false,
  orderFieldName: undefined,
  ascending: true,
};
// 表格组件表格组件
const formTourBrowseRecordsTable = ref();
const formTourBrowseRecordsTableWidget = useTable(formTourBrowseRecordsTableOptions);
const {
  dataList: formTourBrowseRecordsTableWidgetDataList,
  currentPage: formTourBrowseRecordsTableWidgetCurrentPage,
  pageSize: formTourBrowseRecordsTableWidgetPageSize,
  totalCount: formTourBrowseRecordsTableWidgetTotalCount,
} = formTourBrowseRecordsTableWidget;
/**
 * 浏览项目类型下拉数据获取函数
 */
const loadItemTypeIdFilterDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    DictionaryController.dictGlobalDict({ dictCode: 'ViewItemType', itemIdType: 'Integer' }).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
// 浏览项目类型配置参数
const itemTypeIdFilterOptions: DropdownOptions<DictData> = {
  loadData: loadItemTypeIdFilterDropdownList,
  isTree: false,
};
// 浏览项目类型下拉组件
const itemTypeIdFilterWidget = useDropdown(itemTypeIdFilterOptions);
const { dropdownList: itemTypeIdFilterWidgetDropdownList } = itemTypeIdFilterWidget
const refreshFormTourBrowseRecords = () => {
  // 刷新段落
  formTourBrowseRecordsTableWidget.refreshTable();
};
/**
 * 重置过滤值
 */
const resetFormTourBrowseRecords = () => {
  formFilter.visitorIdFilter = undefined;
  formFilterCopy.visitorIdFilter = undefined;
  formFilter.itemTypeIdFilter = undefined;
  formFilterCopy.itemTypeIdFilter = undefined;
  refreshFormTourBrowseRecords();
};
/**
 * 重置所有过滤值
 */
const resetFilter = () => {
  resetFormTourBrowseRecords();
};
const formInit = () => {
  itemTypeIdFilterWidget.onVisibleChange(true).catch(e => {console.error(e)});
  refreshFormTourBrowseRecords();
};

onMounted(() => {
  formInit();
});

onActivated(() => {
  onResume();
});
</script> -->
