<template>
  <div class="page-box" style="position: relative;">
    <el-form
      ref="formTourHouseSaleInfoRef"
      :model="formData"
      :size="layoutStore.defaultFormItemSize"
      label-width="120px"
      label-position="right"
      @submit.prevent
    >
      <filter-box :item-width="350" @search="refreshFormTourHouseSaleInfo()" @reset="resetFormTourHouseSaleInfo">
        <el-form-item label="所属地区类型">
          <el-cascader
            class="filter-item"
            v-model="areaIdFilterPath"
            :options="areaIdFilterWidgetDropdownList"
            placeholder=""
            :clearable="true"
            :filterable="true"
            :show-all-levels="false"
            :props="{ value: 'id', label: 'name', children: 'children', checkStrictly: true }"
            @change="onAreaIdFilterValueChange"
          />
        </el-form-item>
        <el-form-item label="是否房东自售 ">
          <el-select
            class="filter-item"
            v-model="formFilter.isSaleByLandlordFilter"
            placeholder=""
            :clearable="true"
            :filterable="true"
            @visible-change="isSaleByLandlordFilterWidget.onVisibleChange"
          >
            <el-option
              v-for="item in isSaleByLandlordFilterWidgetDropdownList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="房源类型 ">
          <el-select
            class="filter-item"
            v-model="formFilter.houseSourceTypeFilter"
            placeholder=""
            :clearable="true"
            :filterable="true"
            @visible-change="houseSourceTypeFilterWidget.onVisibleChange"
          >
            <el-option
              v-for="item in houseSourceTypeFilterWidgetDropdownList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="厅室类型">
          <el-select
            class="filter-item"
            v-model="formFilter.officeTypeFilter"
            placeholder=""
            :clearable="true"
            :filterable="true"
            @visible-change="officeTypeFilterWidget.onVisibleChange"
          >
            <el-option
              v-for="item in officeTypeFilterWidgetDropdownList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="房屋类型 ">
          <el-select
            class="filter-item"
            v-model="formFilter.houseTypeFilter"
            placeholder=""
            :clearable="true"
            :filterable="true"
            @visible-change="houseTypeFilterWidget.onVisibleChange"
          >
            <el-option
              v-for="item in houseTypeFilterWidgetDropdownList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="朝向类型">
          <el-select
            class="filter-item"
            v-model="formFilter.orientationFilter"
            placeholder=""
            :clearable="true"
            :filterable="true"
            @visible-change="orientationFilterWidget.onVisibleChange"
          >
            <el-option
              v-for="item in orientationFilterWidgetDropdownList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="装修类型">
          <el-select
            class="filter-item"
            v-model="formFilter.decorationFilter"
            placeholder=""
            :clearable="true"
            :filterable="true"
            @visible-change="decorationFilterWidget.onVisibleChange"
          >
            <el-option
              v-for="item in decorationFilterWidgetDropdownList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="是否在售 ">
          <el-select
            class="filter-item"
            v-model="formFilter.isOnSaleFilter"
            placeholder=""
            :clearable="true"
            :filterable="true"
            @visible-change="isOnSaleFilterWidget.onVisibleChange"
          >
            <el-option
              v-for="item in isOnSaleFilterWidgetDropdownList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="联系电话">
          <el-input
            class="filter-item"
            v-model="formFilter.mobileFilter"
            type="text"
            placeholder=""
            :clearable="true"
            :show-word-limit="false"
            maxlength=""
          />
        </el-form-item> -->
        <el-form-item label="是否唯一住房">
          <el-select
            class="filter-item"
            v-model="formFilter.isSoleDwellingFilter"
            placeholder=""
            :clearable="true"
            :filterable="true"
            @visible-change="isSoleDwellingFilterWidget.onVisibleChange"
          >
            <el-option
              v-for="item in isSoleDwellingFilterWidgetDropdownList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
      </filter-box>
    </el-form>
    <table-box
      ref="formTourHouseSaleInfoTable"
      class="page-table"
      :data="formTourHouseSaleInfoTableWidgetDataList"
      :size="layoutStore.defaultFormItemSize"
      :row-config="{isCurrent: false, isHover: true}"
      :seq-config="{startIndex: ((formTourHouseSaleInfoTableWidgetCurrentPage - 1) * formTourHouseSaleInfoTableWidgetPageSize)}"
      :sort-config="{remote: true}"
      :hasExtend="true"
      @sort-change="formTourHouseSaleInfoTableWidget.onSortChange"
      @refresh="formTourHouseSaleInfoTableWidget.refreshTable()"
    >
      <template #operator>
        <el-button
          type="primary"
          :size="layoutStore.defaultFormItemSize"
          @click="onAddTourHouseSaleInfoClick()"
          >
          新建
        </el-button>
        <el-button
          type="primary"
          :size="layoutStore.defaultFormItemSize"
          @click="onExportTourHouseSaleInfoClick()"
          >
          导出
        </el-button>
        <el-upload
          class="btn-import"
          :auto-upload="false"
          action=""
          :show-file-list="false"
          accept=".xls,.xlsx"
          style="display: inline-block;"
          :on-change="onImportTourHouseSaleInfoClick"
        >
          <template #trigger>
            <el-button
              type="primary"
              :size="layoutStore.defaultFormItemSize"
            >
              导入
            </el-button>
          </template>
        </el-upload>
      </template>
      <vxe-column title="序号" type="seq" :index="formTourHouseSaleInfoTableWidget.getTableIndex" :width="80" />
      <vxe-column title="房屋标题" field="houseTitle" />
      <vxe-column title="所属地区类型" field="areaIdDictMap.name" />
      <vxe-column title="是否房东自售 " field="isSaleByLandlordDictMap.name" />
      <vxe-column title="房源类型 " field="houseSourceTypeDictMap.name" />
      <vxe-column title="总价" field="totalPrice" />
      <vxe-column title="厅室类型" field="officeTypeDictMap.name" />
      <vxe-column title="面积" field="area" />
      <vxe-column title="房屋类型" field="houseTypeDictMap.name" />
      <vxe-column title="朝向类型" field="orientationDictMap.name" />
      <vxe-column title="所在楼层" field="currentFloor" />
      <vxe-column title="装修类型" field="decorationDictMap.name" />
      <vxe-column title="首页封面图" min-width="100px">
        <template v-slot="scope">
          <el-image v-for="item in parseUploadData(scope.row.coverUrl, { id: scope.row.id, fieldName: 'coverUrl', asImage: true })"
            :preview-src-list="getPictureList(scope.row.coverUrl, { id: scope.row.id, fieldName: 'coverUrl', asImage: true })"
            class="table-cell-image" :key="item.url" :src="item.url" fit="fill">
            <template #error>
              <div class="table-cell-image">
                <i class="el-icon-picture-outline"></i>
              </div>
            </template>
          </el-image>
        </template>
      </vxe-column>
      <vxe-column title="是否在售" field="isOnSaleDictMap.name" />
      <vxe-column title="操作" fixed="right">
        <template v-slot="scope">
          <el-button
            link
            type="primary"
            :size="layoutStore.defaultFormItemSize"
            @click.stop="onFormSaleHouseAdvisorRelationClick(scope.row)"
          >
            买卖房顾问关联查询
          </el-button>
          <el-button
            link
            type="primary"
            :size="layoutStore.defaultFormItemSize"
            @click.stop="onFormTourHouseTypeInfoClick(scope.row)"
          >
            选择户型图集
          </el-button>
          <el-button
            link
            type="primary"
            :size="layoutStore.defaultFormItemSize"
            @click.stop="onEditTourHouseSaleInfoClick(scope.row)"
          >
            编辑
          </el-button>
          <el-button
            link
            type="primary"
            :size="layoutStore.defaultFormItemSize"
            @click.stop="onDeleteTourHouseSaleInfoClick(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="formTourHouseSaleInfoTableWidgetTotalCount"
            :current-page="formTourHouseSaleInfoTableWidgetCurrentPage"
            :page-size="formTourHouseSaleInfoTableWidgetPageSize"
            :page-sizes="[10, 20, 50, 100]"
            layout="total, prev, pager, next, sizes"
            @current-change="formTourHouseSaleInfoTableWidget.onCurrentPageChange"
            @size-change="formTourHouseSaleInfoTableWidget.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: 'formTourHouseSaleInfo',
};
</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 { TourHouseDevelopersTypeData } from '@/api/generated/tourHouseDevelopersTypeController';
import { TourHouseSaleInfoData } from '@/api/generated/tourHouseSaleInfoController';
import { TourHouseAdvisorInfoData } from '@/api/generated/tourHouseAdvisorInfoController';
import { TourHouseFilesData } from '@/api/generated/tourHouseFilesController';
import { TourHouseDevelopersTypeController, TourHouseSaleInfoController, TourHouseAdvisorInfoController, TourHouseFilesController } from '@/api/generated';
import FormEditTourHouseSaleInfo from '@/pages/TourHouseSaleInfo/formEditTourHouseSaleInfo.vue';
import FormSaleHouseAdvisorRelation from '@/pages/TourHouseSaleInfo/formSaleHouseAdvisorRelation.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;
  }>(),
  {
    subPage: 0,
  },
);

