|
@ -1,9 +1,11 @@ |
|
|
|
|
|
|
|
|
// subpages/safetyinspection/pages/safetyinspection/safetyinspection.js
|
|
|
// subpages/safetyinspection/pages/safetyinspection/safetyinspection.js
|
|
|
|
|
|
import { $wuxActionSheet } from '../../../../components/dist/index' |
|
|
const App = getApp() |
|
|
const App = getApp() |
|
|
import { |
|
|
import { |
|
|
showRecord,addRecord,inspectionStaff |
|
|
showRecord,addRecord,inspectionStaff |
|
|
} from "../../../../utils/api" |
|
|
} from "../../../../utils/api" |
|
|
|
|
|
|
|
|
const config = require('../../../../utils/config') |
|
|
const config = require('../../../../utils/config') |
|
|
Page({ |
|
|
Page({ |
|
|
/** |
|
|
/** |
|
@ -16,32 +18,24 @@ Page({ |
|
|
pageSize:'20', |
|
|
pageSize:'20', |
|
|
showList:[], |
|
|
showList:[], |
|
|
imageUrls:[], |
|
|
imageUrls:[], |
|
|
remarks:'',//备注
|
|
|
remark:'',//备注
|
|
|
getData:'', |
|
|
reviewTime:'', |
|
|
gridName:'', |
|
|
checkResultFlag:'', |
|
|
array: ['合格', '不合格'], // 选择器的数据源
|
|
|
array: ['不合格', '合格'], // 选择器的数据源
|
|
|
result: ['a', 'b', 'c'], |
|
|
|
|
|
arrlist:[], |
|
|
arrlist:[], |
|
|
fileList: [], |
|
|
fileList: [], |
|
|
companyId: '', |
|
|
companyId: '', |
|
|
showPopup: false, // 控制弹出层显示/隐藏的状态
|
|
|
showPopup: false, // 控制弹出层显示/隐藏的状态
|
|
|
selectedOptions: [], // 选中的复选框项
|
|
|
selectedOptions: [], // 选中的复选框项
|
|
|
selectedNames:[],//显示检察人员
|
|
|
selectedNames:[],//显示检察人员
|
|
|
// 用于存放复选框选择的结果
|
|
|
newContent: '', |
|
|
result: [], |
|
|
|
|
|
// 用于存放输入框的值
|
|
|
|
|
|
newPassword: '', |
|
|
|
|
|
arr:[ |
|
|
arr:[ |
|
|
], |
|
|
], |
|
|
arr1:[ |
|
|
checkboxOptions:[], |
|
|
{value:"1",name:'1.车间一些软件设备出现生锈断裂情况严重'}, |
|
|
checkboxValue:[], |
|
|
{value:"2",name:'2.还有部分货运车辆已过年检。'}, |
|
|
uploadImageList: [],//图片上传的数组
|
|
|
], |
|
|
imageId:1 |
|
|
arr2:[ |
|
|
|
|
|
{id:"1", data:"2024-05-06 10:20",name:'检察人员',jielun:"不合格",yinhuan:"1.车间一些软件设备出现生锈断裂情况严重",fuchashijian:'2024-01-05',fujian:"1223",beizhu:"qq","dingwei":"山东路"}, |
|
|
|
|
|
{id:"2",data:"2024-05-06 10:20",name:'检察人员',jielun:"不合格",yinhuan:"2.车间一些软件设备出现生锈断裂情况严重",fuchashijian:'2024-01-05',fujian:"1223",beizhu:"qq","dingwei":"山东路"}, |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
/** |
|
|
/** |
|
|
* 生命周期函数--监听页面加载 |
|
|
* 生命周期函数--监听页面加载 |
|
@ -54,7 +48,6 @@ Page({ |
|
|
console.log(App.globalData) |
|
|
console.log(App.globalData) |
|
|
|
|
|
|
|
|
this.showRecordData() |
|
|
this.showRecordData() |
|
|
this.addRecordData() |
|
|
|
|
|
this.toOinspectionStaff() |
|
|
this.toOinspectionStaff() |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
@ -98,12 +91,17 @@ Page({ |
|
|
onShareAppMessage() { |
|
|
onShareAppMessage() { |
|
|
}, |
|
|
}, |
|
|
onChange(event) { |
|
|
onChange(event) { |
|
|
console.log(event) |
|
|
console.log(event.detail); |
|
|
|
|
|
this.data.checkboxOptions.forEach((item,index)=>{ |
|
|
|
|
|
if(event.detail.findIndex(item=>item==index) != -1){ |
|
|
|
|
|
item.hazardStatus = 1 |
|
|
|
|
|
}else{ |
|
|
|
|
|
item.hazardStatus = 0 |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
result: event.detail |
|
|
checkboxValue:event.detail, |
|
|
}); |
|
|
}) |
|
|
// event.detail 为当前输入的值
|
|
|
|
|
|
console.log(this.data.selectedOptions); |
|
|
|
|
|
}, |
|
|
}, |
|
|
afterRead(event) { |
|
|
afterRead(event) { |
|
|
const { |
|
|
const { |
|
@ -135,11 +133,15 @@ Page({ |
|
|
}, |
|
|
}, |
|
|
showRecordData() { |
|
|
showRecordData() { |
|
|
let parm = { |
|
|
let parm = { |
|
|
companyId: this.data.companyId |
|
|
id: this.data.companyId |
|
|
} |
|
|
} |
|
|
console.log(parm) |
|
|
|
|
|
showRecord(parm).then(res => { |
|
|
showRecord(parm).then(res => { |
|
|
console.log(res) |
|
|
if(res.data[0].hiddenDangeList){ |
|
|
|
|
|
let checkboxOptions = res.data[0].hiddenDangeList.filter(item=>item.hazardStatus === 0).map(item=>({hazardDesc:item.hazardDesc,hazardStatus:0})); |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
checkboxOptions |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
showList:res.data |
|
|
showList:res.data |
|
|
}) |
|
|
}) |
|
@ -147,7 +149,6 @@ Page({ |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
toOinspectionStaff(){ |
|
|
toOinspectionStaff(){ |
|
|
console.log("我执行了") |
|
|
|
|
|
let parm = { |
|
|
let parm = { |
|
|
orgId:this.data.orgid, |
|
|
orgId:this.data.orgid, |
|
|
orgType:"agency", |
|
|
orgType:"agency", |
|
@ -163,18 +164,7 @@ Page({ |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
addRecordData(){ |
|
|
|
|
|
let parm=({ |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
addRecord(parm).then(res => { |
|
|
|
|
|
console.log("") |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showList:res.data |
|
|
|
|
|
}) |
|
|
|
|
|
console.log(this.data.showList) |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
showPopup() { |
|
|
showPopup() { |
|
|
this.setData({ showPopup: true }); // 点击按钮显示弹出层
|
|
|
this.setData({ showPopup: true }); // 点击按钮显示弹出层
|
|
|
}, |
|
|
}, |
|
@ -203,119 +193,275 @@ Page({ |
|
|
}); // 关闭弹出层
|
|
|
}); // 关闭弹出层
|
|
|
console.log(this.data.selectedNames) |
|
|
console.log(this.data.selectedNames) |
|
|
}, |
|
|
}, |
|
|
changeNewPassword(e){ |
|
|
changenewContent(e){ |
|
|
console.log("执行了") |
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
newPassword: e.detail.value |
|
|
newContent: e.detail.value |
|
|
}); |
|
|
}); |
|
|
console.log(this.data.newPassword) |
|
|
|
|
|
}, |
|
|
}, |
|
|
addAnother() { |
|
|
addAnother() { |
|
|
// // 获取输入框的值
|
|
|
let newArr = this.data.checkboxOptions.concat({ hazardDesc: this.data.newContent, hazardStatus: 0 }); |
|
|
// const newPassword = this.data.newPassword;
|
|
|
|
|
|
// // 将值添加到arr数组中
|
|
|
|
|
|
// const arr = this.data.arr.concat(newPassword);
|
|
|
|
|
|
// // 更新数据
|
|
|
|
|
|
// this.setData({
|
|
|
|
|
|
// arr: arr,
|
|
|
|
|
|
// // 清空输入框的值
|
|
|
|
|
|
// newPassword: ''
|
|
|
|
|
|
// });
|
|
|
|
|
|
let newValue = this.data.arr1.length + 1; // 根据数组长度确定新值
|
|
|
|
|
|
let newArr = this.data.arr1.concat({ value: newValue.toString(), name: this.data.newPassword }); |
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
arr1: newArr, |
|
|
checkboxOptions: newArr, |
|
|
newPassword: '', // 清空输入框的值
|
|
|
newContent: '', // 清空输入框的值
|
|
|
}); |
|
|
}); |
|
|
console.log('添加后的数组:', this.data.arr1); |
|
|
console.log('添加后的数组:', this.data.checkboxOptions); |
|
|
}, |
|
|
}, |
|
|
|
|
|
// 删除选中的图片
|
|
|
|
|
|
deleteImage(e) { |
|
|
|
|
|
console.log(this.data.uploadImageList,'data中'); |
|
|
|
|
|
console.log(e.currentTarget.dataset.imageid,'图片Id'); |
|
|
|
|
|
const index = this.data.uploadImageList.findIndex(item => item.imageId === e.currentTarget.dataset.imageid) |
|
|
|
|
|
if (index > -1) { |
|
|
|
|
|
this.data.uploadImageList.splice(index, 1) |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
uploadImageList: this.data.uploadImageList |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
getCurrentDateTime() { |
|
|
|
|
|
const now = new Date(); |
|
|
|
|
|
const year = now.getFullYear(); |
|
|
|
|
|
const month = (now.getMonth() + 1).toString().padStart(2, '0'); |
|
|
|
|
|
const day = now.getDate().toString().padStart(2, '0'); |
|
|
|
|
|
const hours = now.getHours().toString().padStart(2, '0'); |
|
|
|
|
|
const minutes = now.getMinutes().toString().padStart(2, '0'); |
|
|
|
|
|
const seconds = now.getSeconds().toString().padStart(2, '0'); |
|
|
|
|
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
handelClickSave(){ |
|
|
|
|
|
if(this.data.selectedOptions.length === 0){ |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '请选择检查人员', |
|
|
|
|
|
icon:'none' |
|
|
|
|
|
}) |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
if(!this.data.checkResultFlag){ |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '请选择检查结论', |
|
|
|
|
|
icon:'none' |
|
|
|
|
|
}) |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
if(this.data.checkResultFlag == 0 && !this.data.reviewTime){ |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '请选择拟复查时间', |
|
|
|
|
|
icon:'none' |
|
|
|
|
|
}) |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
if(this.data.checkResultFlag == 0 && this.data.hiddenDangeList.length<0){ |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '请填写隐患明细', |
|
|
|
|
|
icon:'none' |
|
|
|
|
|
}) |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const now = new Date(); |
|
|
|
|
|
const hours = now.getHours().toString().padStart(2, '0'); |
|
|
|
|
|
const minutes = now.getMinutes().toString().padStart(2, '0'); |
|
|
|
|
|
const seconds = now.getSeconds().toString().padStart(2, '0'); |
|
|
|
|
|
let form = { |
|
|
|
|
|
companyId:this.data.companyId, |
|
|
|
|
|
checkTime:this.getCurrentDateTime(), |
|
|
|
|
|
checkPersonsIdList:this.data.selectedOptions, |
|
|
|
|
|
checkResultFlag:this.data.checkResultFlag, |
|
|
|
|
|
reviewTime:`${this.data.reviewTime} ${hours}:${minutes}:${seconds}`, |
|
|
|
|
|
hiddenDangeList:this.data.checkboxOptions, |
|
|
|
|
|
attachmentUrls:this.data.uploadImageList.map(item=>({fileName:item.originFileName,attachmentUrl:item.ossUrl.url})), |
|
|
|
|
|
remark:this.data.remark |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
addRecord(form).then(res => { |
|
|
|
|
|
if(res.code == 0){ |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '新增成功', |
|
|
|
|
|
duration:2000, |
|
|
|
|
|
success:function(){ |
|
|
|
|
|
setTimeout(()=>{ |
|
|
|
|
|
wx.navigateBack({ |
|
|
|
|
|
delta: 1 |
|
|
|
|
|
}) |
|
|
|
|
|
},2000) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
console.log(form); |
|
|
|
|
|
}, |
|
|
|
|
|
chooseImage() { |
|
|
|
|
|
if (this.data.uploadImageList.length > 3) { |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: "最多上传3张照片", |
|
|
|
|
|
icon: "none" |
|
|
|
|
|
}) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
const _this = this |
|
|
|
|
|
$wuxActionSheet().showSheet({ |
|
|
|
|
|
buttons: [ |
|
|
|
|
|
{ text: '拍照' }, |
|
|
|
|
|
{ text: '从相册中获取',openType:null, }, |
|
|
|
|
|
], |
|
|
|
|
|
className: 'dialog-class', |
|
|
|
|
|
buttonClicked(index) { |
|
|
|
|
|
if (index === 0) { |
|
|
|
|
|
wx.chooseMedia({ |
|
|
|
|
|
count: 1, |
|
|
|
|
|
sizeType: ['original', 'compressed'], |
|
|
|
|
|
sourceType: ['camera'], |
|
|
|
|
|
success(res) { |
|
|
|
|
|
console.log(res); |
|
|
|
|
|
let deleteLength = _this.data.uploadImageList.length |
|
|
|
|
|
const uploadImageList = [..._this.data.uploadImageList] |
|
|
|
|
|
if (res.tempFiles[0].size <= 5 * 1024 * 1024) { |
|
|
|
|
|
uploadImageList.push({ |
|
|
|
|
|
uploaded: false, |
|
|
|
|
|
ossUrl: {url:res.tempFiles[0].tempFilePath}, |
|
|
|
|
|
imgUrl: res.tempFiles[0].tempFilePath, |
|
|
|
|
|
imageId: ++_this.data.imageId, |
|
|
|
|
|
type:res.tempFiles[0].tempFilePath.substr(res.tempFiles[0].tempFilePath.length -3,3), |
|
|
|
|
|
format:"image", |
|
|
|
|
|
name:'wximage' |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
_this.showToast('图片上限5M,请压缩后重试~') |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
_this.setData({ |
|
|
|
|
|
uploadImageList |
|
|
|
|
|
}) |
|
|
|
|
|
wx.uploadFile({ |
|
|
|
|
|
url: `${config.BASEURL()}oss/file/uploadvariedfile`, |
|
|
|
|
|
filePath: res.tempFiles[0].tempFilePath, |
|
|
|
|
|
name: 'file', |
|
|
|
|
|
header: { |
|
|
|
|
|
'Content-type': 'application/json;charset=UTF-8', |
|
|
|
|
|
'Authorization': wx.getStorageSync('token') |
|
|
|
|
|
}, |
|
|
|
|
|
success(fileRes) { |
|
|
|
|
|
if (!JSON.parse(fileRes.data).data) { |
|
|
|
|
|
_this.showToast('图片上传失败,请重试~') |
|
|
|
|
|
// 删除
|
|
|
|
|
|
const index = _this.data.uploadImageList.findIndex(item => item.imageId === _this.data.imageId) |
|
|
|
|
|
if (index > -1) { |
|
|
|
|
|
_this.data.uploadImageList.splice(index, 1) |
|
|
|
|
|
_this.setData({ |
|
|
|
|
|
uploadImageList: _this.data.uploadImageList |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
uploadImageList[uploadImageList.length - 1].uploaded = true |
|
|
|
|
|
uploadImageList[uploadImageList.length - 1].ossUrl = JSON.parse(fileRes.data).data |
|
|
|
|
|
_this.setData({ |
|
|
|
|
|
uploadImageList |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
fail(fileRes) { |
|
|
|
|
|
_this.setData({ |
|
|
|
|
|
uploadImageList: [] |
|
|
|
|
|
}) |
|
|
|
|
|
_this.showToast('图片上传失败,请重试~') |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} else if (index === 1) { |
|
|
|
|
|
wx.chooseMedia({ |
|
|
|
|
|
count: 1, |
|
|
|
|
|
type:'image', |
|
|
|
|
|
sourceType: ['album'], |
|
|
|
|
|
success(res) { |
|
|
|
|
|
console.log(res,'图片上传的res'); |
|
|
|
|
|
let deleteLength = _this.data.uploadImageList.length |
|
|
|
|
|
const uploadImageList = [] |
|
|
|
|
|
const endIndex = _this.data.uploadImageList.length |
|
|
|
|
|
res.tempFiles.forEach((item,index) => { |
|
|
|
|
|
if (item.size <= 5 * 1024 * 1024) { |
|
|
|
|
|
uploadImageList.push({ |
|
|
|
|
|
uploaded: false, |
|
|
|
|
|
ossUrl: {url:item.tempFilePath}, |
|
|
|
|
|
imgUrl: item.tempFilePath, |
|
|
|
|
|
imageId: ++_this.data.imageId, |
|
|
|
|
|
format:"image", |
|
|
|
|
|
type:item.tempFilePath.substr(item.tempFilePath.length -3,3), |
|
|
|
|
|
originFileName:'image' + index + 1 |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
_this.showToast('图片上限5M,请压缩后重试~') |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
_this.setData({ |
|
|
|
|
|
uploadImageList: [..._this.data.uploadImageList, ...uploadImageList] |
|
|
|
|
|
}) |
|
|
|
|
|
uploadImageList.forEach((item, index) => { |
|
|
|
|
|
return (function (index) { |
|
|
|
|
|
wx.uploadFile({ |
|
|
|
|
|
url: `${config.BASEURL()}oss/file/uploadvariedfile`, |
|
|
|
|
|
filePath: res.tempFiles[index].tempFilePath, |
|
|
|
|
|
name: 'file', |
|
|
|
|
|
header: { |
|
|
|
|
|
'Content-type': 'application/json;charset=UTF-8', |
|
|
|
|
|
'Authorization': wx.getStorageSync('token') |
|
|
|
|
|
}, |
|
|
|
|
|
success(fileRes) { |
|
|
|
|
|
if (!JSON.parse(fileRes.data).data) { |
|
|
|
|
|
_this.showToast('图片上传失败,请重试~') |
|
|
|
|
|
_this.data.uploadImageList.splice(deleteLength, _this.data.uploadImageList.length - deleteLength) |
|
|
|
|
|
_this.setData({ |
|
|
|
|
|
uploadImageList: _this.data.uploadImageList |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log(uploadImageList,'see'); |
|
|
|
|
|
uploadImageList[index].uploaded = true |
|
|
|
|
|
uploadImageList[index].ossUrl = JSON.parse(fileRes.data).data |
|
|
|
|
|
_this.data.uploadImageList = _this.data.uploadImageList.slice(0, endIndex) |
|
|
|
|
|
_this.setData({ |
|
|
|
|
|
uploadImageList: [..._this.data.uploadImageList, ...uploadImageList] |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
fail(fileRes) { |
|
|
|
|
|
_this.setData({ |
|
|
|
|
|
uploadImageList: [] |
|
|
|
|
|
}) |
|
|
|
|
|
_this.showToast('图片上传失败,请重试~') |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
})(index) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
return true |
|
|
|
|
|
}, |
|
|
|
|
|
cancelText: '取消', |
|
|
|
|
|
cancel() { }, |
|
|
|
|
|
destructiveButtonClicked() { }, |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
pickerChange: function(e) { |
|
|
pickerChange: function(e) { |
|
|
// 更新当前选中的索引
|
|
|
console.log(e.detail.value); |
|
|
console.log(e.detail.value), |
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
gridName: this.data.array[e.detail.value] |
|
|
checkResultFlag:e.detail.value, |
|
|
|
|
|
checkResultFlagName:this.data.array[e.detail.value] |
|
|
}); |
|
|
}); |
|
|
console.log(this.data.gridName) |
|
|
|
|
|
// 在这里可以根据选择的值进行相应的逻辑处理
|
|
|
|
|
|
}, |
|
|
}, |
|
|
pickerChange1: function(e) { |
|
|
pickerChange1: function(e) { |
|
|
// 更新当前选中的索引
|
|
|
|
|
|
console.log(e.detail.value), |
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
getData: e.detail.value |
|
|
reviewTime: e.detail.value |
|
|
}); |
|
|
}); |
|
|
console.log(this.data.getData) |
|
|
|
|
|
// 在这里可以根据选择的值进行相应的逻辑处理
|
|
|
|
|
|
}, |
|
|
}, |
|
|
bindRemarkInput(e){ |
|
|
bindRemarkInput(e){ |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
remarks: e.detail.value |
|
|
remark: e.detail.value |
|
|
}); |
|
|
}); |
|
|
console.log(this.data.remarks) |
|
|
console.log(this.data.remark) |
|
|
}, |
|
|
}, |
|
|
chooseImage() { |
|
|
|
|
|
const that = this; |
|
|
|
|
|
wx.chooseMedia({ |
|
|
|
|
|
count: 1, |
|
|
|
|
|
sizeType: ['original', 'compressed'], |
|
|
|
|
|
sourceType: ['album', 'camera'], |
|
|
|
|
|
success(res) { |
|
|
|
|
|
console.log(res) |
|
|
|
|
|
const tempFilePaths = res; |
|
|
|
|
|
console.log(tempFilePaths); |
|
|
|
|
|
const imageUrls = [...that.data.imageUrls] |
|
|
|
|
|
|
|
|
|
|
|
if (that.data.imageUrls) { |
|
|
|
|
|
that.setData({ |
|
|
|
|
|
imageUrls: that.data.imageUrls.concat(tempFilePaths) |
|
|
|
|
|
}) |
|
|
|
|
|
wx.uploadFile({ |
|
|
|
|
|
url: `${config.BASEURL()}oss/file/uploadvariedfile`, |
|
|
|
|
|
filePath: res.tempFiles[0].tempFilePath, |
|
|
|
|
|
name: 'file', |
|
|
|
|
|
header: { |
|
|
|
|
|
'Content-type': 'application/json;charset=UTF-8', |
|
|
|
|
|
'Authorization': wx.getStorageSync('token') |
|
|
|
|
|
}, |
|
|
|
|
|
success(fileRes) { |
|
|
|
|
|
if (!JSON.parse(fileRes.data).data) { |
|
|
|
|
|
that.showToast('图片上传失败,请重试~') |
|
|
|
|
|
// 删除
|
|
|
|
|
|
const index = that.data.imageUrls.findIndex(item => item.imageId === that.data.imageId) |
|
|
|
|
|
if (index > -1) { |
|
|
|
|
|
that.data.imageUrls.splice(index, 1) |
|
|
|
|
|
that.setData({ |
|
|
|
|
|
imageUrls: that.data.imageUrls |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
imageUrls[imageUrls.length - 1].uploaded = true |
|
|
|
|
|
imageUrls[imageUrls.length - 1].ossUrl = JSON.parse(fileRes.data).data |
|
|
|
|
|
that.setData({ |
|
|
|
|
|
imageUrls |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
fail(fileRes) { |
|
|
|
|
|
that.setData({ |
|
|
|
|
|
imageUrls: [] |
|
|
|
|
|
}) |
|
|
|
|
|
that.showToast('图片上传失败,请重试~') |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 将选定的图片显示在页面上
|
|
|
|
|
|
// this.setData({
|
|
|
|
|
|
// imageUrl: tempFilePaths[0]
|
|
|
|
|
|
// });
|
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|