<template>
  <div class="page-box" style="position: relative;">
    <el-form
      ref="formSaleHouseAdvisorRelationRef"
      :model="formData"
      :size="layoutStore.defaultFormItemSize"
      label-width="120px"
      label-position="right"
      @submit.prevent
    >
      <!-- <filter-box :item-width="350" @search="refreshFormSaleHouseAdvisorRelation()" @reset="resetFormSaleHouseAdvisorRelation">
        <el-form-item label="姓名">
          <el-input
            class="filter-item"
            v-model="tourHouseAdvisorRelationDtoFilter.nameFilter"
            type="text"
            placeholder=""
            :clearable="true"
            :show-word-limit="false"
            maxlength=""
          />
        </el-form-item>
        <el-form-item label="手机号">
          <el-input
            class="filter-item"
            v-model="tourHouseAdvisorRelationDtoFilter.mobileFilter"
            type="text"
            placeholder=""
            :clearable="true"
            :show-word-limit="false"
            maxlength=""
          />
        </el-form-item>
      </filter-box> -->
    </el-form>
    <table-box
      ref="tourHouseAdvisorRelation"
      class="page-table"
      :data="tourHouseAdvisorRelationWidgetDataList"
      :size="layoutStore.defaultFormItemSize"
      :row-config="{isCurrent: false, isHover: true}"
      :seq-config="{startIndex: ((tourHouseAdvisorRelationWidgetCurrentPage - 1) * tourHouseAdvisorRelationWidgetPageSize)}"
      :sort-config="{remote: true}"
      :hasExtend="true"
      @sort-change="tourHouseAdvisorRelationWidget.onSortChange"
      @refresh="tourHouseAdvisorRelationWidget.refreshTable()"
    >
      <template #operator>
        <el-button
          type="primary"
          :size="layoutStore.defaultFormItemSize"
          @click="onFormSetTourHouseAdvisorInfoClick()"
          >
          设置房屋顾问信息管理
        </el-button>
      </template>
      <vxe-column title="序号" type="seq" :index="tourHouseAdvisorRelationWidget.getTableIndex" :width="80" />
      <vxe-column title="顾问名称" field="tourHouseAdvisorInfo.name" />
      <vxe-column title="顾问类型" field="tourHouseAdvisorInfo.developersIdDictMap.name" />
      <vxe-column title="行业经验年限" field="tourHouseAdvisorInfo.experienceAge" />
      <vxe-column title="成功交房数量" field="tourHouseAdvisorInfo.successfulDeliveryCount" />
      <vxe-column title=" 是否金牌顾问" field="tourHouseAdvisorInfo.isGoldAdvisorDictMap.name" />
      <!-- <vxe-column title="头像url" min-width="100px">
        <template v-slot="scope">
          <el-image v-for="item in parseUploadData((scope.row.tourHouseAdvisorInfo || {}).avatarUrl, { id: scope.row.TourHouseAdvisorInfo.id, fieldName: 'avatarUrl', asImage: true })"
            :preview-src-list="getPictureList((scope.row.tourHouseAdvisorInfo || {}).avatarUrl, { id: scope.row.TourHouseAdvisorInfo.id, fieldName: 'avatarUrl', 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="tourHouseAdvisorInfo.enableDictMap.name" />
      <vxe-column title="手机号" field="tourHouseAdvisorInfo.mobile" />
      <vxe-column title="操作" fixed="right">
        <template v-slot="scope">
          <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="tourHouseAdvisorRelationWidgetTotalCount"
            :current-page="tourHouseAdvisorRelationWidgetCurrentPage"
            :page-size="tourHouseAdvisorRelationWidgetPageSize"
            :page-sizes="[10, 20, 50, 100]"
            layout="total, prev, pager, next, sizes"
            @current-change="tourHouseAdvisorRelationWidget.onCurrentPageChange"
            @size-change="tourHouseAdvisorRelationWidget.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: 'formSaleHouseAdvisorRelation',
};
</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 { TourHouseSaleInfoData } from '@/api/generated/tourHouseSaleInfoController';
import { TourHouseAdvisorRelationData } from '@/api/generated/tourHouseAdvisorRelationController';
import { TourHouseAdvisorInfoData } from '@/api/generated/tourHouseAdvisorInfoController';
import { TourHouseSaleInfoController, TourHouseAdvisorRelationController, TourHouseAdvisorInfoController } from '@/api/generated';
import FormSetTourHouseAdvisorInfo from '@/pages/TourHouseSaleInfo/formSetTourHouseAdvisorInfo.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;
    // id?: route.query.id;
  }>(),
  {
    subPage: 0,
    id: undefined,
  },
);

