zhengyiming
昨天 1d472eb06970c85b0edfb58871956bc2c8d69916
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<template>
  <ProCategory ref="categoryRef" :category="category" @change="change" class="category-page-inner">
    <nut-category-pane :categoryChild="data.categoryChild" @onChange="onChange">
    </nut-category-pane>
  </ProCategory>
</template>
 
<script setup lang="ts">
import Taro from '@tarojs/taro';
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({
  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) => {
  const current = positionList.value[index];
  data.categoryChild = convertCategoryChild(
    current.value,
    standardServiceListForCategoryMap.value[current.value]
  );
};
const onChange = (ev) => {
  console.log('当前分类数据', ev);
  Taro.navigateTo({
    url: `${RouterPath.serciceDetail}?id=${ev.catId}`,
  });
};
</script>
 
<style lang="scss">
@import '@/styles/common.scss';
 
.task-page-wrapper {
  .category-page-inner {
    height: 100%;
    background-color: transparent;
  }
}
</style>