xusd
7 days ago 998218675eb243d43912c203174a6b72b299c0f8
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
// pages/materialUpload/index.js
const app = getApp();
const $$ = require('../../utils/util');
 
// 删除附件
function delfileApi(id) {
    return $$.request({ url: 'fileInfo/deleteById?id=' + id, type: 'get', service: 'sys', v1: true });
}
 
Page({
    /**
     * 页面的初始数据
     */
    previewImageVisible: false, // 判断是否进入查看图片
    filesArr: [],
    data: {
        popup: {}, // 下拉弹出框数据
        data: [], // 材料数据
        activeMaterial: 0, // 当前选中的材料下标
        person: [], // 身份证明材料中选择的人员数据
        activePerson: 0, // 人员数据下标
        formatData: {
            fileList: [],
            personFile: [],
        }, // 调整展示数据格式
        caseId: 0, // 案件id
        fileUrl: $$.baseUrl + $$.url.fileShowUrl,
    },
 
    // 展示弹出层
    handleShowPopup(e) {
        let data =
            e.currentTarget.dataset.type === 'materialtype'
                ? this.data.data.map((x) => {
                        delete x.fileList;
                        x.label = x.title;
                        return x;
                  })
                : this.data.person.map((x) => {
                        x.label = x.trueName;
                        return x;
                  });
        let index = 0;
        foreach: for (let i = 0; i <= data.length; i++) {
            if (data[i].label === e.currentTarget.dataset.value) {
                index = i;
                break foreach;
            }
        }
        this.setData({
            popup: {
                visible: true,
                title: e.currentTarget.dataset.title,
                selectData: data,
                type: e.currentTarget.dataset.type,
                noPicker: true,
                activeIndex: index,
            },
        });
    },
 
    // 关闭弹出层
    handleClosePopup() {
        this.data.popup.visible = false;
        this.setData({ popup: this.data.popup });
    },
 
    // 下拉框确认选择
    handleConfirmPicker({ detail }) {
        let type = this.data.popup.type;
        let index = detail.detail.index;
        this.data.popup.visible = false;
        if (type === 'materialtype') {
            this.data.activeMaterial = index;
        } else {
            this.data.activePerson = index;
        }
        this.setData({ popup: this.data.popup, activeMaterial: this.data.activeMaterial, activePerson: this.data.activePerson }, () => {
            this.formatData();
        });
    },
 
    // 预览图片
    handlePreviewImage(e) {
        let index = e.currentTarget.dataset.index;
        let personindex = e.currentTarget.dataset.personindex;
        let urls = [];
        let arr = this.data.activeMaterial !== 2 ? this.data.formatData.fileList : this.data.formatData.personFile[personindex].fileList;
        arr.forEach((x) => {
            urls.push(x.wxurl ? x.wxurl : `${this.data.fileUrl}${x.id}`);
        });
        wx.previewImage({
            current: arr[index].wxurl || `${this.data.fileUrl}${arr[index].id}`,
            urls: urls,
        });
        this.previewImageVisible = true;
    },
 
    // 删除图片
    async handleDelImage(e) {
        let ownerType = e.currentTarget.dataset.ownertype;
        let ownerId = e.currentTarget.dataset.ownerid;
        let id = e.currentTarget.dataset.id;
        $$.showLoading();
        const res = await delfileApi(id);
        if (res.type) {
            $$.showToast({ icon: 'success', title: '删除成功', duration: 500 });
            let files = this.data.data[this.data.activeMaterial].files;
            let num = this.data.data[this.data.activeMaterial].num;
            let fileList = [];
            if (this.data.activeMaterial !== 2) {
                fileList = files.filter((item) => item.ownerType === ownerType)[0].fileList;
            } else {
                fileList = files.filter((item) => item.ownerId === ownerId)[0].fileList;
            }
            fileList.forEach((x, t) => {
                if (x.id === id) {
                    fileList.splice(t, 1);
                    num = num - 1;
                }
            });
            this.data.data[this.data.activeMaterial].num = num;
            this.setData({ data: this.data.data }, () => {
                app.globalData.material.data = this.data.data;
                this.formatData();
            });
        }
    },
 
    // 数据格式化显示
    formatData() {
        let fileList = [];
        let personFile = [];
        if (this.data.activeMaterial !== 2) {
            fileList = this.data.data[this.data.activeMaterial].files[0]?.fileList || [];
        } else {
            let person = this.data.person;
            let files = this.data.data[this.data.activeMaterial].files;
            let personId = person[this.data.activePerson].id;
            let personFiles = files.filter((item) => item.ownerId === personId)[0]?.fileList || [];
            if (person[this.data.activePerson].agent) {
                // 代理人
                personFile = [
                    {
                        ownerId: personId,
                        value: '22_00018-205',
                        title: '身份证明材料',
                        fileList: personFiles.filter((item) => item.ownerType === '22_00018-205'),
            text: '请上传“居民身份证”',
                    },
                    {
                        ownerId: personId,
                        value: '22_00018-207',
                        title: '授权委托书',
                        fileList: personFiles.filter((item) => item.ownerType === '22_00018-207'),
            text: '请上传代理人的“授权委托书”',
                    },
                ];
            } else {
        // 当事人
                if (person[this.data.activePerson].perClass === '09_01001-1') {
                    // 申请人 or 被申请人的人员类型:自然人
                    personFile = [
                        {
                            ownerId: personId,
                            value: '22_00018-202',
                            title: '身份证明材料',
                            fileList: personFiles.filter((item) => item.ownerType === '22_00018-202'),
                            text: '请上传“居民身份证”',
                        },
                    ];
                } else if (person[this.data.activePerson].perClass === '09_01001-2' || person[this.data.activePerson].perClass === '09_01001-3') {
                    // 申请人 or 被申请人的人员类型:法人,非法人组织
                    let name = person[this.data.activePerson].perClass === '09_01001-2' ? '法定' : '机构';
                    personFile = [
                        {
                            ownerId: personId,
                            value: '22_00018-204',
                            title: name + '代表人身份证明',
                            text:
                                person[this.data.activePerson].perClass === '09_01001-2'
                                    ? '请上传“法定代表人居民身份证”和“法定代表人证明书”'
                                    : '请上传“机构代表人居民身份证”',
                            fileList: personFiles.filter((item) => item.ownerType === '22_00018-204'),
                        },
                        {
                            ownerId: personId,
                            value: '22_00018-203',
                            title: name + '登记材料',
                            text: '可上传“工商登记证明”或“组织机构代码证”',
                            fileList: personFiles.filter((item) => item.ownerType === '22_00018-203'),
                        },
                    ];
                }
            }
        }
        this.setData({ formatData: { fileList, personFile } });
    },
 
    // 上传文件图片
    async handleUploadFile(e) {
        let id = e.currentTarget.dataset.id;
        let type = e.currentTarget.dataset.type;
        let that = this;
        this.filesArr = [];
        wx.chooseMedia({
            mediaType: ['image'],
            success(res2) {
                const tempFiles = res2.tempFiles;
                // 多个文件逐一上传
                tempFiles.forEach((x, t) => {
                    $$.showLoading('上传中...');
                    wx.uploadFile({
                        url: `${$$.baseUrl}${$$.url.sys}/api/v1/fileInfo/wechatUpload/${id}/${type}`,
                        filePath: x.tempFilePath,
                        name: 'file',
                        header: { Authorization: app.globalData.token },
                        complete(res) {
                            $$.hideLoading();
                            if (res.errMsg === 'uploadFile:ok') {
                                const data = { ...JSON.parse(res.data), wxurl: x.tempFilePath };
                                that.filesArr.splice(t, 0, data);
                            } else {
                                that.filesArr.splice(t, 0, { code: '400' });
                            }
                            if (tempFiles.length === that.filesArr.length) {
                                let errNum = 0;
                                let files = that.data.data[that.data.activeMaterial].files;
                                let num = that.data.data[that.data.activeMaterial].num;
                                that.filesArr.forEach((y) => {
                                    if (y.code == 0) {
                                        // 将文件数据回填展示
                                        let file = y.data[0];
                                        file.wxurl = y.tempFilePath;
                                        let fileList = [];
                                        // 判断是否是人员的身份材料上传
                                        if (that.data.activeMaterial !== 2) {
                                            if (files.length === 0) {
                                                // 当无时添加默认
                                                files[0] = { ownerType: type, fileList: [] };
                                            }
                                            fileList = files.filter((item) => item.ownerType === type)[0].fileList;
                                        } else {
                                            let personFiles = files.filter((item) => item.ownerId === id);
                                            if (personFiles.length === 0) {
                                                // 当无时添加默认
                                                files.push({ ownerId: id, ownerName: that.data.person[that.data.activePerson].trueName, fileList: [] });
                                            }
                                            fileList = files.filter((item) => item.ownerId === id)[0].fileList;
                                        }
                                        num = num + 1;
                                        fileList.push(file);
                                    } else {
                                        errNum = errNum + 1;
                                    }
                                });
                                if (errNum !== 0) {
                                    $$.showToast({ title: `已上传:${tempFiles.length - errNum},失败:${errNum}`, duration: 500 });
                                } else {
                                    $$.showToast({ icon: 'success', title: '上传成功', duration: 500 });
                                }
                                app.globalData.material.uploadVisible = true;
                                that.data.data[that.data.activeMaterial].num = num;
                                that.setData({ data: that.data.data }, () => {
                                    app.globalData.material.data = that.data.data;
                                    that.formatData();
                                });
                            }
                        },
                    });
                });
            },
        });
    },
 
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        if (!this.previewImageVisible) {
            this.setData(
                {
                    data: app.globalData.material.data,
                    activeMaterial: parseInt(options.activeMaterial),
                    person: app.globalData.material.person,
                    caseId: options.caseId,
                },
                () => {
                    this.formatData();
                }
            );
        }
        if (this.previewImageVisible) {
            this.previewImageVisible = false;
        }
    },
});