<template>
  <div class="dialog-box" style="position: relative">
    <el-scrollbar class="custom-scroll content-box">
      <el-form
        ref="formEditTourismProjectRef"
        :model="formData"
        :size="layoutStore.defaultFormItemSize"
        :rules="rules"
        label-width="120px"
        label-position="right"
        @submit.prevent
      >
        <el-row :gutter="16">
          <el-col :span="24">
            <el-form-item label="旅游项目标题" prop="TourismProject.projectTitle">
              <el-input
                class="input-item"
                v-model="formData.TourismProject.projectTitle"
                type="textarea"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="500"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="旅游项目简述" prop="TourismProject.remarks">
              <el-input
                class="input-item"
                v-model="formData.TourismProject.remarks"
                type="textarea"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="500"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否热点" prop="TourismProject.isHotspot">
              <el-select
                class="input-item"
                v-model="formData.TourismProject.isHotspot"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="isHotspotWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in isHotspotWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="短标题" prop="TourismProject.shortTitle">
              <el-input
                class="input-item"
                v-model="formData.TourismProject.shortTitle"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="20"
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="是否优质推荐" prop="TourismProject.isQualityRecommendation">
              <el-select
                class="input-item"
                v-model="formData.TourismProject.isQualityRecommendation"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="isQualityRecommendationWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in isQualityRecommendationWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="24">
            <el-form-item label="短描述" prop="TourismProject.shortDescription">
              <el-input
                class="input-item"
                v-model="formData.TourismProject.shortDescription"
                type="textarea"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="255"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="标签" prop="TourismProject.projectLabel">
              <el-input
                class="input-item"
                v-model="formData.TourismProject.projectLabel"
                type="textarea"
                placeholder="多个标签请以&分割"
                :clearable="true"
                :show-word-limit="false"
                maxlength="40"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人描述" prop="TourismProject.contactDescription">
              <el-input
                class="input-item"
                v-model="formData.TourismProject.contactDescription"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="255"
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="联系人二维码" prop="TourismProject.contactCode">
              <el-upload
                class="upload-image-item"
                name="uploadFile"
                :headers="getUploadHeaders"
                :action="getUploadActionUrl('/admin/app/tourismProject/upload')"
                :data="{fieldName: 'contactCode', asImage: true}"
                :on-success="onContactCodeUploadSuccess"
                :on-remove="onContactCodeRemoveFile"
                :on-error="onUploadError"
                :show-file-list="false"
              >
                <div v-if="contactCodeWidgetFileList && contactCodeWidgetFileList[0] != null" style="position: relative">
                  <img class="upload-image-show"
                       :src="contactCodeWidgetFileList[0].url" />
                  <div class="upload-img-del el-icon-close"
                       @click.stop="onContactCodeRemoveFile(null, null)" />
                </div>
                <i v-else class="el-icon-plus upload-image-item"></i>
              </el-upload>
            </el-form-item>
          </el-col> -->
          <el-col :span="24">
            <el-form-item label="首页热门图片" prop="TourismProject.homeHotPicture">
              <el-upload
                class="upload-image-item"
                name="uploadFile"
                :headers="getUploadHeaders"
                :action="getUploadActionUrl('/admin/app/tourismProject/upload')"
                :data="{fieldName: 'homeHotPicture', asImage: true}"
                :on-success="onHomeHotPictureUploadSuccess"
                :on-remove="onHomeHotPictureRemoveFile"
                :on-error="onUploadError"
                :show-file-list="false"
              >
              <div v-if="homeHotPictureWidgetFileList && homeHotPictureWidgetFileList[0] != null" style="position: relative">
                <img class="upload-image-show"
                  :src="homeHotPictureWidgetFileList[0].url" />
                <div class="upload-img-del el-icon-close"
                  @click.stop="onHomeHotPictureRemoveFile(null, null)" />
              </div>
              <i v-else class="el-icon-plus upload-image-item"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="是否启用" prop="TourismProject.enable">
              <el-select
                class="input-item"
                v-model="formData.TourismProject.enable"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="enableWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in enableWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="显示顺序" prop="TourismProject.showOrder">
              <el-input-number
                class="input-item"
                v-model="formData.TourismProject.showOrder"
                placeholder=""
                :clearable="true"
                :step="1"
                :controls="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出发地" prop="TourismProject.startPlace">
              <el-input
                class="input-item"
                v-model="formData.TourismProject.startPlace"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="30"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="目的地" prop="TourismProject.endPlace">
              <el-input
                class="input-item"
                v-model="formData.TourismProject.endPlace"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="30"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否精选目的地 " prop="TourismProject.isWinnowDestination">
              <el-select
                class="input-item"
                v-model="formData.TourismProject.isWinnowDestination"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="isWinnowDestinationWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in isWinnowDestinationWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属分类" prop="TourismProject.belongTab">
              <el-cascader
                class="input-item"
                v-model="belongTabPath"
                :options="belongTabWidgetDropdownList"
                placeholder=""
                :clearable="true"
                :filterable="true"
                :show-all-levels="false"
                :props="{ value: 'id', label: 'name', children: 'children', checkStrictly: true }"
                @change="onBelongTabValueChange"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="旅游项目展示图" prop="TourismProject.tourismUrl">
              <el-upload
                class="upload-image-item"
                name="uploadFile"
                :headers="getUploadHeaders"
                :action="getUploadActionUrl('/admin/app/tourismProject/upload')"
                :data="{fieldName: 'tourismUrl', asImage: true}"
                :on-success="onTourismUrlUploadSuccess"
                :on-remove="onTourismUrlRemoveFile"
                :on-error="onUploadError"
                :show-file-list="false"
              >
              <div v-if="tourismUrlWidgetFileList && tourismUrlWidgetFileList[0] != null" style="position: relative">
                <img class="upload-image-show"
                  :src="tourismUrlWidgetFileList[0].url" />
                <div class="upload-img-del el-icon-close"
                  @click.stop="onTourismUrlRemoveFile(null, null)" />
              </div>
              <i v-else class="el-icon-plus upload-image-item"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="旅游项目图集" prop="TourismProject.tourismFile.fileUrl">
              <el-upload
                class="upload-image-item upload-image-multi"
                name="uploadFile"
                :headers="getUploadHeaders"
                :action="getUploadActionUrl('/admin/app/tourismFile/upload')"
                :data="{fieldName: 'fileUrl', asImage: true}"
                :on-success="onFileUrlUploadSuccess"
                :on-remove="onFileUrlRemoveFile"
                :on-error="onUploadError"
                :on-exceed="onUploadLimit"
                list-type="picture-card"
                :file-list="fileUrlWidgetFileList"
                :limit="fileUrlWidgetMaxCount"
                :show-file-list="true"
              >
              <i class="el-icon-plus upload-image-item"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="浏览量" prop="TourismProject.pageViewCount">
              <el-input-number
                class="input-item"
                v-model="formData.TourismProject.pageViewCount"
                placeholder=""
                :clearable="true"
                :min="0"
                :step="1"
                :controls="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="点赞量" prop="TourismProject.likeCount">
              <el-input-number
                class="input-item"
                v-model="formData.TourismProject.likeCount"
                placeholder=""
                :clearable="true"
                :min="0"
                :step="1"
                :controls="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目价格" prop="TourismProject.price">
              <el-input-number
                class="input-item"
                v-model="formData.TourismProject.price"
                placeholder=""
                :clearable="true"
                :min="0"
                :step="1"
                :controls="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="价格单位" prop="TourismProject.priceUnit">
              <el-input
                class="input-item"
                v-model="formData.TourismProject.priceUnit"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="32"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="TourismProject.contactNumber">
              <el-input
                class="input-item"
                v-model="formData.TourismProject.contactNumber"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="50"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="产品卖点" prop="TourismProject.sellingPoint">
              <el-input
                class="input-item"
                v-model="formData.TourismProject.sellingPoint"
                type="textarea"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="500"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总天数" prop="TourismProject.countTimes">
              <el-input
                class="input-item"
                v-model="formData.TourismProject.countTimes"
                type="text"
                placeholder="例(7天)"
                :clearable="true"
                :show-word-limit="false"
                maxlength="20"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="推荐指数" prop="TourismProject.recommendationRate">
              <el-input-number
                class="input-item"
                v-model="formData.TourismProject.recommendationRate"
                placeholder="1-5"
                :clearable="true"
                :min="1"
                :max="5"
                :step="1"
                :controls="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="富文本内容" class="rich-input" prop="TourismProject.tourismContent.content">
              <rich-editor
                ref="content"
                class="input-item"
                v-model="formData.TourismProject.tourismContent.content"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="费用说明" class="rich-input" prop="TourismProject.tourismContent.costDescription">
              <rich-editor
                ref="costDescription"
                class="input-item"
                v-model="formData.TourismProject.tourismContent.costDescription"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="预定须知" class="rich-input" prop="TourismProject.tourismContent.bookingNotice">
              <rich-editor
                ref="bookingNotice"
                class="input-item"
                v-model="formData.TourismProject.tourismContent.bookingNotice"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-scrollbar>
    <el-row class="footer-box" type="flex" justify="end" align="middle">
      <el-button :size="layoutStore.defaultFormItemSize" @click="onCancel()">取消</el-button>
      <el-button :size="layoutStore.defaultFormItemSize" type="primary" @click="onSubmitTourismProjectClick()">保存</el-button>
    </el-row>
  </div>
