From 4b48bacef8646cee8b66f5e10b0ed7124534e93e Mon Sep 17 00:00:00 2001
From: odc.xiaohui <xiaohui@Q1>
Date: 星期五, 12 五月 2023 17:10:47 +0800
Subject: [PATCH] 首页修改

---
 miniprogram/pages/user/report/submitReport/index.ts |  462 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 396 insertions(+), 66 deletions(-)

diff --git a/miniprogram/pages/user/report/submitReport/index.ts b/miniprogram/pages/user/report/submitReport/index.ts
index 3ffafab..5eb26a5 100644
--- a/miniprogram/pages/user/report/submitReport/index.ts
+++ b/miniprogram/pages/user/report/submitReport/index.ts
@@ -1,115 +1,336 @@
 // index.ts
-const submitReport =getApp()
+const submitReport = getApp()
+import Toast from '@vant/weapp/toast/toast';
+import { formatTime } from 'miniprogram/utils/util';
 Page({
     data: {
-        items:  { name: '鏃ユ湡鏃堕棿閫夋嫨', value: 'dateTime' },
+        phoneDisab:true,
+        isInGroup:'',
+        remarks: '',
+        addFig:false,
+        aaaform: {},
+        capture: ['camera'],
+        beforList: 'a',
+        amountInvolved: '',
+        workingLocation: '',
+        Location: '',
+        userIdCard: '',
+        sex: '鐢�',
+        realName: '',
+        phone: '',
+        fileImgList: [],
+        transactionReceiptList: [],
+        otherList: [],
+        causeIndex: null,
+        items: { name: '鏃ユ湡鏃堕棿閫夋嫨', value: 'dateTime' },
         mode: 'dateTime',
-        reportDetail: {},
+        reportDetail: {
+            causeId:''
+        },
         causeList: [],
         imagesFile: [],
+        cardIdList: [],
         images: [],
-        materials:"",
-        cheatTime:"",
+        materials: '',
+        cheatTime: "",
+        arraySex: [
+            { sex: '鐢�', id: 1 },
+            { sex: '濂�', id: 0 }
+        ],
+        sexId: 0
     },
-
+    afterRadeDel(e){
+        console.log(e);
+        console.log(this.data.cardIdList);
+        let arr=this.data.cardIdList
+        arr.splice(e.detail.index,1)
+        this.setData({
+            cardIdList: arr
+        })
+    },
+    afterRadeDelFile(e){
+        let arr=this.data.fileImgList
+        arr.splice(e.detail.index,1)
+        this.setData({
+            fileImgList: arr
+        })
+    }, 
+    afterRadeDelTran(e){
+        let arr=this.data.transactionReceiptList
+        arr.splice(e.detail.index,1)
+        this.setData({
+            transactionReceiptList: arr
+        })
+    },
+    afterRadeDelOther(e){
+        let arr=this.data.otherList
+        arr.splice(e.detail.index,1)
+        this.setData({
+            otherList: arr
+        })
+    },
+    getrealName(e) {
+        this.setData({
+            realName: e.detail
+        })
+    },
+    getsex(e) {
+        this.setData({
+            sex: e.detail
+        })
+    },
+    getuserIdCard(e) {
+        this.setData({
+            userIdCard: e.detail
+        })
+    },
+    getuserPhone(e){
+        this.setData({
+            phone: e.detail
+        })
+    },
+    getLocation(e) {
+        this.setData({
+            Location: e.detail
+        })
+    },
+    getworkingLocation(e) {
+        this.setData({
+            workingLocation: e.detail
+        })
+    },
+    getamountInvolved(e) {
+        this.setData({
+            amountInvolved: e.detail
+        })
+    },
+    onChangeTabs(e) {
+        this.setData({
+            beforList: e.detail.name
+        })
+    },
+    afterReadImg(event: { detail: { file: any; }; }, name) {
+        const { file } = event.detail;
+        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: result.data });
+                    that.setData({ cardIdList });
+                    console.log(that.data.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; }; }) {
+        this.setData({
+            causeIndex: e.detail.value
+        })
+        this.data.reportDetail.causeId = this.data.causeList[e.detail.value].id
+        console.log(e,this.data.causeIndex,this.data.reportDetail.causeId);
+        
+    },
     uploadImage() {
         wx.chooseMedia({
+            sourceType: ['camera'],
             mediaType: ['image'],
             success: res => {
                 this.setData({
                     imagesFile: res.tempFiles
                 })
-                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
-                        })
-                        if(index< this.data.imagesFile.length-1){
-                             this.data.materials+=result.data+","
-                        }else{
-                            this.data.materials+=result.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 + ","
+                            })
                         }
