<template>
  <div class="dialog-box" style="position: relative">
    <el-scrollbar class="custom-scroll content-box">
      <el-form
        ref="formEditTourTourismTravelNotes"
        :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="TourTourismProjectTravelNotes.projectTitle">
              <el-input
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.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="TourTourismProjectTravelNotes.remarks">
              <el-input
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.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="TourTourismProjectTravelNotes.isHotspot">
              <el-select
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.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="TourTourismProjectTravelNotes.shortTitle">
              <el-input
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.shortTitle"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="20"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="短描述" prop="TourTourismProjectTravelNotes.shortDescription">
              <el-input
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.shortDescription"
                type="textarea"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="255"
              />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="首页热门图片" prop="TourTourismProjectTravelNotes.homeHotPicture">
              <el-upload
                class="upload-image-item"
                name="uploadFile"
                :headers="getUploadHeaders"
                :action="getUploadActionUrl('/admin/app/tourTourismProjectTravelNotes/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="TourTourismProjectTravelNotes.contactCode">
              <el-upload
                class="upload-image-item"
                name="uploadFile"
                :headers="getUploadHeaders"
                :action="getUploadActionUrl('/admin/app/tourTourismProjectTravelNotes/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="12">
            <el-form-item label="联系人描述" prop="TourTourismProjectTravelNotes.contactDescription">
              <el-input
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.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="游记banner" prop="TourTourismProjectTravelNotes.travelNotesBanner">
              <el-upload
                class="upload-image-item"
                name="uploadFile"
                :headers="getUploadHeaders"
                :action="getUploadActionUrl('/admin/app/tourTourismProjectTravelNotes/upload')"
                :data="{fieldName: 'travelNotesBanner', asImage: true}"
                :on-success="onTravelNotesBannerUploadSuccess"
                :on-remove="onTravelNotesBannerRemoveFile"
                :on-error="onUploadError"
                :show-file-list="false"
              >
              <div v-if="travelNotesBannerWidgetFileList && travelNotesBannerWidgetFileList[0] != null" style="position: relative">
                <img class="upload-image-show"
                  :src="travelNotesBannerWidgetFileList[0].url" />
                <div class="upload-img-del el-icon-close"
                  @click.stop="onTravelNotesBannerRemoveFile(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="TourTourismProjectTravelNotes.projectLabel">
              <el-input
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.projectLabel"
                type="textarea"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="200"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="显示顺序" prop="TourTourismProjectTravelNotes.showOrder">
              <el-input-number
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.showOrder"
                placeholder=""
                :clearable="true"
                :step="1"
                :controls="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否启用" prop="TourTourismProjectTravelNotes.enable">
              <el-select
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.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="TourTourismProjectTravelNotes.countTimes">
              <el-input
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.countTimes"
                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="TourTourismProjectTravelNotes.startPlace">
              <el-input
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.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="TourTourismProjectTravelNotes.endPlace">
              <el-input
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.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="TourTourismProjectTravelNotes.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="TourTourismProjectTravelNotes.tourismUrl">
              <el-upload
                class="upload-image-item"
                name="uploadFile"
                :headers="getUploadHeaders"
                :action="getUploadActionUrl('/admin/app/tourTourismProjectTravelNotes/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="TourTourismProjectTravelNotes.tourTourismTravelNotesFile.fileUrl">
              <el-upload
                class="upload-image-item upload-image-multi"
                name="uploadFile"
                :headers="getUploadHeaders"
                :action="getUploadActionUrl('/admin/app/tourTourismTravelNotesFile/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="TourTourismProjectTravelNotes.hotValue">
              <el-input-number
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.hotValue"
                placeholder=""
                :clearable="true"
                :step="1"
                :controls="true"
              />
            </el-form-item>
          </el-col>       
          <el-col :span="12">
            <el-form-item label="点赞量" prop="TourTourismProjectTravelNotes.likeCount">
              <el-input-number
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.likeCount"
                placeholder=""
                :clearable="true"
                :step="1"
                :controls="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="浏览量" prop="TourTourismProjectTravelNotes.pageViewCount">
              <el-input-number
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.pageViewCount"
                placeholder=""
                :clearable="true"
                :step="1"
                :controls="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="人物" prop="TourTourismProjectTravelNotes.role">
              <el-input
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.role"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="50"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出发时间" prop="TourTourismProjectTravelNotes.departureTime">
              <el-date-picker
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.departureTime"
                type="date"
                placeholder=""
                :clearable="true"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="人均费用" prop="TourTourismProjectTravelNotes.averageCost">
              <el-input
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.averageCost"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength="50"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="推荐指数" prop="TourTourismProjectTravelNotes.recommendationRate">
              <el-input-number
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.recommendationRate"
                placeholder=""
                :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="TourTourismProjectTravelNotes.tourTourismTravelNotesContent.content">
              <rich-editor
                ref="content"
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.tourTourismTravelNotesContent.content"
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="24">
            <el-form-item label="费用说明" class="rich-input" prop="TourTourismProjectTravelNotes.tourTourismTravelNotesContent.costDescription">
              <rich-editor
                ref="costDescription"
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.tourTourismTravelNotesContent.costDescription"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="预定须知" class="rich-input" prop="TourTourismProjectTravelNotes.tourTourismTravelNotesContent.bookingNotice">
              <rich-editor
                ref="bookingNotice"
                class="input-item"
                v-model="formData.TourTourismProjectTravelNotes.tourTourismTravelNotesContent.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="onUpdateClick()">保存</el-button>
    </el-row>
  </div>
