souceinfo.vue 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <view class="bg-#FBFDFB border-#AFDDBB pd-24 b-radius mb-10">
  3. <view v-if="showClose" class="c-#F81242 f-s-36 ab2-10-10 pl-20 pr-10"
  4. style="position: absolute; right: 10rpx; top: 0rpx" @click="() => handleClose(index)"> × </view>
  5. <view class="d-flex a-c pb-10">
  6. <view class="c-primary pd-4 bg-#E7F4EA radius-10" style="font-style: italic">{{ index + 1 < 10 ? '0' +
  7. (index + 1) : index + 1 }}</view>
  8. <view class="c-#333 f-s-34 f-w-5 ml-10 mr-10">{{ data?.variety }}</view>
  9. <span class="f-s-24 c-#666">{{ selectDictLabel(pt_seed_type, data?.seedType) }}</span>
  10. </view>
  11. <view class="pt-6 pb-6 d-flex a-c">
  12. <view class="c-#666 f-s-28"> 入库批次号:</view>
  13. <view class="c-#333 f-s-28 f-w-5">{{ data?.batchCode }}</view>
  14. </view>
  15. <view class="pt-6 pb-6 d-flex a-c">
  16. <view class="c-#666 f-s-28"> 供应商:</view>
  17. <view class="c-#333 f-s-28 f-w-5">{{ data?.supplier }}</view>
  18. </view>
  19. <view class="pt-6 pb-6 d-flex a-c">
  20. <view class="c-#666 f-s-28 w-s-no"> 所在库房:</view>
  21. <view class="c-#333 f-s-28 f-w-5">{{ data?.warehouses }}</view>
  22. </view>
  23. <view class="pt-6 pb-6 d-flex mb-12">
  24. <view class="w-50% d-flex a-c">
  25. <view class="c-#666 f-s-28"> 入库量:</view>
  26. <view class="c-#333 f-s-28 f-w-5">{{ data?.capacity }}{{ data?.unit }}</view>
  27. </view>
  28. <view class="w-50% d-flex a-c">
  29. <view class="c-#666 f-s-28"> 剩余量:</view>
  30. <view class="c-primary f-s-28 f-w-5">{{ data?.restAmount }}{{ data?.unit }}</view>
  31. </view>
  32. </view>
  33. <up-line color="#AFDDBB" style="margin-left: -24rpx; margin-right: -24rpx; width: auto"></up-line>
  34. <view class="f-s-28 c-#666 pt-16">本次使用量:</view>
  35. <view class="pt-6 pb-6 d-flex a-c">
  36. <view class="flex1 mr-10">
  37. <up-input v-model="inputsModel.inputAmount" placeholder="请输入本次使用量" border="bottom"
  38. style="padding-left: 0">
  39. <template #suffix>
  40. <view class="c-#333 f-s-28 f-w-5">{{ data?.unit }}</view>
  41. </template>
  42. </up-input>
  43. </view>
  44. <view class="">
  45. <up-checkbox label="全部使用" usedAlone v-model:checked="hasChecked"
  46. @change="handleUseAllChange"></up-checkbox>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script setup lang="ts">
  52. import { ref, watch, computed, nextTick } from 'vue';
  53. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  54. const { pt_seed_instore_type, pt_seed_type, pt_fungus_code_type } = toRefs<any>(proxy?.useDict('pt_seed_instore_type', 'pt_seed_type', 'pt_fungus_code_type'));
  55. // 从外部获取数据
  56. const props = defineProps<{
  57. showClose?: boolean;
  58. index: number;
  59. data: any;
  60. }>();
  61. const emit = defineEmits<{
  62. close: [index: number];
  63. }>();
  64. const inputsModel = defineModel<any>('inputs', { default: () => { } });
  65. // 处理关闭事件
  66. const handleClose = (index: number) => {
  67. emit('close', index);
  68. };
  69. // 建立一个计算属性 如果props.data.restAmount 等于或者大于inputsModel.inputAmount 那么就为true
  70. const hasChecked = computed(() => {
  71. return +inputsModel?.value.inputAmount >= +props.data.restAmount;
  72. });
  73. const handleUseAllChange = () => {
  74. console.log(hasChecked.value, 'hasChecked.value');
  75. if (!hasChecked.value || +hasChecked.value == 0) {
  76. inputsModel.value.inputAmount = props.data.restAmount;
  77. }
  78. };
  79. watch(
  80. () => inputsModel.value?.inputAmount,
  81. (val) => {
  82. if (val === undefined || val === null) return;
  83. const numVal = Number(val);
  84. if (!isNaN(numVal) && numVal > props.data.restAmount) {
  85. // 使用 nextTick 确保 UI 更新
  86. nextTick(() => {
  87. inputsModel.value.inputAmount = props.data.restAmount;
  88. });
  89. }
  90. },
  91. { flush: 'post' },
  92. );
  93. </script>