select-warehouse-dialog.vue 6.4 KB

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