<!-- 路线导航管理列表 -->
<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" id="search_div" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="70px">
            <el-form-item label="线路标题" prop="">
              <el-input v-model="queryParams.title" class="inputWidth" placeholder="请输入线路标题" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="发布状态" prop="">
              <el-select v-model="queryParams.status" class="inputWidth" placeholder="请选择发布状态" clearable>
                <el-option v-for="dict in note_publish_list" :key="dict.value" :label="dict.label" :value="dict.value" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
              <el-button v-hasPermi="['system:Route:add']" type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-table v-loading="loading" :height="autoTableHeight" :data="RouteList" border @selection-change="handleSelectionChange">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="线路标题" align="center" prop="title" />
      <el-table-column label="线路封面" align="center" prop="" />
      <el-table-column label="线路标签" align="center" prop="tagId">
        <template #default="scope">
          <span>{{ formatTag(scope.row.tagId) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="行程天数" align="center" prop="routeDays">
        <template #default="scope">
          <div>{{ scope.row.routeDays }}天</div>
        </template>
      </el-table-column>
      <el-table-column label="行程里数" align="center" prop="routeMileage">
        <template #default="scope">
          <div>{{ scope.row.routeMileage }}公里</div>
        </template>
      </el-table-column>
      <el-table-column label="行驶时长" align="center" prop="routeDriveHour">
        <template #default="scope">
          <div>{{ scope.row.routeDriveHour }}小时</div>
        </template>
      </el-table-column>
      <el-table-column label="最佳时间" align="center" prop="appropriateTime">
        <template #default="scope">
          <div>{{ scope.row.appropriateTime }}月</div>
        </template>
      </el-table-column>
      <el-table-column label="行程" align="center" prop="">
        <template #default="scope">
          <el-button link type="primary" @click="linkontent(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
      <el-table-column label="加入行程数" align="center" prop="joinRouteCount" />
      <el-table-column label="喜欢数" align="center" prop="routeAgreeCount" />
      <el-table-column label="线路评论数" align="center" prop="routeCommentCount" />
      <el-table-column label="发布状态" align="center" prop="status">
        <template #default="scope">
          <el-tag v-if="scope.row.status == 0" type="info">未发布</el-tag>
          <el-tag v-if="scope.row.status == 1" type="success">审核中</el-tag>
          <el-tag v-if="scope.row.status == 2" type="primary">已发布</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-tooltip content="编辑" placement="top">
            <el-button v-hasPermi="['system:Route:edit']" link type="primary" icon="Edit" @click="handleUpdate(scope.row)"></el-button>
          </el-tooltip>
          <el-tooltip content="删除" placement="top">
            <el-button v-hasPermi="['system:Route:remove']" link type="primary" icon="Delete" @click="handleDelete(scope.row)"></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      id="table_page"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      :total="total"
      @pagination="getList"
    />
    <!-- 添加或修改景点、租赁管理对话框 -->
    <el-dialog v-model="dialog.visible" :title="dialog.title" width="60%" append-to-body>
      <el-form ref="RouteFormRef" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="线路标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入路线标题" style="width: 400px" />
        </el-form-item>
        <!--        <el-form-item label="路线封面" prop="attribute">-->
        <el-form-item label="路线封面">
          <!--          <imageUpload :model-value="form.img" :file-size="20" />-->
        </el-form-item>
        <el-form-item label="路线标签" prop="tagvalue">
          <!-- <el-input v-model="form.province" placeholder="请输入省code" /> -->
          <el-select v-model="tagvalue" filterable placeholder="请输入要搜索的标签" style="width: 400px" multiple>
            <el-option v-for="item in sys_user_tagOptions" :key="item.id" :label="item.title" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="涉及的行政区域" prop="treevalue">
          <el-cascader v-model="treevalue" :options="regiontree" :props="props" clearable placeholder="请选择涉及的行政区域" style="width: 400px" />
        </el-form-item>
        <div style="display: flex">
          <el-form-item label="行程天数" prop="routeDays">
            <el-input v-model="form.routeDays" placeholder="请输入" style="width: 100px" />天
          </el-form-item>
          <el-form-item label="行程里数" prop="routeMileage">
            <el-input v-model="form.routeMileage" placeholder="请输入" style="width: 100px" />公里
          </el-form-item>
          <el-form-item label="行驶时长" prop="routeDriveHour">
            <el-input v-model="form.routeDriveHour" placeholder="请输入" style="width: 100px" />小时
          </el-form-item>
          <el-form-item label="最佳时间" prop="appropriateTime">
            <el-input v-model="form.appropriateTime" placeholder="请输入" style="width: 100px" />月
          </el-form-item>
        </div>
        <el-form-item label="添加行程">
          <el-button type="primary" :icon="Plus" @click="add">添加</el-button>
        </el-form-item>
        <!--        展示数据-->
        <div v-for="(item, index) in bookrouteDetailsList" :key="item.id">
          <div class="routeDetailsListitem">
            <div style="display: flex; justify-content: space-between">
              <div class="title">DAY{{ index + 1 }}·{{ item.title }}</div>
              <div>
                <el-button :loading="buttonLoading" type="text" @click="editlistitem(item, index)">编 辑</el-button>
                <el-button type="text" @click="dellistitem(index)">删 除</el-button>
              </div>
            </div>
            <div>{{ item.description }}</div>
            <div v-for="(er, index_r) in item.lowerList">
              <div style="font-weight: 600">景点{{ index_r + 1 }} {{ er.articleName }}</div>
              <div>建议游玩{{ er.routeHours }}小时 | {{ er.address }}</div>
              <div>{{ er.recommend }}</div>
              <div>{{ er.addressDes }}</div>
              <div>{{ er.guide }}</div>
            </div>

            <div class="hotellistcalss">
              <div v-for="rr in item.hotelVoList" class="hotelitem">
                <div class="title">{{ rr.name }}</div>
                <div class="address">{{ rr.address }}</div>
                <div class="address">{{ rr.number }}</div>
              </div>
            </div>
          </div>
        </div>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="yulanform">预 览</el-button>
          <el-button :loading="buttonLoading" type="primary" @click="submitForm('0')">存 草 稿</el-button>
          <el-button :loading="buttonLoading" type="primary" @click="submitForm('1')">提 交</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 添加或修改行程 -->
    <el-dialog v-model="addressdialog.visible" :title="addressdialog.title" width="50%" append-to-body>
      <el-form ref="RouteFormRef" :model="routeDetailsList" :rules="rules" label-width="120px">
        <el-form-item label="标题">
          <el-input v-model="routeDetailsList.title" placeholder="请输入标题" style="width: 500px" />
        </el-form-item>
        <el-form-item label="描述">
          <el-input v-model="routeDetailsList.description" placeholder="请输入描述" style="width: 500px" autosize type="textarea" />
        </el-form-item>
        <el-form-item label="添加地点">
          <el-button type="primary" @click="addjingdain">添加景点</el-button>
        </el-form-item>
        <div v-for="(item, index) in routeDetailsList.lowerList" class="articlelist">
          <CircleClose v-if="index != 0" style="width: 2em; height: 2em; position: relative; left: 98%" @click="delLowerList(index)" />
          <el-form-item label="添加地点">
            <el-select v-model="item.articleId" placeholder="请选择标记地点" size="large" style="width: 500px">
              <el-option v-for="item in sys_user_contentOptions" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="建议游玩时长">
            <el-input v-model="item.routeHours" placeholder="请输入建议游玩时长" style="width: 500px" />
          </el-form-item>
          <el-form-item label="推荐语">
            <el-input v-model="item.recommend" placeholder="请输入推荐语" style="width: 500px" />
          </el-form-item>
          <el-form-item label="地点描述">
            <el-input v-model="item.addressDes" placeholder="请输入地点描述" style="width: 500px" autosize type="textarea" />
          </el-form-item>
          <el-form-item label="避坑指南">
            <el-input v-model="item.guide" placeholder="请输入避坑指南" style="width: 500px" autosize type="textarea" />
          </el-form-item>
        </div>

        <el-form-item label="添加住宿攻略">
          <el-select v-model="hotelallvalue" placeholder="请选择住宿攻略" size="large" style="width: 500px" multiple>
            <el-option v-for="item in sys_user_hotelall" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="savereginer">提 交</el-button>
          <el-button @click="savecancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <!--    预览-->
    <el-dialog v-model="yulandialog.visible" :title="yulandialog.title" width="60%" append-to-body>
      <el-form ref="RouteFormRef" :model="form" :rules="rules" label-width="120px">
        <div>{{ form.title }}</div>
        <!--        <el-form-item label="路线封面" prop="attribute">-->
        <div>{{ formatTag(tagvalue) }}</div>
        <div>{{ addressdata(form.region) }}</div>
        <!--        <el-form-item label="涉及的行政区域" prop="treevalue">-->
        <!--          <el-cascader v-model="treevalue" :options="regiontree" :props="props" clearable placeholder="请选择涉及的行政区域" style="width: 400px" />-->
        <!--        </el-form-item>-->
        <div style="display: flex">
          <div>行程天数:{{ form.routeDays }}天</div>
          <div>行程里数:{{ form.routeMileage }}公里</div>
          <div>行驶时长:{{ form.routeDriveHour }}小时</div>
          <div>最佳时间:{{ form.appropriateTime }}月</div>
        </div>
        <div>行程：</div>
        <!--        展示数据-->
        <div v-for="(item, index) in bookrouteDetailsList" :key="item.id">
          <div class="routeDetailsListitem">
            <div style="display: flex; justify-content: space-between">
              <div class="title">DAY{{ index + 1 }}·{{ item.title }}</div>
            </div>
            <div>{{ item.description }}</div>
            <div v-for="(rr, index) in item.lowerList" :key="item.id">
              <div style="font-weight: 600">景点 {{ index + 1 }} &nbsp;&nbsp;&nbsp;{{ rr.articleName }}</div>
              <div>建议游玩{{ rr.routeHours }}小时 | {{ rr.address }}</div>
              <div>{{ rr.recommend }}</div>
              <div>{{ rr.addressDes }}</div>
              <div>{{ rr.guide }}</div>
            </div>

            <div class="hotellistcalss">
              <div v-for="rr in item.hotelVoList" class="hotelitem">
                <div class="title">{{ rr.name }}</div>
                <div class="address">{{ rr.address }}</div>
                <div class="address">{{ rr.number }}</div>
              </div>
            </div>
          </div>
        </div>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="yulanquxiao">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Route" lang="ts">
import { listRoute, getRoute, delRoute, addRoute, updateRoute, getRegionTree, hotelall } from '@/api/manage/route';
import { RouteVO, RouteQuery, RouteForm } from '@/api/manage/route/types';
import { Plus } from '@element-plus/icons-vue';
import { contentall, tagall } from '@/api/manage/notebook';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const autoTableHeight = ref<number>(750);
const RouteList = ref<RouteVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const sys_user_tagOptions = ref([]); //标签库
const sys_user_contentOptions = ref([]); //地点
const sys_user_hotelall = ref([]); //地点
const value = ref('');
const tagvalue = ref('');
const treevalue = ref('');
const hotelallvalue = ref('');

const note_publish_list = ref([
  { label: '已发布', value: 2 },
  { label: '审核中', value: 1 },
  { label: '未发布', value: 0 }
]);
const regiontree = ref([]);
const props = { multiple: true, value: 'id' };
const queryFormRef = ref<ElFormInstance>();
const RouteFormRef = ref<ElFormInstance>();
const jingdianList = ref([
  {
    articleId: '',
    routeHours: '',
    recommend: '',
    addressDes: '',
    guide: ''
  }
]);
const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});
const typeindex = ref('');
const addressdialog = reactive<DialogOption>({
  visible: false,
  title: ''
});
const yulandialog = reactive<DialogOption>({
  visible: false,
  title: '预览'
});
const initFormData: RouteForm = {
  id: undefined,
  type: undefined,
  secondType: undefined,
  isOpen: undefined,
  attribute: undefined,
  status: undefined,
  province: undefined,
  city: undefined,
  remark: undefined,
  memberLevel: undefined,
  tagId: undefined,
  recommend: undefined,
  intro: undefined,
  address: undefined,
  longitude: undefined,
  latitude: undefined,
  orderNum: undefined,
  level: undefined
};
const data = reactive<PageData<RouteForm, RouteQuery>>({
  form: { ...initFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    title: undefined,
    status: undefined,
    isOpen: undefined,
    attribute: undefined,
    province: undefined,
    city: undefined,
    memberLevel: undefined,
    tagId: undefined,
    recommend: undefined,
    intro: undefined,
    address: undefined,
    longitude: undefined,
    latitude: undefined,
    orderNum: undefined,
    level: undefined,
    params: {}
  },
  rules: {
    id: [{ required: true, message: '景点ID/租赁ID/游艇ID不能为空', trigger: 'blur' }],
    type: [{ required: true, message: '类别 景点-0、租赁-1 游艇-2不能为空', trigger: 'change' }],
    secondType: [{ required: true, message: '二级类别不能为空', trigger: 'change' }],
    isOpen: [{ required: true, message: '开放/营业不能为空', trigger: 'blur' }],
    attribute: [{ required: true, message: '景点属性/商家属性不能为空', trigger: 'blur' }],
    status: [{ required: true, message: '状态 0-未发布 1-审核中 2-发布不能为空', trigger: 'change' }],
    province: [{ required: true, message: '省code不能为空', trigger: 'blur' }],
    city: [{ required: true, message: '市/区不能为空', trigger: 'blur' }],
    remark: [{ required: true, message: '个人简介不能为空', trigger: 'blur' }],
    memberLevel: [{ required: true, message: '会员等级不能为空', trigger: 'blur' }],
    // tagId: [{ required: true, message: '标签不能为空', trigger: 'blur' }],
    appropriateTime: [{ required: true, message: '最佳时间', trigger: 'blur' }],
    routeDriveHour: [{ required: true, message: '行驶时长', trigger: 'blur' }],
    routeMileage: [{ required: true, message: '行程里数', trigger: 'blur' }],
    routeDays: [{ required: true, message: '行程天数', trigger: 'blur' }],
    region: [{ required: true, message: '涉及的行政区', trigger: 'blur' }],
    tagId: [{ required: true, message: '标签不能为空', trigger: 'blur' }],
    title: [{ required: true, message: '线路标题', trigger: 'blur' }]
  }
});