const formFilter = reactive({
  // 所属地区类型
  areaIdFilter: undefined,
  // 是否房东自售
  isSaleByLandlordFilter: undefined,
  // 房源类型
  houseSourceTypeFilter: undefined,
  // 厅室类型
  officeTypeFilter: undefined,
  // 房屋类型
  houseTypeFilter: undefined,
  // 朝向类型
  orientationFilter: undefined,
  // 装修类型
  decorationFilter: undefined,
  // 是否在售
  isOnSaleFilter: undefined,
  // 联系电话
  mobileFilter: undefined,
  // 是否唯一住房
  isSoleDwellingFilter: undefined,
});
const formFilterCopy = reactive({
  // 所属地区类型
  areaIdFilter: undefined,
  // 是否房东自售
  isSaleByLandlordFilter: undefined,
  // 房源类型
  houseSourceTypeFilter: undefined,
  // 厅室类型
  officeTypeFilter: undefined,
  // 房屋类型
  houseTypeFilter: undefined,
  // 朝向类型
  orientationFilter: undefined,
  // 装修类型
  decorationFilter: undefined,
  // 是否在售
  isOnSaleFilter: undefined,
  // 联系电话
  mobileFilter: undefined,
  // 是否唯一住房
  isSoleDwellingFilter: undefined,
});

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

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