</template>

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

<script setup lang="ts">
import { DialogProp } from '@/components/Dialog/types';
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 { TourismProjectData } from '@/api/generated/tourismProjectController';
import { TourismContentData } from '@/api/generated/tourismContentController';
import { TourismFileData } from '@/api/generated/tourismFileController';
import { TourismProjectController,TourismContentController, TourismFileController } 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;
    id?: ANY_OBJECT;
    saveOnSubmit?: boolean;
    rowData?: ANY_OBJECT;
    // 当使用Dialog.show弹出组件时，须定义该prop属性，以便对dialog进行回调
    dialog?: DialogProp<ANY_OBJECT[]>;
  }>(),
  {
    subPage: 0,
    id: undefined,
    saveOnSubmit: true,
    rowData: undefined,
    dialog: undefined,
  },
);

const formEditTourismProjectRef = ref();
// 表单数据定义
type FormEditTourismProjectData = {
  TourismProject: TourismProjectData;
};
// 表单数据
const formData = reactive<FormEditTourismProjectData>({
  TourismProject: {
    // 上传的联系二维码
    // contactCode: undefined,
    // 主键id
    id: undefined,
    // 项目标题
    projectTitle: undefined,
    // 项目简述
    remarks: undefined,
    // 是否热点
    isHotspot: undefined,
    // 标签
    projectLabel: undefined,
    // 显示顺序
    showOrder: undefined,
    // 是否启用
    enable: undefined,
    // 所属分类
    belongTab: undefined,
    // 出发地
    startPlace: undefined,
    // 目的地
    endPlace: undefined,
    // 总天数
    countTimes: undefined,
    // 项目价格
    price: undefined,
    // 项目展示图片
    tourismUrl: undefined,
    // 创建用户
    createUserId: undefined,
    // 创建时间
    createTime: undefined,
    // 更新用户
    updateUserId: undefined,
    // 更新时间
    updateTime: undefined,
    // 删除标记(1: 正常 -1: 已删除)
    dataState: undefined,
    // 价格单位
    priceUnit: undefined,
    // 服务保障
    serviceEnsure: undefined,
    // 联系电话
    contactNumber: undefined,
    // 产品卖点
    sellingPoint: undefined,
    // 短标题
    shortTitle: undefined,
    // 短描述
    shortDescription: undefined,
    // 首页热门图片
    homeHotPicture: undefined,
    // 联系人描述
    contactDescription: undefined,
    // 游记banner
    travelNotesBanner: undefined,
    // 点赞量
    likeCount: undefined,
    // 浏览量
    pageViewCount: undefined,
    // 人物关系
    role: undefined,
    // 出发时间
    departureTime: undefined,
    // 人均费用
    averageCost: undefined,
    // 推荐指数
    recommendationRate: undefined,
    // 是否精选目的地 1是 2不是
    isWinnowDestination: undefined,
      tourismFile: {
      // 主键id
      id: undefined,
      // 文件名称
      fileName: undefined,
      // 文件大小
      fileSize: undefined,
      // 文件类型
      fileType: undefined,
      // 文件存储地址
      fileUrl: undefined,
      // 关联表id
      associationTableId: undefined,
      // 上传时间
      uploadTime: undefined,
      // 创建用户
      createUserId: undefined,
      // 创建时间
      createTime: undefined,
      // 更新用户
      updateUserId: undefined,
      // 更新时间
      updateTime: undefined,
      // 删除标记(1: 正常 -1: 已删除)
      dataState: undefined,
    },
    tourismContent: {
      // 主键id
      id: undefined,
      // 富文本内容
      content: undefined,
      // 关联表id
      associationId: undefined,
      // 创建用户
      createUserId: undefined,
      // 创建时间
      createTime: undefined,
      // 更新用户
      updateUserId: undefined,
      // 更新时间
      updateTime: undefined,
      // 删除标记(1: 正常 -1: 已删除)
      dataState: undefined,
      // 费用说明
      costDescription: undefined,
      // 预定须知
      bookingNotice: undefined,
    }
  }
},
);
// 表单验证规则
const rules = reactive({
  'TourismProject.shortDescription': [
    {required: true, message: '请输入短描述', trigger: 'blur'},
    {type: 'string', max: 255, message: '短描述长度必须小于255位', trigger: 'blur'}
  ],
  'TourismProject.tourismContent.bookingNotice': [
  ],
  'TourismProject.pageViewCount': [
    {required: true, message: '请输入浏览量', trigger: 'blur'}
  ],
  'TourismProject.tourismFile.fileUrl': [
  ],
  'TourismProject.tourismContent.costDescription': [
  ],
  'TourismProject.contactDescription': [
    {required: false, message: '请输入联系人描述', trigger: 'blur'},
    {type: 'string', max: 255, message: '联系人描述长度必须小于255位', trigger: 'blur'}
  ],
  'TourismProject.recommendationRate': [
    {required: true, message: '请输入推荐指数', trigger: 'blur'}
  ],
  'TourismProject.tourismContent.content': [
    {required: true, message: '请输入富文本内容', trigger: 'blur'}
  ],
  'TourismProject.remarks': [
    {required: true, message: '请输入旅游项目简述', trigger: 'blur'},
    {type: 'string', max: 500, message: '旅游项目简述长度必须小于500位', trigger: 'blur'}
  ],
  'TourismProject.projectTitle': [
    {required: true, message: '请输入旅游项目标题', trigger: 'blur'},
    {type: 'string', max: 500, message: '旅游项目标题长度必须小于500位', trigger: 'blur'}
  ],
  'TourismProject.projectLabel': [
    {required: true, message: '请输入标签', trigger: 'blur'},
    {type: 'string', max: 200, message: '标签长度必须小于200位', trigger: 'blur'}
  ],
  'TourismProject.isHotspot': [
    {required: true, message: '请输入是否热点', trigger: 'blur'}
  ],
  // 'TourismProject.enable': [
  //   {required: true, message: '请输入是否启用', trigger: 'blur'}
  // ],
  'TourismProject.shortTitle': [
    {required: true, message: '请输入短标题', trigger: 'blur'},
    {type: 'string', max: 20, message: '短标题长度必须小于20位', trigger: 'blur'}
  ],
  'TourismProject.showOrder': [
    {required: true, message: '请输入显示顺序', trigger: 'blur'}
  ],
  'TourismProject.startPlace': [
    {required: true, message: '请输入出发地', trigger: 'blur'},
    {type: 'string', max: 30, message: '出发地长度必须小于30位', trigger: 'blur'}
  ],
  'TourismProject.belongTab': [
    {required: true, message: '请输入所属分类', trigger: 'blur'}
  ],
  'TourismProject.likeCount': [
    {required: true, message: '请输入点赞量', trigger: 'blur'}
  ],
  'TourismProject.homeHotPicture': [
    {required: true, message: '请输入首页热门图片', trigger: 'blur'}
  ],
  'TourismProject.priceUnit': [
    {required: true, message: '请输入价格单位', trigger: 'blur'}
  ],
  'TourismProject.contactNumber': [
    {required: false, message: '请输入联系电话', trigger: 'blur'},
    {type: 'string', max: 30, message: '联系电话长度必须小于30位', trigger: 'blur'}
  ],
  'TourismProject.endPlace': [
    {required: true, message: '请输入目的地', trigger: 'blur'},
    {type: 'string', max: 30, message: '目的地长度必须小于30位', trigger: 'blur'}
  ],
  // 'TourismProject.contactCode': [
  //   {required: true, message: '请输入联系人二维码', trigger: 'blur'}
  // ],
  'TourismProject.price': [
    {required: true, message: '请输入项目价格', trigger: 'blur'}
  ],
  'TourismProject.countTimes': [
    {required: true, message: '请输入总天数', trigger: 'blur'}
  ],
  'TourismProject.tourismUrl': [
    {required: true, message: '请输入旅游项目展示图', trigger: 'blur'}
  ],
  'TourismProject.isWinnowDestination': [
  ],
  'TourismProject.sellingPoint': [
    {required: true, message: '请输入产品卖点', trigger: 'blur'},
    {type: 'string', max: 500, message: '产品卖点长度必须小于500位', trigger: 'blur'}
  ],
});