-                        this.setData({
-                            materials:this.data.materials
-                        })
-                        } 
-                    })             
+                    })
                 }
             }
         })
-   
+ 
     },
-//琚獥鏃堕棿
-onPickerChange(e){
-    console.log(e)
-    this.data.cheatTime=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)
-   },
+    //琚獥鏃堕棿
+    onPickerChange(e) {
+        this.data.cheatTime = e.detail.value
+    },
+    subSex(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) {
+        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() {
-        this.data.reportDetail.materials=this.data.materials
-        this.data.reportDetail.userId=wx.getStorageSync('id')
-        this.data.reportDetail.cheatTime=this.data.cheatTime
-        if (  this.data.reportDetail.materials == null||  this.data.reportDetail.information==null||  this.data.reportDetail.reportDescription==null) {
-            wx.showToast({
-                icon: "none",
-                title: '璇峰畬鏁村~瀹岃〃鍗曪紒',
-            })
+        console.log(this.data.reportDetail.causeId);
+        
+        if (this.data.realName == '') {
+            Toast('璇疯緭鍏ュ鍚嶏紒');
+            return
+        } else if (this.data.userIdCard == '') {
+            Toast('璇疯緭鍏ヨ韩浠借瘉锛�');
+            return
+        } else if (this.data.Location == '') {
+            Toast('璇疯緭鍏ョ幇浣忓潃锛�');
+            return
+        } else if (this.data.workingLocation == '') {
+            Toast('璇疯緭鍏ュ伐浣滃崟浣嶏紒');
+            return
+        }else if (this.data.reportDetail.causeId == '') {
+            Toast('璇烽�夋嫨鎻忚堪锛�');
+            return
+        } else if (this.data.amountInvolved == '') {
+            Toast('璇疯緭鍏ュ彈鎹熼噾棰濓紒');
+            return
+        } 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 {
+            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.reportDetail.idCardMaterials =this.data.cardIdList.length>0? this.data.cardIdList.map(res => res.url).join(','):null
+        this.data.reportDetail.contractMaterials =this.data.fileImgList.length>0? this.data.fileImgList.map(res => res.url).join(','):null
+        this.data.reportDetail.transactionMaterials =this.data.transactionReceiptList.length>0? this.data.transactionReceiptList.map(res => res.url).join(','):null
+        this.data.reportDetail.elseMaterials =this.data.otherList.length>0? this.data.otherList.map(res => res.url).join(','):null;;
+        // if (  this.data.reportDetail.information==null||  this.data.reportDetail.reportDescription==null) {
+        //     wx.showToast({
+        //         icon: "none",
+        //         title: '璇峰畬鏁村~瀹岃〃鍗曪紒',
+        //     })
+        //     return
+        // }
+      if (wx.getStorageSync('role')==1) {
         wx.request(
             {
-                url: submitReport.globalData.url+"/wx/user/addReport",
-                method: "POST",
+                url: submitReport.globalData.url + "/wx/user/policeAddReport",
+                method: this.data.addFig?"PUT":"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'
                     })
                 }
             })
-
-
+      }else{
+        wx.request(
+            {
+                url: submitReport.globalData.url + "/wx/user/addReport",
+                method: this.data.addFig?"PUT":"POST",
+                data: this.data.reportDetail,
+                header: {
+                    'token': wx.getStorageSync('token'),
+                    'content-type': 'application/json'
+                }, success: (res) => {
+                    wx.reLaunch({
+                        url: '../../report/index'
+                    })
+                }
+            })
+      }
+      
     },
