epmet 工作端 小程序
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.

433 lines
12 KiB

import {agencyGridDepttree, getCategoryTree, icEventOldReply} from "../../../../utils/statisticsApi";
const config = require('../../../../utils/config')
Page({
/**
* 页面的初始数据
*/
data: {
tabVal: "0",
category: "",
uploadImageList: [], //图片上传的数组
visible1: false,
visible2: false,
orgOptions: [],
casOptions: [],
catField: {text: 'categoryName', value: 'id', children: 'children'},
orgField: {text: 'agencyName', value: 'agencyId', children: 'subAgencyList'},
id: '',
fileList: [],
timeLimit: [],
operationType: ["0"],
categoryIds:'',
currentDate: new Date().getTime(),
minDate: new Date(2020, 0, 1).getTime(),
maxDate: new Date(2030, 12, 31).getTime(),
form: {
operationType: "0", //处理方式[0:已回复 5、指派 6、完成并回复]
content: "",//转办意见
timeLimit: "",//办结时限
categoryId: "",//事件分类
deptId: "", //指派部门
deptName: "",
categoryList: [],
files: [], //附件
sendMsg: 1, // 这个存储选中值(整数1或0)
sendMsgArray: ['1'] // 默认选中,值为数组['1']
},
categoryTreeData:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
if (options.id) {
this.setData({
id: options.id,
})
}
if (options.categoryIds) {
this.setData({
categoryIds: options.categoryIds,
})
}
this.getCategoryList();
this.getOrgTreeList();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
},
handleChangeType(e) {
this.setData({
tabVal: e.detail.value,
"form.operationType": e.detail.value
})
},
getCategoryList() {
console.log("getCategoryList.......");
let params = {};
getCategoryTree(params).then(res => {
let treeDataNew = this.deepTree(res.data, "children");
// console.log('treeDataNew:'+JSON.stringify(treeDataNew))
this.setData({
casOptions: this.deleteChildren(treeDataNew, "children"),
categoryTreeData:treeDataNew
});
const ids = this.data.categoryIds.split(",");
const categoryPath = this.getCategoryPath(treeDataNew, ids);
console.log("ids:"+ids);
console.log("categoryPath:"+categoryPath);
this.setData({
casOptions: this.deleteChildren(treeDataNew, "children"),
category:this.getCategoryPath(treeDataNew, ids)
});
})
},
getCategoryPath(tree, ids) {
let path = [];
const traverse = (node) => {
// 如果当前节点的id在ids中,添加到路径数组
if (ids.includes(node.id)) {
path.push(node.categoryName);
// 如果当前节点是最后一个id,返回路径
if (node.id === ids[ids.length - 1]) {
return true;
}
}
// 递归遍历子节点
if (node.children) {
for (let child of node.children) {
if (traverse(child)) {
return true; // 找到路径后停止遍历
}
}
}
// 如果当前节点不匹配或者没有找到路径,从路径中移除该节点
if (path[path.length - 1] === node.categoryName) {
path.pop();
}
return false;
};
// 遍历整个树结构,查找路径
for (let node of tree) {
if (traverse(node)) {
break; // 找到路径后停止遍历
}
}
return path.join('/');
},
getOrgTreeList() {
let params = {
agencyId: this.data.agencyId,
purpose: "query"
}
agencyGridDepttree(params).then(res => {
this.setData({
orgOptions: this.deleteChildren([res.data], 'subAgencyList')
})
})
},
//重构树,去除网格
deepTree(arr, children) {
if (Array.isArray(arr) && arr.length > 0) {
return arr.map((item) => {
return {
...item,
[children]:
(item[children] &&
item[children].length > 0 &&
this.deepTree(item[children], children)) ||
null,
};
});
}
},
deleteChildren(node, key) {
node.forEach(item => {
if (key in item && !item[key]) {
delete item[key]
} else if (key in item && item[key].length) {
this.deleteChildren(item[key], key)
}
})
return node
},
onOpen1() {
this.setData({visible1: true})
},
onClose1() {
this.setData({visible1: false})
console.log('onClose1')
},
onConfirm1(e) {
console.log('onConfirm1', e.detail)
let data = e.detail
let params = data.selectedOptions[data.selectedOptions.length - 1]
this.setData({
"form.categoryId": params.id,
"form.categoryList": {...params, children: null},
visible1: false
})
console.log("form.categoryId:"+this.data.form.categoryId);
console.log("form.categoryList:"+JSON.stringify(this.data.form.categoryList));
this.setData({category: data.selectedOptions.map(item => item.categoryName).join('/')})
},
onOpen2() {
this.setData({visible2: true})
},
onClose2() {
this.setData({visible2: false})
},
onChange2(e) {
let data = e.detail
let params = data.selectedOptions[data.selectedOptions.length - 1]
this.setData({
"form.deptId": params.agencyId,
"form.deptName": params.agencyName,
"form.level": params.level
})
this.setData({orgName: data.selectedOptions.map(item => item.agencyName).join('/')})
},
onConfirm2(e) {
let data = e.detail
let params = data.selectedOptions[data.selectedOptions.length - 1]
this.setData({
"form.deptId": params.agencyId,
"form.deptName": params.agencyName,
"form.level": params.level,
visible2: false
})
this.setData({orgName: data.selectedOptions.map(item => item.agencyName).join('/')})
},
afterRead(event) {
const { file } = event.detail;
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
const files = Array.isArray(file) ? file : [file];
files.forEach(fileItem => {
wx.uploadFile({
url: `${config.BASEURL()}oss/file/uploadvariedfile`,
name: 'file',
header: {
'Content-type': 'application/json;charset=UTF-8',
'Authorization': wx.getStorageSync('token')
},
filePath: fileItem.url,
success: (res) => {
let data = JSON.parse(res.data);
console.log("data:" + JSON.stringify(fileItem));
const fileList = this.data.fileList;
fileList.push({
...fileItem,
attachmentUrl: data.data.url,
attachmentName: fileItem.url.split('/').pop(),
attachmentFormat: fileItem.type,
attachmentType: fileItem.type
});
console.log(fileList);
this.setData({ fileList });
},
});
});
},
deleteFile(e) {
console.log(e)
let index = e.detail.index
let fileList = this.data.fileList
fileList.splice(index, 1)
this.setData({
fileList
})
},
openCalendar1() {
console.log("openCalendar1.....")
this.setData({
showDate: true
})
},
closePopup() {
this.setData({ showPopup: false });
},
onCloseDate() {
this.setData({showDate: false});
},
formatDate(date) {
date = new Date(date);
return `${date.getFullYear()}-${date.getMonth() + 1 > 10 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1)}-${date.getDate() > 10 ? date.getDate() : '0' + date.getDate()}`;
},
onInput(event) {
var date = new Date(event.detail);
var year = date.getFullYear();
var month = ("0" + (date.getMonth() + 1)).slice(-2);
var day = ("0" + date.getDate()).slice(-2);
var hour = ("0" + date.getHours()).slice(-2);
var minute = ("0" + date.getMinutes()).slice(-2);
var second = ("0" + date.getSeconds()).slice(-2);
var formattedDateTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
this.setData({
getData:formattedDateTime
})
},
onConfirmDate(e) {
this.setData({
'form.timeLimit': e.detail.label + ':00',
showDate: false,
})
},
// 双向绑定 内容输入框
bindTextareaInput(e) {
this.setData({
'form.content': e.detail.value
})
console.log(this.data.fmData);
},
submitEventReplyInfo(){
console.log("this.data.form:"+this.data.form.content);
if (!this.data.category) {
this.showToast('事件类型不能为空')
return
}
if (!this.data.form.content) {
this.showToast('回复意见不能为空')
return
}
if (!this.data.form.timeLimit && (this.data.tabVal==0 || this.data.tabVal==5)) {
this.showToast('办结时限不能为空')
return
}
if (!this.data.form.deptId && this.data.tabVal==5) {
this.showToast('指派部门不能为空')
return
}
let params = {
...this.data.form,
files: this.data.fileList,
icEventId: this.data.id,
status: this.data.tabVal==="6"?"closed_case":"processing",
// timeLimit: this.data.value1 && this.data.value1.length ? this.data.value1[0] : ""
}
icEventOldReply(params).then(res => {
wx.showToast({
icon: 'success',
title: '操作成功'
})
this.close()
})
console.log(params)
},
close() {
this.triggerEvent('close')
setTimeout(() => {
//返回上一级,关闭当前页面
wx.navigateBack({
delta: 1
})
}, 1000); // 1000毫秒 = 1秒
},
// 代码简化,弹窗统一封装
showToast(title) {
wx.showToast({
title: title,
icon: 'none',
duration: 2000
})
},
sendMsgChange(e) {
const selected = e.detail.length > 0; // 判断复选框是否选中
this.setData({
'form.sendMsg': selected ? 1 : 0, // 如果选中则值为1,否则为0
'form.sendMsgArray': selected ? ['1'] : [] // 更新sendMsgArray
});
},
})