/**
 * 表格组件数据获取函数，返回Promise
 */
const loadFormTourHouseSaleInfoTableWidgetData = (params: ANY_OBJECT) => {
  if (params == null) params = {};
  params = {
    ...params,
    tourHouseSaleInfoDtoFilter: {
      houseType:formFilter.houseTypeFilter,
      areaId: formFilter.areaIdFilter,
      isSaleByLandlord: formFilter.isSaleByLandlordFilter,
      houseSourceType: formFilter.houseSourceTypeFilter,
      officeType: formFilter.officeTypeFilter,
      orientation: formFilter.orientationFilter,
      decoration: formFilter.decorationFilter,
      isOnSale: formFilter.isOnSaleFilter,
      mobile: formFilter.mobileFilter,
      isSoleDwelling: formFilter.isSoleDwellingFilter,
    }
  };
  return new Promise((resolve, reject) => {
    TourHouseSaleInfoController.list(params).then(res => {
      resolve({
        dataList: res.data.dataList,
        totalCount: res.data.totalCount
      });
    }).catch(e => {
      reject(e);
    });
  });
};
/**
 * 表格组件数据获取检测函数，返回true正常获取数据，返回false停止获取数据
 */
const loadFormTourHouseSaleInfoTableVerify = () => {
  formFilterCopy.areaIdFilter = formFilter.areaIdFilter;
  formFilterCopy.isSaleByLandlordFilter = formFilter.isSaleByLandlordFilter;
  formFilterCopy.houseSourceTypeFilter = formFilter.houseSourceTypeFilter;
  formFilterCopy.officeTypeFilter = formFilter.officeTypeFilter;
  formFilterCopy.houseTypeFilter = formFilter.houseTypeFilter;
  formFilterCopy.orientationFilter = formFilter.orientationFilter;
  formFilterCopy.decorationFilter = formFilter.decorationFilter;
  formFilterCopy.isOnSaleFilter = formFilter.isOnSaleFilter;
  formFilterCopy.mobileFilter = formFilter.mobileFilter;
  formFilterCopy.isSoleDwellingFilter = formFilter.isSoleDwellingFilter;
  return true;
};
/**
 * 新建
 */
