祖安之光
2025-08-07 41193d186d157937ba052e73dd04c12018e9ecab
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
const app = getApp();
const take = '/static/take.png';
const takeAll = '/static/takeAll.png';
const takeBack = '/static/return.png';
const check = '/static/check.png';
const del = '/static/delete.png';
const sell = '/static/sell.png';
const api = require('../../../utils/api');
const cloudApi = require('../../../utils/cloudApi')
Page({
  data: {
    page: 'pages/tabBar/firstPage/firstPage',
    statusBarHeight: '',
    cardList1: [
      { icon: take, title: '常规取用', type: 1 },
      { icon: takeAll, title: '用尽取用', type: 5 },
      { icon: takeBack, title: '归还', type: 2 },
      { icon: check, title: '用尽登记', type: 3 },
      { icon: del, title: '扫码作废', type: 4 }
    ],
    cardList2: [
      { icon: sell, title: '销售', type: 1 },
      { icon: del, title: '扫码作废', type: 4 }
    ],
    showModal: false,
    modalTitle: '取用',
    hazmat: {},
    product: {},
    hazmatBack: { id: null, remaining: '' },
    user: {},
    tabNum: 1,
    blockText: '危化品',
    blockStyle: { transform: 'translateX(0px)' }
  },
 
  onLoad() {
    // 获取手机状态栏高度
    this.setData({
      statusBarHeight: wx.getSystemInfoSync()['statusBarHeight']
    });
    wx.hideTabBar();
    this.getUserInfo();
  },
 
  onShow() {
    
  },
 
    // 输入框实现双向绑定
    onFormInput(e) {
      const field = e.currentTarget.dataset.field; // 获取字段名
      this.setData({
        [field]: e.detail.value  // 动态更新对应字段
      });
    },
 
  getUserInfo() {
    // 云开发
    // const companyId = wx.getStorageSync('user').companyId
    // cloudApi.queryPost('userInfoList',{company_id: companyId}).then(res=>{
    //   if(res.data.length>0){
    //     this.setData({
    //       user: cloudApi.changeKey(res.data)[0]
    //     });
    //     wx.setStorageSync('userSet', cloudApi.changeKey(res.data)[0])
    //   }
    // })
    // api
    api.getUserInfo().then(res => {
      if(res.code == 200) {
        this.setData({
          user: res.data
        });
        wx.setStorageSync('userSet', res.data);
      } else {
        wx.showToast({
          title: res.message,
          icon: 'none'
        });
      }
    });
  },
  closeModal(){
    this.setData({
      showModal: false,
      hazmat: {},
      product: {}
    });
  },
  scanCode(e) {
    const title = e.currentTarget.dataset.title;
    const t = this;
    t.setData({
      modalTitle: title
    });
    
    wx.scanCode({
      autoZoom: false,
      scanType: ['qrCode'],
      success(res) {
        if(res && res.result) {
          if(res.result.indexOf('SJ') == -1 && res.result.indexOf('CP') == -1) {
            wx.showToast({
              title: '没有识别到正确的编码,请重新扫码',
              icon: 'error',
              duration: 2000
            });
            return;
          }
          if(t.data.tabNum == 1) {
            // 云开发请求
            // wx.cloud.callFunction({
            //   name: 'getHazmatInfo',
            //   data: {
            //     code: 'SJ08202502250003'
            //   }
            // }).then(res=>{
            //   if(res.result && Array.isArray(res.result.list) && res.result.list.length>0){
            //     t.setData({
            //       hazmat: cloudApi.changeKey(res.result.list[0]),
            //       showModal: true
            //     })
            //   }else{
            //     wx.showToast({
            //       title: '无条码信息',
            //       icon: 'error',
            //       duration: 2000
            //     });
            //   }
            // })
            // api请求
            api.getHazmatByCode({code: res.result}).then((re) => {
              if(re.code == 200) {
                t.setData({
                  hazmat: re.data,
                  showModal: true
                });
              } else {
                wx.showToast({
                  title: re.message,
                  icon: 'error',
                  duration: 2000
                });
              }
            }).catch(err => {
              wx.showToast({
                title: err,
                duration: 2000
              });
            });
          } else {
            // 云开发请求
            // wx.cloud.callFunction({
            //   name: 'getProductInfo',
            //   data: {
            //     code: res.result
            //   }
            // }).then(res=>{
            //   if(res.result && Array.isArray(res.result.list) && res.result.list.length>0){
            //     t.setData({
            //       product: cloudApi.changeKey(res.result.list[0]),
            //       showModal: true
            //     })
            //   }else{
            //     wx.showToast({
            //       title: '无条码信息',
            //       icon: 'error',
            //       duration: 2000
            //     });
            //   }
            // })
            // api请求
            api.getProductByCode({code: res.result}).then((re) => {
              if(re.code == 200) {
                t.setData({
                  product: re.data,
                  showModal: true
                });
              } else {
                wx.showToast({
                  title: re.message,
                  icon: 'error',
                  duration: 2000
                });
              }
            }).catch(err => {
              wx.showToast({
                title: err,
                duration: 2000
              });
            });
          }
 
 
        } else {
          wx.showToast({
            title: '该二维码已失效或不包含条码信息',
            icon: 'error',
            duration: 2000
          });
        }
      }
    });
 
 
  },
 
  confirmTake1() {
    const t = this;
 
    // 云服务请求
    // wx.cloud.callFunction({
    //   name: 'hazmatUsing',
    //   data: {
    //     warehouseId: t.data.hazmat.warehouseId,
    //     basicId: t.data.hazmat.basicId,
    //     companyId: t.data.hazmat.companyId,
    //     cupboardId: t.data.hazmat.cupboardId,
    //     hazmatId: t.data.hazmat.id,
    //     uid: wx.getStorageSync('user').id,
    //     id: t.data.hazmat.Id,
    //     remaining: t.data.hazmat.remaining,
    //     status: 0
    //   }
    // }).then(res=>{
    //   if(res.result.code == 200){
    //       wx.showToast({
    //         title: '取用成功',
    //         icon: 'success',
    //         duration: 2000
    //       });
    //   }
    // })
    
 
    // api请求
    api.postHazmatUse(t.data.hazmat.id, 0).then((r) => {
      wx.showToast({
        title: r.message,
        icon: 'none'
      });
    }).catch(err => {
      wx.showToast({
        title: err,
        duration: 2000
      });
    });
    t.closeModal();
  },
 
  confirmTake2() {
    const t = this;
 
    // 云服务请求
    // wx.cloud.callFunction({
    //   name: 'hazmatUsing',
    //   data: {
    //     warehouseId: t.data.hazmat.warehouseId,
    //     basicId: t.data.hazmat.basicId,
    //     companyId: t.data.hazmat.companyId,
    //     cupboardId: t.data.hazmat.cupboardId,
    //     hazmatId: t.data.hazmat.id,
    //     uid: wx.getStorageSync('user').id,
    //     id: t.data.hazmat.Id,
    //     remaining: t.data.hazmat.remaining,
    //     status: 1
    //   }
    // }).then(res=>{
    //   if(res.result.code == 200){
    //       wx.showToast({
    //         title: '取用成功',
    //         icon: 'success',
    //         duration: 2000
    //       });
    //   }
    // })
 
    // api请求
    api.postHazmatUse(t.data.hazmat.id, 1).then((r) => {
      wx.showToast({
        title: r.message,
        icon: 'none'
      });
    }).catch(err => {
      wx.showToast({
        title: err,
        duration: 2000
      });
    });
    t.closeModal();
  },
 
  confirmBack() {
    const t = this;
    if (!t.data.hazmatBack.remaining) {
      wx.showToast({
        title: '归还剩余量不可为空',
        icon: 'none'
      });
      return;
    }
    
    t.setData({
      'hazmatBack.id': t.data.hazmat.id,
    });
    api.postHazmatReturn(t.data.hazmatBack).then((r) => {
      wx.showToast({
        title: r.message,
        icon: 'none'
      });
    }).catch(err => {
      wx.showToast({
        title: err,
        duration: 2000
      });
    });
    t.closeModal();
  },
 
  confirmCheck() {
    const t = this;
    api.postHazmatUsed(t.data.hazmat.id).then((r) => {
      wx.showToast({
        title: r.message,
        icon: 'none'
      });
    }).catch(err => {
      wx.showToast({
        title: err,
        duration: 2000
      });
    });
    t.closeModal();
  },
 
  confirmSell() {
    const t = this;
    api.postProductSold(t.data.product.id).then((r) => {
      wx.showToast({
        title: r.message,
        icon: 'none'
      });
    }).catch(err => {
      wx.showToast({
        title: err,
        duration: 2000
      });
    });
    t.closeModal();
  },
 
  confirmCancle() {
    const t = this;
    if(t.data.tabNum == 1) {
      api.postHazmatDiscard(t.data.hazmat.id).then((r) => {
        wx.showToast({
          title: r.message,
          icon: 'none'
        });
      }).catch(err => {
        wx.showToast({
          title: err,
          duration: 2000
        });
      });
    } else {
      api.postProductDiscard(t.data.product.id).then((r) => {
        wx.showToast({
          title: r.message,
          icon: 'none'
        });
      }).catch(err => {
        wx.showToast({
          title: err,
          duration: 2000
        });
      });
    }
    t.closeModal();
  },
 
  closeModal() {
    this.setData({
      hazmat: {},
      product: {},
      hazmatBack: { id: null, remaining: '' },
      showModal: false
    });
  },
 
  changeTab(e) {
    const num = e.currentTarget.dataset.num;
    if(num == 1) {
      this.setData({
        tabNum: 1,
        blockStyle: { transform: 'translateX(0px)' },
        blockText: '危化品'
      });
    } else {
      this.setData({
        tabNum: 2,
        blockStyle: { transform: 'translateX(calc(100% - 2px))' },
        blockText: '成品'
      });
    }
  },
 
  toStudy(e) {
    const item = e.currentTarget.dataset.item;
    wx.setStorageSync("prevPage", '/pages/tabBar/firstPage/firstPage');
    wx.navigateTo({
      url: `/pages/tabBar/current/detail?bank=` + encodeURIComponent(JSON.stringify(item))
    });
  },
 
  toCourses() {
    wx.switchTab({
      url: '/pages/tabBar/current/current'
    });
  }
});