257 lines
5.6 KiB
JavaScript
Raw Normal View History

2024-07-30 17:43:32 +08:00
const app = getApp()
2024-08-14 15:12:02 +08:00
import Notify from '@vant/weapp/notify/notify';
2024-08-14 12:00:14 +08:00
import {
2024-08-14 15:12:02 +08:00
deviceTypeListRq,
deviceListRq,
2024-08-14 12:00:14 +08:00
getDetailRq,
2024-08-14 15:12:02 +08:00
getStatusName,
flowHandleRq
2024-08-14 12:00:14 +08:00
} from "../../../../api/repair/repair.js"
2024-07-30 17:43:32 +08:00
Page({
/**
* 页面的初始数据
*/
data: {
IMG_NAME: app.IMG_NAME,
2024-08-14 12:00:14 +08:00
id: '',
detail: {},
2024-08-14 15:12:02 +08:00
currentLog: {},
typeVisible: false,
typeColumns: [{
values: [],
className: 'column1',
},
{
values: [],
className: 'column2',
},
],
"typeId": null, //故障类型
"typeName": "", //故障名称
"deviceId": null, //设备
"deviceName": "", //设备名称
2024-07-30 17:43:32 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
2024-08-14 12:00:14 +08:00
console.log('onLoad', options);
let _this = this
_this.setData({
...options
})
_this.getDetail(options.id)
2024-08-14 15:12:02 +08:00
// 查询设备类型
_this.queryDeviceType()
2024-07-30 17:43:32 +08:00
},
2024-08-14 15:12:02 +08:00
back() {
2024-07-30 17:43:32 +08:00
wx.navigateBack()
},
2024-08-14 12:00:14 +08:00
getDetail(id) {
let _this = this
getDetailRq({
id
}).then(res => {
console.log("getDetailRq", res);
// 详情
let detail = res.repair
detail.statusName = getStatusName(detail.status)
2024-08-14 15:12:02 +08:00
// 日志
if (detail.logId) {
let firstLog = res.log.find(item => item.id == detail.logId)
if (firstLog) {
let preLog = res.log.find(item => item.id == firstLog.pid)
_this.setData({
currentLog: preLog
})
}
}
2024-08-14 12:00:14 +08:00
_this.setData({
detail,
})
})
},
2024-08-14 15:12:02 +08:00
showType() {
this.setData({
typeVisible: true,
2024-07-30 17:43:32 +08:00
})
},
2024-08-14 15:12:02 +08:00
hideType() {
this.setData({
typeVisible: false,
})
},
2024-07-30 17:43:32 +08:00
2024-08-14 15:12:02 +08:00
// 查询设备类型
queryDeviceType() {
let _this = this
deviceTypeListRq().then(res => {
console.log('deviceTypeListRq', res);
let list = res.rows.map(item => {
return {
id: item.id,
text: item.name
}
})
let typeColumns = _this.data.typeColumns
typeColumns[0].values = list
_this.setData({
typeColumns
})
// 查询设备
_this.queryDevice(list[0].id)
2024-07-30 17:43:32 +08:00
})
},
2024-08-14 15:12:02 +08:00
// 查询设备
queryDevice(id) {
let _this = this
deviceListRq({
typeId: id
}).then(res => {
console.log('deviceListRq', res);
let list = res.rows.map(item => {
return {
id: item.id,
text: item.name
}
})
let typeColumns = _this.data.typeColumns
typeColumns[1].values = list
_this.setData({
typeColumns
})
})
},
// 选择设备类型
typeColumnsChange(e) {
console.log('typeColumnsChange', e.detail);
let _this = this
const {
picker,
value,
index
} = e.detail;
if (index == 0) { // 选择类型
let obj = value[index]
_this.queryDevice(obj.id)
} else if (index == 1) { // 选择设备
let obj = value[index]
}
},
// 确认设备
typeColumnsConfirm(e) {
console.log('typeColumnsConfirm', e.detail);
let _this = this
const {
picker,
value,
index
} = e.detail;
_this.setData({
typeId: value[0].id,
typeName: value[0].text,
deviceId: value[1].id,
deviceName: value[1].text,
typeVisible: false
})
},
submit() {
let _this = this
// 参数校验
if (!_this.data.typeId) {
// 危险通知
app.vantNotifyErrTop(Notify, '请选择故障类型!')
return
}
// 提交参数
let data = {
"repair": {
id: _this.data.id,
typeId: _this.data.typeId,
typeName: _this.data.typeName,
deviceId: _this.data.deviceId,
deviceName: _this.data.deviceName,
},
"content": '重新指派设备类型',
"operate": "NEXT"
}
flowHandleRq(data).then(res => {
console.log('flowHandleRq', res);
if (res.code == 0) {
app.vantNotifySuccessTop(Notify, res.msg)
wx.navigateBack({
delta: 2
})
} else {
app.vantNotifyErrTop(Notify, res.msg)
}
})
2024-07-30 17:43:32 +08:00
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})