<template>
  <div class="dialog-box" style="position: relative">
    <el-scrollbar class="custom-scroll content-box">
      <el-form
        ref="viewTravelNotesInfoRef"
        :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="TourismProjectTravelNotesWrite.projectTitle">
              <el-input
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.projectTitle"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
                :disabled="true"
                :readonly="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出发时间" prop="TourismProjectTravelNotesWrite.departureTime">
              <el-date-picker
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.departureTime"
                type="date"
                placeholder=""
                :clearable="true"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出行天数" prop="TourismProjectTravelNotesWrite.countTimes">
              <el-input
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.countTimes"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
                :disabled="true"
                :readonly="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="人物关系" prop="TourismProjectTravelNotesWrite.role">
              <el-input
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.role"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
                :disabled="true"
                :readonly="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="推荐指数" prop="TourismProjectTravelNotesWrite.recommendationRate">
              <el-input-number
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.recommendationRate"
                placeholder=""
                :clearable="true"
                :step="1"
                :controls="true"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="人均费用" prop="TourismProjectTravelNotesWrite.averageCost">
              <el-input
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.averageCost"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                :disabled="true"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="目的地" prop="TourismProjectTravelNotesWrite.endPlace">
              <el-cascader
                class="input-item"
                v-model="endPlacePath"
                :options="endPlaceWidgetDropdownList"
                placeholder=""
                :clearable="true"
                :filterable="true"
                :show-all-levels="false"
                :props="{ value: 'id', label: 'name', children: 'children', checkStrictly: true }"
                :disabled="true"
                @change="onEndPlaceValueChange"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="项目展示图片" prop="TourismProjectTravelNotesWrite.tourismUrl">
              <div style="width: 50%">
                <img
                  :src="formData.TourismProjectTravelNotesWrite.tourismUrl"
                  style="width: 100%"
                />
              </div>
              <!-- <img :src="" alt="" srcset=""> -->
              <!-- <el-upload
                class="upload-image-item"
                name="uploadFile"
                :headers="getUploadHeaders"
                :action="getUploadActionUrl('/admin/app/tourismProjectTravelNotesWrite/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="24">
            <el-form-item
              label="发布游记的banner图"
              prop="TourismProjectTravelNotesWrite.travelNotesBanner"
            >
              <div style="width: 50%">
                <img
                  :src="formData.TourismProjectTravelNotesWrite.travelNotesBanner"
                  style="width: 100%"
                  alt=""
                  srcset=""
                />
              </div>

              <!-- <el-upload
                class="upload-image-item"
                name="uploadFile"
                :headers="getUploadHeaders"
                :action="getUploadActionUrl('/admin/app/tourismProjectTravelNotesWrite/upload')"
                :data="{ fieldName: 'travelNotesBanner', asImage: true }"
                :on-success="onTravelNotesBannerUrlUploadSuccess"
                :on-remove="onTravelNotesBannerUrlRemoveFile"
                :on-error="onUploadError"
                :show-file-list="false"
              >
                <div
                  v-if="
                    travelNotesBannerUrlWidgetFileList &&
                    travelNotesBannerUrlWidgetFileList[0] != null
                  "
                  style="position: relative"
                >
                  <img class="upload-image-show" :src="travelNotesBannerUrlWidgetFileList[0].url" />
                  <div
                    class="upload-img-del el-icon-close"
                    @click.stop="onTravelNotesBannerUrlRemoveFile(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="TourismProjectTravelNotesWrite.remarks">
              <el-input
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.remarks"
                type="textarea"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
                :disabled="true"
                :readonly="true"
              />
            </el-form-item>
          </el-col>
          <el-form-item label="详细内容">
            <div>
              <template v-for="item in formData.TourismProjectTravelNotesWrite.travelNotesContent">
                <template v-if="item.type === 'sectionTitle'">
                  <div style="font-size: 14px; color: #333">
                    {{ item.content }}
                  </div>
                </template>
                <template v-else-if="item.type === 'sectionContent'">
                  <div style="font-size: 14px; color: #444">
                    {{ item.content }}
                  </div>
                </template>
                <template v-else-if="item.type === 'image'">
                  <img :src="item.content" style="width: 100%" alt="" srcset="" />
                </template>
              </template>
            </div>
          </el-form-item>

          <!-- <el-col :span="12">
            <el-form-item label="上下架状态" prop="TourismProjectTravelNotesWrite.unmountState">
              <el-select
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.unmountState"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="unmountStateWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in unmountStateWidgetDropdownList"
                  :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="TourismProjectTravelNotesWrite.autoAuditStatus"
            >
              <el-select
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.autoAuditStatus"
                placeholder=""
                :clearable="true"
                :filterable="true"
                :disabled="true"
                @visible-change="autoAuditStatusWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in autoAuditStatusWidgetDropdownList"
                  :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="TourismProjectTravelNotesWrite.autoRejectReason"
            >
              <el-input
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.autoRejectReason"
                type="textarea"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
                :disabled="true"
                :readonly="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="审核状态" prop="TourismProjectTravelNotesWrite.state">
              <el-select
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.state"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="stateWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in stateWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-show="formData.TourismProjectTravelNotesWrite.state == 2">
            <el-form-item label="审核不通过的原因" prop="TourismProjectTravelNotesWrite.reason">
              <el-input
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.reason"
                type="textarea"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-show="formData.TourismProjectTravelNotesWrite.state == 3">
            <el-form-item label="标签" prop="TourismProjectTravelNotesWrite.noteLabel">
              <el-input
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.noteLabel"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-show="formData.TourismProjectTravelNotesWrite.state == 3">
            <el-form-item label="是否热点" prop="TourismProjectTravelNotesWrite.isHotspot">
              <el-select
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.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" v-show="formData.TourismProjectTravelNotesWrite.state == 3">
            <el-form-item label="点赞数" prop="TourismProjectTravelNotesWrite.likeCount">
              <el-input
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.likeCount"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-show="formData.TourismProjectTravelNotesWrite.state == 3">
            <el-form-item label="浏览量" prop="TourismProjectTravelNotesWrite.pageViewCount">
              <el-input
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.pageViewCount"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-show="formData.TourismProjectTravelNotesWrite.state == 3">
            <el-form-item label="热度值" prop="TourismProjectTravelNotesWrite.hotValue">
              <el-input
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.hotValue"
                type="text"
                placeholder=""
                :clearable="true"
                :show-word-limit="false"
                maxlength=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-show="formData.TourismProjectTravelNotesWrite.state == 3">
            <el-form-item label="是否原创" prop="TourismProjectTravelNotesWrite.isOriginal">
              <el-select
                class="input-item"
                v-model="formData.TourismProjectTravelNotesWrite.isOriginal"
                placeholder=""
                :clearable="true"
                :filterable="true"
                @visible-change="isOriginalWidget.onVisibleChange"
              >
                <el-option
                  v-for="item in isOriginalWidgetDropdownList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </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="onSaveClick()"
        >保存</el-button
      >
    </el-row>
  </div>