-    onLoad(e) {
+    onLoad:function(e) {
+        console.log(e);
+        let that = this
+        let role = wx.getStorageSync('role')
+        if (role==1) {
+            that.setData({
+                phoneDisab :false
+            })
+        }
+        let phone = wx.getStorageSync('phone')
+        that.setData({
+            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
@@ -126,7 +347,116 @@
         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
+        if (e.id ) {
+            this.loadData(e)
+        }else{
+            wx.request(
+                {
+                    url: submitReport.globalData.url + "/cause/getVxCauseList?phone=" + that.data.phone,
+                    method: "GET",
+                    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({                              
+                                causeIndex: causes.findIndex(i => i.id == that.data.aaaform.causeId)
+                            })
+                        }                       
+                        this.setData({
+                            causeList: causes,
+                            // causeIndex: causes.findIndex(i => i.id == that.data.aaaform.causeId)
+                        })
+                        console.log(this.data.causeList,this.data.causeIndex);
+                        
+                    }
+                })
+        }
+       
+      
+    },
+    loadData(e: any) {
+        console.log(e);
+        let that = this
+        that.setData({
+            addFig:true
+        })
+        const { arraySex } = that.data
+            wx.request({
+                url: submitReport.globalData.url + "/report/rejectReport/" + e.id,
+                method: "GET",
+                header: { 'token': wx.getStorageSync('token') },
+                success: res => {
+                    let form = res.data.data
+                    console.log(arraySex,arraySex.findIndex(val=>{return val.sex == form.sex}),form.sex)
+                    
+                    this.setData({
+                        remarks:form.remarks,
+                        isInGroup:form.isInGroup,
+                        reportDetail:{
+                            causeId:form.causeId,
+                            id:form.id
+                        },
+                        causeList:[{
+                            id:form.causeId,
+                            name:form.description
+                        }],
+                        causeIndex: 0,
+                        aaaform: form,
+                        realName: form.realName,
+                        phone: form.mobile,
+                        userIdCard: form.userIdCard,
+                        amountInvolved: form.amountInvolved,
+                        sex: form.sex,
+                        sexId: arraySex.findIndex(val=>{return val.sex == form.sex}),
+                        Location: form.location,
+                        workingLocation: form.workingLocation,
+                        cardIdList:form.idCardMaterials? form.idCardMaterials.split(',').map(i => {
+                            return {
+                                thumb: that.imgComplete(i),
+                                url: i,
+                                type: "image",
+                                size: 999999
+                            }
+                        }):[],
+                        fileImgList:form.contractMaterials? form.contractMaterials.split(',').map(i => {
+                            return {
+                                thumb: that.imgComplete(i),
+                                url: i,
+                                type: "image",
+                                size: 999999
+                            }
+                        }):[],
+                        transactionReceiptList:form.transactionMaterials? form.transactionMaterials.split(',').map(i => {
+                            return {
+                                thumb: that.imgComplete(i),
+                                url: i,
+                                type: "image",
+                                size: 999999
+                            }
+                        }):[],
+                        otherList:form.elseMaterials? form.elseMaterials.split(',').map(i => {
+                            return {
+                                thumb: that.imgComplete(i),
+                                url: i,
+                                type: "image",
+                                size: 999999
+                            }
+                        }):[]
+                    })
+                    console.log(this.data.cardIdList);
+                    
+                }
+            })
+      
+        
+    },
+    imgComplete(file: String): String {
+        return submitReport.globalData.imageUrl + "/img/" + file
     }
 })
\ No newline at end of file

--
Gitblit v1.8.0