const onAddTourHouseSaleInfoClick = (row?: TourHouseSaleInfoData) => {
  let params: ANY_OBJECT = {
  };

  Dialog
    .show('新建', FormEditTourHouseSaleInfo, { area: ['900px','700px'] }, { ...params, subPage: true })
    .then(res => {
      formTourHouseSaleInfoTableWidget.refreshTable();
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
};
/**
 * 买卖房顾问关联查询
 */
const onFormSaleHouseAdvisorRelationClick = (row?: TourHouseSaleInfoData) => {
  let params: ANY_OBJECT = {
    id: row?.id,
  };

  router.push({
    name: 'formSaleHouseAdvisorRelation',
    query: { ...params, subPage: true }
  });
};
/**
 * 选择户型图集
 */
const onFormTourHouseTypeInfoClick = (row?: TourHouseSaleInfoData) => {
  let params: ANY_OBJECT = {
    houseId: row?.id,
  };

  router.push({
    name: 'formTourHouseTypeInfo',
    query: { ...params, subPage: true }
  });
};
/**
 * 编辑
 */
const onEditTourHouseSaleInfoClick = (row?: TourHouseSaleInfoData) => {
  let params: ANY_OBJECT = {
    id: row?.id,
  };

  Dialog
    .show('编辑', FormEditTourHouseSaleInfo, { area: ['900px','700px'] }, { ...params, subPage: true })
    .then(res => {
      formTourHouseSaleInfoTableWidget.refreshTable();
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
};
/**
 * 导出
 */
const onExportTourHouseSaleInfoClick = (row?: TourHouseSaleInfoData) => {
  let params: ANY_OBJECT = {
  };

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

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

  ElMessageBox.confirm('是否删除此记录？').then(res => {
    TourHouseSaleInfoController.delete(params).then(res => {
      ElMessage.success('删除成功');
      formTourHouseSaleInfoTableWidget.refreshTable(false, 1);
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
  }).catch(e => {
    // TODO: 异常处理
    console.error(e);
  });
};
// 表格组件表格组件参数
const formTourHouseSaleInfoTableOptions: TableOptions<TourHouseSaleInfoData> = {
  loadTableData: loadFormTourHouseSaleInfoTableWidgetData,
  verifyTableParameter: loadFormTourHouseSaleInfoTableVerify,
  paged: true,
  rowSelection: false,
  orderFieldName: 'updateTime',
  ascending: false,
};
// 表格组件表格组件
const formTourHouseSaleInfoTable = ref();
const formTourHouseSaleInfoTableWidget = useTable(formTourHouseSaleInfoTableOptions);
const {
  dataList: formTourHouseSaleInfoTableWidgetDataList,
  currentPage: formTourHouseSaleInfoTableWidgetCurrentPage,
  pageSize: formTourHouseSaleInfoTableWidgetPageSize,
  totalCount: formTourHouseSaleInfoTableWidgetTotalCount,
} = formTourHouseSaleInfoTableWidget;
/**
 * 所属地区类型下拉数据获取函数
 */
const loadAreaIdFilterDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    const params = {
    };
    DictionaryController.dictTourHouseAreaMenu(params).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
/**
 * 所属地区类型选中值改变
 */
 const onAreaIdFilterValueChange = (value) => {
  formFilter.areaIdFilter = Array.isArray(value) ? value[value.length - 1] : value;
};
// 所属地区类型配置参数
const areaIdFilterOptions: DropdownOptions<DictData> = {
  loadData: loadAreaIdFilterDropdownList,
  isTree: true,
};
// 所属地区类型选中数据
const areaIdFilterPath = ref<Array<string | number>>([]);
// 所属地区类型下拉组件
const areaIdFilterWidget = useDropdown(areaIdFilterOptions);
const { dropdownList: areaIdFilterWidgetDropdownList } = areaIdFilterWidget
/**
 * 是否房东自售 下拉数据获取函数
 */
const loadIsSaleByLandlordFilterDropdownList = (): Promise<ListData<DictData>> => {
  return Promise.resolve({
    dataList: StaticDict.IsSaleByLandlord.getList(),
  });
};
// 是否房东自售 配置参数
const isSaleByLandlordFilterOptions: DropdownOptions<DictData> = {
  loadData: loadIsSaleByLandlordFilterDropdownList,
  isTree: false,
};
// 是否房东自售 下拉组件
const isSaleByLandlordFilterWidget = useDropdown(isSaleByLandlordFilterOptions);
const { dropdownList: isSaleByLandlordFilterWidgetDropdownList } = isSaleByLandlordFilterWidget
/**
 * 房源类型 下拉数据获取函数
 */
const loadHouseSourceTypeFilterDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    DictionaryController.dictGlobalDict({ dictCode: 'HouseSourceType', itemIdType: 'Integer' }).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
// 房源类型 配置参数
const houseSourceTypeFilterOptions: DropdownOptions<DictData> = {
  loadData: loadHouseSourceTypeFilterDropdownList,
  isTree: false,
};
// 房源类型 下拉组件
const houseSourceTypeFilterWidget = useDropdown(houseSourceTypeFilterOptions);
const { dropdownList: houseSourceTypeFilterWidgetDropdownList } = houseSourceTypeFilterWidget
/**
 * 厅室类型下拉数据获取函数
 */
const loadOfficeTypeFilterDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    DictionaryController.dictGlobalDict({ dictCode: 'OfficeType', itemIdType: 'Integer' }).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
// 厅室类型配置参数
const officeTypeFilterOptions: DropdownOptions<DictData> = {
  loadData: loadOfficeTypeFilterDropdownList,
  isTree: false,
};
// 厅室类型下拉组件
const officeTypeFilterWidget = useDropdown(officeTypeFilterOptions);
const { dropdownList: officeTypeFilterWidgetDropdownList } = officeTypeFilterWidget
/**
 * 房屋类型 下拉数据获取函数
 */
const loadHouseTypeFilterDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    DictionaryController.dictGlobalDict({ dictCode: 'HouseType', itemIdType: 'Integer' }).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
// 房屋类型 配置参数
const houseTypeFilterOptions: DropdownOptions<DictData> = {
  loadData: loadHouseTypeFilterDropdownList,
  isTree: false,
};
// 房屋类型 下拉组件
const houseTypeFilterWidget = useDropdown(houseTypeFilterOptions);
const { dropdownList: houseTypeFilterWidgetDropdownList } = houseTypeFilterWidget
/**
 * 朝向类型下拉数据获取函数
 */
const loadOrientationFilterDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    DictionaryController.dictGlobalDict({ dictCode: 'Orientation', itemIdType: 'Integer' }).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
// 朝向类型配置参数
const orientationFilterOptions: DropdownOptions<DictData> = {
  loadData: loadOrientationFilterDropdownList,
  isTree: false,
};
// 朝向类型下拉组件
const orientationFilterWidget = useDropdown(orientationFilterOptions);
const { dropdownList: orientationFilterWidgetDropdownList } = orientationFilterWidget
/**
 * 装修类型下拉数据获取函数
 */
const loadDecorationFilterDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    DictionaryController.dictGlobalDict({ dictCode: 'Decoration', itemIdType: 'Integer' }).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
// 装修类型配置参数
const decorationFilterOptions: DropdownOptions<DictData> = {
  loadData: loadDecorationFilterDropdownList,
  isTree: false,
};
// 装修类型下拉组件
const decorationFilterWidget = useDropdown(decorationFilterOptions);
const { dropdownList: decorationFilterWidgetDropdownList } = decorationFilterWidget
/**
 * 是否在售 下拉数据获取函数
 */
const loadIsOnSaleFilterDropdownList = (): Promise<ListData<DictData>> => {
  return Promise.resolve({
    dataList: StaticDict.IsOnSale.getList(),
  });
};
// 是否在售 配置参数
const isOnSaleFilterOptions: DropdownOptions<DictData> = {
  loadData: loadIsOnSaleFilterDropdownList,
  isTree: false,
};
// 是否在售 下拉组件
const isOnSaleFilterWidget = useDropdown(isOnSaleFilterOptions);
const { dropdownList: isOnSaleFilterWidgetDropdownList } = isOnSaleFilterWidget
/**
 * 是否唯一住房下拉数据获取函数
 */
const loadIsSoleDwellingFilterDropdownList = (): Promise<ListData<DictData>> => {
  return Promise.resolve({
    dataList: StaticDict.IsSoleDwelling.getList(),
  });
};
// 是否唯一住房配置参数
const isSoleDwellingFilterOptions: DropdownOptions<DictData> = {
  loadData: loadIsSoleDwellingFilterDropdownList,
  isTree: false,
};
// 是否唯一住房下拉组件
const isSoleDwellingFilterWidget = useDropdown(isSoleDwellingFilterOptions);
const { dropdownList: isSoleDwellingFilterWidgetDropdownList } = isSoleDwellingFilterWidget
const refreshFormTourHouseSaleInfo = () => {
  // 刷新段落
  formTourHouseSaleInfoTableWidget.refreshTable();
};
/**
 * 重置过滤值
 */
const resetFormTourHouseSaleInfo = () => {
  formFilter.areaIdFilter = undefined;
  formFilterCopy.areaIdFilter = undefined;
  areaIdFilterPath.value = [];
  formFilter.isSaleByLandlordFilter = undefined;
  formFilterCopy.isSaleByLandlordFilter = undefined;
  formFilter.houseSourceTypeFilter = undefined;
  formFilterCopy.houseSourceTypeFilter = undefined;
  formFilter.officeTypeFilter = undefined;
  formFilterCopy.officeTypeFilter = undefined;
  formFilter.houseTypeFilter = undefined;
  formFilterCopy.houseTypeFilter = undefined;
  formFilter.orientationFilter = undefined;
  formFilterCopy.orientationFilter = undefined;
  formFilter.decorationFilter = undefined;
  formFilterCopy.decorationFilter = undefined;
  formFilter.isOnSaleFilter = undefined;
  formFilterCopy.isOnSaleFilter = undefined;
  formFilter.mobileFilter = undefined;
  formFilterCopy.mobileFilter = undefined;
  formFilter.isSoleDwellingFilter = undefined;
  formFilterCopy.isSoleDwellingFilter = undefined;
  refreshFormTourHouseSaleInfo();
};
/**
 * 重置所有过滤值
 */
const resetFilter = () => {
  resetFormTourHouseSaleInfo();
};
const formInit = () => {
  areaIdFilterWidget.onVisibleChange(true).then(res => {
    // TODO: 获取级联选中路径
    areaIdFilterPath.value = findTreeNodePath(res, formFilter.areaIdFilter);
  }).catch(e => {
    // TODO: 异常处理
    console.error(e);
  });
  isSaleByLandlordFilterWidget.onVisibleChange(true).catch(e => {console.error(e)});
  houseSourceTypeFilterWidget.onVisibleChange(true).catch(e => {console.error(e)});
  officeTypeFilterWidget.onVisibleChange(true).catch(e => {console.error(e)});
  houseTypeFilterWidget.onVisibleChange(true).catch(e => {console.error(e)});
  orientationFilterWidget.onVisibleChange(true).catch(e => {console.error(e)});
  decorationFilterWidget.onVisibleChange(true).catch(e => {console.error(e)});
  isOnSaleFilterWidget.onVisibleChange(true).catch(e => {console.error(e)});
  isSoleDwellingFilterWidget.onVisibleChange(true).catch(e => {console.error(e)});
  refreshFormTourHouseSaleInfo();
};

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