riku
2025-04-25 b515fae43490ab20977d559e19d4e5f63a4fd96d
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
import { conclusionForm } from '../clue-item.js';
 
import { uploadConclusion } from '../../../services/clue/fetchClue';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    formArray: [],
    // 模式,add: 新增;update:更新
    mode: 'add',
    submitText: '保存',
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getOpenerEventChannel().on('acceptConclusionData', data => {
      const { conclusion, clue, isInternal } = data;
      const formArray = conclusionForm(conclusion);
      const mode = conclusion ? 'update' : 'add';
 
      this.setData({ formArray, mode, clue, isInternal });
    });
  },
 
  // 提交表单
  submit(e) {
    const { mode, clue, isInternal } = this.data;
 
    const formObj = e.detail;
    formObj.cid = clue.cid;
    formObj.ccInternal = isInternal;
    if (mode == 'add') {
      this.create(formObj);
    } else {
      this.update(formObj);
    }
  },
 
  // 取消表单
  cancel() {
    wx.navigateBack({
      delta: 1,
    });
  },
 
  // 新增
  create(formObj) {
    uploadConclusion(formObj).then(res => {
      if (res.success) {
        this.getOpenerEventChannel().emit('uploadOver');
        wx.navigateBack({
          delta: 1,
          success: () => {
            wx.showToast({
              title: '结论提交成功',
              duration: 2000,
              icon: 'success',
              mask: true,
            });
          },
        });
      } else {
        wx.showToast({
          title: res.message,
          duration: 2000,
          icon: 'error',
          mask: true,
        });
      }
    });
  },
 
  // 更新
  update(formObj) {
    this.create(formObj);
  },
});