</template>

<script lang="ts">
export default {
  name: 'formEditTourTourismTravelNotes',
};
</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 { TourTourismTravelNotesContentData } from '@/api/generated/tourTourismTravelNotesContentController';
import { TourTourismTravelNotesFileData } from '@/api/generated/tourTourismTravelNotesFileController';
import { TourTourismProjectTravelNotesData } from '@/api/generated/tourTourismProjectTravelNotesController';
import { TourismProjectController, TourTourismTravelNotesContentController, TourTourismTravelNotesFileController, TourTourismProjectTravelNotesController } 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 formEditTourTourismTravelNotes = ref();
// 表单数据定义
type FormEditTourTourismTravelNotesData = {
  TourTourismProjectTravelNotes: TourTourismProjectTravelNotesData;
};
// 表单数据
const formData = reactive<FormEditTourTourismTravelNotesData>({
  TourTourismProjectTravelNotes: {
    // 主键id
    id: undefined,
    // 项目标题
    projectTitle: undefined,
    // 项目简述
    remarks: undefined,
    // 是否热点，0非热点，1热点
    isHotspot: undefined,
    // 标签
    projectLabel: undefined,
    // 显示顺序
    showOrder: undefined,
    // 是否启用，0禁用，1启用
    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,
    // 热度值
    hotValue: undefined,
    // 点赞量
    likeCount: undefined,
    // 浏览量
    pageViewCount: undefined,
    // 人物
    role: undefined,
    // 出发时间
    departureTime: undefined,
    // 人均费用
    averageCost: undefined,
    // 推荐指数
    recommendationRate: undefined,
    // 旅游项目(以逗号分割，最多为三个项目)
    projectIds: undefined,
    // 上传的联系二维码
    contactCode: undefined,
    tourTourismTravelNotesFile: {
      // 主键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,
    },
    tourTourismTravelNotesContent: {
      // 主键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 xxRequireed = ref(false)
watch(() => (formData.TourTourismProjectTravelNotes.isHotspot) , (val) =>{
 if (val === 1) {
 xxRequireed.value = true; 
 return
}
 xxRequireed.value = false
})
// 表单验证规则
const rules = reactive({
  // 'TourTourismProjectTravelNotes.contactCode': [
  //   {required: true, message: '请输入联系人二维码', trigger: 'blur'}
  // ],
  'TourTourismProjectTravelNotes.hotValue': [
    {required: true, message: '请输入热度值', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.pageViewCount': [
    {required: true, message: '请输入浏览量', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.tourTourismTravelNotesContent.costDescription': [
  ],
  'TourTourismProjectTravelNotes.tourTourismTravelNotesContent.bookingNotice': [
  ],
  'TourTourismProjectTravelNotes.travelNotesBanner': [
    {required: true, message: '请输入游记banner', trigger: 'blur'},
    {type: 'string', max: 255, message: '游记banner长度必须小于255位', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.recommendationRate': [
    {required: true, message: '请输入推荐指数', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.tourismUrl': [
    {required: xxRequireed, message: '请输入项目展示图片', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.countTimes': [
    {required: true, message: '请输入总时长', trigger: 'blur'},
    {type: 'string', max: 20, message: '总时长长度必须小于20位', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.averageCost': [
    {required: true, message: '请输入人均费用', trigger: 'blur'},
  ],
  'TourTourismProjectTravelNotes.endPlace': [
    {required: true, max: 30, message: '目的地长度必须小于30位', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.startPlace': [
    {required: true, max: 30, message: '出发地长度必须小于30位', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.belongTab': [
    {required: true, message: '请输入所属分类', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.enable': [
    {required: true, message: '请输入是否启用', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.showOrder': [
    {required: true, message: '请输入显示顺序', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.homeHotPicture': [
  {required: xxRequireed, message: '请选择首页热门项目', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.tourTourismTravelNotesFile.fileUrl': [
  ],
  'TourTourismProjectTravelNotes.likeCount': [
    {required: true, message: '请输入点赞量', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.contactDescription': [
    { type: 'string', message: '请输入联系人描述', trigger: 'blur'},
  ],
  'TourTourismProjectTravelNotes.tourTourismTravelNotesContent.content': [
    {required: true, message: '请输入富文本内容', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.projectLabel': [
    {required: true, message: '请输入标签', trigger: 'blur'},
    {type: 'string', max: 200, message: '标签长度必须小于200位', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.role': [
    {required: true, message: '请输入人物', trigger: 'blur'},
    {type: 'string', max: 50, message: '人物长度必须小于50位', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.isHotspot': [
    {required: true, message: '请输入是否热点', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.remarks': [
    {required: true, message: '请输入项目简述', trigger: 'blur'},
    {type: 'string', max: 500, message: '项目简述长度必须小于500位', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.projectTitle': [
    {required: true, message: '请输入项目标题', trigger: 'blur'},
    {type: 'string', max: 500, message: '项目标题长度必须小于500位', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.shortDescription': [
    {type: 'string', max: 255, message: '短描述长度必须小于255位', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.shortTitle': [
  {required: require, max: 20, message: '短标题长度必须小于20位', trigger: 'blur'}
  ],
  'TourTourismProjectTravelNotes.departureTime': [
    {required: true, message: '请输入出发时间', trigger: 'blur'}
  ],
});

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

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

// 初始化页面数据
const loadTourTourismProjectTravelNotesData = () => {
  return new Promise<void>((resolve, reject) => {
    if (!isEdit.value) {
      resolve();
      return;
    }
    if (!props.saveOnSubmit && props.rowData != null) {
      formData.TourTourismProjectTravelNotes = JSON.parse(JSON.stringify(props.rowData));
      resolve();
      return;
    }
    let params: ANY_OBJECT = {
      id: props.id
    };
    TourTourismProjectTravelNotesController.view(params).then(res => {
      formData.TourTourismProjectTravelNotes = { ...res.data };
      if (formData.TourTourismProjectTravelNotes.tourTourismTravelNotesFile == null) {
        formData.TourTourismProjectTravelNotes.tourTourismTravelNotesFile = {
          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.TourTourismProjectTravelNotes.tourTourismTravelNotesContent == null) {
        formData.TourTourismProjectTravelNotes.tourTourismTravelNotesContent = {
          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 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.TourTourismProjectTravelNotes.homeHotPicture = fileListToJson(homeHotPictureWidgetFileList.value);
  } else {
    ElMessage.error(response.message);
  }
};
/**
 * 移除首页热门图片
 */
const onHomeHotPictureRemoveFile = (file: UploadFile | null, fileList: UploadFile[] | null) => {
  homeHotPictureWidget.onFileChange(file, fileList);
  formData.TourTourismProjectTravelNotes.homeHotPicture = fileListToJson(homeHotPictureWidgetFileList.value);
};
// 首页热门图片上传文件组件
const homeHotPictureWidget = useUploadWidget(1);
const { fileList: homeHotPictureWidgetFileList, maxCount: homeHotPictureWidgetMaxCount } = homeHotPictureWidget;
/**
 * 联系人二维码上传成功
 */
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.TourTourismProjectTravelNotes.contactCode = fileListToJson(contactCodeWidgetFileList.value);
  } else {
    ElMessage.error(response.message);
  }
};
/**
 * 移除联系人二维码
 */
const onContactCodeRemoveFile = (file: UploadFile | null, fileList: UploadFile[] | null) => {
  contactCodeWidget.onFileChange(file, fileList);
  formData.TourTourismProjectTravelNotes.contactCode = fileListToJson(contactCodeWidgetFileList.value);
};
// 联系人二维码上传文件组件
const contactCodeWidget = useUploadWidget(1);
const { fileList: contactCodeWidgetFileList, maxCount: contactCodeWidgetMaxCount } = contactCodeWidget;
/**
 * 游记banner上传成功
 */
const onTravelNotesBannerUploadSuccess = (
  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);
    travelNotesBannerWidget.onFileChange(file, fileList);
    formData.TourTourismProjectTravelNotes.travelNotesBanner = fileListToJson(travelNotesBannerWidgetFileList.value);
  } else {
    ElMessage.error(response.message);
  }
};
/**
 * 移除游记banner
 */
const onTravelNotesBannerRemoveFile = (file: UploadFile | null, fileList: UploadFile[] | null) => {
  travelNotesBannerWidget.onFileChange(file, fileList);
  formData.TourTourismProjectTravelNotes.travelNotesBanner = fileListToJson(travelNotesBannerWidgetFileList.value);
};
// 游记banner上传文件组件
const travelNotesBannerWidget = useUploadWidget(1);
const { fileList: travelNotesBannerWidgetFileList, maxCount: travelNotesBannerWidgetMaxCount } = travelNotesBannerWidget;
/**
 * 是否启用下拉数据获取函数
 */
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.TourTourismProjectTravelNotes.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.TourTourismProjectTravelNotes.tourismUrl = fileListToJson(tourismUrlWidgetFileList.value);
  } else {
    ElMessage.error(response.message);
  }
};
/**
 * 移除项目展示图片
 */
const onTourismUrlRemoveFile = (file: UploadFile | null, fileList: UploadFile[] | null) => {
  tourismUrlWidget.onFileChange(file, fileList);
  formData.TourTourismProjectTravelNotes.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.TourTourismProjectTravelNotes.tourTourismTravelNotesFile.fileUrl = fileListToJson(fileUrlWidgetFileList.value);
  } else {
    ElMessage.error(response.message);
  }
};
/**
 * 移除旅游项目图集
 */
const onFileUrlRemoveFile = (file: UploadFile | null, fileList: UploadFile[] | null) => {
  fileUrlWidget.onFileChange(file, fileList);
  formData.TourTourismProjectTravelNotes.tourTourismTravelNotesFile.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 refreshFormEditTourTourismTravelNotes = () => {
  // 刷新段落
};
/**
 * 重置过滤值
 */
const resetFormEditTourTourismTravelNotes = () => {
  refreshFormEditTourTourismTravelNotes();
};
/**
 * 重置所有过滤值
 */
const resetFilter = () => {
  resetFormEditTourTourismTravelNotes();
};
/**
 * 编辑
 */
const onUpdateClick = () => {
  // 更新富文本字段值
  formData.TourTourismProjectTravelNotes.tourTourismTravelNotesContent.content = content.value?.getHtml();
  formData.TourTourismProjectTravelNotes.tourTourismTravelNotesContent.costDescription = costDescription.value?.getHtml();
  formData.TourTourismProjectTravelNotes.tourTourismTravelNotesContent.bookingNotice = bookingNotice.value?.getHtml();
  formEditTourTourismTravelNotes.value.validate((valid) => {
    if (!valid) return;
    // 级联操作
    if (!props.saveOnSubmit) {
      let formData = {
        ...formData.TourTourismProjectTravelNotes
      };
    formData.isHotspotDictMap = findItemFromList(isHotspotWidgetDropdownList, formData.isHotspot, 'id');
    formData.enableDictMap = findItemFromList(enableWidgetDropdownList, formData.enable, 'id');
    formData.belongTabDictMap = findTreeNode(belongTabWidgetDropdownList, formData.belongTab, 'id');
  props.dialog?.submit(formData);
      return;
    }
    let params: ANY_OBJECT = {
      tourTourismTravelNotesContentDto: formData.TourTourismProjectTravelNotes.tourTourismTravelNotesContent,
      tourTourismTravelNotesFileDto: formData.TourTourismProjectTravelNotes.tourTourismTravelNotesFile,
      tourTourismProjectTravelNotesDto: {
        contactCode: formData.TourTourismProjectTravelNotes.contactCode,
        id: formData.TourTourismProjectTravelNotes.id,
        hotValue: formData.TourTourismProjectTravelNotes.hotValue,
        likeCount: formData.TourTourismProjectTravelNotes.likeCount,
        pageViewCount: formData.TourTourismProjectTravelNotes.pageViewCount,
        role: formData.TourTourismProjectTravelNotes.role,
        departureTime: formData.TourTourismProjectTravelNotes.departureTime,
        averageCost: formData.TourTourismProjectTravelNotes.averageCost,
        recommendationRate: formData.TourTourismProjectTravelNotes.recommendationRate,
        projectTitle: formData.TourTourismProjectTravelNotes.projectTitle,
        remarks: formData.TourTourismProjectTravelNotes.remarks,
        isHotspot: formData.TourTourismProjectTravelNotes.isHotspot,
        projectLabel: formData.TourTourismProjectTravelNotes.projectLabel,
        showOrder: formData.TourTourismProjectTravelNotes.showOrder,
        enable: formData.TourTourismProjectTravelNotes.enable,
        belongTab: formData.TourTourismProjectTravelNotes.belongTab,
        startPlace: formData.TourTourismProjectTravelNotes.startPlace,
        endPlace: formData.TourTourismProjectTravelNotes.endPlace,
        countTimes: formData.TourTourismProjectTravelNotes.countTimes,
        price: formData.TourTourismProjectTravelNotes.price,
        tourismUrl: formData.TourTourismProjectTravelNotes.tourismUrl,
        createUserId: formData.TourTourismProjectTravelNotes.createUserId,
        createTime: formData.TourTourismProjectTravelNotes.createTime,
        updateUserId: formData.TourTourismProjectTravelNotes.updateUserId,
        updateTime: formData.TourTourismProjectTravelNotes.updateTime,
        priceUnit: formData.TourTourismProjectTravelNotes.priceUnit,
        serviceEnsure: formData.TourTourismProjectTravelNotes.serviceEnsure,
        contactNumber: formData.TourTourismProjectTravelNotes.contactNumber,
        sellingPoint: formData.TourTourismProjectTravelNotes.sellingPoint,
        shortTitle: formData.TourTourismProjectTravelNotes.shortTitle,
        shortDescription: formData.TourTourismProjectTravelNotes.shortDescription,
        homeHotPicture: formData.TourTourismProjectTravelNotes.homeHotPicture,
        contactDescription: formData.TourTourismProjectTravelNotes.contactDescription,
        travelNotesBanner: formData.TourTourismProjectTravelNotes.travelNotesBanner,
      }
    };

    let httpCall = isEdit.value ? TourTourismProjectTravelNotesController.update : TourTourismProjectTravelNotesController.add;
    httpCall(params).then(res => {
      ElMessage.success('编辑成功');
      props.dialog?.submit();
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
  });
};
const formInit = () => {
  loadTourTourismProjectTravelNotesData().then(res => {
    isHotspotWidget.onVisibleChange(true).catch(e => {console.error(e)});
    let homeHotPictureDownloadParams = {
      id: formData.TourTourismProjectTravelNotes.id,
      fieldName: 'homeHotPicture',
      asImage: true
    };
    homeHotPictureWidgetFileList.value = parseUploadData(formData.TourTourismProjectTravelNotes.homeHotPicture, homeHotPictureDownloadParams);
    let contactCodeDownloadParams = {
      id: formData.TourTourismProjectTravelNotes.id,
      fieldName: 'contactCode',
      asImage: true
    };
    contactCodeWidgetFileList.value = parseUploadData(formData.TourTourismProjectTravelNotes.contactCode, contactCodeDownloadParams);
    let travelNotesBannerDownloadParams = {
      id: formData.TourTourismProjectTravelNotes.id,
      fieldName: 'travelNotesBanner',
      asImage: true
    };
    travelNotesBannerWidgetFileList.value = parseUploadData(formData.TourTourismProjectTravelNotes.travelNotesBanner, travelNotesBannerDownloadParams);
    enableWidget.onVisibleChange(true).catch(e => {console.error(e)});
    belongTabWidget.onVisibleChange(true).then(res => {
      // TODO: 获取级联选中路径
      belongTabPath.value = findTreeNodePath(res, formData.TourTourismProjectTravelNotes.belongTab);
    }).catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
    let tourismUrlDownloadParams = {
      id: formData.TourTourismProjectTravelNotes.id,
      fieldName: 'tourismUrl',
      asImage: true
    };
    tourismUrlWidgetFileList.value = parseUploadData(formData.TourTourismProjectTravelNotes.tourismUrl, tourismUrlDownloadParams);
    let fileUrlDownloadParams = {
      id: formData.TourTourismProjectTravelNotes.tourTourismTravelNotesFile.id,
      fieldName: 'fileUrl',
      asImage: true
    };
    fileUrlWidgetFileList.value = parseUploadData(formData.TourTourismProjectTravelNotes.tourTourismTravelNotesFile.fileUrl, fileUrlDownloadParams);
    if (isEdit.value) refreshFormEditTourTourismTravelNotes();
  }).catch(e => {
    // TODO: 异常处理
    console.error(e);
  });
};

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