const onCancel = () => {
  if (props.dialog) {
    props.dialog.cancel();
  }
};

const isEdit = computed(() => {
  return props.saveOnSubmit ? props.id != null : props.rowData != null;
});

// 初始化页面数据
const loadTourismProjectData = () => {
  return new Promise<void>((resolve, reject) => {
    if (!isEdit.value) {
      resolve();
      return;
    }
    if (!props.saveOnSubmit && props.rowData != null) {
      formData.TourismProject = JSON.parse(JSON.stringify(props.rowData));
      resolve();
      return;
    }
    let params: ANY_OBJECT = {
      id: props.id
    };
    TourismProjectController.view(params).then(res => {
      formData.TourismProject = { ...res.data };
      if (formData.TourismProject.tourismFile == null) {
        formData.TourismProject.tourismFile = {
          id: undefined,
          fileName: undefined,
          fileSize: undefined,
          fileType: undefined,
          fileUrl: undefined,
          associationTableId: undefined,
          uploadTime: undefined,
          createUserId: undefined,
          createTime: undefined,
          updateUserId: undefined,
          updateTime: undefined,
          dataState: undefined
        };
      }
      if (formData.TourismProject.tourismContent == null) {
        formData.TourismProject.tourismContent = {
          id: undefined,
          content: undefined,
          associationId: undefined,
          createUserId: undefined,
          createTime: undefined,
          updateUserId: undefined,
          updateTime: undefined,
          dataState: undefined,
          costDescription: undefined,
          bookingNotice: undefined
        };
      }
      resolve();
    }).catch(e => {
      reject(e);
    });
  });
};
/**
 * 是否热点下拉数据获取函数
 */
