安瑾然
2023-03-21 b4661f300194a13c4bc391f2f45a3f7a0a8dff08
miniprogram/pages/user/report/submitReport/index.ts
@@ -1,121 +1,114 @@
// index.ts
const submitReport =getApp()
const submitReport = getApp()
import Toast from '@vant/weapp/toast/toast';
Page({
    data: {
        capture:['camera'],
        beforList:'a',
        amountInvolved:'',
        workingLocation:'',
        Location:'',
        userIdCard:'',
        sex:'男',
        realName:'',
        phone:'',
        aaaform: {},
        capture: ['camera'],
        beforList: 'a',
        amountInvolved: '',
        workingLocation: '',
        Location: '',
        userIdCard: '',
        sex: '男',
        realName: '',
        phone: '',
        fileImgList: [],
        transactionReceiptList:[],
        otherList:[],
        transactionReceiptList: [],
        otherList: [],
        causeIndex: null,
        items:  { name: '日期时间选择', value: 'dateTime' },
        items: { name: '日期时间选择', value: 'dateTime' },
        mode: 'dateTime',
        reportDetail: {},
        causeList: [],
        imagesFile: [],
        cardIdList:[],
        cardIdList: [],
        images: [],
        materials:'',
        cheatTime:"",
        materials: '',
        cheatTime: "",
        arraySex: [
             {sex:'男',id:1},
             {sex:'女',id:0}
            ],
            sexId:0
            { sex: '男', id: 1 },
            { sex: '女', id: 0 }
        ],
        sexId: 0
    },
    getrealName(e){
    getrealName(e) {
        this.setData({
            realName:e.detail
            realName: e.detail
        })
    },
    getsex(e){
    getsex(e) {
        this.setData({
            sex:e.detail
            sex: e.detail
        })
    },
    getuserIdCard(e){
    getuserIdCard(e) {
        this.setData({
            userIdCard:e.detail
            userIdCard: e.detail
        })
    },
    getLocation(e){
    getLocation(e) {
        this.setData({
            Location:e.detail
            Location: e.detail
        })
    },
    getworkingLocation(e){
    getworkingLocation(e) {
        this.setData({
            workingLocation:e.detail
            workingLocation: e.detail
        })
    },
    getamountInvolved(e){
    getamountInvolved(e) {
        this.setData({
            amountInvolved:e.detail
            amountInvolved: e.detail
        })
    },
    onChangeTabs(e){
    onChangeTabs(e) {
        this.setData({
            beforList:e.detail.name
            beforList: e.detail.name
        })
    },
    afterReadImg(event: { detail: { file: any; }; },name){
        console.log(event,name);
    afterReadImg(event: { detail: { file: any; }; }, name) {
        const { file } = event.detail;
        let that=this
        console.log(file);
        let that = this
        // 当设置 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;
            const { transactionReceiptList = [] } = that.data;
            const { otherList = [] } = that.data;
            const { cardIdList = [] } = that.data;
            let result = JSON.parse(res.data)
            if (that.data.beforList=='a') {
                cardIdList.push({ ...file, url: res.data });
                that.setData({ cardIdList });
            }else if(that.data.beforList=='b'){
                fileImgList.push({ ...file, url: res.data });
                that.setData({ fileImgList });
            }else if(that.data.beforList=='c'){
                transactionReceiptList.push({ ...file, url: res.data });
                that.setData({ transactionReceiptList });
            }else if(that.data.beforList=='d'){
                otherList.push({ ...file, url: res.data });
                that.setData({ otherList });
            }
            that.setData({
                materials: that.data.materials+=result.data+","
            })
            console.log(that.data.materials);
          },
            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;
                const { transactionReceiptList = [] } = that.data;
                const { otherList = [] } = that.data;
                const { cardIdList = [] } = that.data;
                let result = JSON.parse(res.data)
                if (that.data.beforList == 'a') {
                    cardIdList.push({ ...file, url: result.data });
                    that.setData({ cardIdList });
                } else if (that.data.beforList == 'b') {
                    fileImgList.push({ ...file, url: result.data });
                    that.setData({ fileImgList });
                } else if (that.data.beforList == 'c') {
                    transactionReceiptList.push({ ...file, url: result.data });
                    that.setData({ transactionReceiptList });
                } else if (that.data.beforList == 'd') {
                    otherList.push({ ...file, url: result.data });
                    that.setData({ otherList });
                }
                that.setData({
                    materials: that.data.materials += result.data + ","
                })
            },
        });
    },
    //选择案件
    pickCause(e: { detail: { value: string | number; }; }) {
        console.log(e);
        this.setData({
            causeIndex: e.detail.value
        })
@@ -123,117 +116,109 @@
    },
    uploadImage() {
        wx.chooseMedia({
            sourceType:['camera'],
            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++) {
                for (let index = 0; index < this.data.imagesFile.length; index++) {
                    wx.uploadFile({
                        filePath:  this.data.imagesFile[index].tempFilePath,
                        filePath: this.data.imagesFile[index].tempFilePath,
                        name: "file",
                        header: {
                            'token': wx.getStorageSync('token'),
                            'content-type': 'application/json'
                        },
                        url: submitReport.globalData.url+"/minio/upload",
                        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);
                        }
                    })
                            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 + ","
                            })
                        }
                    })
                }
            }
        })
    },
