<template>
  <div class="page-box" style="position: relative;">
    <table-box
      ref="tourProjectGroupPurchaseDetail"
      class="page-table"
      :data="tourProjectGroupPurchaseDetailWidgetDataList"
      :size="layoutStore.defaultFormItemSize"
      :row-config="{isCurrent: false, isHover: true}"
      :seq-config="{startIndex: ((tourProjectGroupPurchaseDetailWidgetCurrentPage - 1) * tourProjectGroupPurchaseDetailWidgetPageSize)}"
      :sort-config="{remote: true}"
      :hasExtend="true"
      @sort-change="tourProjectGroupPurchaseDetailWidget.onSortChange"
      @refresh="tourProjectGroupPurchaseDetailWidget.refreshTable()"
    >
      <template #operator>
        <el-button
          type="primary"
          :size="layoutStore.defaultFormItemSize"
          @click="onAddClick()"
          >
          新增
        </el-button>
      </template>
      <vxe-column title="序号" type="seq" :index="tourProjectGroupPurchaseDetailWidget.getTableIndex" :width="80" />
      <vxe-column title="成人价格" field="adultPrice" />
      <vxe-column title="儿童价格" field="childrenPrice" />
      <vxe-column title="阶梯的人数(下限包含)" field="minCount" />
      <vxe-column title="阶梯的人数(上限包含)" field="maxCount" />
      <vxe-column title="操作" fixed="right">
        <template v-slot="scope">
          <el-button
            link
            type="primary"
            :size="layoutStore.defaultFormItemSize"
            @click.stop="onEditClick(scope.row)"
          >
            编辑
          </el-button>
          <el-button
            link
            type="primary"
            :size="layoutStore.defaultFormItemSize"
            @click.stop="onDeleteClick(scope.row)"
          >
            删除
          </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="tourProjectGroupPurchaseDetailWidgetTotalCount"
            :current-page="tourProjectGroupPurchaseDetailWidgetCurrentPage"
            :page-size="tourProjectGroupPurchaseDetailWidgetPageSize"
            :page-sizes="[10, 20, 50, 100]"
            layout="total, prev, pager, next, sizes"
            @current-change="tourProjectGroupPurchaseDetailWidget.onCurrentPageChange"
            @size-change="tourProjectGroupPurchaseDetailWidget.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: 'formTourProjectGroupPurchaseDetail',
};
</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 { TourProjectGroupPurchaseData } from '@/api/generated/tourProjectGroupPurchaseController';
import { TourProjectGroupPurchaseDetailData } from '@/api/generated/tourProjectGroupPurchaseDetailController';
import { TourProjectGroupPurchaseController, TourProjectGroupPurchaseDetailController } from '@/api/generated';
import EditFormProjectGroupPurchaseDetail from '@/pages/tourProjectGroupPurchase/editFormProjectGroupPurchaseDetail.vue';

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;
    groupPurchaseCode?: ANY_OBJECT;
  }>(),
  {
    subPage: 0,
    groupPurchaseCode: undefined,
  },
);


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

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

/**
 * 表格组件数据获取函数，返回Promise
 */
const loadTourProjectGroupPurchaseDetailWidgetData = (params: ANY_OBJECT) => {
  if (params == null) params = {};
  params = {
    ...params,
    tourProjectGroupPurchaseDetailDtoFilter:{
      groupPurchaseCode : props.groupPurchaseCode
    }
  };
  return new Promise((resolve, reject) => {
    TourProjectGroupPurchaseDetailController.list(params).then(res => {
      resolve({
        dataList: res.data.dataList,
        totalCount: res.data.totalCount,
      });
    }).catch(e => {
      reject(e);
    });
  });
};
/**
 * 表格组件数据获取检测函数，返回true正常获取数据，返回false停止获取数据
 */
const loadTourProjectGroupPurchaseDetailVerify = () => {
  return true;
};
/**
 * 新增
 */
const onAddClick = (row?: TourProjectGroupPurchaseDetailData) => {
  let params: ANY_OBJECT = {
    groupPurchaseCode: props.groupPurchaseCode,
  };

  Dialog
    .show('新增', EditFormProjectGroupPurchaseDetail, { area: ['900px', '700px'] }, { ...params, subPage: true })
    .then(res => {
      tourProjectGroupPurchaseDetailWidget.refreshTable();
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
};
/**
 * 编辑
 */
const onEditClick = (row?: TourProjectGroupPurchaseDetailData) => {
  let params: ANY_OBJECT = {
    groupPurchaseCode: props.groupPurchaseCode,
    id: row?.id,
  };

  Dialog
    .show('编辑', EditFormProjectGroupPurchaseDetail, { area: ['900px', '700px'] }, { ...params, subPage: true })
    .then(res => {
      tourProjectGroupPurchaseDetailWidget.refreshTable();
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
};
/**
 * 删除
 */
const onDeleteClick = (row?: TourProjectGroupPurchaseDetailData) => {
  let params: ANY_OBJECT = {
    id: row?.id,
  };

  ElMessageBox.confirm('是否删除该条数据?').then(res => {
    TourProjectGroupPurchaseDetailController.delete(params).then(res => {
      ElMessage.success('删除成功');
      tourProjectGroupPurchaseDetailWidget.refreshTable(false, 1);
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
  }).catch(e => {
    // TODO: 异常处理
    console.error(e);
  });
};
// 表格组件表格组件参数
const tourProjectGroupPurchaseDetailOptions: TableOptions<TourProjectGroupPurchaseDetailData> = {
  loadTableData: loadTourProjectGroupPurchaseDetailWidgetData,
  verifyTableParameter: loadTourProjectGroupPurchaseDetailVerify,
  paged: true,
  rowSelection: false,
  orderFieldName: undefined,
  ascending: true,
};
// 表格组件表格组件
const tourProjectGroupPurchaseDetail = ref();
const tourProjectGroupPurchaseDetailWidget = useTable(tourProjectGroupPurchaseDetailOptions);
const {
  dataList: tourProjectGroupPurchaseDetailWidgetDataList,
  currentPage: tourProjectGroupPurchaseDetailWidgetCurrentPage,
  pageSize: tourProjectGroupPurchaseDetailWidgetPageSize,
  totalCount: tourProjectGroupPurchaseDetailWidgetTotalCount,
} = tourProjectGroupPurchaseDetailWidget;
const refreshFormTourProjectGroupPurchaseDetail = () => {
  // 刷新段落
  tourProjectGroupPurchaseDetailWidget.refreshTable();
};
/**
 * 重置过滤值
 */
const resetFormTourProjectGroupPurchaseDetail = () => {
  refreshFormTourProjectGroupPurchaseDetail();
};
/**
 * 重置所有过滤值
 */
const resetFilter = () => {
  resetFormTourProjectGroupPurchaseDetail();
};
const formInit = () => {
  refreshFormTourProjectGroupPurchaseDetail();
};

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

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