const loadIsHotspotDropdownList = (): Promise<ListData<DictData>> => {
  return Promise.resolve({
    dataList: StaticDict.Hotspot.getList(),
  });
};
// 是否热点配置参数
const isHotspotOptions: DropdownOptions<DictData> = {
  loadData: loadIsHotspotDropdownList,
  isTree: false,
};
// 是否热点下拉组件
const isHotspotWidget = useDropdown(isHotspotOptions);
const { dropdownList: isHotspotWidgetDropdownList } = isHotspotWidget
/**
 * 是否精选目的地 下拉数据获取函数
 */
const loadIsWinnowDestinationDropdownList = (): Promise<ListData<DictData>> => {
  return Promise.resolve({
    dataList: StaticDict.IsWinnowDestination.getList(),
  });
};
// 是否精选目的地 配置参数
const isWinnowDestinationOptions: DropdownOptions<DictData> = {
  loadData: loadIsWinnowDestinationDropdownList,
  isTree: false,
};
// 是否精选目的地 下拉组件
const isWinnowDestinationWidget = useDropdown(isWinnowDestinationOptions);
const { dropdownList: isWinnowDestinationWidgetDropdownList } = isWinnowDestinationWidget
// /**
//  * 联系人二维码上传成功
//  */
// const onContactCodeUploadSuccess = (
//   response: ANY_OBJECT,
//   file: UploadFile,
//   fileList: UploadFile[],
// ) => {
//   if (response.success) {
//     file.downloadUri = response.data.downloadUri;
//     file.filename = response.data.filename;
//     file.uploadPath = response.data.uploadPath;
//     file.url = URL.createObjectURL(file.raw);
//     contactCodeWidget.onFileChange(file, fileList);
//     formData.TourismProject.contactCode = fileListToJson(contactCodeWidgetFileList.value);
//   } else {
//     ElMessage.error(response.message);
//   }
// };
// /**
//  * 移除联系人二维码
//  */
// const onContactCodeRemoveFile = (file: UploadFile | null, fileList: UploadFile[] | null) => {
//   contactCodeWidget.onFileChange(file, fileList);
//   formData.TourismProject.contactCode = fileListToJson(contactCodeWidgetFileList.value);
// };
// // 联系人二维码上传文件组件
// const contactCodeWidget = useUploadWidget(1);
// const { fileList: contactCodeWidgetFileList, maxCount: contactCodeWidgetMaxCount } = contactCodeWidget;
/**
 * 首页热门图片上传成功
 */
