You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

307 lines
6.8 KiB

import {
getUser
} from '../../util/user'
import {
getSex
} from '../../util/utils'
import {
validatorPhone
} from '../../util/validator'
import {
addMail
} from '../../api/mail'
import {
send
} from '../../api/sms'
import {
upload
} from '../../api/request'
import {
saveDraft,
getDraft
} from '../../api/mailDraft'
import {
BASE_URL
} from '../../api/request'
Page({
data: {
depts: [{
text: "芙蓉分局",
value: 6,
},
{
text: "天心分局",
value: 29,
},
{
text: "岳麓分局",
value: 34,
},
{
text: "开福分局",
value: 20,
},
{
text: "雨花分局",
value: 33,
},
{
text: "高新分局",
value: 7,
},
{
text: "望城分局",
value: 31,
},
{
text: "长沙县局",
value: 35,
},
{
text: "浏阳市局",
value: 22,
},
{
text: "宁乡市局",
value: 24,
},
{
text: "交警支队",
value: 14,
},
{
text: "其他单位",
value: 0,
},
],
showPicker: false,
sendBtnDisabled: false,
time: 30,
contactName: '',
contactSex: '',
contactIdCard: '',
contactPhone: '',
code: '',
smsRequestId: '',
caseNumber: '',
involvedDeptName: '',
involvedDeptId: '',
content: '',
fileList: [],
attachments: [],
phoneErrMsg: '',
contentErrMsg: '',
codeErrMsg: ''
},
onLoad(options) {
if (options.draftId) {
getDraft(options.draftId).then(data => {
const attachments = JSON.parse(data.attachments)
this.setData({
contactName: data.contactName,
contactIdCard: data.contactIdCard,
contactSex: data.contactSex,
contactPhone: data.contactPhone,
caseNumber: data.caseNumber,
involvedDeptId: data.involvedDeptId,
involvedDeptName: data.involvedDeptName,
content: data.content,
attachments,
fileList: attachments.map(item => {
return {
url: BASE_URL + '/file/stream/' + item.filepath,
isImage: true
}
})
})
})
} else {
const user = getUser();
this.setData({
contactName: user.realName,
contactIdCard: user.idCard,
contactSex: getSex(user.idCard),
contactPhone: user.phone
})
}
},
handleShowPicker() {
this.setData({
showPicker: true
})
},
handleCancelPicker() {
this.setData({
showPicker: false,
involvedDeptName: '',
involvedDeptId: ''
})
},
handleConfirmPicker(data) {
this.setData({
showPicker: false,
involvedDeptName: data.detail.value.text,
involvedDeptId: data.detail.value.value
})
},
onPhoneInput(data) {
const phoneRes = validatorPhone(this.data.contactPhone);
if (phoneRes === true) {
this.setData({
phoneErrMsg: ''
})
return
}
},
handleSave() {
const phoneRes = validatorPhone(this.data.contactPhone);
if (phoneRes !== true) {
this.setData({
phoneErrMsg: phoneRes
})
return
}
if (!this.data.code) {
this.setData({
codeErrMsg: '请输入验证码'
})
return
}
if (!this.data.content) {
this.setData({
contentErrMsg: '请输入信件内容'
})
return
}
if (this.data.content.length < 15) {
this.setData({
contentErrMsg: '信件内容不能少于15个字'
})
return
}
addMail({
contactName: this.data.contactName,
contactSex: this.data.contactSex,
contactIdCard: this.data.contactIdCard,
contactPhone: this.data.contactPhone,
code: this.data.code,
smsRequestId: this.data.smsRequestId,
caseNumber: this.data.caseNumber,
content: this.data.content,
involvedDeptId: this.data.involvedDeptId,
involvedDeptName: this.data.involvedDeptName,
attachments: this.data.attachments
}).then(() => {
wx.showToast({
title: '操作成功',
icon: 'success',
duration: 3000
});
setTimeout(() => {
wx.redirectTo({
url: '/pages/myMail/index',
})
}, 1000)
})
},
handleSaveDraft() {
if (!this.data.content) {
this.setData({
contentErrMsg: '请输入信件内容'
})
return
}
if (this.data.content.length < 15) {
this.setData({
contentErrMsg: '信件内容不能少于15个字'
})
return
}
saveDraft({
contactName: this.data.contactName,
contactSex: this.data.contactSex,
contactIdCard: this.data.contactIdCard,
contactPhone: this.data.contactPhone,
code: this.data.code,
smsRequestId: this.data.smsRequestId,
caseNumber: this.data.caseNumber,
content: this.data.content,
involvedDeptId: this.data.involvedDeptId,
involvedDeptName: this.data.involvedDeptName,
attachments: this.data.attachments
}).then(data => {
wx.showToast({
title: '保存成功',
icon: 'success',
duration: 2000
});
setTimeout(() => {
wx.redirectTo({
url: '/pages/myMailDraft/index',
})
}, 1000)
})
},
sendSms() {
const phoneRes = validatorPhone(this.data.contactPhone);
if (phoneRes !== true) {
this.setData({
phoneErrMsg: phoneRes
})
return
}
send(this.data.contactPhone).then(data => {
this.setData({
smsRequestId: data.requestId
})
})
this.setData({
sendBtnDisabled: true,
time: 30
})
let timer = setInterval(() => {
if (this.data.time === 1) {
clearInterval(timer)
this.setData({
sendBtnDisabled: false
})
}
this.setData({
time: this.data.time - 1
})
}, 1000)
},
afterRead(data) {
console.log(data)
data.detail.file.forEach(file => {
this.data.fileList.push({
url: file.tempFilePath,
isImage: true
})
this.setData({
fileList: this.data.fileList
})
upload(file.tempFilePath).then(res => {
this.data.attachments.push({
filepath: res.filepath,
type: 'image',
originFilename: file.tempFilePath.substr(file.tempFilePath.lastIndexOf('/'))
})
this.setData({
attachments: this.data.attachments
})
})
})
},
delFile(event) {
this.data.fileList.splice(event.detail.index, 1)
this.data.attachments.splice(event.detail.index, 1)
this.setData({
fileList: this.data.fileList,
attachments: this.data.attachments
})
}
});