index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <z-paging ref="paging" safe-area-inset-bottom v-model="list">
  3. <template #top>
  4. <ut-navbar title="请选择/填写规格等级" :fixed="false"></ut-navbar>
  5. <view class="">
  6. <up-tabs :list="list1" @change="changeType" lineWidth="30" :current="activetab"></up-tabs>
  7. </view>
  8. </template>
  9. <view class="">
  10. <view class="pd-24 pt-0 d-flex flex-cln">
  11. <!-- 常用标签页 -->
  12. <template v-if="+activetab == 0">
  13. <view v-if="commonly?.length > 0" class="pt-16 d-flex flex-wrap gap-16" style="justify-content: start">
  14. <view v-for="(item, idnex) in commonly" :key="idnex" class="bg-#fff c-#333 radius-10 pd4-16-24-16-24 mb-16" @click="selectItem(item)">
  15. {{ item }}
  16. </view>
  17. </view>
  18. <template v-else>
  19. <ut-empty class="mg-at mt-30" color="#ccc" size="28rpx">暂无常用规格等级</ut-empty>
  20. </template>
  21. </template>
  22. <!-- 规格等级库标签页 -->
  23. <template v-if="+activetab == 1">
  24. <view class="d-flex flex-cln" style="justify-content: start">
  25. <view v-for="(item, idnexs) in ptechData" :key="idnexs">
  26. <view class="pt-16 pb-16 f-s-28 f-w-5 c-#666">{{ item?.dictTypeLabel }}</view>
  27. <view class="d-flex flex-wrap gap-16">
  28. <view v-for="(items, idnex) in item?.childVos" :key="idnex" class="bg-#fff c-#333 radius-10 pd4-16-24-16-24 mb-10" @click="selectItem(items?.dictLabel)">
  29. {{ items?.dictLabel }}
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <!-- 自行填写标签页 -->
  36. <template v-if="+activetab == 2">
  37. <view class="d-flex flex-cln">
  38. <view class="pt-16 f-s-28 c-#333">规格等级</view>
  39. <view class="d-flex flex-wrap gap-16 f-s-28 mt-16">
  40. <up-input v-model="temPtech" clearable border="bottom" placeholder="请输入规格等级">
  41. <template #suffix>
  42. <up-button type="primary" @click="confirmAdd()" style="height: 60rpx; width: 120rpx; font-size: 22rpx">确认添加</up-button>
  43. </template>
  44. </up-input>
  45. </view>
  46. </view>
  47. </template>
  48. </view>
  49. </view>
  50. </z-paging>
  51. </template>
  52. <script setup lang="ts">
  53. import { useClientRequest } from '@/utils/request';
  54. const list = ref<any>();
  55. const activetab = ref<number>(0);
  56. const STORAGE_KEY = 'specification-level-cache';
  57. const temPtech = ref<string>('');
  58. const list1 = reactive([
  59. { name: '常用', value: 0 },
  60. { name: '规格等级库', value: 1 },
  61. { name: '自行填写', value: 2 },
  62. ]);
  63. const changeType = (tabItem: any) => {
  64. activetab.value = tabItem?.value;
  65. };
  66. const commonly = ref<string[]>([]);
  67. const ptechData = ref<any[]>([]);
  68. // 选中项并返回
  69. const selectItem = (item: string) => {
  70. if (!item) return;
  71. // 添加到常用缓存
  72. let cached = uni.getStorageSync(STORAGE_KEY) || '';
  73. let items = cached ? cached.split(',') : [];
  74. // 去重
  75. const index = items.indexOf(item);
  76. if (index > -1) {
  77. items.splice(index, 1);
  78. }
  79. items.push(item);
  80. // 限制最多 40 个
  81. const MAX_ITEMS = 40;
  82. if (items.length > MAX_ITEMS) {
  83. items.splice(0, items.length - MAX_ITEMS);
  84. }
  85. // 更新缓存
  86. const newCached = items.join(',');
  87. uni.setStorageSync(STORAGE_KEY, newCached);
  88. commonly.value = items;
  89. // 返回选择结果
  90. uni?.$emit('updateSpecificationLevel', {
  91. data: item,
  92. });
  93. setTimeout(() => {
  94. uni.navigateBack({
  95. delta: 1,
  96. });
  97. }, 300);
  98. };
  99. // 确认添加(自行填写)
  100. const confirmAdd = () => {
  101. if (!temPtech.value) {
  102. uni.showToast({
  103. title: '请输入规格等级',
  104. icon: 'none',
  105. });
  106. return;
  107. }
  108. // 添加到常用缓存
  109. let cached = uni.getStorageSync(STORAGE_KEY) || '';
  110. let items = cached ? cached.split(',') : [];
  111. // 去重
  112. const index = items.indexOf(temPtech.value);
  113. if (index > -1) {
  114. items.splice(index, 1);
  115. }
  116. items.push(temPtech.value);
  117. // 限制最多 40 个
  118. const MAX_ITEMS = 40;
  119. if (items.length > MAX_ITEMS) {
  120. items.splice(0, items.length - MAX_ITEMS);
  121. }
  122. // 更新缓存
  123. const newCached = items.join(',');
  124. uni.setStorageSync(STORAGE_KEY, newCached);
  125. commonly.value = items;
  126. // 返回选择结果
  127. uni?.$emit('updateSpecificationLevel', {
  128. data: temPtech.value,
  129. });
  130. setTimeout(() => {
  131. uni.navigateBack({
  132. delta: 1,
  133. });
  134. }, 300);
  135. };
  136. const query = async () => {
  137. const res = await useClientRequest.get(`/plt-api/app/process/tech/listAllGroup`, {
  138. groupType: 'specn_level',
  139. });
  140. ptechData.value = res?.data;
  141. };
  142. onLoad(() => {
  143. query();
  144. let cached = uni.getStorageSync(STORAGE_KEY) || '';
  145. commonly.value = cached ? cached.split(',') : [];
  146. });
  147. </script>