</template>

<script lang="ts">
export default {
  name: 'viewTravelNotesInfo',
};
</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,
  stringCase,
} from '@/common/utils';
import { TourismTravelNotesContentWriteData } from '@/api/generated/tourismTravelNotesContentWriteController';
import { TourismProjectTravelNotesWriteData } from '@/api/generated/tourismProjectTravelNotesWriteController';
import {
  TourismTravelNotesContentWriteController,
  TourismProjectTravelNotesWriteController,
} 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 viewTravelNotesInfoRef = ref();
// 表单数据定义
type ViewTravelNotesInfoData = {
  TourismProjectTravelNotesWrite: TourismProjectTravelNotesWriteData;
};
// 表单数据
const formData = reactive<ViewTravelNotesInfoData>({
  TourismProjectTravelNotesWrite: {
    // 主键id
    id: undefined,
    // 项目标题
    projectTitle: undefined,
    // 出发时间
    departureTime: undefined,
    // 总天数
    countTimes: undefined,
    // 人物关系
    role: undefined,
    // 推荐指数
    recommendationRate: undefined,
    // 人均费用
    averageCost: undefined,
    // 审核状态(0,草稿;1,待审核;2,审核通过3,审核不通过;)
    state: undefined,
    // 审核不通过的原因
    reason: undefined,
    // 创建用户
    createUserId: undefined,
    // 发布游记的banner图
    travelNotesBanner: undefined,
    // 创建时间
    createTime: undefined,
    // 更新用户
    updateUserId: undefined,
    // 更新时间
    updateTime: undefined,
    // 删除标记(1: 正常 -1: 已删除)
    dataState: undefined,
    // 游记内容中的图片
    tourismTavelNotesUrl: undefined,
    // 上下架状态(0,下架;1,上架)
    unmountState: undefined,
    // 项目展示图片
    tourismUrl: undefined,
    // 项目简述
    remarks: undefined,
    // 是否热点，0非热点，1热点
    isHotspot: undefined,
    // 标签
    noteLabel: undefined,
    // 点赞数
    likeCount: undefined,
    // 浏览量
    pageViewCount: undefined,
    // 热度值
    hotValue: undefined,
    // 是否原创(0:非原创;1:原创)
    isOriginal: undefined,
    // 自动审核结果1：通过，2未通过
    autoAuditStatus: undefined,
    // 自动审核未通过原因
    autoRejectReason: undefined,
    // 目的地
    endPlace: undefined,
    // 发布游记的文本框数据
    tourismTravelNotesContentWriteList: [],
  },
});
// 表单验证规则
const rules = reactive({
  // 'TourismProjectTravelNotesWrite.pageViewCount': [
  //   { required: true, message: '请输入浏览量', trigger: 'blur' },
  // ],
  'TourismProjectTravelNotesWrite.state': [
    { required: true, message: '请输入审核状态', trigger: 'blur' },
  ],
  // 'TourismProjectTravelNotesWrite.averageCost': [],
  // 'TourismProjectTravelNotesWrite.reason': [
  //   {
  //     message: '请输入审核不通过的原因',
  //   },
  // ],
  // 'TourismProjectTravelNotesWrite.unmountState': [
  //   { required: true, message: '请输入上下架状态', trigger: 'blur' },
  // ],
  // 'TourismProjectTravelNotesWrite.countTimes': [],
  // 'TourismProjectTravelNotesWrite.departureTime': [],
  // 'TourismProjectTravelNotesWrite.endPlace': [],
  // 'TourismProjectTravelNotesWrite.recommendationRate': [],
  // 'TourismProjectTravelNotesWrite.role': [],
  // 'TourismProjectTravelNotesWrite.projectTitle': [],
  // 'TourismProjectTravelNotesWrite.noteLabel': [
  //   { required: true, message: '请输入标签', trigger: 'blur' },
  // ],
  // 'TourismProjectTravelNotesWrite.remarks': [],
  // 'TourismProjectTravelNotesWrite.tourismUrl': [],
  // 'TourismProjectTravelNotesWrite.travelNotesBanner': [],
  // 'TourismProjectTravelNotesWrite.likeCount': [
  //   { required: true, message: '请输入点赞数', trigger: 'blur' },
  // ],
  // 'TourismProjectTravelNotesWrite.hotValue': [
  //   { required: true, message: '请输入热度值', trigger: 'blur' },
  // ],
  // 'TourismProjectTravelNotesWrite.isHotspot': [
  //   { required: true, message: '请输入是否热点', trigger: 'blur' },
  // ],
  // 'TourismProjectTravelNotesWrite.isOriginal': [
  //   { 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 loadEndPlaceDropdownList = (): Promise<ListData<DictData>> => {
  return new Promise((resolve, reject) => {
    const params = {};
    DictionaryController.dictDirectoryInfo(params)
      .then(res => {
        resolve({
          dataList: res.getList(),
        });
      })
      .catch(e => {
        reject(e);
      });
  });
};
/**
 * 目的地选中值改变
 */
const onEndPlaceValueChange = value => {
  formData.TourismProjectTravelNotesWrite.endPlace = Array.isArray(value)
    ? value[value.length - 1]
    : value;
};
// 目的地配置参数
const endPlaceOptions: DropdownOptions<DictData> = {
  loadData: loadEndPlaceDropdownList,
  isTree: true,
};

// 目的地选中数据
const endPlacePath = ref<Array<string | number>>([]);
// 目的地下拉组件
const endPlaceWidget = useDropdown(endPlaceOptions);
const { dropdownList: endPlaceWidgetDropdownList } = endPlaceWidget;

// 初始化页面数据
const loadTourismProjectTravelNotesWriteData = () => {
  return new Promise<void>((resolve, reject) => {
    if (!isEdit.value) {
      resolve();
      return;
    }
    if (!props.saveOnSubmit && props.rowData != null) {
      formData.TourismProjectTravelNotesWrite = JSON.parse(JSON.stringify(props.rowData));
      resolve();
      return;
    }
    let params: ANY_OBJECT = {
      id: props.id,
    };
    TourismProjectTravelNotesWriteController.view(params)
      .then(res => {
        formData.TourismProjectTravelNotesWrite = { ...res.data };
        resolve();
      })
      .catch(e => {
        reject(e);
      });
  });
};
/**
 * 项目展示图片上传成功
 */
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.TourismProjectTravelNotesWrite.tourismUrl = fileListToJson(
      tourismUrlWidgetFileList.value,
    );
  } else {
    ElMessage.error(response.message);
  }
};
/**
 * 移除项目展示图片
 */
