ZN
22 小时以前 077ab59c700b85efdd057265bf752ad5942395b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<template>
  <view class="subtract-stock-page">
    <PageHeader title="出库" @back="goBack" />
 
    <scroll-view scroll-y class="content-scroll">
      <view class="form-section">
        <view class="section-title">库存信息</view>
        <view class="info-row">
          <text class="label">产品大类</text>
          <text class="value">{{ stockRecord.productName }}</text>
        </view>
        <view class="info-row">
          <text class="label">规格型号</text>
          <text class="value">{{ stockRecord.model }}</text>
        </view>
        <view class="info-row">
          <text class="label">可用库存</text>
          <text class="value highlight">{{ stockRecord.unLockedQuantity }}</text>
        </view>
      </view>
 
      <view class="form-section">
        <view class="section-title">出库信息</view>
        <view class="form-row">
          <text class="form-label required">出库数量</text>
          <up-input v-model="form.stockOutNum" type="number" :placeholder="'最大' + stockRecord.unLockedQuantity" />
        </view>
        <view class="form-row" v-if="isQualified">
          <text class="form-label">车牌号</text>
          <up-input v-model="form.licensePlateNo" placeholder="请输入车牌号" />
        </view>
        <view class="form-row" v-if="isQualified">
          <text class="form-label">毛重(吨)</text>
          <up-input v-model="form.grossWeight" type="number" placeholder="请输入毛重" />
        </view>
        <view class="form-row" v-if="isQualified">
          <text class="form-label">皮重(吨)</text>
          <up-input v-model="form.tareWeight" type="number" placeholder="请输入皮重" />
        </view>
        <view class="form-row" v-if="isQualified">
          <text class="form-label">净重(吨)</text>
          <up-input v-model="form.netWeight" type="number" disabled placeholder="自动计算" />
        </view>
        <view class="form-row" v-if="isQualified">
          <text class="form-label">过磅日期</text>
          <view class="selector-trigger" @click="openWeighingDatePicker">
            <text class="selector-text" :class="{ placeholder: !form.weighingDate }">
              {{ form.weighingDate || "请选择过磅日期" }}
            </text>
            <up-icon name="calendar" size="16" color="#999"></up-icon>
          </view>
        </view>
        <view class="form-row" v-if="isQualified">
          <text class="form-label">过磅员</text>
          <up-input v-model="form.weighingOperator" placeholder="请输入过磅员" />
        </view>
        <view class="form-row">
          <text class="form-label">备注</text>
          <up-input v-model="form.remark" type="textarea" placeholder="选填" />
        </view>
      </view>
    </scroll-view>
 
    <view class="bottom-bar">
      <view class="btn-submit" @click="handleSubmit">提交</view>
    </view>
 
    <up-popup :show="showWeighingDatePicker" mode="bottom" @close="showWeighingDatePicker = false">
      <up-datetime-picker
        :show="true"
        v-model="weighingDateValue"
        mode="datetime"
        @confirm="onWeighingDateConfirm"
        @cancel="showWeighingDatePicker = false"
      />
    </up-popup>
  </view>
</template>
 
<script setup>
import { computed, reactive, ref, watch } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import dayjs from "dayjs";
import PageHeader from "@/components/PageHeader.vue";
import { subtractConsumablesIn } from "@/api/consumablesLogistics/consumablesIn.js";
import { subtractConsumablesUnInventory } from "@/api/consumablesLogistics/consumablesUninventory.js";
 
const type = ref("0");
const isQualified = computed(() => type.value === "0");
 
const stockRecord = reactive({
  id: "",
  productName: "",
  model: "",
  unLockedQuantity: 0,
});
 
const form = reactive({
  stockOutNum: "",
  licensePlateNo: "",
  grossWeight: "",
  tareWeight: "",
  netWeight: "",
  weighingDate: "",
  weighingOperator: "",
  remark: "",
});
 
const showWeighingDatePicker = ref(false);
const weighingDateValue = ref(Date.now());
 
onLoad((options) => {
  if (options && options.type != null) {
    type.value = options.type;
  }
  const cached = uni.getStorageSync("stockSubtractRecord");
  if (cached) {
    try {
      const payload = typeof cached === "string" ? JSON.parse(cached) : cached;
      const item = payload && payload.item != null ? payload.item : payload;
      stockRecord.id = item.id;
      stockRecord.productName = item.productName;
      stockRecord.model = item.model;
      stockRecord.unLockedQuantity = item.unLockedQuantity || 0;
      uni.removeStorageSync("stockSubtractRecord");
    } catch (e) {
      uni.removeStorageSync("stockSubtractRecord");
    }
  }
});
 
