wtt
2026-03-08 c5bf6bcd4d5b89c78db0a47e880521660ab45fdd
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<template>
    <view>
        <view class="form-item">
            <view class="title">生产资源:</view>
            <view class="right">
                <uni-combox :candidates="arrayHSourceName" placeholder="请选择生产资源" v-model="hform.HSourceName"
                    @input="HSourceNameChange">
                </uni-combox>
            </view>
        </view>
 
        <view class="form-item">
            <view class="title">负责人:</view>
            <view class="right">
                <uni-combox :candidates="arrayHManagerName" placeholder="请选择负责人" v-model="hform.HManagerName"
                    @input="HManagerNameChange">
                </uni-combox>
            </view>
        </view>
 
        <view class="form-item">
            <view class="title">班组:</view>
            <view class="right">
                <uni-combox :candidates="arrayHGroupName" placeholder="请选择班组" v-model="hform.HGroupName"
                    @input="HGroupNameChange">
                </uni-combox>
            </view>
        </view>
 
        <view class="form-item">
            <view class="title">创建日期:</view>
            <view class="righton">
                <input disabled v-model="hform.HCreateDate" />
            </view>
        </view>
 
        <view class="form-item">
            <view class="title">备注:</view>
            <view class="right">
                <textarea v-model="hform.HRemark" placeholder="请输入备注" auto-height />
            </view>
        </view>
 
        <!-- 操作按钮 -->
        <view class="buttons" id="buttons">
            <button class="btn-c" size="mini" @tap="save">保存</button>
            <view style="flex: 1;"></view>
            <button class="btn-a" size="mini" @tap="goBack">返回</button>
        </view>
 
    </view>
</template>
 
