// pages/progressQuery/progressQuery.js const app = getApp(); var Validator = require("../../utils/validate.tools.js"); const verify = Validator.Validator; Page({ /** * 页面的初始数据 */ data: { contantType: ['电话号码', 'QQ', '电子邮箱'], user: app.globalData.imgUrl + '/image/user.svg', add: app.globalData.imgUrl + '/image/add.svg', del: app.globalData.imgUrl + '/image/del.svg', videoIcon: app.globalData.imgUrl + '/image/video.png', disabled: false, id: '', picType: '', evalList: {}, picturesInfo: {}, ReplyLogs: [], showType: 0 }, inputChange: function(e) { var name = e.currentTarget.dataset.name; this.setData({ picturesInfo: { ...this.data.picturesInfo, [name]: e.detail.value } }) }, selectChange: function(e) { this.setData({ "showType": e.detail.value, }) }, //选择地址 chooseLocation: function(e) { var status = e.currentTarget.dataset.status; var that = this; if (status == 0) { wx.chooseLocation({ success: function(res) { that.setData({ picturesInfo: { ...that.data.picturesInfo, address: res.address } }) }, }) } else {} }, onLoad: function(option) { var that = this; console.log(option.type) this.setData({ id: option.id, picType: option.type }) var userinfo = wx.getStorageSync("user"); wx.getLocation({ success: function(res) { var url = ""; if (that.data.id == 'new') { url = app.globalData.url + '/api/v1/pictures/find?id=' + that.data.id + '&flag=WX&lat=' + res.latitude + '&lng=' + res.longitude; } else { url = app.globalData.url + '/api/v1/pictures/find?id=' + that.data.id + '&flag=WX'; } wx.request({ url: url, success: function(res) { if (res.data.code == 0) { var data = res.data.data.pictures; var data1 = res.data.data.ReplyLogs || []; var status = data.status; var disabled = app.judgeDisable(status); var attList = data.attList || []; var evalList1015 = app.where(attList, { associateTypeId: 1015 //图片 }) || []; var evalList1016 = app.where(attList, { associateTypeId: 1016 //视频 }) || []; var evalList = { evalList1015, evalList1016 }; for (var i in evalList) { evalList[i] = evalList[i].map(({ path: pic, id }) => ({ pic, id })) } that.setData({ picturesInfo: { ...data, createId: userinfo.id }, disabled: disabled, evalList, id: data.id, showTime: app.formatDate(data.createTime), status, ReplyLogs:data1 }) console.log(that.data.picturesInfo); } else { wx.showModal({ title: '提示', content: "请求失败!" }) } } }) res.latitude, res.longitude } }) }, submit: function(e) { var picturesInfo = this.data.picturesInfo; var status = e.currentTarget.dataset.type; picturesInfo.status = status; picturesInfo.picType = this.data.picType; var showType = this.data.showType; var title = ''; if (status == "1") { const { evalList1015, evalList1016 } = this.data.evalList; if (!picturesInfo.userName) { return app.showModal("请填写姓名!"); } if (!picturesInfo.mobile) { if (showType == 0) { return app.showModal("请填写电话号码!"); } else if (showType == 2) { return app.showModal("请填写电子邮箱!"); }else{ return app.showModal("请填写QQ号码!"); } } else { if (showType == 0) { if (!verify.phone(picturesInfo.mobile)) { return app.showModal("手机号码格式不正确!") } } else if (showType == 2) { if (!verify.email(picturesInfo.mobile)) { return app.showModal("电子邮箱格式不正确!") } } } if (!picturesInfo.address) { return app.showModal("请填写拍摄地址!"); } if (!picturesInfo.content) { return app.showModal("请填写详细内容!"); } if (evalList1015.length == 0 && evalList1016.length == 0) { return app.showModal("请上传照片/图片!"); } if (picturesInfo.idCard && !verify.carIdNumber(picturesInfo.idCard)) { return app.showModal("身份证号码格式不正确!") } } var that = this; wx.request({ url: app.globalData.url + '/api/v1/pictures/save', data: picturesInfo, method: 'POST', header: { "Content-Type": "application/json" }, success: function(res) { if (res.data.code == 0) { if (status == 0) { title = '保存草稿成功!'; } else { title = '提交成功!'; } wx.showToast({ title, icon: 'success', duration: 2000 }) setTimeout(function() { wx.reLaunch({ url: '../index/index', }) }, 2000) } else { wx.showModal({ title: '提示', content: "提交失败!" }) } } }) }, reply: function (e) { var that = this; var openId = wx.getStorageSync("openId") var obj = { openId: openId, content: that.data.picturesInfo.replyContent, busType: 25, busId: that.data.id }; wx.request({ url: app.globalData.url + '/api/v1/pictures/reply', data: obj, method: 'POST', header: { "Content-Type": "application/json" }, success: function (res) { if (res.data.code == 0) { wx.showToast({ title: '提交回复成功', icon: 'success', duration: 2000 }) setTimeout(function () { wx.navigateBack({ changed: true }); //返回上一页 }, 2000) } else { wx.showModal({ title: '提示', content: "提交失败!" }) } } }) }, joinVideo: function(e) { var that = this; app.joinVideo(e, that) }, // 删除图片 clearImg: function(e) { var that = this; app.clearImg(e, that) }, //预览图片 previewImage: function(e) { app.previewImage(e) }, //预览视频 previewVideo: function(e) { console.log(e.currentTarget.dataset.src) var src = e.currentTarget.dataset.src; wx.navigateTo({ url: '../videoPreview/videoPreview?src=' + src, }) }, goback: function() { wx.navigateBack({ changed: true }); //返回上一页 }, uploadFiles: function(e) { var that = this; wx.showActionSheet({ itemList: ['拍照上传', '选择图片', '选择视频'], success: function(res) { let xindex = res.tapIndex; if (xindex == 0 || xindex == 1) { app.joinPicture(e, that, 1015) } else if (xindex == 2) { app.joinVideo(e, that, 1016) } }, fail: function(res) {} }) }, })