const onHomeHotPictureUploadSuccess = (
  response: ANY_OBJECT,
  file: UploadFile,
  fileList: UploadFile[],
) => {
  if (response.success) {
    file.downloadUri = response.data.downloadUri;
    file.filename = response.data.filename;
    file.uploadPath = response.data.uploadPath;
    file.url = URL.createObjectURL(file.raw);
    homeHotPictureWidget.onFileChange(file, fileList);
    formData.TourismProject.homeHotPicture = fileListToJson(homeHotPictureWidgetFileList.value);
  } else {
    ElMessage.error(response.message);
  }
};
/**
 * 移除首页热门图片
 */
const onHomeHotPictureRemoveFile = (file: UploadFile | null, fileList: UploadFile[] | null) => {
  homeHotPictureWidget.onFileChange(file, fileList);
  formData.TourismProject.homeHotPicture = fileListToJson(homeHotPictureWidgetFileList.value);
};
// 首页热门图片上传文件组件
const homeHotPictureWidget = useUploadWidget(1);
const { fileList: homeHotPictureWidgetFileList, maxCount: homeHotPictureWidgetMaxCount } = homeHotPictureWidget;
/**
 * 是否启用下拉数据获取函数
 */
const loadEnableDropdownList = (): Promise<ListData<DictData>> => {
  return Promise.resolve({
    dataList: StaticDict.Enable.getList(),
  });
};
// 是否启用配置参数
const enableOptions: DropdownOptions<DictData> = {
  loadData: loadEnableDropdownList,
  isTree: false,
};
// 是否启用下拉组件
// const enableWidget = useDropdown(enableOptions);
// const { dropdownList: enableWidgetDropdownList } = enableWidget
/**
 * 所属分类下拉数据获取函数
 */
const loadBelongTabDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    const params = {
    };
    DictionaryController.dictDirectoryInfo(params).then(res => {
      resolve({
        dataList: res.getList(),
      });
    }).catch(e => {
      reject(e);
    });
  });
};
/**
 * 所属分类选中值改变
 */
const onBelongTabValueChange = (value) => {
  formData.TourismProject.belongTab = Array.isArray(value) ? value[value.length - 1] : value;
};
// 所属分类配置参数
const belongTabOptions: DropdownOptions<DictData> = {
  loadData: loadBelongTabDropdownList,
  isTree: true,
};
// 所属分类选中数据
const belongTabPath = ref<Array<string | number>>([]);
// 所属分类下拉组件
const belongTabWidget = useDropdown(belongTabOptions);
const { dropdownList: belongTabWidgetDropdownList } = belongTabWidget
/**
 * 旅游项目展示图上传成功
 */
const onTourismUrlUploadSuccess = (
  response: ANY_OBJECT,
  file: UploadFile,
  fileList: UploadFile[],
) => {
  if (response.success) {
    file.downloadUri = response.data.downloadUri;
    file.filename = response.data.filename;
    file.uploadPath = response.data.uploadPath;
    file.url = URL.createObjectURL(file.raw);
    tourismUrlWidget.onFileChange(file, fileList);
    formData.TourismProject.tourismUrl = fileListToJson(tourismUrlWidgetFileList.value);
  } else {
    ElMessage.error(response.message);
  }
};
/**
 * 移除旅游项目展示图
 */