<script>
    import dayjs from "dayjs";
    import {
        CommonUtils
    } from "@/utils/common";
    import {
        getUserInfo
    } from "@/utils/auth";
 
    export default {
        name: 'AddLineBind',
        data() {
            return {
                // 移除btnTop,改用固定底部布局
                // 数据列表
                HSourceNameList: [],
                HManagerNameList: [],
                HGroupNameList: [],
 
                // 用于uni-combox的数组
                arrayHSourceName: [],
                arrayHManagerName: [],
                arrayHGroupName: [],
 
                hform: {
                    HUserName: getUserInfo()['Czymc'] || uni.getStorageSync('HUserName'),
                    HSourceID: getUserInfo()['HSourceID'],
                    HSourceName: getUserInfo()['HSource'],
                    HManagerID: getUserInfo()['HKeeperID'],
                    HManagerName: getUserInfo()['HKeeper'],
                    HGroupID: getUserInfo()['HGroupID'],
                    HGroupName: getUserInfo()['HGroup'],
                    HCreateDate: dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss"),
                    HRemark: ''
                },
 
                // 服务器地址
                serverUrl: uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API',
 
                // 添加窗口高度
                windowHeight: 0
            };
        },
        onUnload() {
            // 页面关闭时触发刷新
            uni.$emit('refreshDeviceList');
        },
        methods: {
            // 获取所有列表数据
            async getListData() {
                // 获取生产资源列表
                await this.getSourceList();
                // 获取负责人列表(人员列表)
                await this.getManagerList();
                // 获取班组列表
                await this.getGroupList();
            },
 
            // 获取生产资源列表
            async getSourceList() {
                try {
                    const res = await uni.request({
                        url: this.serverUrl + '/api/newBill/getSourceList',
                        data: {
                            sWhere: ""
                        }
                    });
 
                    if (res[1].data.code == 1) {
                        this.HSourceNameList = res[1].data.data.Gy_Source || [];
                        for (let i = 0; i < this.HSourceNameList.length; i++) {
                            this.arrayHSourceName[i] = this.HSourceNameList[i].生产资源;
                        }
                        this.$forceUpdate();
                    } else {
                        uni.showToast({
                            title: '获取生产资源列表失败',
                            icon: 'none'
                        });
                    }
                } catch (error) {
                    console.log(error);
                    uni.showToast({
                        title: '获取生产资源列表失败',
                        icon: 'none'
                    });
                }
            },
 
            // 获取负责人列表(人员列表)
            async getManagerList() {
                try {
                    const res = await uni.request({
                        url: this.serverUrl + '/Web/GetEmployeeList_Json',
                        data: {
                            Employee: '',
                            HGroupID: 0,
                            HDeptID: uni.getStorageSync("HDeptID")
                        }
                    });
 
                    if (res[1].data.count == 1) {
                        this.HManagerNameList = res[1].data.data || [];
                        for (let i = 0; i < this.HManagerNameList.length; i++) {
                            this.arrayHManagerName[i] = this.HManagerNameList[i].HName;
                        }
                        this.$forceUpdate();
                    } else {
                        uni.showToast({
                            title: '获取负责人列表失败',
                            icon: 'none'
                        });
                    }
                } catch (error) {
                    console.log(error);
                    uni.showToast({
                        title: '获取负责人列表失败',
                        icon: 'none'
                    });
                }
            },
 
            // 获取班组列表
            async getGroupList() {
                try {
                    const res = await uni.request({
                        url: this.serverUrl + '/Gy_Group/list',
                        method: 'GET',
                        data: {
                            sWhere: "",
                            user: uni.getStorageSync('HUserName')
                        }
                    });
 
                    if (res[1].data.count == 1) {
                        this.HGroupNameList = res[1].data.data || [];
                        for (let i = 0; i < this.HGroupNameList.length; i++) {
                            this.arrayHGroupName[i] = this.HGroupNameList[i].班组名称 || this.HGroupNameList[i].HName;
                        }
                        this.$forceUpdate();
                    } else {
                        uni.showToast({
                            title: '获取班组列表失败',
                            icon: 'none'
                        });
                    }
                } catch (error) {
                    console.log(error);
                    uni.showToast({
                        title: '获取班组列表失败',
                        icon: 'none'
                    });
                }
            },
 
            // 选择生产资源
            HSourceNameChange(e) {
                for (let i = 0; i < this.HSourceNameList.length; i++) {
                    if (this.HSourceNameList[i].生产资源 == e) {
                        this.hform.HSourceName = this.HSourceNameList[i].生产资源;
                        this.hform.HSourceID = this.HSourceNameList[i].HItemID;
                        this.hform.HSourceCode = this.HSourceNameList[i].资源代码 || '';
                        break;
                    }
                }
            },
 
            // 选择负责人
            HManagerNameChange(e) {
                for (let i = 0; i < this.HManagerNameList.length; i++) {
                    if (this.HManagerNameList[i].HName == e) {
                        this.hform.HManagerName = this.HManagerNameList[i].HName;
                        this.hform.HManagerID = this.HManagerNameList[i].HItemID;
                        break;
                    }
                }
            },
 
            // 选择班组
            HGroupNameChange(e) {
                for (let i = 0; i < this.HGroupNameList.length; i++) {
                    const groupName = this.HGroupNameList[i].班组名称 || this.HGroupNameList[i].HName;
                    if (groupName == e) {
                        this.hform.HGroupName = groupName;
                        this.hform.HGroupID = this.HGroupNameList[i].HItemID;
                        break;
                    }
                }
            },
 
            // 验证表单
            validateForm() {
                if (!this.hform.HSourceID || this.hform.HSourceID == 0) {
                    uni.showToast({
                        title: '请选择生产资源',
                        icon: 'none'
                    });
                    return false;
                }
 
                if (!this.hform.HManagerID || this.hform.HManagerID == 0) {
                    uni.showToast({
                        title: '请选择负责人',
                        icon: 'none'
                    });
                    return false;
                }
 
                return true;
            },
 
            // 保存数据
            async save() {
                if (!this.validateForm()) {
                    return;
                }
 
                uni.showLoading({
                    title: '保存中...'
                });
 
                try {
                    const res = await CommonUtils.doRequest2Sync({
                        url: "/ReportPlatForm/SaveGetLineBindBillList",
                        data: {
                            HUserName: this.hform.HUserName,
                            HSourceID: this.hform.HSourceID,
                            HSourceName: this.hform.HSourceName,
                            HManagerID: this.hform.HManagerID,
                            HManagerName: this.hform.HManagerName,
                            HGroupID: this.hform.HGroupID,
                            HGroupName: this.hform.HGroupName,
                            HCreateDate: this.hform.HCreateDate,
                            HRemark: this.hform.HRemark
                        },
                        method: "GET"
                    });
 
                    uni.hideLoading();
 
                    if (res.data.count == 1) {
                        uni.showToast({
                            title: '保存成功',
                            icon: 'success',
                            success: () => {
                                setTimeout(() => {
                                    // 保存成功后返回上一页
                                    uni.navigateBack();
                                }, 1500);
                            }
                        });
                    } else {
                        uni.showToast({
                            title: res.data.Message || '保存失败',
                            icon: 'none'
                        });
                    }
                } catch (err) {
                    uni.hideLoading();
                    uni.showToast({
                        title: '保存失败: ' + err,
                        icon: 'none'
                    });
                }
            },
 
            // 返回上一页
            goBack() {
                uni.navigateBack();
            }
        },
        onLoad() {
            // 初始化数据
            this.hform.HUserName = getUserInfo()['Czymc'] || uni.getStorageSync('HUserName');
            // 获取所有列表数据
            this.getListData();
 
            // 获取窗口高度
            const systemInfo = uni.getSystemInfoSync();
            this.windowHeight = systemInfo.windowHeight;
        },
        onReady() {
            // 移除原来的按钮位置计算,使用固定底部布局
        }
    }
