123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699 |
- var imgarr = [], UIAlbumBrowser= "";
- var pageId="", pageRecordParentId= "", recordParentId= "",
- templateId="", templateName="",departmentId="",userId= "",userName= "";
- var i = 0;
- // // 记录模版内容
- // function recodeContent(id,recodeId) {
- // var param={
- // pageId:'f8bdc7c051f14b6ea690081f55043384',
- // pageRecordId:'064cfd8b66cd42169606ab78f283f0b4',
- // recordParentId:'',
- // }
- // $http.fnReuestDataNologing(UrlRouter.getInspection,'','get',param,function (ret,err) {
- // if (ret.code === '200') {
- // pageRecordParentId = ret.data.parentId;
- // templateId = ret.data.recordTemplate.id
- // templateName = ret.data.recordTemplate.templateName
- // $apis.html(recode_content, '#addRecodeTemplate',ret.data.recordTemplate);
- // // $apis.CloseUILoading();
- // }
- // })
- // }
- // 录音
- // 删除录音
- function delAudio(that) {
- $(that).hide();
- $(that).parent().find('.upload-btn').show();
- $(that).parent().parent().find('audio').remove();
- }
- // 视频
- // 删除视频
- function delVedio(that) {
- $(that).hide();
- $(that).parent().find('.upload-btn1').show();
- $(that).parent().parent().find('video').remove();
- }
- // 状态
- function checkbox(el,list,titles) {
- var itmes = {title:'',value:''},itmesArray = [];
- for (var j= 0;j<list.length;j++) {
- itmes = {};
- itmes.title = list[j].statusContent;
- itmes.value = list[j].id;
- itmesArray.push(itmes)
- }
- setTimeout(function () {
- $('#'+el).select({
- title: titles,
- multi: true,
- items: itmesArray
- });
- },1000)
- return ''
- }
- // 记录项多选-单选
- function checkboxRecord(el,list) {
- var itmes = {title:'',value:''},itmesArray = [],idArray=[],titleArray=[];
- for (var j= 0;j<list.length;j++) {
- itmes = {};
- if (list[j].isDefault === true) {
- titleArray.push(list[j].itemValue)
- idArray.push(list[j].id)
- }
- itmes.title = list[j].itemValue;
- itmes.value = list[j].id;
- itmesArray.push(itmes)
- }
- setTimeout(function () {
- $("#"+el).select({
- multi: true,
- items: itmesArray
- });
- $("#"+el).attr("data-values",idArray.join(','))
- $("#"+el).attr("value",titleArray.join(','))
- },1000)
- return ''
- }
- function radioRecord(el,list) {
- var itmes = {title:'',value:''},itmesArray = [],idArray=[],titleArray=[];
- for (var j= 0;j<list.length;j++) {
- itmes = {};
- if (list[j].isDefault === true) {
- titleArray.push(list[j].itemValue)
- idArray.push(list[j].id)
- }
- itmes.title = list[j].itemValue;
- itmes.value = list[j].id;
- itmesArray.push(itmes)
- }
- setTimeout(function () {
- $("#"+el).select({
- multi: false,
- items: itmesArray
- });
- $("#"+el).attr("data-values",idArray.join(','))
- $("#"+el).attr("value",titleArray.join(','))
- },1000)
- return ''
- }
- //状态
- // 多选
- function statusCheckbox(el,list,titles) {
- var itmes = {title:'',value:''},itmesArray = [];
- for (var j= 0;j<list.length;j++) {
- itmes = {};
- itmes.title = list[j].statusContent;
- itmes.value = list[j].id;
- itmesArray.push(itmes)
- }
- setTimeout(function () {
- $("#"+el).select({
- title: titles,
- multi: true,
- items: itmesArray
- });
- },1000)
- return ''
- }
- // 单选
- function statusRadio(el,list,titles) {
- var itmes = {title:'',value:''},itmesArray = [];
- for (var j= 0;j<list.length;j++) {
- itmes = {};
- itmes.title = list[j].statusContent;
- itmes.value = list[j].id;
- itmesArray.push(itmes)
- }
- setTimeout(function () {
- $("#"+el).select({
- title: titles,
- multi: false,
- items: itmesArray
- });
- },1000)
- return ''
- }
- // 上传图片
- function uploadImg(type,that) {
- if (type == 'remote') {
- api.getPicture({
- sourceType: 'camera'
- }, function(ret, err){
- if(ret && ret.data!=""){
- uploadHead(ret.data,that);
- }
- });
- }else {
- api.actionSheet({
- title: '选择',
- cancelTitle: '取消',
- buttons: ['相机','相册']
- }, function(ret, err) {
- if (ret.buttonIndex !=3) {
- var type = 'camera';
- if(ret.buttonIndex == 1){
- type = 'camera';
- api.getPicture({
- sourceType: type
- }, function(ret, err){
- if(ret && ret.data!=""){
- uploadHead(ret.data,that);
- }
- });
- }else {
- type = 'album';
- // 支持多图片上传,UIAlbumBrowser模块获取图片路径
- changeImageUrl(that)
- }
- }
- });
- }
- }
- // upload img
- function uploadHead(imgUrl,that){
- api.showProgress({
- title: '',
- text: '上传中...',
- modal: true
- });
- api.ajax({
- url:UrlRouter.uploadFile,
- method: 'post',
- data: {
- files: {
- file:imgUrl
- }
- }
- },function(ret, err){
- if (ret) {
- if(ret.code === '200'){
- var html = `<div class="img-item file-width" img-Url="${ret.data.fullURL}">
- <img src="${ret.data.fullURL}" alt="">
- </div>`;
- $api.append(that.parentNode,html);
- api.toast({
- msg: '上传成功',
- duration: 2000,
- location: 'top'
- });
- api.hideProgress()
- }else {
- api.hideProgress()
- api.toast({
- msg: '上传失败',
- duration: 2000,
- location: 'top'
- });
- }
- } else {
- api.hideProgress()
- api.toast({
- msg: '网络错误',
- duration: 2000,
- location: 'top'
- });
- }
- });
- }
- // 获取相册图片路径
- function changeImageUrl(el) {
- UIAlbumBrowser.imagePicker({
- max: 9,
- styles: {
- bg: '#000000',
- //cameraImg: 'widget://res/cameraImg.png',
- mark: {
- position: 'top_right',
- size: 20
- },
- nav: {
- bg: '#000000',
- cancelColor: '#fff',
- cancelSize: 16,
- nextStepColor: '#7fff00',
- nextStepSize: 16
- },
- thumbnail: {
- w: 100,
- h: 100
- }
- },
- animation: true,
- }, function(ret) {
- if (ret.eventType == 'nextStep') {
- UIAlbumBrowser.closePicker();
- if (ret.list && ret.list.length > 0) {
- imgarr = ret.list;
- // 转换缩略图路径 ios
- UIAlbumBrowser_transPath(el);
- }
- }
- if (ret.originalPath && ret.originalPath.length > 0) {
- uploadHead(ret.originalPath,el)
- }
- });
- }
- // 转换缩略图路径 ios
- function UIAlbumBrowser_transPath(el) {
- UIAlbumBrowser.transPath({
- path: imgarr[i].path
- }, function(ret, err) {
- if (ret) {
- i++;
- if (i < imgarr.length) {
- UIAlbumBrowser_transPath(el);
- } else {
- i = 0;
- }
- uploadHead(ret.path,el)
- }
- });
- }
- // 上传文件
- // 浏览手机文件夹,获取文件路径
- // 上传文件
- function uploadFile(el,fileUrl) {
- api.showProgress({
- title: '',
- text: '上传中...',
- modal: true
- });
- api.ajax({
- url: UrlRouter.uploadFile,
- method: 'post',
- data: {
- files: {
- file:fileUrl
- }
- }
- },function(ret, err){
- if (ret) {
- api.hideProgress()
- if(ret.code === '200'){
- api.toast({
- msg: '上传成功',
- duration: 2000,
- location: 'top'
- });
- var fileType = ret.data.fileName.substr(ret.data.fileName.length-3,3);
- if (
- fileType == 'ppt' ||
- fileType == 'ptx' ||
- fileType == 'lsx' ||
- fileType == 'xls' ||
- fileType == 'doc' ||
- fileType == 'ocx' ||
- fileType == 'zip' ||
- fileType == 'rar' ||
- fileType == 'pdf'
- ){
- var html = `<div class="file-item-add file-width" file-Url="${ret.data.fullURL}" file-Name="${ret.data.fileName}">
- <img src="../../icon/${ret.data.fullURL.substr(ret.data.fullURL.length-3,3)}.png"/>
- <p>${ret.data.fileName}</p>
- </div>`;
- $api.append(el.parentNode,html);
- }else {
- api.toast({
- msg: '文件格式不对',
- duration: 2000,
- location: 'top'
- });
- }
- }else {
- api.toast({
- msg: '上传失败',
- duration: 2000,
- location: 'top'
- });
- }
- } else {
- api.hideProgress()
- api.toast({
- msg: '网络错误',
- duration: 2000,
- location: 'top'
- });
- }
- });
- }
- // 上传音频
- function uploadAudio(el,fileUrl) {
- api.showProgress({
- title: '',
- text: '上传中...',
- modal: true
- });
- api.ajax({
- url: UrlRouter.uploadFile,
- method: 'post',
- data: {
- files: {
- file:fileUrl
- }
- },
- timeout:60
- },function(ret, err){
- if (ret) {
- api.hideProgress()
- if(ret.code === '200'){
- api.toast({
- msg: '上传成功',
- duration: 2000,
- location: 'top'
- });
- var fileType = ret.data.fileExt;
- if (
- fileType == 'm4a' ||
- fileType == 'mp3' ||
- fileType == 'amr' ||
- fileType == 'AMR' ||
- fileType == 'WAV' ||
- fileType == 'wav' ||
- fileType == 'AWB' ||
- fileType == 'awb'
- ){
- $(el).hide();
- $(el).parent().find('.del-btn').show();
- var html = `<audio src="${ret.data.fullURL}" controls></audio>`;
- $(el).parent().parent().find('.audio-content').html(html)
- }else {
- api.toast({
- msg: '音频格式不对',
- duration: 2000,
- location: 'top'
- });
- }
- }else {
- api.toast({
- msg: '上传失败',
- duration: 2000,
- location: 'top'
- });
- }
- } else {
- api.hideProgress()
- api.toast({
- msg: '网络错误',
- duration: 2000,
- location: 'top'
- });
- }
- });
- }
- // 上传视频
- function uploadVedio(el,fileUrl) {
- api.showProgress({
- title: '',
- text: '上传中...',
- modal: true
- });
- api.ajax({
- url: UrlRouter.uploadFile,
- method: 'post',
- data: {
- files: {
- file:fileUrl
- }
- },
- timeout:60
- },function(ret, err){
- if (ret) {
- api.hideProgress()
- if(ret.code === '200'){
- api.toast({
- msg: '上传成功',
- duration: 2000,
- location: 'top'
- });
- var fileType = ret.data.fileExt;
- if (
- fileType == 'mp4' ||
- fileType == 'avi' ||
- fileType == 'wmv' ||
- fileType == '3gp' ||
- fileType == 'mkv' ||
- fileType == 'flv' ||
- fileType == 'rmvb'
- ){
- $(el).hide();
- $(el).parent().find('.del-btn').show();
- var html = `<video controls="controls" style="width: 100%;height: 200px;">
- <source src="${ret.data.fullURL}">
- 当前不支持播放该视频
- </video>`;
- $(el).parent().parent().find('.audio-content').html(html)
- }else {
- api.toast({
- msg: '视频格式不对',
- duration: 2000,
- location: 'top'
- });
- }
- }else {
- api.toast({
- msg: '上传失败',
- duration: 2000,
- location: 'top'
- });
- }
- } else {
- api.hideProgress()
- api.toast({
- msg: '网络错误',
- duration: 2000,
- location: 'top'
- });
- }
- });
- }
- //提交
- function mvalidate() {
- var isOptionals = $('.isOptionals')
- var opnum=0,eachnum=0;
- isOptionals.each(function (index) {
- if ($(this).attr('isOptional') == 'true'){
- ++opnum;
- }
- if ($(this).attr('isOptional') == 'true' && $(this).parent().find('.isOptional').val() !== "") {
- ++eachnum
- }
- })
- if (opnum == eachnum) {
- return true;
- }else {
- return false;
- }
- }
- function submitRecode() {
- if (mvalidate()) {
- // api.showProgress({
- // title: '',
- // text: '提交中...',
- // modal: true
- // });
- // 检查项
- var inspectTremA = $('.checked'),checkItemArray = [];
- var obj = {checkItemId:'',instanceValue:''}
- for (var i = 0; i < inspectTremA.length; i++) {
- obj = {}
- if (inspectTremA[i].checked) {
- obj.checkItemId = inspectTremA[i].value
- obj.instanceValue = true;
- checkItemArray.push(obj)
- }
- }
- // 记录项
- var inutItme =[],recordTrems = $('.recordTrems'),inputObj = {inputId:'',inputValue:''},changeInput = $('.changeInput');
- //// 1.文本, 时间,日期,数字
- recordTrems.each(function () {
- inputObj = {};
- var inputValue = $(this).val(),
- inputId = $(this).attr('recordTrem-id'),
- datetime = $(this).attr('data-datetime');
- if (datetime) {
- inputObj.inputId = inputId;
- inputObj.inputValue = inputValue.replace("T"," ");
- }else {
- inputObj.inputId = inputId;
- inputObj.inputValue = inputValue;
- }
- inutItme.push(inputObj);
- });
- var classSign = $('.classSign')
- // 记录项,手写签名
- classSign.each(function () {
- inputObj = {};
- $(this).attr('recordTrem-id')
- inputObj.inputId = $(this).attr('recordTrem-id')
- inputObj.inputValue = sign
- inutItme.push(inputObj);
- })
- //2.多选,单选
- changeInput.each(function () {
- inputObj = {};
- inputObj.inputId = $(this).attr('recordTrem-id');
- inputObj.inputValue = $(this).attr('data-values');
- inutItme.push(inputObj);
- });
- //3.录音
- var mp3_wrap = $('.mp3_wrap');
- mp3_wrap.each(function () {
- inputObj = {};
- inputObj.inputId = $(this).attr('recordTrem-id');
- inputObj.inputValue = $(this).find('audio').attr('src');
- inutItme.push(inputObj);
- });
- //4.视频
- var mp4_wrap = $('.mp4_wrap');
- mp4_wrap.each(function () {
- inputObj = {};
- inputObj.inputId = $(this).attr('recordTrem-id');
- inputObj.inputValue = $(this).find('video>source').attr('src');
- inutItme.push(inputObj);
- });
- //5.文件
- var fileList_warp = $('.fileList_warp'),fileArray = [],fileName = [],num = 0;
- fileList_warp.each(function (index) {
- inputObj = {};
- fileArray= [];
- inputObj.inputId = $(this).attr('recordTrem-id');
- var fileList = $(this).find('.file-item-add');
- fileList.each(function () {
- fileArray.push($(this).attr('file-Url')+"-"+$(this).attr('file-Name'));
- });
- inputObj.inputValue = fileArray.join(',');
- inutItme.push(inputObj);
- });
- //6.图片
- var photoFile = $('.photoFile'),photoArray = [];
- var isOptional = true
- photoFile.each(function () {
- inputObj = {};
- photoArray =[];
- inputObj.inputId = $(this).attr('recordTrem-id');
- var photoList = $(this).find('.img-item');
- photoList.each(function () {
- photoArray.push($(this).attr('img-Url'));
- });
- inputObj.inputValue = photoArray.join(',');
- if ($(this).attr('isOptional') === "true" && inputObj.inputValue =="") {
- isOptional = false
- }
- inutItme.push(inputObj);
- });
- if (isOptional === false) {
- return api.toast({
- msg: '请上传带*号的图片',
- duration: 2000,
- location: 'top'
- });
- }
- // 状态项
- // 状态
- var moreStatusA = $('.moreStatusA'),statusA = [],statusObj = {statusId:"",statusValue:''};
- moreStatusA.each(function () {
- statusObj = {};
- statusObj.statusId = $(this).attr('statusId');
- statusObj.statusValue = $(this).attr('data-values');
- statusA.push(statusObj);
- });
- var filterl= inutItme.filter(function (item) {
- if (item.inputValue != undefined){
- return item.inputValue !=""
- }
- });
- var param= {
- checkItems: checkItemArray,
- createBy: userId,
- createName: userName,
- inputs:filterl,
- pageId:pageId,
- pageRecordParentId:pageRecordParentId,
- recordParentId:recordParentId,
- status:statusA.length !=0? statusA : [],
- statusContent:$('.statusContent').val(),
- templateId:templateId,
- templateName:templateName,
- departmentId:departmentId,
- spName:spName,
- lng:lon,
- lat:lat
- }
- $.ajax({
- url: UrlRouter.addRecordInstance,
- type: 'post',
- contentType:'application/json;charset=UTF-8',
- dataType: 'json',
- data: JSON.stringify(param),
- success: function (ret) {
- if(ret.code === '200') {
- $('.submit-btn').attr('disabled','disabled')
- api.hideProgress()
- $event.openTabLayout('recodeDetails'+Math.random(),'recodeDetails','记录详情',{recordParentId:ret.data});
- }else if (ret.code == 422) {
- api.hideProgress()
- api.alert({
- title: '提示',
- msg: '请填写记录项',
- });
- }
- },
- error:function (err) {
- api.hideProgress()
- api.toast({
- msg: err,
- duration: 3000,
- location: 'top'
- });
- }
- })
- }else {
- api.toast({
- msg: '请填写带*号的内容!',
- duration: 3000,
- location: 'top'
- });
- }
- }
- // 定位初始化
- var spName = '',lon='',lat='';
- function getLonLat(flag) {
- if (flag) {
- api.showProgress({
- title: '提示',
- text: '定位中...',
- });
- }
- var aMap = api.require('aMap');
- aMap.getLocation(function(ret, err) {
- if (ret.status) {
- api.hideProgress();
- lon= ret.lon; lat=ret.lat;
- aMap.getNameFromCoords({
- lon: ret.lon,
- lat: ret.lat
- }, function(ret, err) {
- if (ret.status) {
- spName = ret.address
- $apis.html(position_warp, '#mapTemplate',ret);
- } else {
- api.toast({
- msg: '请打开手机定位',
- duration: 2000,
- location: 'top'
- });
- }
- });
- } else {
- api.hideProgress();
- api.toast({
- msg: '定位失败请重新定位',
- duration: 2000,
- location: 'top'
- });
- }
- });
- return '';
- }
|