const onTourismUrlRemoveFile = (file: UploadFile | null, fileList: UploadFile[] | null) => {
  tourismUrlWidget.onFileChange(file, fileList);
  formData.TourismProject.tourismUrl = fileListToJson(tourismUrlWidgetFileList.value);
};
// 旅游项目展示图上传文件组件
const tourismUrlWidget = useUploadWidget(1);
const { fileList: tourismUrlWidgetFileList, maxCount: tourismUrlWidgetMaxCount } = tourismUrlWidget;
/**
 * 旅游项目图集上传成功
 */
const onFileUrlUploadSuccess = (
  response: ANY_OBJECT,
  file: UploadFile,
  fileList: UploadFile[],
) => {
  if (response.success) {
    file.downloadUri = response.data.downloadUri;
    file.filename = response.data.filename;
    file.uploadPath = response.data.uploadPath;
    file.url = URL.createObjectURL(file.raw);
    fileUrlWidget.onFileChange(file, fileList);
    formData.TourismProject.tourismFile.fileUrl = fileListToJson(fileUrlWidgetFileList.value);
  } else {
    ElMessage.error(response.message);
  }
};
/**
 * 移除旅游项目图集
 */
const onFileUrlRemoveFile = (file: UploadFile | null, fileList: UploadFile[] | null) => {
  fileUrlWidget.onFileChange(file, fileList);
  formData.TourismProject.tourismFile.fileUrl = fileListToJson(fileUrlWidgetFileList.value);
};
// 旅游项目图集上传文件组件
const fileUrlWidget = useUploadWidget(5);
const { fileList: fileUrlWidgetFileList, maxCount: fileUrlWidgetMaxCount } = fileUrlWidget;
const content = ref();
const costDescription = ref();
const bookingNotice = ref();
const onUploadError = () => {
  ElMessage.error('文件上传失败');
};
const onUploadLimit = () => {
  ElMessage.error('已经超出最大上传个数限制');
};
const refreshFormEditTourismProject = () => {
  // 刷新段落
};
/**
 * 重置过滤值
 */
const resetFormEditTourismProject = () => {
  refreshFormEditTourismProject();
};
/**
 * 重置所有过滤值
 */
const resetFilter = () => {
  resetFormEditTourismProject();
};
/**
 * 保存
 */