const { queryParams, form, rules } = toRefs(data);
const routeDetailsList = ref({
  title: '',
  description: '',
  routeHours: '',
  recommend: '',
  articleId: '',
  addressDes: '',
  guide: '',
  hotelIds: '',
  lowerList: [
    {
      articleId: '',
      routeHours: '',
      recommend: '',
      addressDes: '',
      guide: ''
    }
  ]
});
const bookrouteDetailsList = ref([]);
const options = [
  {
    value: 'Option1',
    label: 'Option1'
  },
  {
    value: 'Option2',
    label: 'Option2'
  },
  {
    value: 'Option3',
    label: 'Option3'
  },
  {
    value: 'Option4',
    label: 'Option4'
  },
  {
    value: 'Option5',
    label: 'Option5'
  }
];
onMounted(() => {
  getList();
  getRegionTreelist();
  getContent();
  getTag();
  gethotelall();
  nextTick(() => {
    autoTableHeight.value = proxy?.autoTableHeight();
  });
  window.onresize = () => {
    autoTableHeight.value = proxy?.autoTableHeight();
  };
});
/** 查询景点、租赁管理列表 */
const getList = async () => {
  loading.value = true;
  const res = await listRoute(queryParams.value).finally(() => (loading.value = false));
  RouteList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
};