const onTourismUrlRemoveFile = (file: UploadFile | null, fileList: UploadFile[] | null) => {
  tourismUrlWidget.onFileChange(file, fileList);
  formData.TourismProjectTravelNotesWrite.tourismUrl = fileListToJson(
    tourismUrlWidgetFileList.value,
  );
};
// 项目展示图片上传文件组件
const tourismUrlWidget = useUploadWidget(1);
const { fileList: tourismUrlWidgetFileList, maxCount: tourismUrlWidgetMaxCount } = tourismUrlWidget;
/**
 * 发布游记的banner图上传成功
 */
const onTravelNotesBannerUrlUploadSuccess = (
  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);
    travelNotesBannerUrlWidget.onFileChange(file, fileList);
    formData.TourismProjectTravelNotesWrite.travelNotesBanner = fileListToJson(
      travelNotesBannerUrlWidgetFileList.value,
    );
  } else {
    ElMessage.error(response.message);
  }
};
/**
 * 移除发布游记的banner图
 */
const onTravelNotesBannerUrlRemoveFile = (
  file: UploadFile | null,
  fileList: UploadFile[] | null,
) => {
  travelNotesBannerUrlWidget.onFileChange(file, fileList);
  formData.TourismProjectTravelNotesWrite.travelNotesBanner = fileListToJson(
    travelNotesBannerUrlWidgetFileList.value,
  );
};
// 发布游记的banner图上传文件组件
const travelNotesBannerUrlWidget = useUploadWidget(1);
const {
  fileList: travelNotesBannerUrlWidgetFileList,
  maxCount: travelNotesBannerUrlWidgetMaxCount,
} = travelNotesBannerUrlWidget;
/**
 * 自动审核结果下拉数据获取函数
 */
