zhengyiming
2 天以前 25708e3f81956c1517f495e3303a6c8d08bb730c
apps/housekeepingMiniApp/src/pages/service/InnerPage.vue
@@ -1,32 +1,112 @@
<template>
  <nut-category :category="data.category" @change="change" class="category-page-inner">
  <ProCategory ref="categoryRef" :category="category" @change="change" class="category-page-inner">
    <nut-category-pane :categoryChild="data.categoryChild" @onChange="onChange">
    </nut-category-pane>
  </nut-category>
  </ProCategory>
</template>
<script setup lang="ts">
import Taro from '@tarojs/taro';
import { useCheckReceiveTasks, useTaskList } from '@12333/hooks';
import { EnumTaskCheckReceiveStatus, EnumTaskCheckReceiveMethod } from '@12333/constants';
import dayjs from 'dayjs';
import { categorydata } from './3x_categoryData';
import { useDictionaryDataSelect, useStandardServiceList } from '@12333/hooks';
import { CategoryCode, EnumStandardServiceReleaseStatus, PositionCodeEnum } from '@12333/constants';
import { setOSSLink } from '@12333/utils';
import { ProCategory } from '@12333/components';
import { useSystemStore } from '@/stores/modules/system';
defineOptions({
  name: 'InnerPage',
});
const router = Taro.useRouter();
const systemStore = useSystemStore();
const { servicePageJobCode } = storeToRefs(systemStore);
const categoryRef = ref();
const data = reactive({
  categoryInfo: categorydata.categoryInfo,
  category: categorydata.categoryInfo.category,
  categoryChild: categorydata.categoryChild,
  category: [],
  categoryChild: [],
});
const { dictionaryDataList: positionList, ensureQueryData } = useDictionaryDataSelect({
  categoryCode: CategoryCode.Position,
  field1: PositionCodeEnum.Housekeeping,
});
const { ensureStandardServiceList, standardServiceListForCategoryMap } = useStandardServiceList({
  params: {
    releaseStatus: EnumStandardServiceReleaseStatus.InProcess,
  },
});
onMounted(async () => {
  try {
    await Promise.all([ensureQueryData(), ensureStandardServiceList()]);
    if (positionList.value.length > 0 && categoryRef.value) {
      initCategory();
      // const first = positionList.value[0];
      // data.categoryChild = convertCategoryChild(
      //   first.value,
      //   standardServiceListForCategoryMap.value[first.value]
      // );
    }
  } catch (error) {}
});
function initCategory() {
  const currentIndex = Math.max(
    positionList.value.findIndex((x) => x.value === servicePageJobCode.value),
    0
  );
  categoryRef.value.getChildList(currentIndex);
  systemStore.setServicePageJobCode('');
}
watch(servicePageJobCode, () => {
  if (servicePageJobCode.value) {
    initCategory();
  }
});
function convertCategoryChild(jobCode: string, list: API.GetStandardServicesQueryResultItem[]) {
  const categoryChild = {
    catId: jobCode,
    catName: '',
    catLevel: 2,
    catType: 1,
    childCateList: [],
  };
  if (list?.length > 0) {
    categoryChild.childCateList = list.map((x) => ({
      backImg: setOSSLink(x.file),
      catId: x.id,
      catName: x.name,
      showPic: true,
      showVideo: false,
    }));
  }
  return [categoryChild];
}
const category = computed(() =>
  positionList.value.map((x) => ({
    ...x,
    catName: x.label,
  }))
);
const change = (index: number) => {
  data.categoryChild = [].concat(data.categoryInfo.category[index + 1].children);
  const current = positionList.value[index];
  data.categoryChild = convertCategoryChild(
    current.value,
    standardServiceListForCategoryMap.value[current.value]
  );
};
const onChange = () => {
  console.log('当前分类数据');
const onChange = (ev) => {
  console.log('当前分类数据', ev);
  Taro.navigateTo({
    url: `${RouterPath.serciceDetail}?id=${ev.catId}`,
  });
};
</script>