odc.xiaohui
2023-03-20 190f42003ed5f96f285e8ff9517dbfbe70ef0ba5
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
// index.ts
const submitReport =getApp()
Page({
    data: {
        fileImgList: [],
        causeIndex: null,
        items:  { name: '日期时间选择', value: 'dateTime' },
        mode: 'dateTime',
        reportDetail: {},
        causeList: [],
        imagesFile: [],
        images: [],
        materials:"",
        cheatTime:"",
        arraySex: [
             {sex:'男',id:1},
             {sex:'女',id:0}
            ],
            sexId:0
    },
    afterReadImg(event: { detail: { file: any; }; }){
        const { file } = event.detail;
        let that=this
        console.log(file);
        
        // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
        wx.uploadFile({
            // filePath:  this.data.imagesFile[index].tempFilePath,
                        header: {
                            'token': wx.getStorageSync('token'),
                            'content-type': 'application/json'
                        },
          url: submitReport.globalData.url+"/minio/upload", 
          filePath: file.url,
          name: 'file',
          formData: { user: 'test' },
          success(res) {
            // 上传完成需要更新 fileList
            const { fileImgList = [] } = that.data;
            fileImgList.push({ ...file, url: res.data });
            that.setData({ fileImgList });
 
 
            const result = JSON.parse(res.data)
           
            that.setData({
                materials: that.data.materials+=result.data+","
            })
            console.log(that.data.materials);
          },
        });
    },
    //选择案件
    pickCause(e: { detail: { value: string | number; }; }) {
        console.log(e);
        this.setData({
            causeIndex: e.detail.value
        })
        this.data.reportDetail.causeId = this.data.causeList[e.detail.value].id
    },
    uploadImage() {
        wx.chooseMedia({
            sourceType:['camera'],
            mediaType: ['image'],
            success: res => {
                this.setData({
                    imagesFile: res.tempFiles
                })
                console.log(this.data.imagesFile);
                
                for (let index = 0; index <  this.data.imagesFile.length; index++) {
                    wx.uploadFile({
                        filePath:  this.data.imagesFile[index].tempFilePath,
                        name: "file",
                        header: {
                            'token': wx.getStorageSync('token'),
                            'content-type': 'application/json'
                        },
                        url: submitReport.globalData.url+"/minio/upload",
                        success: res => {
                            const result = JSON.parse(res.data)
                                this.data.images.push({
                                    url:submitReport.globalData.imageUrl+"/img/"+result.data
                                })
                                this.setData({
                                    images:this.data.images
                                })  
                                this.setData({
                                    materials: this.data.materials+=result.data+","
                                })
                                console.log(this.data.materials);
                        } 
                    })            
                }
            }
        })
   
    },
//被骗时间
onPickerChange(e){
    console.log(e)
    this.data.cheatTime=e.detail.value
},
subSex(e){
console.log(e);
 
},
bindPickerChangeSex(e){
console.log(e);
this.setData({
    sexId:e.detail.value
})
},
getMoney:function(e){
 console.log(e.detail.value)
 this.data.reportDetail.amountInvolved=e.detail.value
},
getDe:function(e){
    console.log(e.detail.value)
    this.data.reportDetail.reportDescription=e.detail.value
   },
   getInfor:function(e){
    this.data.reportDetail.information=e.detail.value
    console.log(e.detail.value)
   },
    //通过
    cancel(){
       wx.navigateBack({
        delta:1
       })
    },
    pass() {
        this.data.materials=this.data.materials.substring(0,this.data.materials.length-1);
        this.data.reportDetail.reportMaterials=this.data.materials
        this.data.reportDetail.userId=wx.getStorageSync('id')
        this.data.reportDetail.cheatTime=this.data.cheatTime
        // if (  this.data.reportDetail.information==null||  this.data.reportDetail.reportDescription==null) {
        //     wx.showToast({
        //         icon: "none",
        //         title: '请完整填完表单!',
        //     })
        //     return
        // }
        wx.request(
            {
                url: submitReport.globalData.url+"/wx/user/addReport",
                method: "POST",
                data: this.data.reportDetail,
                header: {
                    'token': wx.getStorageSync('token'),
                    'content-type': 'application/json'
                }, success: (res) => {
                    console.log(res)
                    wx.reLaunch({
                        url:'../../report/index'
                    })
                }
            })
 
 
    },
    onLoad(e) {
        var date = new Date()
        var month = date.getMonth() + 1
        var day = date.getDate()
        var hours=date.getHours()
        var minutes=date.getMinutes()
        var secends=date.getSeconds()
        var time
        if (month < 10) {
            month = "0" + month
        }
        if (day < 10) {
            day = "0" + day
        }
        if (minutes < 10) {
            minutes = "0" + minutes
        }
        if (hours < 10) {
            hours = "0" + hours
        }
        if (secends < 10) {
            secends = "0" + secends
        }
        this.data.cheatTime = date.getFullYear() + "-" + month + "-" + day + " " + hours+":"+minutes+":"+secends
        console.log( this.data.cheatTime)
        wx.request(
            {
                url: submitReport.globalData.url+  "/cause/getCauseList",
                method: "GET",
                header: { 'token': wx.getStorageSync('token')},
                success: (res) => {
                    this.setData({
                        causeList: res.data.data.records
                    })
                }
            })
    }
})