const loadAutoAuditStatusDropdownList = (): Promise<ListData<DictData>> => {
  return Promise.resolve({
    dataList: StaticDict.AudioState.getList(),
  });
};
// 自动审核结果配置参数
const autoAuditStatusOptions: DropdownOptions<DictData> = {
  loadData: loadAutoAuditStatusDropdownList,
  isTree: false,
};
// 自动审核结果下拉组件
const autoAuditStatusWidget = useDropdown(autoAuditStatusOptions);
const { dropdownList: autoAuditStatusWidgetDropdownList } = autoAuditStatusWidget;
/**
 * 审核状态下拉数据获取函数
 */
const loadStateDropdownList = (): Promise<ListData<DictData>> => {
  return Promise.resolve({
    dataList: StaticDict.AuditState.getList(),
  });
};
// 审核状态配置参数
const stateOptions: DropdownOptions<DictData> = {
  loadData: loadStateDropdownList,
  isTree: false,
};
// 审核状态下拉组件
const stateWidget = useDropdown(stateOptions);
const { dropdownList: stateWidgetDropdownList } = stateWidget;
/**
 * 上下架状态下拉数据获取函数
 */
const loadUnmountStateDropdownList = (): Promise<ListData<DictData>> => {
  return Promise.resolve({
    dataList: StaticDict.UnmountState.getList(),
  });
};
// 上下架状态配置参数
const unmountStateOptions: DropdownOptions<DictData> = {
  loadData: loadUnmountStateDropdownList,
  isTree: false,
};
// 上下架状态下拉组件
const unmountStateWidget = useDropdown(unmountStateOptions);
const { dropdownList: unmountStateWidgetDropdownList } = unmountStateWidget;
/**
 * 是否热点下拉数据获取函数
 */
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 loadIsOriginalDropdownList = (): Promise<ListData<DictData>> => {
  return Promise.resolve({
    dataList: StaticDict.IsOriginal.getList(),
  });
};
// 是否原创配置参数
const isOriginalOptions: DropdownOptions<DictData> = {
  loadData: loadIsOriginalDropdownList,
  isTree: false,
};
// 是否原创下拉组件
const isOriginalWidget = useDropdown(isOriginalOptions);
const { dropdownList: isOriginalWidgetDropdownList } = isOriginalWidget;
const onUploadError = () => {
  ElMessage.error('文件上传失败');
};
const onUploadLimit = () => {
  ElMessage.error('已经超出最大上传个数限制');
};
const refreshViewTravelNotesInfo = () => {
  // 刷新段落
};
/**
 * 重置过滤值
 */