</script>
 
<style lang="scss" scoped>
    .form {
        padding: 20rpx;
        // 使用 calc 计算高度
        height: calc(100vh - 160rpx);
        /* 减去底部按钮区域的高度 */
        overflow: auto;
        box-sizing: border-box;
        /* 确保内边距不影响高度计算 */
    }
 
    .form-item {
        display: flex;
        align-items: center;
        font-size: 28rpx;
        padding: 6rpx 0;
        margin-bottom: 20rpx;
        margin-left: 10px;
 
        .title {
            width: 180rpx;
            flex-shrink: 0;
        }
 
        .right {
            flex: 1;
            border-radius: 22rpx;
            border: 1px solid #acacac;
            padding: 0 20rpx;
            min-height: 70rpx;
            display: flex;
            align-items: center;
 
            input,
            textarea {
                width: 100%;
                font-size: 30rpx;
            }
 
            textarea {
                padding: 20rpx 0;
                min-height: 100rpx;
            }
        }
 
        .righton {
            flex: 1;
            border-radius: 22rpx;
            border: 1px solid #e4e4e4;
            background-color: #e4e4e4;
            padding: 0 20rpx;
            min-height: 70rpx;
            display: flex;
            align-items: center;
 
            input {
                width: 100%;
                font-size: 30rpx;
                color: #666;
            }
        }
    }
 
    .buttons {
        position: fixed; // 改为固定定位
        bottom: 0; // 固定在底部
        left: 0;
        right: 0;
        width: 100%;
        display: flex;
        padding: 20rpx;
        background-color: #fff;
        border-top: 1px solid #eee;
        box-sizing: border-box; // 确保内边距不影响宽度
        z-index: 999; // 确保按钮在最上层
 
        button {
            border-radius: 50rpx;
            width: 180rpx;
            height: 66rpx;
            line-height: 66rpx;
            font-size: 28rpx;
        }
 
        .btn-a {
            background-color: #acacac;
            color: #fff;
        }
 
        .btn-c {
            background-color: #3a78ff;
            color: #fff;
        }
    }
</style>