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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<template>
  <view class="repair-acceptance">
    <PageHeader title="设备报修验收"
                @back="goBack" />
    <view class="section"
          v-if="detail">
      <view class="section-title">报修信息</view>
      <view class="info-item">
        <text class="info-label">设备名称</text>
        <text class="info-value">{{ detail.deviceName || '-' }}</text>
      </view>
      <view class="info-item">
        <text class="info-label">验收人</text>
        <text class="info-value">{{ detail.acceptanceName || '-' }}</text>
      </view>
    </view>
    <u-form ref="formRef"
            :model="form"
            label-width="110">
      <u-cell-group title="验收信息">
        <u-form-item label="验收人"
                     border-bottom>
          <u-input v-model="form.acceptanceName"
                   disabled
                   placeholder="验收人" />
        </u-form-item>
        <u-form-item label="验收时间"
                     required
                     border-bottom>
          <u-input v-model="form.acceptanceTime"
                   placeholder="请选择验收时间"
                   readonly
                   @click="showDatePicker = true" />
          <template #right>
            <u-icon name="arrow-right"
                    @click="showDatePicker = true" />
          </template>
        </u-form-item>
        <u-form-item label="验收备注"
                     required
                     border-bottom>
          <u-textarea v-model="form.acceptanceRemark"
                      placeholder="请输入验收备注"
                      :maxlength="200"
                      count
                      :autoHeight="true" />
        </u-form-item>
      </u-cell-group>
      <view class="footer-btns">
        <u-button class="cancel-btn"
                  @click="goBack">取消</u-button>
        <u-button class="save-btn"
                  type="primary"
                  :loading="loading"
                  @click="submitAcceptance">确认验收</u-button>
      </view>
    </u-form>
    <up-datetime-picker :show="showDatePicker"
                        v-model="pickerDateValue"
                        mode="datetime"
                        @confirm="onDateConfirm"
                        @cancel="showDatePicker = false" />
  </view>
</template>
 
<script setup>
  import { ref, onMounted } from "vue";
  import { onLoad } from "@dcloudio/uni-app";
  import PageHeader from "@/components/PageHeader.vue";
  import useUserStore from "@/store/modules/user";
  import { getRepairById, acceptRepair } from "@/api/equipmentManagement/repair";
  import dayjs from "dayjs";
 
  defineOptions({ name: "设备报修验收" });
 
  const userStore = useUserStore();
  const repairId = ref("");
  const detail = ref(null);
  const loading = ref(false);
  const showDatePicker = ref(false);
  const pickerDateValue = ref(Date.now());
 
  const form = ref({
    id: "",
    acceptanceName: "",
    acceptanceTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
    acceptanceRemark: "",
  });
 
  const showToast = message => {
    uni.showToast({ title: message, icon: "none" });
  };
 
  const getCurrentUserName = () =>
    (userStore.nickName || userStore.name || "").trim();
 
  const canAccept = acceptanceName => {
    const current = getCurrentUserName();
    const target = (acceptanceName || "").trim();
    return current && target && current === target;
  };
 
  const loadDetail = async () => {
    if (!repairId.value) {
      showToast("参数错误");
      return;
    }
    try {
      uni.showLoading({ title: "加载中...", mask: true });
      const { code, data } = await getRepairById(repairId.value);
      if (code !== 200) {
        showToast("获取详情失败");
        return;
      }
      detail.value = data;
      if (Number(data.status) !== 3) {
        showToast("当前状态不可验收");
        setTimeout(() => goBack(), 1500);
        return;
      }
      if (!canAccept(data.acceptanceName)) {
        showToast("仅指定验收人可进行验收");
        setTimeout(() => goBack(), 1500);
        return;
      }
      form.value.id = data.id;
      form.value.acceptanceName = data.acceptanceName || "";
      form.value.acceptanceTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
    } catch (e) {
      showToast("获取详情失败");
    } finally {
      uni.hideLoading();
    }
  };
 
  const onDateConfirm = e => {
    form.value.acceptanceTime = dayjs(e.value).format("YYYY-MM-DD HH:mm:ss");
    pickerDateValue.value = e.value;
    showDatePicker.value = false;
  };
 
  const submitAcceptance = async () => {
    if (!form.value.acceptanceTime?.trim()) {
      showToast("请选择验收时间");
      return;
    }
    if (!form.value.acceptanceRemark?.trim()) {
      showToast("请输入验收备注");
      return;
    }
    try {
      loading.value = true;
      const { code, msg } = await acceptRepair({
        id: form.value.id,
        acceptanceTime: form.value.acceptanceTime,
        acceptanceRemark: form.value.acceptanceRemark.trim(),
      });
      if (code === 200) {
        showToast("验收成功");
        setTimeout(() => goBack(), 1500);
      } else {
        showToast(msg || "验收失败");
        loading.value = false;
      }
    } catch (e) {
      loading.value = false;
      showToast("验收失败");
    }
  };
 
  const goBack = () => {
    uni.removeStorageSync("repairId");
    uni.navigateBack();
  };
 
  onLoad(options => {
    repairId.value = options?.id || uni.getStorageSync("repairId") || "";
    form.value.id = repairId.value;
  });
 
  onMounted(() => {
    loadDetail();
  });
</script>
 
<style scoped lang="scss">
  @import "@/static/scss/form-common.scss";
 
  .repair-acceptance {
    min-height: 100vh;
    background: #f8f9fa;
    padding-bottom: 5rem;
  }
 
  .section {
    margin: 12px 16px;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  }
 
  .section-title {
    padding: 14px 16px;
    font-size: 16px;
    font-weight: 600;
    color: #303133;
    border-bottom: 1px solid #f0f0f0;
  }
 
  .info-item {
    display: flex;
    padding: 12px 16px;
    border-bottom: 1px solid #f8f8f8;
  }
 
  .info-label {
    width: 90px;
    font-size: 14px;
    color: #606266;
  }
 
  .info-value {
    flex: 1;
    font-size: 14px;
    color: #303133;
    text-align: right;
  }
 
  .footer-btns {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.75rem 0;
    box-shadow: 0 -0.125rem 0.5rem rgba(0, 0, 0, 0.05);
    z-index: 1000;
  }
 
  .cancel-btn {
    font-size: 1rem;
    color: #ffffff;
    width: 6.375rem;
    background: #c7c9cc;
    border-radius: 2.5rem;
  }
 
  .save-btn {
    font-size: 1rem;
    color: #ffffff;
    width: 14rem;
    background: linear-gradient(140deg, #00baff 0%, #006cfb 100%);
    border-radius: 2.5rem;
  }
</style>