316 lines
8.4 KiB
JavaScript
Raw Normal View History

2024-07-30 16:33:21 +08:00
const app = getApp()
2024-08-15 14:07:00 +08:00
import {
checkIsImg
} from "../../../../utils/util.js"
2024-08-08 09:16:37 +08:00
import {
2024-08-13 17:39:38 +08:00
getDetailRq,
getStatusName
} from "../../../../api/repair/repair.js"
2024-08-08 09:16:37 +08:00
2024-07-30 16:33:21 +08:00
Page({
/**
* 页面的初始数据
*/
data: {
IMG_NAME: app.IMG_NAME,
2024-08-14 11:44:30 +08:00
title: '详情',
2024-08-15 16:02:52 +08:00
userDetail: {},
2024-08-08 09:16:37 +08:00
id: '',
detail: {},
2024-08-13 17:39:38 +08:00
files: {},
2024-08-20 11:20:42 +08:00
log: {
feedback: {}, //反馈
invalid: {}, // 无效原因
},
2024-08-08 10:42:56 +08:00
innerAudioContext: null, // 音频对象
innerAudioContextIsPlay: false, // 音频对象-是否播放
2024-08-15 16:02:52 +08:00
operatorBtn: {
invalid: false, //无效申请
affirm: false, // 确认损坏
feedback: false, // 提交反馈
again: false, // 重新派单
evaluate: false, // 评价
}
2024-07-30 16:33:21 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
2024-08-08 09:16:37 +08:00
console.log('onLoad', options);
let _this = this
2024-08-15 16:02:52 +08:00
let userDetail = wx.getStorageSync('user')
2024-08-08 09:16:37 +08:00
_this.setData({
2024-08-15 16:02:52 +08:00
...options,
userDetail
2024-08-08 09:16:37 +08:00
})
2024-07-30 16:33:21 +08:00
},
2024-08-08 09:16:37 +08:00
back() {
2024-08-15 14:59:35 +08:00
app.selfBackPage(1)
2024-07-30 16:33:21 +08:00
},
2024-08-08 09:16:37 +08:00
getDetail(id) {
2024-08-08 10:42:56 +08:00
let _this = this
2024-08-13 17:39:38 +08:00
getDetailRq({
id
}).then(res => {
console.log("getDetailRq", res);
// 详情
let detail = res.repair
detail.statusName = getStatusName(detail.status)
// 附件
let files = res.files
2024-08-14 11:44:30 +08:00
files.repair = files.repair.map(item => {
item.url = app.IMG_NAME + item.url
2024-08-13 17:39:38 +08:00
return item
})
2024-08-15 09:58:01 +08:00
files.feedback = files.feedback.map(item => {
item.url = app.IMG_NAME + item.url
return item
})
files.eval = files.eval.map(item => {
item.url = app.IMG_NAME + item.url
return item
})
2024-08-14 11:44:30 +08:00
files.voice = files.voice.map(item => {
item.url = app.IMG_NAME + item.url
2024-08-13 17:39:38 +08:00
return item
})
2024-08-14 15:12:02 +08:00
// 日志
2024-08-20 11:20:42 +08:00
let log = _this.data.log
// 派单反馈
if (detail.status == 3) {
log.feedback = _this.findLog(res.log, detail.logId, 1)
}
// 无效原因
if (detail.status == 11) {
log.invalid = _this.findLog(res.log, detail.logId, 1)
2024-08-14 15:12:02 +08:00
}
if (detail.status == 1) {
log.back = _this.findLog(res.log, detail.logId, 1)
}
console.log(log)
2024-08-20 11:20:42 +08:00
_this.setData({
log
})
2024-08-15 14:07:00 +08:00
// 第一张图片
let firstImg = files.repair.find(item => checkIsImg(item.url))
if (firstImg) {
detail.visibleImg = firstImg.url
} else {
detail.visibleImg = app.IMG_NAME + '/profile/static/repair/index/noneImg.png'
}
2024-08-15 16:02:52 +08:00
//
2024-08-08 10:42:56 +08:00
_this.setData({
2024-08-13 17:39:38 +08:00
detail,
files
2024-08-08 10:42:56 +08:00
})
2024-08-15 16:02:52 +08:00
// 初始化按钮
_this.initOperatorBtn()
})
},
2024-08-20 11:20:42 +08:00
findLog(logs, logId, step) {
let log = logs.find(item => item.id == logId)
if (log) {
for (let i = 0; i < step; i++) {
log = logs.find(item => item.id == log.pid)
if (!log) {
return {}
}
}
return log
} else {
return {}
}
},
2024-08-15 16:02:52 +08:00
// 初始化按钮
initOperatorBtn() {
console.log('initOperatorBtn', 111);
let _this = this
let userDetail = _this.data.userDetail
let detail = _this.data.detail
let operatorBtn = _this.data.operatorBtn
// 登录用户id
let loginUserId = userDetail.id
// 角色类型
let dataType = userDetail.dataType
2024-08-15 16:04:51 +08:00
// 订单状态
let status = detail.status
2024-08-15 16:02:52 +08:00
//
2024-08-20 11:44:05 +08:00
// 角色类型 1.普通用户3派单员5维修工7管理员, 9楼层
2024-08-15 16:02:52 +08:00
// 订单状态 1 待派单,3 重新派单,5 已派单,7 处理中, 9已完成 待评价, 11 已关闭 13 已评价
//
if (status == 1) { // 1 待派单
2024-08-15 16:25:45 +08:00
if ((dataType == 3 && detail.typeId == userDetail.typeId) || dataType == 7) { // 派单员 or 管理员
operatorBtn.invalid = true // 无效申请
2024-08-15 16:02:52 +08:00
operatorBtn.affirm = true // 确认损坏
operatorBtn.feedback = true // 提交反馈
}
}
if (status == 3) { // 3 重新派单
if (dataType == 7) { // 管理员
operatorBtn.again = true //重新派单
}
}
if (status == 9) { // 9已完成 待评价
if (loginUserId == detail.createBy) { // 创建报修单的人才能评价
operatorBtn.evaluate = true //评价
}
}
_this.setData({
operatorBtn
2024-08-08 09:16:37 +08:00
})
},
2024-08-08 10:42:56 +08:00
// 播放语音
startAudio() {
console.log('startAudio');
let _this = this
// 获取innerAudioContext实例
let innerAudioContext = _this.data.innerAudioContext
let innerAudioContextIsPlay = _this.data.innerAudioContextIsPlay
if (!innerAudioContext) {
// 全局设置播放声音
wx.setInnerAudioOption({
obeyMuteSwitch: false
});
innerAudioContext = wx.createInnerAudioContext()
// 设置音频文件的路径
2024-08-13 17:39:38 +08:00
innerAudioContext.src = _this.data.files.voice[0].url
2024-08-08 10:42:56 +08:00
innerAudioContextIsPlay = false
innerAudioContext.onEnded(() => {
2024-08-16 14:20:57 +08:00
console.log('innerAudioContext.onEnded', _this.data.files.voice[0].url);
2024-08-08 10:42:56 +08:00
_this.setData({
innerAudioContextIsPlay: false
})
})
2024-08-16 14:20:57 +08:00
innerAudioContext.onError((errMsg, errCode) => {
console.log('innerAudioContext.onError', errMsg, errCode);
})
2024-08-08 10:42:56 +08:00
}
if (innerAudioContextIsPlay) { // 播放中
innerAudioContext.stop()
innerAudioContextIsPlay = false
} else { // 未播放
innerAudioContext.play()
innerAudioContextIsPlay = true
}
//
_this.setData({
innerAudioContext,
innerAudioContextIsPlay
})
},
2024-08-08 09:16:37 +08:00
// 确认损坏
jumpAffirm() {
2024-08-14 10:21:46 +08:00
let _this = this
2024-07-30 16:33:21 +08:00
wx.navigateTo({
2024-08-14 10:21:46 +08:00
url: `/pages/reportRepair/assign/affirm/affirm?id=${_this.data.id}`,
2024-07-30 16:33:21 +08:00
})
},
// 提交反馈
2024-08-08 09:16:37 +08:00
jumpFeedback() {
2024-08-14 10:21:46 +08:00
let _this = this
2024-07-30 16:33:21 +08:00
wx.navigateTo({
2024-08-14 10:21:46 +08:00
url: `/pages/reportRepair/assign/feedback/feedback?id=${_this.data.id}`,
2024-07-30 16:33:21 +08:00
})
},
// 无效
2024-08-14 11:44:30 +08:00
jumpInvalid() {
2024-08-14 10:21:46 +08:00
let _this = this
wx.navigateTo({
url: `/pages/reportRepair/assign/nullify/nullify?id=${_this.data.id}`,
})
2024-07-30 16:33:21 +08:00
},
2024-08-14 11:44:30 +08:00
// 重新派单
jumpAgain() {
let _this = this
wx.navigateTo({
url: `/pages/reportRepair/assign/again/again?id=${_this.data.id}`,
})
},
2024-08-15 14:07:00 +08:00
// 评价
jumpEvaluate() {
let _this = this
wx.navigateTo({
url: `/pages/reportRepair/assign/evaluate/evaluate?id=${_this.data.id}`,
})
},
2024-07-30 16:33:21 +08:00
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
2024-08-16 10:33:06 +08:00
let _this = this
_this.getDetail(_this.data.id)
2024-07-30 16:33:21 +08:00
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
2024-08-15 14:07:00 +08:00
console.log('onShareAppMessage');
let _this = this;
let obj = _this.data.detail
2024-08-20 14:48:02 +08:00
let title = `${obj.address + '/' + obj.floor}${obj.room}${obj.repairName}`
2024-08-15 14:07:00 +08:00
//
let param = {
2024-08-20 14:48:02 +08:00
title,
2024-08-15 14:07:00 +08:00
path: `/pages/reportRepair/assign/detail/detail?id=${obj.id}`,
imageUrl: obj.visibleImg,
}
console.log('onShareAppMessage', param);
return param;
2024-07-30 16:33:21 +08:00
}
})