const resetViewTravelNotesInfo = () => {
  refreshViewTravelNotesInfo();
};
/**
 * 重置所有过滤值
 */
const resetFilter = () => {
  resetViewTravelNotesInfo();
};
/**
 * 保存
 */
const onSaveClick = () => {
  viewTravelNotesInfoRef.value.validate(valid => {
    if (!valid) return;
    // 级联操作
    if (!props.saveOnSubmit) {
      let retFormData = {
        ...formData.TourismProjectTravelNotesWrite,
      };
      retFormData.endPlaceDictMap = findTreeNode(
        endPlaceWidgetDropdownList,
        retFormData.endPlace,
        'id',
      );
      retFormData.stateDictMap = findItemFromList(stateWidgetDropdownList, retFormData.state, 'id');
      retFormData.unmountStateDictMap = findItemFromList(
        unmountStateWidgetDropdownList,
        retFormData.unmountState,
        'id',
      );
      retFormData.isHotspotDictMap = findItemFromList(
        isHotspotWidgetDropdownList,
        retFormData.isHotspot,
        'id',
      );
      retFormData.isOriginalDictMap = findItemFromList(
        isOriginalWidgetDropdownList,
        retFormData.isOriginal,
        'id',
      );
      props.dialog?.submit(retFormData);
      return;
    }
    let params: ANY_OBJECT = {
      tourismProjectTravelNotesWriteDto: {
        id: formData.TourismProjectTravelNotesWrite.id,
        travelNotesBanner: formData.TourismProjectTravelNotesWrite.travelNotesBanner,
        unmountState: formData.TourismProjectTravelNotesWrite.unmountState,
        isHotspot: formData.TourismProjectTravelNotesWrite.isHotspot,
        noteLabel: formData.TourismProjectTravelNotesWrite.noteLabel,
        likeCount: formData.TourismProjectTravelNotesWrite.likeCount,
        pageViewCount: formData.TourismProjectTravelNotesWrite.pageViewCount,
        hotValue: formData.TourismProjectTravelNotesWrite.hotValue,
        isOriginal: formData.TourismProjectTravelNotesWrite.isOriginal,
        projectTitle: formData.TourismProjectTravelNotesWrite.projectTitle,
        departureTime: formData.TourismProjectTravelNotesWrite.departureTime,
        countTimes: formData.TourismProjectTravelNotesWrite.countTimes,
        role: formData.TourismProjectTravelNotesWrite.role,
        recommendationRate: formData.TourismProjectTravelNotesWrite.recommendationRate,
        averageCost: formData.TourismProjectTravelNotesWrite.averageCost,
        state: formData.TourismProjectTravelNotesWrite.state,
        reason: formData.TourismProjectTravelNotesWrite.reason,
        createUserId: formData.TourismProjectTravelNotesWrite.createUserId,
        createTime: formData.TourismProjectTravelNotesWrite.createTime,
        updateUserId: formData.TourismProjectTravelNotesWrite.updateUserId,
        updateTime: formData.TourismProjectTravelNotesWrite.updateTime,
        tourismTavelNotesUrl: formData.TourismProjectTravelNotesWrite.tourismTavelNotesUrl,
      },
    };

    // let httpCall = isEdit.value
    //   ? TourismProjectTravelNotesWriteController.update
    //   : TourismProjectTravelNotesWriteController.audit;
    TourismProjectTravelNotesWriteController.audit(params)
      .then(res => {
        ElMessage.success('保存成功');
        props.dialog?.submit();
      })
      .catch(e => {
        // TODO: 异常处理
        console.error(e);
      });
  });
};
const formInit = () => {
  loadTourismProjectTravelNotesWriteData()
    .then(res => {
      endPlaceWidget
        .onVisibleChange(true)
        .then(res => {
          console.log(123123123123132132);
          console.log(res);
          // TODO: 获取级联选中路径
          endPlacePath.value = findTreeNodePath(
            res,
            formData.TourismProjectTravelNotesWrite.endPlace,
          );
        })
        .catch(e => {
          // TODO: 异常处理
          console.error(e);
        });
      let tourismUrlDownloadParams = {
        id: formData.TourismProjectTravelNotesWrite.id,
        fieldName: 'tourismUrl',
        asImage: true,
      };
      tourismUrlWidgetFileList.value = parseUploadData(
        formData.TourismProjectTravelNotesWrite.tourismUrl,
        tourismUrlDownloadParams,
      );
      let travelNotesBannerUrlDownloadParams = {
        id: formData.TourismProjectTravelNotesWrite.id,
        fieldName: 'travelNotesBanner',
        asImage: true,
      };
      travelNotesBannerUrlWidgetFileList.value = parseUploadData(
        formData.TourismProjectTravelNotesWrite.travelNotesBanner,
        travelNotesBannerUrlDownloadParams,
      );
      stateWidget.onVisibleChange(true).catch(e => {
        console.error(e);
      });
      unmountStateWidget.onVisibleChange(true).catch(e => {
        console.error(e);
      });
      isHotspotWidget.onVisibleChange(true).catch(e => {
        console.error(e);
      });
      isOriginalWidget.onVisibleChange(true).catch(e => {
        console.error(e);
      });
      if (isEdit.value) refreshViewTravelNotesInfo();
    })
    .catch(e => {
      // TODO: 异常处理
      console.error(e);
    });
};

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