//被骗时间
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
})
this.setData({
    sex:this.data.arraySex[e.detail.value].sex
})
},
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)
   },
    },
    //被骗时间
    onPickerChange(e) {
        this.data.cheatTime = e.detail.value
    },
    subSex(e) {
    },
    bindPickerChangeSex(e) {
        this.setData({
            sexId: e.detail.value
        })
        this.setData({
            sex: this.data.arraySex[e.detail.value].sex
        })
    },
    getMoney: function (e) {
        this.data.reportDetail.amountInvolved = e.detail.value
    },
    getDe: function (e) {
        this.data.reportDetail.reportDescription = e.detail.value
    },
    getInfor: function (e) {
        this.data.reportDetail.information = e.detail.value
    },
    //通过
    cancel(){
       wx.navigateBack({
        delta:1
       })
    cancel() {
        wx.navigateBack({
            delta: 1
        })
    },
    pass() {
        console.log(this.data.realName);
        if (this.data.realName=='') {
        if (this.data.realName == '') {
            Toast('请输入姓名!');
            return
        } else if(this.data.userIdCard=='') {
        } else if (this.data.userIdCard == '') {
            Toast('请输入身份证!');
            return
        }else if(this.data.Location=='') {
        } else if (this.data.Location == '') {
            Toast('请输入现住址!');
            return
        }else if(this.data.workingLocation=='') {
        } else if (this.data.workingLocation == '') {
            Toast('请输入工作单位!');
            return
        }else if(this.data.amountInvolved=='') {
        } else if (this.data.amountInvolved == '') {
            Toast('请输入受损金额!');
            return
        }else if(this.data.cardIdList.length!=2) {
        } else if (this.data.cardIdList.length != 2) {
            Toast('请选择身份证照片!');
            return
        }
        if (this.data.fileImgList.length!=0||this.data.transactionReceiptList.length!=0||this.data.otherList.length!=0) {
        }else{
        if (this.data.fileImgList.length != 0 || this.data.transactionReceiptList.length != 0 || this.data.otherList.length != 0) {
        } else {
            Toast('相关合同,交易凭证,其他;必填一项!');
            return
        }
        this.data.materials=this.data.materials.substring(0,this.data.materials.length-1);
        this.data.reportDetail.amountInvolved=this.data.amountInvolved,
        this.data.reportDetail.workingLocation=this.data.workingLocation,
        this.data.reportDetail.Location=this.data.Location,
        this.data.reportDetail.userIdCard=this.data.userIdCard,
        this.data.reportDetail.sex=this.data.sex,
        this.data.reportDetail.realName=this.data.realName,
        this.data.reportDetail.phone=this.data.phone,
        this.data.reportDetail.reportMaterials=this.data.materials
        this.data.reportDetail.userId=wx.getStorageSync('id')
        this.data.reportDetail.cheatTime=this.data.cheatTime
        this.data.materials = this.data.materials.substring(0, this.data.materials.length - 1);
        this.data.reportDetail.amountInvolved = this.data.amountInvolved
        this.data.reportDetail.workingLocation = this.data.workingLocation
        this.data.reportDetail.location = this.data.Location
        this.data.reportDetail.userIdCard = this.data.userIdCard
        this.data.reportDetail.sex = this.data.sex
        this.data.reportDetail.realName = this.data.realName
        this.data.reportDetail.phone = this.data.phone
        this.data.reportDetail.reportMaterials = this.data.materials
        this.data.reportDetail.userId = wx.getStorageSync('id')
        this.data.reportDetail.cheatTime = this.data.cheatTime
        this.data.reportDetail.idCardMaterials = this.data.cardIdList.map(res => res.url).join(',')
        this.data.reportDetail.contractMaterials = this.data.fileImgList.map(res => res.url).join(',')
        this.data.reportDetail.transactionMaterials = this.data.transactionReceiptList.map(res => res.url).join(',')
        this.data.reportDetail.elseMaterials = this.data.otherList.map(res => res.url).join(',')
        // if (  this.data.reportDetail.information==null||  this.data.reportDetail.reportDescription==null) {
        //     wx.showToast({
        //         icon: "none",
@@ -243,33 +228,31 @@
        // }
        wx.request(
            {
                url: submitReport.globalData.url+"/wx/user/addReport",
                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'
                        url: '../../report/index'
                    })
                }
            })
    },
    onLoad(e) {
        let that = this
        let phone = wx.getStorageSync('phone')
        this.setData({
            phone:phone
            phone: phone
        })
        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 hours = date.getHours()
        var minutes = date.getMinutes()
        var secends = date.getSeconds()
        var time
        if (month < 10) {
            month = "0" + month
@@ -286,18 +269,87 @@
        if (secends < 10) {
            secends = "0" + secends
        }
        this.data.cheatTime = date.getFullYear() + "-" + month + "-" + day + " " + hours+":"+minutes+":"+secends
        console.log( this.data.cheatTime)
        this.data.cheatTime = date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + secends
        this.loadData(e)
        wx.request(
            {
                url: submitReport.globalData.url+  "/cause/getCauseList",
                url: submitReport.globalData.url + "/cause/getVxCauseList?phone=" + that.data.phone,
                method: "GET",
                header: { 'token': wx.getStorageSync('token')},
                header: { 'token': wx.getStorageSync('token') },
                success: (res) => {
                    let causes = res.data.data
                    console.log(that.data.aaaform);
                    if (e.id) {
                        causes.push({
                            id: that.data.aaaform.causeId,
                            name: that.data.aaaform.description
                        })
                    }
                    this.setData({
                        causeList: res.data.data.records
                        causeList: causes,
                        causeIndex: causes.findIndex(i => i.id == that.data.aaaform.causeId)
                    })
                }
            })
    },
    loadData(e: any) {
        let that = this
        const { arraySex } = this.data
        if (e.id) {
            wx.request({
                url: submitReport.globalData.url + "/report/rejectReport/" + e.id,
                method: "GET",
                header: { 'token': wx.getStorageSync('token') },
                success: res => {
                    let form = res.data.data
                    this.setData({
                        aaaform: form,
                        realName: form.realName,
                        phone: form.mobile,
                        userIdCard: form.userIdCard,
                        amountInvolved: form.amountInvolved,
                        sex: form.sex,
                        sexId: arraySex.filter(i => i.sex == form.sex)[0].code,
                        Location: form.location,
                        workingLocation: form.workingLocation,
                        cardIdList: form.idCardMaterials.split(',').map(i => {
                            return {
                                thumb: that.imgComplete(i),
                                url: i,
                                type: "image",
                                size: 999999
                            }
                        }),
                        fileImgList: form.contractMaterials.split(',').map(i => {
                            return {
                                thumb: that.imgComplete(i),
                                url: i,
                                type: "image",
                                size: 999999
                            }
                        }),
                        transactionReceiptList: form.transactionMaterials.split(',').map(i => {
                            return {
                                thumb: that.imgComplete(i),
                                url: i,
                                type: "image",
                                size: 999999
                            }
                        }),
                        otherList: form.elseMaterials.split(',').map(i => {
                            return {
                                thumb: that.imgComplete(i),
                                url: i,
                                type: "image",
                                size: 999999
                            }
                        })
                    })
                }
            })
        }
    },
    imgComplete(file: String): String {
        return submitReport.globalData.imageUrl + "/img/" + file
    }
})