Browse Source

问题处理 权限

master
巴林闲侠 2 years ago
parent
commit
2f9e3bba0b
  1. 5
      api/app/lib/controllers/organization/user.js
  2. 47
      api/app/lib/controllers/patrolManage/patrolRecord.js
  3. 1
      weapp/common.js
  4. 105
      weapp/package/troubleshooting/index.js
  5. 42
      weapp/package/troubleshooting/shootingForm/index.js

5
api/app/lib/controllers/organization/user.js

@ -396,12 +396,17 @@ async function getStructuresUsers (ctx, next) {
where: {},
attributes: ['id', 'name',],
order: [['id', 'asc']],
include: [{
model: models.Point,
attributes: ['id', 'name',],
}]
})
const rslt = [];
structs.map(s => {
rslt.push({
id: s.id,
name: s.name,
points: s.points,
users: userRes.filter(x => x.structure && x.structure.find(v => v == s.id)).map(d => { return { id: d.id, name: d.name, department: d.department } })
});
})

47
api/app/lib/controllers/patrolManage/patrolRecord.js

@ -1,5 +1,7 @@
'use strict';
const moment = require("moment");
async function findPatrolRecord (ctx, next) {
let rslt = [];
let error = { name: 'FindError', message: '获取巡检记录失败' };
@ -136,7 +138,7 @@ async function findPatrolRecord (ctx, next) {
}
}
async function findPatrolRecordUnlicensed(ctx, next) {
async function findPatrolRecordUnlicensed (ctx, next) {
let rslt = [];
let error = { name: 'FindError', message: '获取巡检记录失败' };
try {
@ -212,42 +214,59 @@ async function getPatrolRecordIssueHandle (ctx) {
const { models } = ctx.fs.dc;
const { userId, userInfo } = ctx.fs.api
const { type, } = ctx.query
const { type, pointId, startTime, endTime } = ctx.query
let findOption = {
where: {
$or: []
},
include: [{
model: models.PatrolRecord
model: models.PatrolRecord,
where: {
}
}]
}
if (type == 'backlog') {
// 待办
// let stateArr = []
if (pointId) {
findOption.include[0].where.pointId = { $in: pointId.split(',') }
}
if (startTime && endTime) {
findOption.where.createTime = {
$between: [moment(parseInt(startTime)).format(), moment(parseInt(endTime)).format()]
}
}
let isSuperA = userInfo.username == 'SuperAdmin'
let focusStruct = userInfo.structure || []
if (!isSuperA) {
findOption.include[0].where.points = {
project: {
id: { $in: focusStruct }
}
}
}
if (type == 'backlog') { // 待办
if (userInfo && userInfo.userResources.includes('ZHIDINGJIHUA')) {
// stateArr.push(1)
findOption.where['$or'].push({ state: 1 })
findOption.where['$or'].push({ state: 3 })
}
// 有审批权限且关注此结构物
// findOption.where['$or'].push({ state: 2, approvePerson: { id: userId } })
if (userInfo && userInfo.userResources.includes('SHENHE')) {
findOption.where['$or'].push({ state: 2 })
}
findOption.where['$or'].push({ state: 4, repairPerson: { id: userId } })
findOption.where['$or'].push({ state: 5, checkPerson: { id: userId } })
findOption.where['$or'].push({ state: 7, repairPerson: { id: userId } })
findOption.where = {
...findOption.where,
}
} else if (type == 'haveDone') {
// 已办
findOption.where['$or'].push({ state: { $notIn: [1, 2] }, creator: { id: userId } })
findOption.where['$or'].push({ state: { $gt: 2 }, approvePerson: { id: userId } })
findOption.where['$or'].push({ state: { $gt: 4, $ne: 7 }, repairPerson: { id: userId } })
findOption.where['$or'].push({ state: { $gt: 5 }, checkPerson: { id: userId } })
findOption.where = {
...findOption.where,
}
}
const res = await models.PatrolRecordIssueHandle.findAll(findOption)

1
weapp/common.js

@ -3,7 +3,6 @@ const { baseUrl } = app.globalData;
// 全局配置 请求拦截, 长时间
const buildRequest = (type, url, data) => {
console.log(type, url, data);
return new Promise((resolve, reject) => {
if (url.indexOf('token') == -1) {
let token = wx.getStorageSync('token');

105
weapp/package/troubleshooting/index.js

@ -1,5 +1,5 @@
// package/bindTroubleshooting/index.js
import { getPatrolRecordIssueHandle } from "../../utils/getApiUrl";
import { getPatrolRecordIssueHandle, getStructuresUsers } from "../../utils/getApiUrl";
import { Request } from "../../common";
const moment = require("../../utils/moment");
@ -9,16 +9,21 @@ Page({
* 页面的初始数据
*/
data: {
userInfo: wx.getStorageSync("userInfo"),
//
dataList: [],
currentTab: '0',
// 筛选选择
structList: ['a', 'b', 'c'],
structResult: ['a', 'b'],
pointList: ['a', 'b', 'c'],
pointResult: ['a', 'b'],
structList: [],
structResult: [],
pointList: [],
pointResult: [],
// 时间筛选
startTime: '',
endTime: ''
endTime: '',
//
timeSelectedUnrealFlag: true,
powerCheckDetail: false
},
// 顶部tab切换
@ -45,7 +50,6 @@ Page({
Request.get(getPatrolRecordIssueHandle(), {
...params,
}).then(res => {
console.log(res);
this.setData({
dataList: res.map(r => {
return {
@ -59,9 +63,33 @@ Page({
// 筛选选择
onStructChange (event) {
const { structList, pointList } = this.data
let nextPointList = []
for (let s of structList) {
if (event.detail.some(ed => ed == s.id)) {
// 选了这个结构物
for (let sp of s.points) {
let corPoint = pointList.find(pl => pl.id == sp.id)
if (corPoint) {
// 有这个点
nextPointList.push({
...sp,
selected: corPoint.selected
})
} else {
nextPointList.push({
...sp,
selected: true
})
}
}
}
}
this.setData({
structResult: event.detail,
});
pointList: nextPointList,
})
},
structToggle (event) {
@ -77,31 +105,63 @@ Page({
},
pointToggle (event) {
const { index } = event.currentTarget.dataset;
const checkbox = this.selectComponent(`.checkboxes-point-${index}`);
checkbox.toggle();
const { index, id } = event.currentTarget.dataset;
const checkbox = this.selectComponent(`.checkboxes-point-${id}`);
// checkbox.toggle();
const { pointList } = this.data
let pointList_ = JSON.parse(JSON.stringify(pointList))
pointList_[index].selected = !pointList_[index].selected
this.setData({
pointList: pointList_
})
},
noop () { },
// 时间选择
onStartTimeChange (event) {
const { timeSelectedUnrealFlag, startTime, endTime } = this.data
if (timeSelectedUnrealFlag && event.detail == 1640966400000) {
return
}
this.setData({
startTime: event.detail,
endTime: endTime ? endTime : 1640966400000
});
},
onEndTimeChange (event) {
const { timeSelectedUnrealFlag, startTime, endTime } = this.data
if (timeSelectedUnrealFlag && event.detail == 1640966400000) {
return
}
this.setData({
startTime: startTime ? startTime : 1640966400000,
endTime: event.detail,
});
},
search () {
console.log(this.data);
onDropDownClose () {
const { currentTab, startTime, endTime, pointList, structResult } = this.data
this.getData({
type: currentTab == '0' ? 'backlog' : 'haveDone',
startTime,
endTime,
pointId: pointList.length ? (() => {
let sendPointId = []
for (let p of pointList) {
if (p.selected) {
sendPointId.push(p.id)
}
}
if (!sendPointId.length) {
sendPointId.push('-1')
}
return sendPointId.join(',')
})() : structResult.length ? '-1' : ''
})
},
// 页面跳转
toShootingForm (e) {
console.log(e);
const { shootingid } = e.currentTarget.dataset
wx.navigateTo({
url: '/package/troubleshooting/shootingForm/index?shootingid=' + shootingid + '&tabIndex=' + this.data.currentTab,
@ -112,17 +172,30 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad (options) {
Request.get(getStructuresUsers(), {}).then(res => {
this.setData({
structList: res
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady () {
console.log(123);
this.getData({
type: 'backlog'
});
setTimeout(() => {
this.setData({
timeSelectedUnrealFlag: false
})
}, 1000)
if (this.data.userInfo && this.data.userInfo.userResources.includes('CHAKANXIANGQING') || this.data.userInfo.username == 'SuperAdmin') {
this.setData({
powerCheckDetail: true
})
}
},
/**

42
weapp/package/troubleshooting/shootingForm/index.js

@ -59,7 +59,6 @@ Page({
Request.get(getStructuresUsers(), {})
]
).then(res => {
console.log(res, 222);
const [issue, strucUser] = res
const nextData = {
...issue,
@ -81,7 +80,6 @@ Page({
}
}
}
console.log(nextData);
this.setData({
data: nextData,
isPlanState: tabIndex == 0 && (issue.state == 1 || issue.state == 3),
@ -100,7 +98,6 @@ Page({
})
if (issue.state > 1) {
let maintenancePersonIndex = focusPerson.findIndex(f => f.id == issue.repairPerson.id)
console.log(maintenancePersonIndex, issue.startTime, moment(issue.startTime).format('YYYY-MM-DD HH:mm:ss'));
this.setData({
maintenancePersonIndex: maintenancePersonIndex,
maintenancePersonDepartmentShow: maintenancePersonIndex >= 0 ? focusPerson[maintenancePersonIndex].department.name : '',
@ -143,7 +140,6 @@ Page({
},
onMaintenancePersonPopupChange (e) {
console.log(e);
if (e.target.dataset.type == 'zhijian') {
this.setData({
qualityPersonIndex: e.detail.value
@ -165,7 +161,6 @@ Page({
closePlanStartTimePopup (e) {
this.setData({ planStartTimePopupShow: false })
console.log(e.target, this.data.planStartTime);
if (e.target.dataset.option == 'cancel') {
// this.setData({ planStartTime: '' })
} else if (e.target.dataset.option == 'confirmed') {
@ -176,7 +171,6 @@ Page({
},
onPlanStartTimeChange (event) {
console.log(event);
this.setData({
planStartTime: event.detail,
})
@ -204,7 +198,6 @@ Page({
},
onInputChange (e) {
console.log(e);
this.setData({
[e.target.dataset.type]: e.detail.value
})
@ -212,7 +205,6 @@ Page({
// 预览图片
previewImg: function (e) {
console.log(e);
const { index, itemindex, type } = e.currentTarget.dataset
const imgs = type == 'point' ? this.data.data.PatrolRecord.points.inspectContent[itemindex].imgs : this.data[type];
const newImgs = imgs.map(i => this.data.imgServer + i);
@ -281,10 +273,8 @@ Page({
success: (resp) => {
wx.hideLoading();
success++;
console.log(resp);
let str = JSON.parse(resp.data) // 返回的结果,可能不同项目结果不一样
str = str.uploaded
console.log(str);
if (imgs.length >= 20) {
return false;
} else {
@ -316,7 +306,6 @@ Page({
// 删除图片
deleteImg: function (e) {
console.log(e);
const { type, index } = e.currentTarget.dataset
const imgs = this.data[type]
imgs.splice(index, 1);
@ -326,12 +315,11 @@ Page({
},
confirm (e) {
console.log(e);
const { approve } = e.target.dataset
const { state } = this.data.data
const {
shootingid, focusPerson,
maintenancePersonIndex, maintenancePersonDepartmentShow, qualityPersonIndex, planStartTime, planEndTime, maintenanceRequirement,
maintenancePersonIndex, maintenancePersonDepartmentShow, qualityPersonIndex, planStartTime, planEndTime, planStartTimeShow, planEndTimeShow, maintenanceRequirement,
userInfo, planApproval,
repair, repairImgs,
checkDesc, checkImgs
@ -350,6 +338,14 @@ Page({
endTime: moment(planEndTime).format(),
repairAsk: maintenanceRequirement,
}
if (!this.mustInput({
repairPerson: focusPerson[maintenancePersonIndex],
checkPerson: focusPerson[qualityPersonIndex],
startTime: planStartTimeShow,
endTime: planStartTimeShow,
})) {
return
}
successMsg = '制定完成'
} else if (state == 2) {
confirmData = {
@ -401,6 +397,26 @@ Page({
})
},
mustInput (field) {
let fieldMap = {
repairPerson: '维修人',
checkPerson: '质检人',
startTime: '计划开始时间',
endTime: '计划结束时间',
}
let fieldKeys = Object.keys(field)
for (let k of fieldKeys) {
if (!field[k]) {
wx.showToast({
title: `请填写/选择 ${fieldMap[k]}`,
icon: 'none'
})
return false
}
}
return true
},
/**
* 生命周期函数--监听页面初次渲染完成
*/

Loading…
Cancel
Save