/** 表单重置 */
const reset = () => {
  form.value = { ...initFormData };
  RouteFormRef.value?.resetFields();
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  queryParams.value.title = '';
  queryParams.value.status = '';

  handleQuery();
};

/** 多选框选中数据 */
const handleSelectionChange = (selection: RouteVO[]) => {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
};

/** 新增按钮操作 */
const handleAdd = () => {
  reset();
  dialog.visible = true;
  dialog.title = '添加路线';
  bookrouteDetailsList.value = [];
  tagvalue.value = [];
  treevalue.value = [];
};
/**
 * 标签格式化
 */
const formatTag = (tagId: string | null) => {
  let tagString = '';
  for (let i = 0; i < sys_user_tagOptions.value.length; i++) {
    const element = sys_user_tagOptions.value[i];
    if (tagId?.includes(element.id)) {
      tagString += ',' + element.title;
    }
  }
  return tagString.substring(1);
};
/** 修改按钮操作 */
const handleUpdate = async (row?: RouteVO) => {
  reset();
  // tagvalue.value=[]
  const _id = row?.id || ids.value[0];
  const res = await getRoute(_id);
  Object.assign(form.value, res.data);
  dialog.visible = true;
  bookrouteDetailsList.value = form.value.routeDetailsList;
  tagvalue.value = form.value.tagId.split(',');
  console.log(tagvalue.value);
  const arr = form.value.region.split(',');
  // 使用循环将数组中的元素转换为整数
  const result = [];
  console.log(arr.length);
  if (arr.length > 1) {
    for (let i = 0; i < arr.length; i += 2) {
      result.push([parseInt(arr[i]), parseInt(arr[i + 1])]);
    }
    treevalue.value = result;
  } else {
    treevalue.value = form.value.region.split(',').map(Number);
  }
  console.log(result, arr);
  dialog.title = '修改路线';
};