const computeNetWeight = () => {
  const gross = Number(form.grossWeight);
  const tare = Number(form.tareWeight);
  if (!isNaN(gross) && !isNaN(tare)) {
    const net = Number((gross - tare).toFixed(2));
    form.netWeight = net > 0 ? net : 0;
  } else {
    form.netWeight = "";
  }
};
 
watch(
  () => [form.grossWeight, form.tareWeight],
  () => computeNetWeight()
);
 
const openWeighingDatePicker = () => {
  weighingDateValue.value = form.weighingDate
    ? dayjs(form.weighingDate, "YYYY-MM-DD HH:mm:ss").valueOf()
    : Date.now();
  showWeighingDatePicker.value = true;
};
 
const onWeighingDateConfirm = (e) => {
  const ts = e?.value ?? weighingDateValue.value;
  form.weighingDate = dayjs(ts).format("YYYY-MM-DD HH:mm:ss");
  showWeighingDatePicker.value = false;
};
 
const handleSubmit = () => {
  const outNum = Number(form.stockOutNum);
  if (!outNum || outNum <= 0 || outNum > Number(stockRecord.unLockedQuantity)) {
    uni.showToast({ title: `请输入 1~${stockRecord.unLockedQuantity} 之间的数量`, icon: "none" });
    return;
  }
  const net = Number(form.netWeight);
  if (!isNaN(net) && net > 0) {
    const max = Number(stockRecord.unLockedQuantity) || 0;
    if (max > 0 && net > max) {
      uni.showToast({ title: `净重不能大于可用库存 ${max}`, icon: "none" });
      return;
    }
    if (net > outNum) {
      uni.showToast({ title: `净重不能大于出库数量 ${outNum}`, icon: "none" });
      return;
    }
  }
  const api = isQualified.value ? subtractConsumablesIn : subtractConsumablesUnInventory;
  api({
    id: stockRecord.id,
    stockOutNum: outNum,
    licensePlateNo: form.licensePlateNo,
    grossWeight: form.grossWeight,
    tareWeight: form.tareWeight,
    netWeight: form.netWeight,
    weighingDate: form.weighingDate,
    weighingOperator: form.weighingOperator,
    remark: form.remark,
  })
    .then(() => {
      uni.showToast({ title: "出库成功", icon: "success" });
      setTimeout(() => uni.navigateBack(), 400);
    })
    .catch(() => {
      uni.showToast({ title: "出库失败", icon: "none" });
    });
};
 
const goBack = () => uni.navigateBack();
</script>
 
<style lang="scss" scoped>
.subtract-stock-page { min-height: 100vh; background: #f5f5f5; padding-bottom: 100rpx; }
.content-scroll { height: calc(100vh - 100rpx); }
.form-section { background: #fff; margin: 24rpx; padding: 24rpx; border-radius: 16rpx; }
.section-title { font-size: 28rpx; font-weight: 500; color: #333; margin-bottom: 12rpx; }
.info-row { display: flex; justify-content: space-between; padding: 12rpx 0; font-size: 26rpx; }
.info-row .label { color: #666; }
.info-row .value { color: #333; }
.info-row .value.highlight { color: #2979ff; font-weight: 500; }
.form-row { margin-bottom: 24rpx; }
.form-label { display: block; font-size: 26rpx; color: #666; margin-bottom: 12rpx; }
.form-label.required:before { content: "*"; color: #f56c6c; margin-right: 6rpx; }
.selector-trigger { display: flex; align-items: center; justify-content: space-between; padding: 20rpx 24rpx; background: #f5f5f5; border-radius: 12rpx; }
.selector-text { font-size: 28rpx; color: #333; }
.selector-text.placeholder { color: #999; }
.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 16rpx 24rpx calc(16rpx + env(safe-area-inset-bottom)); background: #fff; box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.04); }
.btn-submit { height: 88rpx; border-radius: 999rpx; background: #2979ff; color: #fff; font-size: 30rpx; display: flex; align-items: center; justify-content: center; }
</style>