// pages/bankDraft/add/add.js import * as UTIL from '../../../utils/util.js'; import * as API from '../../../utils/API.js'; let EVN_CONFIG = require('../../../env/env'); const app = getApp(); Page({ /** * 页面的初始数据 */ data: { isIPX: app.globalData.isIPX, form:{ eventTime: UTIL.formatDate(new Date()), //开票日期 必填 remark: "", }, showBtn:true, showEventTime:false, status:0, comment:'', pageType:'', fileList:[], uploadOptions:[] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let that = this that.setData({ taskId:options.taskId, pageType:options.type }) if(options.id!=null&&options.id!=""){ this.setData({id:options.id}) UTIL.httpRequest(API.URL_GET_MAJOREVENTGET + this.data.id, {method:'GET'}, { success: (res) => { console.log(res); if(res.data.auditStatus!='0'&&res.data.auditStatus!='2'){ this.setData({'showBtn':false}); } this.setData({'form':res.data}) that.setData({instanceId:res.data.instanceId}) let parData = { processInstanceId:res.data.instanceId, method:'POST' } // 查询审批事项流转进度 UTIL.httpRequest(API.URL_GET_GETPROCESSHISTORY , parData, { success: (res) => { console.log(res); that.setData({spsxOptions:res.rows}) } }) } }) //获取附件字典 UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'common_attach', {method:'GET'}, { success: (res) => { this.setData({ uploadOptions:res.data, }) this.asyncFun(options.id) } }) }else{ this.onShow() } }, commentInput(e){ console.log(e); var that = this; that.setData({ comment:e.detail.value }) }, onConfirmEventTime(e){ let data = this.getNewDate(new Date(e.detail.value)); this.setData({'form.eventTime':data}); }, getHtml(e) {//从组件获取值 this.data.form.eventContent = e.detail.content.html }, insertImage(){ //图片上传插入示例 wx.chooseImage({ count: 1, success: r => { // 本地测试图片插入 // this.selectComponent('#hf_editor').insertSrc(res.tempFilePaths[0]); wx.uploadFile({ //调用图片上传接口 url: wx.getStorageSync('dressCode')+'/common/upload', filePath: r.tempFilePaths[0], name: 'imgFile', success: res => { console.log(); let imgUrl = JSON.parse(res.data).url this.selectComponent('#hf_editor').insertSrc(wx.getStorageSync('dressCode')+'/common/upload' + imgUrl);//调用组件insertSrc方法 } }) } }) }, getNewDate(date){ //date是传过来的时间戳,注意需为13位,10位需*1000 //也可以不传,获取的就是当前时间 var time if(date){ time = new Date(date); }else{ time = new Date(); } var year= time.getFullYear() //年 var month = ("0" + (time.getMonth() + 1)).slice(-2); //月 var day = ("0" + time.getDate()).slice(-2); //日 var mydate = year + "-" + month + "-" + day; return mydate }, asyncFun(id){ let uploadList = this.data.uploadOptions console.log(uploadList); let newList = [] let _this = this uploadList.map( res => { let oData = { tableId: id, tableName: "t_yinnong_majorevent", //上传表 bizPath: "yinnong", fileType: res.dictValue, //附件类型 1原始发票 2会议纪要 3会议照片 4 参会人员签字 method:'GET' } console.log('aaa'); UTIL.httpRequest(API.URL_GET_ATTACHMENTLIST, oData, { success: (rr) => { if(rr.code==200&&rr.rows.length>0){ rr.rows.map((rrr,index) => { rrr.url = wx.getStorageSync('dressCode') + rrr.fileUrl if(index==rr.rows.length-1){ newList.push(Object.assign({},res,{"list":rr.rows})) _this.setData({"fileList":_this.data.fileList.concat(newList)}); _this.setData({"showUpload":true}) } }) }else{ let newuploadList = uploadList newuploadList.map(rd => { rd.list = newList }) _this.setData({"fileList":newuploadList}); _this.setData({"showUpload":true}) } }, fail:(rr) =>{ }, complete:(rr) => { } }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, openBox(even){ console.log(even.currentTarget.dataset.name); this.setData({ [even.currentTarget.dataset.name]:true }) }, onChange(event){ console.log(event); this.setData({ [event.currentTarget.dataset.value]: event.detail, }) }, closeBox(even){ console.log(even.currentTarget.dataset.name); this.setData({ [even.currentTarget.dataset.name]:false }) }, goSubmit(){ if(this.data.form.eventName===''||this.data.form.eventName==null){ //事项名称 UTIL.showToastNoneIcon('请填写事项名称!'); return false; }else if(this.data.form.eventTime===''||this.data.form.eventTime==null){ //事项时间 UTIL.showToastNoneIcon('事项时间不能为空!'); return false; }else if(this.data.form.eventContent===''||this.data.form.eventContent==null){ //事项内容 UTIL.showToastNoneIcon('事项内容不能为空!'); return false; }else if(this.data.status=='0'){ this.setData({'status':'1'}) var that = this; that.data.form.method = 'POST'; that.data.form.eventContent = that.data.form.eventContent.replace(/\\/g,"/") console.log(that.data.form); if(that.data.form.id==""||that.data.form.id==null){ UTIL.httpRequest(API.URL_POST_MAJOREVENTADD, that.data.form , { success: (res) => { this.setData({'status':0}) if(res.code == 200){ UTIL.showToastNoneIcon('新增成功'); setTimeout(function(){ wx.navigateBack({ delta:1 }) },2000) }else{ UTIL.showToastNoneIcon('新增失败:'+res.msg); } } }) }else{ UTIL.httpRequest(API.URL_POST_MAJOREVENTUPDATE, that.data.form , { success: (res) => { this.setData({'status':0}) if(res.code == 200){ UTIL.showToastNoneIcon('修改成功'); setTimeout(function(){ wx.navigateBack({ delta:1 }) },2000) }else{ UTIL.showToastNoneIcon('修改失败:'+res.msg); } } }) } } }, onConfirmTime(event){ this.setData({ [event.currentTarget.dataset.name]: false, [event.currentTarget.dataset.value]: UTIL.formatDate(event.detail), }); }, openBox(even){ console.log(even.currentTarget.dataset.name); this.setData({ [even.currentTarget.dataset.name]:true }) }, closeBox(even){ console.log(even.currentTarget.dataset.name); this.setData({ [even.currentTarget.dataset.name]:false }) }, back:function(){ wx.navigateBack({ delta: 1 }) }, goDis(){ var that = this ; console.log() let data = { taskId:that.data.taskId, instanceId:that.data.instanceId, variables:JSON.stringify({ comment:that.data.comment == '' ? '驳回':that.data.comment, pass:false, }), method:'POST' }; UTIL.httpRequest(API.URL_GET_PROCESSCOMPLETE , data, { success: (res) => { console.log(res); if (res.code == API.SUCCESS_CODE) { wx.showToast({ title: '审批成功', icon: 'success', duration: 2000, complete(){ setTimeout(function(){ that.back(); },2000) } }) }else{ wx.showToast({ title: '操作失败', icon: 'error', duration: 2000 }) } } }) }, goAgree(){ var that = this ; let data = { taskId:that.data.taskId, instanceId:that.data.instanceId, variables:JSON.stringify({ "comment":that.data.comment == '' ? '同意':that.data.comment, "pass":true, }), method:'POST' }; UTIL.httpRequest(API.URL_GET_PROCESSCOMPLETE ,data, { success: (res) => { console.log(res); if (res.code == API.SUCCESS_CODE) { wx.showToast({ title: '审批成功', icon: 'success', duration: 2000, complete(){ setTimeout(function(){ that.back(); },2000) } }) }else{ wx.showToast({ title: '操作失败', icon: 'error', duration: 2000 }) } } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })