// repair/addTask/index.js
|
var Constant = require('../../utils/constant.js');
|
var app = getApp();
|
import Request from "../../utils/api"
|
Page({
|
data: {
|
taskformid: 0,
|
StatueType: '',
|
currentCorpID: 1,
|
currentEmployeeID: 0,
|
contentTitle: "",
|
imageList: [], //图片
|
formType:null,
|
logicID:0
|
},
|
|
onLoad: function (options) {
|
console.log(options,17)
|
var that = this;
|
|
var userInfo = app.globalData.userInfo;
|
if (userInfo) {
|
this.setData({
|
taskformid: options.taskformid,
|
currentCorpID: userInfo.CorpID,
|
currentEmployeeID: userInfo.EmployeeID,
|
StatueType: options.StatueType,
|
formType:options.formType?options.formType:null,
|
logicID:options.logicID
|
});
|
}
|
},
|
|
//
|
inputContentTitle: function (e) {
|
this.setData({
|
contentTitle: e.detail.value
|
})
|
},
|
|
//提交
|
formSubmit: function () {
|
var that = this;
|
|
var imageList = that.data.imageList;
|
console.log(imageList,44)
|
if (imageList.length == 0 || that.data.taskformid == 0) {
|
wx.showToast({
|
title: '请选择图片',
|
icon: 'none',
|
duration: 2000
|
});
|
return
|
}
|
|
wx.showLoading({
|
title: '上传中...',
|
mask: true
|
});
|
|
//var sysInfo = app.globalData.sysInfo;
|
//var userInfo = app.globalData.userInfo;
|
//上传图片
|
that.uploadNextImageFile(that.data.taskformid, 0);
|
},
|
|
//迭代上传
|
uploadNextImageFile: function (taskFileId, index_image) {
|
console.log("taskFileId:"+taskFileId)
|
var that = this;
|
var image_count = this.data.imageList.length;
|
var logicID=this.data.logicID
|
let tokenInfo = wx.getStorageSync('AccessToken')
|
if (index_image >= image_count)
|
return;
|
var url_image = this.data.imageList[index_image];
|
let requestUrl = ""
|
let params={}
|
if(that.data.formType&& that.data.formType == "requestForm"){
|
requestUrl = "Repair/Request/Form/UploadFile@V1.0" //报修单图片上传
|
params={
|
'FormID' :taskFileId
|
}
|
}
|
if(that.data.formType&& that.data.formType == "taskForm"){
|
|
requestUrl = "Repair/Task/Form/UploadFile@V1.0" //维修单图片上传
|
params={
|
'FormID' :taskFileId,
|
'LogID':logicID
|
}
|
}
|
wx.uploadFile({
|
url: Constant.BASE_SERVER_URL + requestUrl,
|
filePath: url_image,
|
header:{
|
"Authorization":'Bearer ' + tokenInfo.Token
|
},
|
formData: params,
|
name: 'file',
|
success: function (res) { //上传完成
|
// console.log(JSON.parse(res.data))
|
if (index_image < image_count - 1) {
|
index_image++;
|
that.uploadNextImageFile(taskFileId, index_image); //迭代下一张
|
return;
|
}
|
|
wx.hideLoading();
|
var pages = getCurrentPages();
|
var currPage = pages[pages.length - 1]; //当前页面
|
var prevPage = pages[pages.length - 2]; //上一个页面
|
|
//直接调用上一个页面对象的告诉它要刷新页面
|
prevPage.refreshTaskFileList();
|
|
that.setData({
|
imageList: [],
|
contentTitle: ""
|
});
|
wx.showToast({
|
title: "上传成功,还可以继续上传",
|
icon: 'none'
|
});
|
|
wx.navigateBack({
|
delta: 1
|
});
|
}
|
});
|
|
},
|
|
//图片上传
|
chooseImage: function () {
|
var that = this;
|
var imageList = this.data.imageList;
|
wx.chooseImage({
|
sizeType: ['original', 'compressed'],
|
sourceType: ['album', 'camera'],
|
count: 9, //最多
|
success: function (res) {
|
var imgPaths = res.tempFilePaths;
|
for (var i = 0; i < imgPaths.length; i++) {
|
var imgPath = res.tempFilePaths[i];
|
imageList.push(imgPath)
|
};
|
that.setData({
|
imageList: imageList
|
})
|
}
|
})
|
},
|
//查看图片
|
previewImage: function (e) {
|
var currentSrc = e.target.dataset.src
|
wx.previewImage({
|
current: currentSrc,
|
urls: this.data.imageList
|
})
|
},
|
//删除图片
|
deleteImage: function (e) {
|
var that = this;
|
var imageList = that.data.imageList;
|
var index = e.currentTarget.dataset.index; //获取当前长按图片下标
|
wx.showModal({
|
title: '系统提醒',
|
content: '确定要删除此图片吗?',
|
success: function (res) {
|
if (res.confirm) {
|
imageList.splice(index, 1);
|
} else if (res.cancel) {
|
return false;
|
}
|
that.setData({
|
imageList: imageList
|
});
|
}
|
})
|
},
|
//一键清空
|
onImageDel() {
|
var that = this;
|
wx.showModal({
|
title: '系统提醒',
|
content: '确定要删除全部图片吗?',
|
success: function (res) {
|
if (res.confirm) {
|
that.setData({
|
imageList: []
|
});
|
} else if (res.cancel) {
|
return false;
|
}
|
|
}
|
});
|
},
|
|
|
onShow: function (e) {},
|
onShareAppMessage: function () {
|
return Constant.Share;
|
},
|
})
|