app-xiangsonghua/app-saas-src/script/inspectionRepair/repairProblem.js
2024-12-26 17:00:06 +08:00

271 lines
7.9 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

apiready = function () {
var ctrl = {
init: {},
bind: {},
backCallback: {},
prId: null,
taskId: null,
qxorderId: null,
baseUrl: '',
pics: [], // 现场照片本地url和base64数据
serverPicUrls: [], // 上传图片 服务器返回的路径
uploadPicNum: 0, // 上传图片 请求完成次数
flag: 0, // 当前设备缺陷是否已经成功提交0未提交1已提交
tabType: '', // 设备缺陷页是从日常、复查、新增三个tab 中的哪个跳转而来
}
ctrl.init = function () {
// 适配安卓状态栏
CommonModel.fitInStatusBar();
ctrl.prId = api.pageParam.prid;
ctrl.taskId = api.pageParam.taskid;
ctrl.qxorderId = api.pageParam.qxorderid;
ctrl.bind();
}
ctrl.bind = function () {
var height = $(window).height() - $("header").height() - $(".tabs").height();
$(".content-container").css("height", height);
//绑定返回按钮
$api.addEvt($api.dom("#back"), "touchend", function () {
ctrl.backCallback();
})
//点击系统返回按钮
api.addEventListener({
name: 'keyback'
}, function (ret, err) {
ctrl.backCallback();
});
// 添加图片按钮
$api.addEvt($api.dom("#pic-add-btn"), "touchend", function () {
var params = {
sourceType: 'camera',
destinationType: 'base64'
}
api.getPicture(params, function(ret, err){
if (ret && ret.data) {
// 创建图片预览dom
var picItemDom = '<span class="pic-item"><i></i><img src="{{url}}" alt=""></span>'
var dom = picItemDom.replace('{{url}}', ret.data)
$('#pic-content').prepend(dom)
// 保存 图片 base64 和 url
ctrl.pics.push({
base64Data: ret.base64Data,
url: ret.data
})
// 点击图片预览
$("#pic-content .pic-item").on("touchend", "img", function (e) {
e.stopPropagation();
var src = $(this).attr('src')
$('#pic-review img').attr('src', src)
$('#pic-review').css('display', 'block')
})
} else {
ctrl.toast(JSON.stringify(err));
}
})
})
// 图片 删除按钮
$("#pic-content").on("touchend", "i", function (e) {
e.stopPropagation();
var url = $($(this).siblings('img')[0]).attr('url')
$(this).parent('.pic-item').remove()
// 从 ctrl.pics 中删除对应url
ctrl.pics.filter(function (item) {
return item.url != url
})
})
// 点击预览图片 关闭预览
$('#pic-review').on("touchend", function () {
$(this).css('display', 'none')
})
// 点击语音按钮 开始录音
// $api.addEvt($api.dom("#audio-add-btn"), "touchstart", function () {
// var recordForMP3 = api.require('recordForMP3');
// recordForMP3.startRecord(function (ret, err) {
// console.log(3333)
// if (ret) {
// console.log(ret.status)
// } else {
// console.log('err')
// }
// })
// })
// 松开录音按钮 停止录音
// $api.addEvt($api.dom("#audio-add-btn"), "touchend", function () {
// alert(222)
// })
// 提交 按钮
$('#problem-submit-btn').on("touchend", function () {
api.showProgress({
title: '提交中...',
text: '请稍后',
modal: false
});
// 判断是否需要上传照片
if (ctrl.pics && ctrl.pics.length > 0) { // 需要上传时,先上传,再提交
ctrl.pics.forEach(function (pic, i) {
ctrl.uploadPic(pic.url)
})
} else { // 不需要上传时,直接提交
ctrl.comitProblem()
}
})
}
/**
* 上传图片
* @param {*} msg
*/
ctrl.uploadPic = function (file) {
var url = "/ems/rest/common/file/pad_upload";
var data = file
$api.uploadFile(url, data, function (res, err) {
if (err) {
ctrl.toast("网络请求失败,请稍后再试");
} else {
if (res.code == 200) {
// 将返回的图片路径保存
if (res.body && res.body.fileUrl) {
ctrl.serverPicUrls.push(res.body.fileUrl)
ctrl.uploadPicNum++
if (ctrl.uploadPicNum == ctrl.pics.length) {// 代表全部图片上传完成
// 2、调用提交 设备缺陷接口
ctrl.comitProblem()
}
} else {
ctrl.toast("服务器错误,未返回数据");
}
} else {
ctrl.toast("服务器响应错误" + (res.code ? (",错误码:" + res.code) : ""));
}
}
})
}
/**
* 提交抢修
* @param {*} msg
*/
ctrl.comitProblem = function () {
var picture = ctrl.serverPicUrls.join(',')
var result = $('#problem-desc').val()
var url = '/ems/rest/qx/task'
var data = {
taskId: ctrl.taskId,
completeTime: new Date().getTime(),
isComplete: true,
picture: picture,
record: '',
result: result
}
$api.put(url, data, function (res, err) {
api.hideProgress();
if (err) {
ctrl.toast("网络请求失败,请稍后再试");
} else {
if (res.code == 200) {
ctrl.flag = 1
api.toast({
msg: '提交成功'
})
var activeNav = $api.getStorage('activeNav')
var url, name;
if (activeNav == 'inspectionFrame') {
name = 'inspectionFrame';
url = '../index/inspectionFrame.html';
} else if (activeNav == 'repairFrame') {
name = 'repairFrame';
url = '../index/repairFrame.html';
}
api.openWin({
name: name,
url: url,
reload: true,
pageParam: {
id: ctrl.prId,
qxorderid: ctrl.qxorderId
}
});
} else {
ctrl.toast("服务器响应错误" + (res.code ? (",错误码:" + res.code) : ""));
}
}
})
}
/**
* 弹出提示框
*/
ctrl.toast = function (msg) {
api.toast({
msg: msg,
duration: 3000,
locaiton: 'top'
});
}
ctrl.backCallback = function () {
//关闭首页正在加载的提示框
api.execScript({
name: 'index',
frameName: 'featureFrame',
script: "api.hideProgress();"
});
api.setScreenOrientation({
orientation: 'auto_portrait'
});
api.setFullScreen({
fullScreen: false
});
api.closeWin({});
}
ctrl.init();
}