/** 提交按钮 */
const submitForm = (type) => {
  form.value.tagId = tagvalue.value.join(',');
  console.log(treevalue.value, '22222');
  form.value.region = treevalue.value.join(',');
  form.value.status = Number(type);
  form.value.routeDetailsList = bookrouteDetailsList.value;
  console.log(form.value, bookrouteDetailsList.value);
  // return;
  RouteFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      if (form.value.id) {
        await updateRoute(form.value).finally(() => (buttonLoading.value = false));
      } else {
        await addRoute(form.value).finally(() => (buttonLoading.value = false));
      }
      proxy?.$modal.msgSuccess('操作成功');
      dialog.visible = false;
      await getList();
    }
  });
};

/** 删除按钮操作 */
const handleDelete = async (row?: RouteVO) => {
  const _ids = row?.id || ids.value;
  const idstitle = row?.title;
  await proxy?.$modal.confirm('是否确认删除线路标题为"' + idstitle + '"的数据项？').finally(() => (loading.value = false));
  await delRoute(_ids);
  proxy?.$modal.msgSuccess('删除成功');
  await getList();
};
const getRegionTreelist = async () => {
  loading.value = true;
  const res = await getRegionTree({ regionParentCode: '460000' }).finally(() => (loading.value = false));
  console.log(res, 'ddddd');
  regiontree.value = res.data;
  // total.value = res.total;
  loading.value = false;
};
/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download(
    'system/Route/export',
    {
      ...queryParams.value
    },
    `Route_${new Date().getTime()}.xlsx`
  );
};
const getContent = async () => {
  const res = await contentall({ status: 2 });
  sys_user_contentOptions.value = res; //地点
};
const getTag = async () => {
  const res = await tagall();
  sys_user_tagOptions.value = res; //标签库
};
const gethotelall = async () => {
  const res = await hotelall({ status: 1 });
  sys_user_hotelall.value = res;
};

