index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <z-paging ref="paging" v-model="list" paging-class="paging-btm-shadow" bgColor="#f7f7f7" @query="query" safe-area-inset-bottom>
  3. <template #top>
  4. <ut-navbar title="请选择使用农资信息" :fixed="false"></ut-navbar>
  5. </template>
  6. <view class="pd-24 pb-0">
  7. <ut-search ref="searchRef" v-model="form.keyword" @search="changeSeach" margin="0" :border="false" placeholder="搜农资名称、批号、库房、供应商" bgColor="#fff" height="86rpx" borderRadius="10rpx"></ut-search>
  8. </view>
  9. <view class="pd-24">
  10. <view v-for="(item, index) in list" :key="index" class="b-radius pd-24 mb-20" :style="{ backgroundColor: isSelected(item) ? '#FBFDFB' : '#fff', border: isSelected(item) ? '2rpx solid #37a954' : '2rpx solid transparent' }" @click="toggleSelect(item)">
  11. <view class="d-flex a-c">
  12. <view class="d-flex" style="align-items: flex-end">
  13. <view class="f-w-5 f-s-34 c-#333">{{ item?.materialName }}</view>
  14. <view class="f-s-24 c-#666 ml-10">化肥</view>
  15. </view>
  16. <view class="flex1"></view>
  17. <view v-if="item?.examinReport.length > 0" class="c-primary bg-#EBF6EE radius-34 pd4-4-12-4-12 f-s-24">已检验</view>
  18. <view v-else class="c-#F74C30 bg-#F9ECEA radius-34 pd4-4-12-4-12 f-s-24">未检验</view>
  19. </view>
  20. <view class="d-flex a-c pt-10 pb-10">
  21. <text class="c-#666 f-s-30 w-s-no">入库批号:</text>
  22. <text class="c-#333 f-w-5 f-s-30 ov-hd tx-ov w-s-no">{{ item?.batchCode }}</text>
  23. </view>
  24. <view class="d-flex a-c pt-10 pb-10">
  25. <text class="c-#666 f-s-30 w-s-no">供应商:</text>
  26. <text class="c-#333 f-w-5 f-s-30 ov-hd tx-ov w-s-no">{{ item?.supplier }}</text>
  27. </view>
  28. <view class="d-flex a-c pt-10 pb-10">
  29. <text class="c-#666 f-s-30 w-s-no">存放库房:</text>
  30. <text class="c-#333 f-w-5 f-s-30 ov-hd tx-ov w-s-no">{{ item?.warehouses }}</text>
  31. </view>
  32. <view class="d-flex a-c pt-10 pb-10">
  33. <text class="c-#666 f-s-30 w-s-no">入库量:</text>
  34. <text class="c-#333 f-w-5 f-s-30 ov-hd tx-ov w-s-no">{{ item?.capacity }}{{ item?.unit }}</text>
  35. </view>
  36. <view class="d-flex a-c pt-10 pb-10">
  37. <view class="d-flex ov-hd w-50%">
  38. <text class="c-#666 f-s-30 w-s-no">出库量:</text>
  39. <text class="c-#333 f-w-5 f-s-30 ov-hd tx-ov w-s-no">{{ item?.inputAmount }}{{ item?.unit }}</text>
  40. </view>
  41. <view class="d-flex ov-hd w-50%">
  42. <text class="c-primary f-s-30 w-s-no">剩余量:</text>
  43. <text class="c-primary f-w-5 f-s-30 ov-hd tx-ov w-s-no">{{ item?.restAmount }}{{ item?.unit }}</text>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <template #bottom>
  49. <view class="pd-24 bg-#fff">
  50. <view class="b-radius bg-#fff d-flex a-c j-sb">
  51. <view class="d-flex c-primary f-s-26">
  52. <text>已选择:</text>
  53. <text>{{ selectedMaterials.length }}</text>
  54. <text>个物料</text>
  55. </view>
  56. </view>
  57. <view class="d-flex gap-20">
  58. <up-button @click="cancel()">取消</up-button>
  59. <up-button type="primary" @click="save()">确认选择</up-button>
  60. </view>
  61. </view>
  62. </template>
  63. </z-paging>
  64. </template>
  65. <script setup lang="ts">
  66. import { useClientRequest } from '@/utils/request';
  67. const list = ref<any>([]);
  68. const paging = ref();
  69. const form = ref({
  70. keyword: '',
  71. });
  72. // 选中的物料数组
  73. const selectedMaterials = ref<any[]>([]);
  74. // 检查物料是否已选中
  75. const isSelected = (item: any) => {
  76. // 使用 id 作为唯一标识符
  77. return selectedMaterials.value.some((m) => m.id === item.id);
  78. };
  79. // 切换选择状态
  80. const toggleSelect = (item: any) => {
  81. const index = selectedMaterials.value.findIndex((m) => m.id === item.id);
  82. if (index > -1) {
  83. // 已选中,取消选择
  84. selectedMaterials.value.splice(index, 1);
  85. } else {
  86. // 未选中,添加选择
  87. selectedMaterials.value.push(item);
  88. }
  89. };
  90. // 搜索变化
  91. const changeSeach = () => {
  92. paging.value.reload();
  93. };
  94. const query = async (pageNo: number, pageSize: number) => {
  95. const params = {
  96. pageNo,
  97. pageSize,
  98. ...form.value,
  99. };
  100. const res = await useClientRequest.get('/plt-api/app/material/list', params);
  101. const { rows } = res;
  102. paging.value.complete(rows);
  103. };
  104. // 取消
  105. const cancel = () => {
  106. uni.navigateBack({
  107. delta: 1,
  108. });
  109. };
  110. // 确认选择
  111. const save = () => {
  112. if (selectedMaterials.value.length === 0) {
  113. return uni.showToast({
  114. title: '请选择农资',
  115. icon: 'none',
  116. });
  117. }
  118. uni.$emit('updateMaterial', {
  119. checkBox: selectedMaterials.value.map((m) => m.id), // 发送batchCode数组
  120. data: selectedMaterials.value, // 发送完整的物料对象
  121. });
  122. uni.navigateBack({
  123. delta: 1,
  124. });
  125. };
  126. onUnload(() => {
  127. uni.$off('updateMaterial');
  128. });
  129. </script>