aqyj/pages/offence/add.js

250 lines
6.1 KiB
JavaScript

const api = require("../../utils/request.js");
var dateTimePicker = require('../../utils/dateTimePicker.js');
Page({
/**
* 页面的初始数据
*/
data: {
offencetype:'公司员工',
offencetime: '',
offenceqy:'',
offenceplace: '',
offenceimg: [],
offencepost:"",
offencedept:"",
offenceparter:"",
typeIndex:0,
typeArray:['公司员工', '外协人员']
},
bindtypeChange: function (e) {
this.setData({
typeIndex: e.detail.value,
})
this.data.offencetype = this.data.typeArray[e.detail.value]
},
bindoffenceplaceInput: function (e) {
this.data.offenceplace = e.detail.value
},
binddescriptionInput: function (e) {
this.data.description = e.detail.value
},
bindoffencepostInput: function (e) {
this.data.offencepost = e.detail.value
},
bindoffencedeptInput: function (e) {
this.data.offencedept = e.detail.value
},
bindoffenceparterInput: function (e) {
this.data.offenceparter = e.detail.value
},
submit: function () {
var that = this
if (that.data.offenceplace == '') {
that.Tap1('请输入发生具体地点!')
} else if (that.data.description == '') {
that.Tap1('请输入简要描述!')
} else if (that.data.offencedept == '') {
that.Tap1('请输入车间!')
} else if (that.data.offencepost == '') {
that.Tap1('请输入岗位!')
}else {
that.upimg(0, that.data.offenceimg.length)
}
},
Tap1: function (x) {
wx.showModal({
title: "系统提示",
content: x,
showCancel: false,
confirmText: "确定"
})
},
//上传图片
upimg: function (x, y) {
var that = this
if (x < y) {
wx.showLoading({
title: '上传现场图片' + (x + 1) + '....',
})
wx.uploadFile({
header: {
'content-type': 'application/json', // 默认值
'Cookie': getApp().globalData.sessionId,
},
url: getApp().globalData.serverUrl + 'upfile',
filePath: that.data.offenceimg[x],
name: 'upfile',
success(res) {
var obj = JSON.parse(res.data);
that.data.offenceimg[x] = obj['filepath']
x = x + 1
if (x < y) {
that.upimg(x, y)
}
else {
that.addoffence()
}
}
})
} else {
that.addoffence()
}
},
addoffence: function () {
var wzdata = {
type: this.data.offencetype,
happentime: this.data.offencetime,
area:this.data.offenceqy,
place: this.data.offenceplace,
description: this.data.description,
imgs: this.data.offenceimg,
post: this.data.offencepost,
dept: this.data.offencedept,
parter: this.data.offenceparter
}
api.request('api/offence/?a=add', 'POST', wzdata).then(res => {
wx.navigateBack({
delta: 0,
})
}
)
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// 获取完整的年月日 时分秒,以及默认显示的数组
var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
var dateTimeArray1 = obj1.dateTimeArray
var dateTime1 = obj1.dateTime
var time = dateTimeArray1[0][dateTime1[0]] + '-' + dateTimeArray1[1][dateTime1[1]] + '-' + dateTimeArray1[2][dateTime1[2]] + ' ' + dateTimeArray1[3][dateTime1[3]] + ':' + dateTimeArray1[4][dateTime1[4]]
this.setData({
dateTimeArray1: obj1.dateTimeArray,
dateTime1: obj1.dateTime,
});
this.data.offencetime = time
//拉取地图权限
if (getApp().globalData.userInfo.perms.indexOf(30) != -1) {
this.setData({
mapright: true
})
} else {
this.setData({
mapright: false
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
changeDateTime1(e) {
var dateTimeArray1 = this.data.dateTimeArray1
var dateTime1 = this.data.dateTime1
var time = dateTimeArray1[0][dateTime1[0]] + '-' + dateTimeArray1[1][dateTime1[1]] + '-' + dateTimeArray1[2][dateTime1[2]] + ' ' + dateTimeArray1[3][dateTime1[3]] + ':' + dateTimeArray1[4][dateTime1[4]]
//console.log(time)
this.data.offencetime = time
this.setData({
dateTime1: e.detail.value,
});
},
changeDateTimeColumn1(e) {
var arr = this.data.dateTime1,
dateArr = this.data.dateTimeArray1;
arr[e.detail.column] = e.detail.value;
dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
this.setData({
dateTimeArray1: dateArr,
dateTime1: arr
});
},
chooseImage: function () {
var that = this
wx.chooseImage({
count: 9,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
that.setData({
offenceimg: that.data.offenceimg.concat(res.tempFilePaths)
})
}
})
},
previewImage: function (e) {
var current = e.target.dataset.src
wx.previewImage({
current: current,
urls: this.data.offenceimg
})
},
deleteImage: function (e) {
var that = this;
var offenceimg = that.data.offenceimg;
var index = e.currentTarget.dataset.index; //获取当前长按图片下标
wx.showModal({
title: '系统提醒',
content: '确定要删除此图片吗?',
success: function (res) {
if (res.confirm) {
offenceimg.splice(index, 1);
} else if (res.cancel) {
return false;
}
that.setData({
offenceimg: offenceimg
});
}
})
},
})