//添加行程
const add = () => {
  typeindex.value = undefined;
  routeDetailsList.value = {
    title: '',
    description: '',
    routeHours: '',
    recommend: '',
    articleId: '',
    addressDes: '',
    guide: '',
    hotelIds: '',
    lowerList: [
      {
        articleId: '',
        routeHours: '',
        recommend: '',
        addressDes: '',
        guide: ''
      }
    ]
  };
  hotelallvalue.value = [];
  addressdialog.visible = true;
  addressdialog.title = `添加DAY${bookrouteDetailsList.value.length + 1}行程`;
};
//编辑单个行程
const editlistitem = (item, index) => {
  typeindex.value = index;
  routeDetailsList.value = item;
  addressdialog.visible = true;
  addressdialog.title = `编辑DAY${index + 1}行程`;
  console.log(item);
  let arr = item.hotelVoList;
  const extractedIds = arr.map((item) => item.id);

  hotelallvalue.value = extractedIds;
};
//删除单个行程
const dellistitem = (index) => {
  bookrouteDetailsList.value.splice(index, 1);
};
const savecancel = () => {
  addressdialog.visible = false;
};
//预览
const yulanform = () => {
  addressdata(form.value.region);
  yulandialog.visible = true;
};
//取消预览
const yulanquxiao = () => {
  yulandialog.visible = false;
};
//查看详情
const linkontent = async (row?: RouteVO) => {
  // reset();
  // tagvalue.value=[]
  const _id = row?.id || ids.value[0];
  const res = await getRoute(_id);
  Object.assign(form.value, res.data);
  yulandialog.visible = true;
  bookrouteDetailsList.value = form.value.routeDetailsList;
  tagvalue.value = form.value.tagId.split(',').map(Number);
  const arr = form.value.region.split(',');
  // 使用循环将数组中的元素转换为整数
  const result = [];
  console.log(arr.length);
  if (arr.length > 1) {
    for (let i = 0; i < arr.length; i += 2) {
      result.push([parseInt(arr[i]), parseInt(arr[i + 1])]);
    }
    treevalue.value = result;
  } else {
    treevalue.value = form.value.region.split(',').map(Number);
  }
  console.log(result, arr);
};