const onSubmitTourismProjectClick = () => {
  // 更新富文本字段值
  formData.TourismProject.tourismContent.content = content.value?.getHtml();
  formData.TourismProject.tourismContent.costDescription = costDescription.value?.getHtml();
  formData.TourismProject.tourismContent.bookingNotice = bookingNotice.value?.getHtml();
  formEditTourismProjectRef.value.validate((valid) => {
    if (!valid) return;
    // 级联操作
    if (!props.saveOnSubmit) {
      let formData = {
        ...formData.TourismProject
      };
    formData.isHotspotDictMap = findItemFromList(isHotspotWidgetDropdownList, formData.isHotspot, 'id');
    formData.isWinnowDestinationDictMap = findItemFromList(isWinnowDestinationWidgetDropdownList, formData.isWinnowDestination, 'id');
    // formData.enableDictMap = findItemFromList(enableWidgetDropdownList, formData.enable, 'id');
    formData.belongTabDictMap = findTreeNode(belongTabWidgetDropdownList, formData.belongTab, 'id');
  props.dialog?.submit(formData);
      return;
    }
    let params: ANY_OBJECT = {
      tourismProjectDto: {
        // contactCode: formData.TourismProject.contactCode,
        id: formData.TourismProject.id,
        priceUnit: formData.TourismProject.priceUnit,
        serviceEnsure: formData.TourismProject.serviceEnsure,
        contactNumber: formData.TourismProject.contactNumber,
        sellingPoint: formData.TourismProject.sellingPoint,
        shortTitle: formData.TourismProject.shortTitle,
        shortDescription: formData.TourismProject.shortDescription,
        homeHotPicture: formData.TourismProject.homeHotPicture,
        contactDescription: formData.TourismProject.contactDescription,
        travelNotesBanner: formData.TourismProject.travelNotesBanner,
        likeCount: formData.TourismProject.likeCount,
        pageViewCount: formData.TourismProject.pageViewCount,
        role: formData.TourismProject.role,
        departureTime: formData.TourismProject.departureTime,
        averageCost: formData.TourismProject.averageCost,
        recommendationRate: formData.TourismProject.recommendationRate,
        projectTitle: formData.TourismProject.projectTitle,
        remarks: formData.TourismProject.remarks,
        isHotspot: formData.TourismProject.isHotspot,
        projectLabel: formData.TourismProject.projectLabel,
        showOrder: formData.TourismProject.showOrder,
        enable: formData.TourismProject.enable,
        belongTab: formData.TourismProject.belongTab,
        startPlace: formData.TourismProject.startPlace,
        endPlace: formData.TourismProject.endPlace,
        countTimes: formData.TourismProject.countTimes,
        price: formData.TourismProject.price,
        tourismUrl: formData.TourismProject.tourismUrl,
        createUserId: formData.TourismProject.createUserId,
        createTime: formData.TourismProject.createTime,
        updateUserId: formData.TourismProject.updateUserId,
        updateTime: formData.TourismProject.updateTime,
        isWinnowDestination: formData.TourismProject.isWinnowDestination,
      },
      tourismFileDto: formData.TourismProject.tourismFile,
      tourismContentDto: formData.TourismProject.tourismContent,
    };

    let httpCall = isEdit.value ? TourismProjectController.update : TourismProjectController.add;
    httpCall(params).then(res => {
      ElMessage.success('保存成功');
      props.dialog?.submit();
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
  });
};
const formInit = () => {
  loadTourismProjectData().then(res => {
    isHotspotWidget.onVisibleChange(true).catch(e => {console.error(e)});
    isWinnowDestinationWidget.onVisibleChange(true).catch(e => {console.error(e)});
    // isQualityRecommendationWidget.onVisibleChange(true).catch(e => {console.error(e)});
    // let contactCodeDownloadParams = {
    //   id: formData.TourismProject.id,
    //   fieldName: 'contactCode',
    //   asImage: true
    // };
    // contactCodeWidgetFileList.value = parseUploadData(formData.TourismProject.contactCode, contactCodeDownloadParams);
    let homeHotPictureDownloadParams = {
      id: formData.TourismProject.id,
      fieldName: 'homeHotPicture',
      asImage: true
    };
    homeHotPictureWidgetFileList.value = parseUploadData(formData.TourismProject.homeHotPicture, homeHotPictureDownloadParams);
    // enableWidget.onVisibleChange(true).catch(e => {console.error(e)});

    belongTabWidget.onVisibleChange(true).then(res => {
      // TODO: 获取级联选中路径
      belongTabPath.value = findTreeNodePath(res, formData.TourismProject.belongTab);
      console.log(11111111111)
      console.log(belongTabPath.value)
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
    let tourismUrlDownloadParams = {
      id: formData.TourismProject.id,
      fieldName: 'tourismUrl',
      asImage: true
    };
    tourismUrlWidgetFileList.value = parseUploadData(formData.TourismProject.tourismUrl, tourismUrlDownloadParams);
    let fileUrlDownloadParams = {
      id: formData.TourismProject.tourismFile.id,
      fieldName: 'fileUrl',
      asImage: true
    };
    fileUrlWidgetFileList.value = parseUploadData(formData.TourismProject.tourismFile.fileUrl, fileUrlDownloadParams);
    if (isEdit.value) refreshFormEditTourismProject();
  }).catch(e => {
    // TODO: 异常处理
    console.error(e);
  });
};

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