const tourHouseAdvisorRelationDtoFilter = reactive({
  // 姓名
  nameFilter: undefined,
  // 手机号
  mobileFilter: undefined,
  houseId: route.query.id
});
const formFilterCopy = reactive({
  // 姓名
  nameFilter: undefined,
  // 手机号
  mobileFilter: undefined,
});

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

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

/**
 * 表格组件数据获取函数，返回Promise
 */
const loadTourHouseAdvisorRelationWidgetData = (params: ANY_OBJECT) => {
  if (params == null) params = {};
  params = {
    ...params,
    tourHouseAdvisorRelationDtoFilter
  };
  console.log(4545645465);  
  console.log(route.query);
  return new Promise((resolve, reject) => {
    TourHouseAdvisorRelationController.list(params).then(res => {
      resolve({
        dataList: res.data.dataList,
        totalCount: res.data.totalCount
      });
    }).catch(e => {
      reject(e);
    });
  });
};
/**
 * 表格组件数据获取检测函数，返回true正常获取数据，返回false停止获取数据
 */
const loadTourHouseAdvisorRelationVerify = () => {
  formFilterCopy.nameFilter = tourHouseAdvisorRelationDtoFilter.nameFilter;
  formFilterCopy.mobileFilter = tourHouseAdvisorRelationDtoFilter.mobileFilter;
  return true;
};
/**
 * 移除
 */
const onDeleteClick = (row?: TourHouseAdvisorRelationData) => {
  let params: ANY_OBJECT = {
    id: row?.id,
  };

  TourHouseAdvisorRelationController.delete(params).then(res => {
    ElMessage.success('移除成功');
    tourHouseAdvisorRelationWidget.refreshTable(false, 1);
  }).catch(e => {
    // TODO: 异常处理
    console.error(e);
  });
};
/**
 * 设置房屋顾问信息管理
 */
const onFormSetTourHouseAdvisorInfoClick = (row?: TourHouseAdvisorRelationData) => {
  let params: ANY_OBJECT = {
    houseId: route.query.id,
  };

  Dialog
    .show('设置房屋顾问信息管理', FormSetTourHouseAdvisorInfo, { area: ['900px','700px'] }, { ...params, subPage: true })
    .then(res => {
      tourHouseAdvisorRelationWidget.refreshTable();
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
};
// 表格组件表格组件参数
const tourHouseAdvisorRelationOptions: TableOptions<TourHouseAdvisorRelationData> = {
  loadTableData: loadTourHouseAdvisorRelationWidgetData,
  verifyTableParameter: loadTourHouseAdvisorRelationVerify,
  paged: true,
  rowSelection: false,
  orderFieldName: undefined,
  ascending: true,
};
// 表格组件表格组件
const tourHouseAdvisorRelation = ref();
const tourHouseAdvisorRelationWidget = useTable(tourHouseAdvisorRelationOptions);
const {
  dataList: tourHouseAdvisorRelationWidgetDataList,
  currentPage: tourHouseAdvisorRelationWidgetCurrentPage,
  pageSize: tourHouseAdvisorRelationWidgetPageSize,
  totalCount: tourHouseAdvisorRelationWidgetTotalCount,
} = tourHouseAdvisorRelationWidget;
const refreshFormSaleHouseAdvisorRelation = () => {
  // 刷新段落
  tourHouseAdvisorRelationWidget.refreshTable();
};
/**
 * 重置过滤值
 */
const resetFormSaleHouseAdvisorRelation = () => {
  tourHouseAdvisorRelationDtoFilter.nameFilter = undefined;
  formFilterCopy.nameFilter = undefined;
  tourHouseAdvisorRelationDtoFilter.mobileFilter = undefined;
  formFilterCopy.mobileFilter = undefined;
  refreshFormSaleHouseAdvisorRelation();
};
/**
 * 重置所有过滤值
 */
const resetFilter = () => {
  resetFormSaleHouseAdvisorRelation();
};
const formInit = () => {
  refreshFormSaleHouseAdvisorRelation();
};

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