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: {}, where: {},
attributes: ['id', 'name',], attributes: ['id', 'name',],
order: [['id', 'asc']], order: [['id', 'asc']],
include: [{
model: models.Point,
attributes: ['id', 'name',],
}]
}) })
const rslt = []; const rslt = [];
structs.map(s => { structs.map(s => {
rslt.push({ rslt.push({
id: s.id, id: s.id,
name: s.name, 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 } }) 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'; 'use strict';
const moment = require("moment");
async function findPatrolRecord (ctx, next) { async function findPatrolRecord (ctx, next) {
let rslt = []; let rslt = [];
let error = { name: 'FindError', message: '获取巡检记录失败' }; 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 rslt = [];
let error = { name: 'FindError', message: '获取巡检记录失败' }; let error = { name: 'FindError', message: '获取巡检记录失败' };
try { try {
@ -212,42 +214,59 @@ async function getPatrolRecordIssueHandle (ctx) {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { userId, userInfo } = ctx.fs.api const { userId, userInfo } = ctx.fs.api
const { type, } = ctx.query const { type, pointId, startTime, endTime } = ctx.query
let findOption = { let findOption = {
where: { where: {
$or: [] $or: []
}, },
include: [{ include: [{
model: models.PatrolRecord model: models.PatrolRecord,
where: {
}
}] }]
} }
if (type == 'backlog') { if (pointId) {
// 待办 findOption.include[0].where.pointId = { $in: pointId.split(',') }
// let stateArr = [] }
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')) { if (userInfo && userInfo.userResources.includes('ZHIDINGJIHUA')) {
// stateArr.push(1)
findOption.where['$or'].push({ state: 1 }) findOption.where['$or'].push({ state: 1 })
findOption.where['$or'].push({ state: 3 }) 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: 4, repairPerson: { id: userId } })
findOption.where['$or'].push({ state: 5, checkPerson: { id: userId } }) findOption.where['$or'].push({ state: 5, checkPerson: { id: userId } })
findOption.where['$or'].push({ state: 7, repairPerson: { id: userId } }) findOption.where['$or'].push({ state: 7, repairPerson: { id: userId } })
findOption.where = {
...findOption.where,
}
} else if (type == 'haveDone') { } else if (type == 'haveDone') {
// 已办 // 已办
findOption.where['$or'].push({ state: { $notIn: [1, 2] }, creator: { id: userId } }) 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: 2 }, approvePerson: { id: userId } })
findOption.where['$or'].push({ state: { $gt: 4, $ne: 7 }, repairPerson: { 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['$or'].push({ state: { $gt: 5 }, checkPerson: { id: userId } })
findOption.where = {
...findOption.where,
}
} }
const res = await models.PatrolRecordIssueHandle.findAll(findOption) const res = await models.PatrolRecordIssueHandle.findAll(findOption)

1
weapp/common.js

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

105
weapp/package/troubleshooting/index.js

@ -1,5 +1,5 @@
// package/bindTroubleshooting/index.js // package/bindTroubleshooting/index.js
import { getPatrolRecordIssueHandle } from "../../utils/getApiUrl"; import { getPatrolRecordIssueHandle, getStructuresUsers } from "../../utils/getApiUrl";
import { Request } from "../../common"; import { Request } from "../../common";
const moment = require("../../utils/moment"); const moment = require("../../utils/moment");
@ -9,16 +9,21 @@ Page({
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
userInfo: wx.getStorageSync("userInfo"),
//
dataList: [], dataList: [],
currentTab: '0', currentTab: '0',
// 筛选选择 // 筛选选择
structList: ['a', 'b', 'c'], structList: [],
structResult: ['a', 'b'], structResult: [],
pointList: ['a', 'b', 'c'], pointList: [],
pointResult: ['a', 'b'], pointResult: [],
// 时间筛选 // 时间筛选
startTime: '', startTime: '',
endTime: '' endTime: '',
//
timeSelectedUnrealFlag: true,
powerCheckDetail: false
}, },
// 顶部tab切换 // 顶部tab切换
@ -45,7 +50,6 @@ Page({
Request.get(getPatrolRecordIssueHandle(), { Request.get(getPatrolRecordIssueHandle(), {
...params, ...params,
}).then(res => { }).then(res => {
console.log(res);
this.setData({ this.setData({
dataList: res.map(r => { dataList: res.map(r => {
return { return {
@ -59,9 +63,33 @@ Page({
// 筛选选择 // 筛选选择
onStructChange (event) { 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({ this.setData({
structResult: event.detail, structResult: event.detail,
}); pointList: nextPointList,
})
}, },
structToggle (event) { structToggle (event) {
@ -77,31 +105,63 @@ Page({
}, },
pointToggle (event) { pointToggle (event) {
const { index } = event.currentTarget.dataset; const { index, id } = event.currentTarget.dataset;
const checkbox = this.selectComponent(`.checkboxes-point-${index}`); const checkbox = this.selectComponent(`.checkboxes-point-${id}`);
checkbox.toggle(); // checkbox.toggle();
const { pointList } = this.data
let pointList_ = JSON.parse(JSON.stringify(pointList))
pointList_[index].selected = !pointList_[index].selected
this.setData({
pointList: pointList_
})
}, },
noop () { }, noop () { },
// 时间选择 // 时间选择
onStartTimeChange (event) { onStartTimeChange (event) {
const { timeSelectedUnrealFlag, startTime, endTime } = this.data
if (timeSelectedUnrealFlag && event.detail == 1640966400000) {
return
}
this.setData({ this.setData({
startTime: event.detail, startTime: event.detail,
endTime: endTime ? endTime : 1640966400000
}); });
}, },
onEndTimeChange (event) { onEndTimeChange (event) {
const { timeSelectedUnrealFlag, startTime, endTime } = this.data
if (timeSelectedUnrealFlag && event.detail == 1640966400000) {
return
}
this.setData({ this.setData({
startTime: startTime ? startTime : 1640966400000,
endTime: event.detail, endTime: event.detail,
}); });
}, },
search () { onDropDownClose () {
console.log(this.data); 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) { toShootingForm (e) {
console.log(e);
const { shootingid } = e.currentTarget.dataset const { shootingid } = e.currentTarget.dataset
wx.navigateTo({ wx.navigateTo({
url: '/package/troubleshooting/shootingForm/index?shootingid=' + shootingid + '&tabIndex=' + this.data.currentTab, url: '/package/troubleshooting/shootingForm/index?shootingid=' + shootingid + '&tabIndex=' + this.data.currentTab,
@ -112,17 +172,30 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad (options) { onLoad (options) {
Request.get(getStructuresUsers(), {}).then(res => {
this.setData({
structList: res
})
})
}, },
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady () { onReady () {
console.log(123);
this.getData({ this.getData({
type: 'backlog' 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(), {}) Request.get(getStructuresUsers(), {})
] ]
).then(res => { ).then(res => {
console.log(res, 222);
const [issue, strucUser] = res const [issue, strucUser] = res
const nextData = { const nextData = {
...issue, ...issue,
@ -81,7 +80,6 @@ Page({
} }
} }
} }
console.log(nextData);
this.setData({ this.setData({
data: nextData, data: nextData,
isPlanState: tabIndex == 0 && (issue.state == 1 || issue.state == 3), isPlanState: tabIndex == 0 && (issue.state == 1 || issue.state == 3),
@ -100,7 +98,6 @@ Page({
}) })
if (issue.state > 1) { if (issue.state > 1) {
let maintenancePersonIndex = focusPerson.findIndex(f => f.id == issue.repairPerson.id) 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({ this.setData({
maintenancePersonIndex: maintenancePersonIndex, maintenancePersonIndex: maintenancePersonIndex,
maintenancePersonDepartmentShow: maintenancePersonIndex >= 0 ? focusPerson[maintenancePersonIndex].department.name : '', maintenancePersonDepartmentShow: maintenancePersonIndex >= 0 ? focusPerson[maintenancePersonIndex].department.name : '',
@ -143,7 +140,6 @@ Page({
}, },
onMaintenancePersonPopupChange (e) { onMaintenancePersonPopupChange (e) {
console.log(e);
if (e.target.dataset.type == 'zhijian') { if (e.target.dataset.type == 'zhijian') {
this.setData({ this.setData({
qualityPersonIndex: e.detail.value qualityPersonIndex: e.detail.value
@ -165,7 +161,6 @@ Page({
closePlanStartTimePopup (e) { closePlanStartTimePopup (e) {
this.setData({ planStartTimePopupShow: false }) this.setData({ planStartTimePopupShow: false })
console.log(e.target, this.data.planStartTime);
if (e.target.dataset.option == 'cancel') { if (e.target.dataset.option == 'cancel') {
// this.setData({ planStartTime: '' }) // this.setData({ planStartTime: '' })
} else if (e.target.dataset.option == 'confirmed') { } else if (e.target.dataset.option == 'confirmed') {
@ -176,7 +171,6 @@ Page({
}, },
onPlanStartTimeChange (event) { onPlanStartTimeChange (event) {
console.log(event);
this.setData({ this.setData({
planStartTime: event.detail, planStartTime: event.detail,
}) })
@ -204,7 +198,6 @@ Page({
}, },
onInputChange (e) { onInputChange (e) {
console.log(e);
this.setData({ this.setData({
[e.target.dataset.type]: e.detail.value [e.target.dataset.type]: e.detail.value
}) })
@ -212,7 +205,6 @@ Page({
// 预览图片 // 预览图片
previewImg: function (e) { previewImg: function (e) {
console.log(e);
const { index, itemindex, type } = e.currentTarget.dataset const { index, itemindex, type } = e.currentTarget.dataset
const imgs = type == 'point' ? this.data.data.PatrolRecord.points.inspectContent[itemindex].imgs : this.data[type]; const imgs = type == 'point' ? this.data.data.PatrolRecord.points.inspectContent[itemindex].imgs : this.data[type];
const newImgs = imgs.map(i => this.data.imgServer + i); const newImgs = imgs.map(i => this.data.imgServer + i);
@ -281,10 +273,8 @@ Page({
success: (resp) => { success: (resp) => {
wx.hideLoading(); wx.hideLoading();
success++; success++;
console.log(resp);
let str = JSON.parse(resp.data) // 返回的结果,可能不同项目结果不一样 let str = JSON.parse(resp.data) // 返回的结果,可能不同项目结果不一样
str = str.uploaded str = str.uploaded
console.log(str);
if (imgs.length >= 20) { if (imgs.length >= 20) {
return false; return false;
} else { } else {
@ -316,7 +306,6 @@ Page({
// 删除图片 // 删除图片
deleteImg: function (e) { deleteImg: function (e) {
console.log(e);
const { type, index } = e.currentTarget.dataset const { type, index } = e.currentTarget.dataset
const imgs = this.data[type] const imgs = this.data[type]
imgs.splice(index, 1); imgs.splice(index, 1);
@ -326,12 +315,11 @@ Page({
}, },
confirm (e) { confirm (e) {
console.log(e);
const { approve } = e.target.dataset const { approve } = e.target.dataset
const { state } = this.data.data const { state } = this.data.data
const { const {
shootingid, focusPerson, shootingid, focusPerson,
maintenancePersonIndex, maintenancePersonDepartmentShow, qualityPersonIndex, planStartTime, planEndTime, maintenanceRequirement, maintenancePersonIndex, maintenancePersonDepartmentShow, qualityPersonIndex, planStartTime, planEndTime, planStartTimeShow, planEndTimeShow, maintenanceRequirement,
userInfo, planApproval, userInfo, planApproval,
repair, repairImgs, repair, repairImgs,
checkDesc, checkImgs checkDesc, checkImgs
@ -350,6 +338,14 @@ Page({
endTime: moment(planEndTime).format(), endTime: moment(planEndTime).format(),
repairAsk: maintenanceRequirement, repairAsk: maintenanceRequirement,
} }
if (!this.mustInput({
repairPerson: focusPerson[maintenancePersonIndex],
checkPerson: focusPerson[qualityPersonIndex],
startTime: planStartTimeShow,
endTime: planStartTimeShow,
})) {
return
}
successMsg = '制定完成' successMsg = '制定完成'
} else if (state == 2) { } else if (state == 2) {
confirmData = { 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