//新增编辑行程
const savereginer = () => {
  if (typeindex.value == undefined) {
    console.log('新增');
    addressdialog.visible = false;
    routeDetailsList.value.hotelIds = hotelallvalue.value.join(',');
    routeDetailsList.value.hotelVoList = hoteldata(hotelallvalue.value);
    // form.value.routeDetailsList.push(routeDetailsList.value);
    bookrouteDetailsList.value.push(routeDetailsList.value);
  } else {
    console.log('修改');
    routeDetailsList.value.hotelIds = hotelallvalue.value.join(',');
    routeDetailsList.value.hotelVoList = hoteldata(hotelallvalue.value);
    const index = bookrouteDetailsList.value.findIndex((item) => item.id === routeDetailsList.value.id);
    if (index !== -1) {
      bookrouteDetailsList.value.splice(index, 1, routeDetailsList.value);
    }
    addressdialog.visible = false;
  }
};
//住宿信息
const hoteldata = (ids: string | null) => {
  let hotelarray = [];
  for (let i = 0; i < sys_user_hotelall.value.length; i++) {
    const item = sys_user_hotelall.value[i];
    if (ids?.includes(item.id)) {
      hotelarray.push(item);
    }
  }
  return hotelarray;
};
//行政区
const addressdata = (ids: string | null) => {
  let addressarray = '';
  for (let i = 0; i < regiontree.value.length; i++) {
    const item = regiontree.value[i];
    if (ids?.includes(item.id)) {
      // addressarray.push(item);
      addressarray += ',' + item.label;
      if (item.children) {
        for (let j = 0; j < item.children.length; j++) {
          const arr = item.children[j];
          console.log(arr, 'arr');

          if (ids?.includes(arr.id)) {
            // addressarray.push(arr);
            console.log(arr, 'arr');
            addressarray += '-' + arr.label;
          }
        }
      }
    }
  }
  console.log(addressarray, 'qqqq');
  return addressarray;
};
//添加景点
const addjingdain = () => {
  routeDetailsList.value.lowerList.push({
    articleId: '',
    routeHours: '',
    recommend: '',
    addressDes: '',
    guide: ''
  });
};
//删除景点
const delLowerList = (index) => {
  // bookrouteDetailsList.lowerList.splice(index, 1);
  routeDetailsList.value.lowerList.splice(index, 1);
};
</script>
<style lang="scss" scoped>
.el-card :deep(.el-card__body) {
  padding-bottom: 0px !important;
}

#table_page {
  height: 50px !important;
  margin-top: 10px !important;
  padding-bottom: 10px !important;
}
.routeDetailsListitem {
  width: 85%;
  margin: 10px auto;
  border-radius: 20px;
  background-color: #f2f2f2;
  padding: 20px;
  line-height: 22px;
  .title {
    font-weight: 600;
    font-size: 16px;
  }
}
.hotellistcalss {
  display: flex;
  margin-top: 20px;
  .hotelitem {
    background-color: #fff;
    padding: 20px;
    border-radius: 10px;
    line-height: 25px;
    margin-right: 20px;
    width: 30%;
    .title {
      font-weight: 600;
      font-size: 14px;
      color: #000;
    }
    .address {
      font-size: 12px;
      color: #4a5663;
    }
  }
}
.articlelist {
  width: 90%;
  margin: 20px auto;
  padding: 20px;
  border-radius: 20px;
  background-color: #f2f2f2;
}
</style>
