document.getElementById('save').addEventListener('tap', function(e) {
if (!navigator.onLine) {
mui.alert("请确认连接网络后再提交");
return;
}
plus.nativeUI.showWaiting("正在保存...");
var itemArray = [];
var imageArray = [];
var recordArray = [];
db.transaction(function(tx) {
//获取整改项数据
tx.executeSql('select id,confirm_id,report_item_id,is_conform from ry_confirm_item where confirm_id=?', [
String(confirm_id)
],
function(tx, rs) {
for (var i = 0; i < rs.rows.length; i++) {
var row = rs.rows.item(i);
var obj = {
id: row.id,
confirm_id: confirm_id,
report_item_id: row.report_item_id,
is_conform: row.is_conform
}
//console.log(row.is_conform);
itemArray.push(obj);
}
//获取整改记录数据
tx.executeSql('select * from ry_rectify_confirm_record where confirm_id=?', [String(confirm_id)],
function(tx, rs) {
for (var i = 0; i < rs.rows.length; i++) {
var row = rs.rows.item(i);
var obj = {
id: row.id,
confirm_id: row.confirm_id,
item_id: row.item_id,
is_conform: row.is_conform,
content: row.content,
create_user: localStorage.getItem("realName"),
create_date: getDate()
}
recordArray.push(obj);
}
//获取图片项数据
tx.executeSql('select * from im_file where business_id=?', [String(confirm_id)],
function(tx, rs) {
for (var i = 0; i < rs.rows.length; i++) {
var row = rs.rows.item(i);
var obj = {
id: row.id,
business_id: row.business_id,
business_type: row.business_type,
item_id: row.item_id,
file_type: row.file_type,
create_user: row.create_user,
create_date: row.create_date,
str_image: row.str_image
}
imageArray.push(obj);
//console.log(row);
}
var url = ServerIp + "/api/rectify/saveoffConfirm";
var data = {
id: confirm_id
}
data["offConfirmItemList"] = itemArray;
data["offConfirmRecordList"] = recordArray;
data["offFileList"] = imageArray;
//console.log(imageArray);
$.ajax({
url: url,
dataType: "json",
type: "post",
contentType: "application/json;charset=UTF-8",
data: JSON.stringify(data),
success: function(result) {
if (result.success) {
mui.alert("提交成功!");
plus.nativeUI.closeWaiting();
delFinishRectify(result.message); //处理离线数据库
var self = plus.webview.currentWebview();
if (self.preload) {
self.hide("auto");
} else {
plus.webview.close(self);
}
plus.webview.getWebviewById("offtask").reload();
} else {
mui.alert(result.message);
plus.nativeUI.closeWaiting();
}
},
error: function(result, status) {
plus.nativeUI.closeWaiting();
mui.alert('连接服务器失败,请确认网络是否可用');
}
});
});
});
});
});
});