select-warehouse-dialog.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <root-portal>
  3. <up-popup :show="show" mode="right" @close="close">
  4. <view class="w-680 p-rtv" style="height: 100vh">
  5. <z-paging ref="paging" v-model="list" bgColor="#fff" :fixed="false" @query="query" safe-area-inset-bottom hide-no-more-inside :show-loading-more-no-more-view="false">
  6. <template #top>
  7. <up-navbar :fixed="false" border>
  8. <template #left>
  9. <view class="f-s-34 c-#333 f-w-500">{{ title }}</view>
  10. </template>
  11. </up-navbar>
  12. </template>
  13. <template>
  14. <view>
  15. <template v-for="item in list" :key="item?.id">
  16. <view @click="expandeds[item?.id] = !expandeds[item?.id]" class="pd-24 d-flex bg-#f7f7f7 btn-row-box a-c">
  17. <view>
  18. <up-checkbox :label="item?.warehouseName" iconSize="36rpx" v-model:checked="aloneCheckeds[item.id]" labelSize="28rpx" name="agree" usedAlone> </up-checkbox>
  19. </view>
  20. <view class="flex1 ov-hd j-ed d-flex">
  21. <up-icon size="30rpx" color="#333" name="arrow-down"></up-icon>
  22. </view>
  23. </view>
  24. <view v-show="expandeds[item?.id]" class="pd4-12-24-12-60">
  25. <SelectShelvesInput :warehouseId="item.id" :warehouseName="item.warehouseName" :expandeds="expandeds" @changeIdNameMap="changeIdNameMap">
  26. <template #default="{ list }">
  27. <template v-for="(sitem, index) in list" :key="sitem?.id">
  28. <view class="pd2-6-12">
  29. <up-checkbox :label="sitem?.shelvesName" iconSize="36rpx" v-model:checked="aloneCheckeds[item.id + '-' + sitem.id]" labelSize="28rpx" name="agree" usedAlone></up-checkbox>
  30. </view>
  31. </template>
  32. </template>
  33. </SelectShelvesInput>
  34. </view>
  35. </template>
  36. </view>
  37. </template>
  38. <!-- 空数据处理 -->
  39. <template #empty>
  40. <ut-empty class="mg-at" size="28rpx" color="#999" padding="10rpx">
  41. <view>暂未设置细分库房,如由需要, </view>
  42. <view>可前往<span class="c-primary">仓储-库房管理</span>里进行设置 </view>
  43. </ut-empty>
  44. </template>
  45. <template #bottom>
  46. <view class="pd-24 bg-#fff d-flex">
  47. <up-button @click="close" class="mr-30" color="#F2F2F2" style="color: #333">取消</up-button>
  48. <up-button @click="confirmSelection" type="primary">确认选择</up-button>
  49. </view>
  50. </template>
  51. </z-paging>
  52. </view>
  53. </up-popup>
  54. </root-portal>
  55. </template>
  56. <script setup lang="ts">
  57. import { useClientRequest } from '@/utils/request';
  58. import SelectShelvesInput from '../select-shelves-input/select-shelves-input.vue';
  59. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  60. const { pt_cus_type, pt_cpy_type } = toRefs<any>(proxy?.useDict('pt_cus_type', 'pt_cpy_type'));
  61. const paging = ref();
  62. const props = defineProps({
  63. params: {
  64. type: Object,
  65. default: () => ({}),
  66. },
  67. show: {
  68. type: Boolean,
  69. default: false,
  70. },
  71. modelValue: {
  72. type: Array,
  73. default: () => [],
  74. },
  75. title: {
  76. type: String,
  77. default: '选择存放库房',
  78. },
  79. });
  80. const aloneCheckeds = reactive<{ [key: string]: boolean }>({});
  81. // 展开收起对象
  82. const expandeds = reactive<{ [key: string]: boolean }>({});
  83. const form = ref({});
  84. const emit = defineEmits(['update:show', 'confirm', 'update:modelValue']);
  85. const list = ref<any[]>([]);
  86. const query = async (pageNum: number, pageSize: number) => {
  87. const params = {
  88. pageNum,
  89. pageSize,
  90. ...props.params,
  91. ...form.value,
  92. };
  93. const res = await useClientRequest.get<any>('/plt-api/app/warehouse/pageList', params);
  94. if (!res || res.code !== 200) return;
  95. const { rows } = res;
  96. // 构建id名称映射
  97. rows.forEach((item: any) => {
  98. idNameMap[item.id] = {
  99. warehouseName: item.warehouseName,
  100. warehouseId: item.id,
  101. };
  102. });
  103. paging.value?.complete(rows);
  104. };
  105. // 根据id获取名称的对象
  106. const idNameMap = reactive<{ [key: string]: { warehouseName?: string; shelvesName?: string; warehouseId?: string; shelfId?: string } }>({});
  107. const confirmSelection = () => {
  108. console.log(aloneCheckeds);
  109. console.log(idNameMap);
  110. const values: any[] = [];
  111. Object.keys(aloneCheckeds).forEach((key) => {
  112. if (aloneCheckeds[key]) {
  113. const names = idNameMap[key];
  114. if (names) {
  115. values.push({
  116. id: key,
  117. warehouseName: names.warehouseName,
  118. shelvesName: names.shelvesName,
  119. warehouseId: names.warehouseId,
  120. shelfId: names.shelfId,
  121. });
  122. }
  123. }
  124. });
  125. emit('update:modelValue', values);
  126. emit('confirm', values);
  127. close();
  128. };
  129. const changeIdNameMap = (map: { [key: string]: { shelvesName: string; warehouseName: string } }) => {
  130. Object.assign(idNameMap, map);
  131. };
  132. const close = () => {
  133. emit('update:show', false);
  134. };
  135. watch(
  136. () => props.modelValue,
  137. (val) => {
  138. // 初始化选中状态
  139. Object.keys(aloneCheckeds).forEach((key) => {
  140. delete aloneCheckeds[key];
  141. });
  142. val.forEach((item: any) => {
  143. // warehouseId-shelfId warehouseName or warehouseId shelvesName
  144. expandeds[item.warehouseId] = true;
  145. aloneCheckeds[item.warehouseId + (item.shelfId ? '-' + item.shelfId : '')] = true;
  146. idNameMap[item.warehouseId + (item.shelfId ? '-' + item.shelfId : '')] = {
  147. warehouseName: item.warehouseName,
  148. shelvesName: item.shelvesName,
  149. warehouseId: item.warehouseId,
  150. shelfId: item.shelfId,
  151. };
  152. });
  153. },
  154. { immediate: true },
  155. );
  156. </script>
  157. <style scoped lang="scss">
  158. .btn-row-box {
  159. margin-top: -1rpx;
  160. border: 1rpx solid #e6e6e6;
  161. }
  162. </style>