addRecode.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. var imgarr = [], UIAlbumBrowser= "";
  2. var pageId="", pageRecordParentId= "", recordParentId= "",
  3. templateId="", templateName="",departmentId="",userId= "",userName= "";
  4. var i = 0;
  5. // // 记录模版内容
  6. // function recodeContent(id,recodeId) {
  7. // var param={
  8. // pageId:'f8bdc7c051f14b6ea690081f55043384',
  9. // pageRecordId:'064cfd8b66cd42169606ab78f283f0b4',
  10. // recordParentId:'',
  11. // }
  12. // $http.fnReuestDataNologing(UrlRouter.getInspection,'','get',param,function (ret,err) {
  13. // if (ret.code === '200') {
  14. // pageRecordParentId = ret.data.parentId;
  15. // templateId = ret.data.recordTemplate.id
  16. // templateName = ret.data.recordTemplate.templateName
  17. // $apis.html(recode_content, '#addRecodeTemplate',ret.data.recordTemplate);
  18. // // $apis.CloseUILoading();
  19. // }
  20. // })
  21. // }
  22. // 录音
  23. // 删除录音
  24. function delAudio(that) {
  25. $(that).hide();
  26. $(that).parent().find('.upload-btn').show();
  27. $(that).parent().parent().find('audio').remove();
  28. }
  29. // 视频
  30. // 删除视频
  31. function delVedio(that) {
  32. $(that).hide();
  33. $(that).parent().find('.upload-btn1').show();
  34. $(that).parent().parent().find('video').remove();
  35. }
  36. // 状态
  37. function checkbox(el,list,titles) {
  38. var itmes = {title:'',value:''},itmesArray = [];
  39. for (var j= 0;j<list.length;j++) {
  40. itmes = {};
  41. itmes.title = list[j].statusContent;
  42. itmes.value = list[j].id;
  43. itmesArray.push(itmes)
  44. }
  45. setTimeout(function () {
  46. $('#'+el).select({
  47. title: titles,
  48. multi: true,
  49. items: itmesArray
  50. });
  51. },1000)
  52. return ''
  53. }
  54. // 记录项多选-单选
  55. function checkboxRecord(el,list) {
  56. var itmes = {title:'',value:''},itmesArray = [],idArray=[],titleArray=[];
  57. for (var j= 0;j<list.length;j++) {
  58. itmes = {};
  59. if (list[j].isDefault === true) {
  60. titleArray.push(list[j].itemValue)
  61. idArray.push(list[j].id)
  62. }
  63. itmes.title = list[j].itemValue;
  64. itmes.value = list[j].id;
  65. itmesArray.push(itmes)
  66. }
  67. setTimeout(function () {
  68. $("#"+el).select({
  69. multi: true,
  70. items: itmesArray
  71. });
  72. $("#"+el).attr("data-values",idArray.join(','))
  73. $("#"+el).attr("value",titleArray.join(','))
  74. },1000)
  75. return ''
  76. }
  77. function radioRecord(el,list) {
  78. var itmes = {title:'',value:''},itmesArray = [],idArray=[],titleArray=[];
  79. for (var j= 0;j<list.length;j++) {
  80. itmes = {};
  81. if (list[j].isDefault === true) {
  82. titleArray.push(list[j].itemValue)
  83. idArray.push(list[j].id)
  84. }
  85. itmes.title = list[j].itemValue;
  86. itmes.value = list[j].id;
  87. itmesArray.push(itmes)
  88. }
  89. setTimeout(function () {
  90. $("#"+el).select({
  91. multi: false,
  92. items: itmesArray
  93. });
  94. $("#"+el).attr("data-values",idArray.join(','))
  95. $("#"+el).attr("value",titleArray.join(','))
  96. },1000)
  97. return ''
  98. }
  99. //状态
  100. // 多选
  101. function statusCheckbox(el,list,titles) {
  102. var itmes = {title:'',value:''},itmesArray = [];
  103. for (var j= 0;j<list.length;j++) {
  104. itmes = {};
  105. itmes.title = list[j].statusContent;
  106. itmes.value = list[j].id;
  107. itmesArray.push(itmes)
  108. }
  109. setTimeout(function () {
  110. $("#"+el).select({
  111. title: titles,
  112. multi: true,
  113. items: itmesArray
  114. });
  115. },1000)
  116. return ''
  117. }
  118. // 单选
  119. function statusRadio(el,list,titles) {
  120. var itmes = {title:'',value:''},itmesArray = [];
  121. for (var j= 0;j<list.length;j++) {
  122. itmes = {};
  123. itmes.title = list[j].statusContent;
  124. itmes.value = list[j].id;
  125. itmesArray.push(itmes)
  126. }
  127. setTimeout(function () {
  128. $("#"+el).select({
  129. title: titles,
  130. multi: false,
  131. items: itmesArray
  132. });
  133. },1000)
  134. return ''
  135. }
  136. // 上传图片
  137. function uploadImg(type,that) {
  138. if (type == 'remote') {
  139. api.getPicture({
  140. sourceType: 'camera'
  141. }, function(ret, err){
  142. if(ret && ret.data!=""){
  143. uploadHead(ret.data,that);
  144. }
  145. });
  146. }else {
  147. api.actionSheet({
  148. title: '选择',
  149. cancelTitle: '取消',
  150. buttons: ['相机','相册']
  151. }, function(ret, err) {
  152. if (ret.buttonIndex !=3) {
  153. var type = 'camera';
  154. if(ret.buttonIndex == 1){
  155. type = 'camera';
  156. api.getPicture({
  157. sourceType: type
  158. }, function(ret, err){
  159. if(ret && ret.data!=""){
  160. uploadHead(ret.data,that);
  161. }
  162. });
  163. }else {
  164. type = 'album';
  165. // 支持多图片上传,UIAlbumBrowser模块获取图片路径
  166. changeImageUrl(that)
  167. }
  168. }
  169. });
  170. }
  171. }
  172. // upload img
  173. function uploadHead(imgUrl,that){
  174. api.showProgress({
  175. title: '',
  176. text: '上传中...',
  177. modal: true
  178. });
  179. api.ajax({
  180. url:UrlRouter.uploadFile,
  181. method: 'post',
  182. data: {
  183. files: {
  184. file:imgUrl
  185. }
  186. }
  187. },function(ret, err){
  188. if (ret) {
  189. if(ret.code === '200'){
  190. var html = `<div class="img-item file-width" img-Url="${ret.data.fullURL}">
  191. <img src="${ret.data.fullURL}" alt="">
  192. </div>`;
  193. $api.append(that.parentNode,html);
  194. api.toast({
  195. msg: '上传成功',
  196. duration: 2000,
  197. location: 'top'
  198. });
  199. api.hideProgress()
  200. }else {
  201. api.hideProgress()
  202. api.toast({
  203. msg: '上传失败',
  204. duration: 2000,
  205. location: 'top'
  206. });
  207. }
  208. } else {
  209. api.hideProgress()
  210. api.toast({
  211. msg: '网络错误',
  212. duration: 2000,
  213. location: 'top'
  214. });
  215. }
  216. });
  217. }
  218. // 获取相册图片路径
  219. function changeImageUrl(el) {
  220. UIAlbumBrowser.imagePicker({
  221. max: 9,
  222. styles: {
  223. bg: '#000000',
  224. //cameraImg: 'widget://res/cameraImg.png',
  225. mark: {
  226. position: 'top_right',
  227. size: 20
  228. },
  229. nav: {
  230. bg: '#000000',
  231. cancelColor: '#fff',
  232. cancelSize: 16,
  233. nextStepColor: '#7fff00',
  234. nextStepSize: 16
  235. },
  236. thumbnail: {
  237. w: 100,
  238. h: 100
  239. }
  240. },
  241. animation: true,
  242. }, function(ret) {
  243. if (ret.eventType == 'nextStep') {
  244. UIAlbumBrowser.closePicker();
  245. if (ret.list && ret.list.length > 0) {
  246. imgarr = ret.list;
  247. // 转换缩略图路径 ios
  248. UIAlbumBrowser_transPath(el);
  249. }
  250. }
  251. if (ret.originalPath && ret.originalPath.length > 0) {
  252. uploadHead(ret.originalPath,el)
  253. }
  254. });
  255. }
  256. // 转换缩略图路径 ios
  257. function UIAlbumBrowser_transPath(el) {
  258. UIAlbumBrowser.transPath({
  259. path: imgarr[i].path
  260. }, function(ret, err) {
  261. if (ret) {
  262. i++;
  263. if (i < imgarr.length) {
  264. UIAlbumBrowser_transPath(el);
  265. } else {
  266. i = 0;
  267. }
  268. uploadHead(ret.path,el)
  269. }
  270. });
  271. }
  272. // 上传文件
  273. // 浏览手机文件夹,获取文件路径
  274. // 上传文件
  275. function uploadFile(el,fileUrl) {
  276. api.showProgress({
  277. title: '',
  278. text: '上传中...',
  279. modal: true
  280. });
  281. api.ajax({
  282. url: UrlRouter.uploadFile,
  283. method: 'post',
  284. data: {
  285. files: {
  286. file:fileUrl
  287. }
  288. }
  289. },function(ret, err){
  290. if (ret) {
  291. api.hideProgress()
  292. if(ret.code === '200'){
  293. api.toast({
  294. msg: '上传成功',
  295. duration: 2000,
  296. location: 'top'
  297. });
  298. var fileType = ret.data.fileName.substr(ret.data.fileName.length-3,3);
  299. if (
  300. fileType == 'ppt' ||
  301. fileType == 'ptx' ||
  302. fileType == 'lsx' ||
  303. fileType == 'xls' ||
  304. fileType == 'doc' ||
  305. fileType == 'ocx' ||
  306. fileType == 'zip' ||
  307. fileType == 'rar' ||
  308. fileType == 'pdf'
  309. ){
  310. var html = `<div class="file-item-add file-width" file-Url="${ret.data.fullURL}" file-Name="${ret.data.fileName}">
  311. <img src="../../icon/${ret.data.fullURL.substr(ret.data.fullURL.length-3,3)}.png"/>
  312. <p>${ret.data.fileName}</p>
  313. </div>`;
  314. $api.append(el.parentNode,html);
  315. }else {
  316. api.toast({
  317. msg: '文件格式不对',
  318. duration: 2000,
  319. location: 'top'
  320. });
  321. }
  322. }else {
  323. api.toast({
  324. msg: '上传失败',
  325. duration: 2000,
  326. location: 'top'
  327. });
  328. }
  329. } else {
  330. api.hideProgress()
  331. api.toast({
  332. msg: '网络错误',
  333. duration: 2000,
  334. location: 'top'
  335. });
  336. }
  337. });
  338. }
  339. // 上传音频
  340. function uploadAudio(el,fileUrl) {
  341. api.showProgress({
  342. title: '',
  343. text: '上传中...',
  344. modal: true
  345. });
  346. api.ajax({
  347. url: UrlRouter.uploadFile,
  348. method: 'post',
  349. data: {
  350. files: {
  351. file:fileUrl
  352. }
  353. },
  354. timeout:60
  355. },function(ret, err){
  356. if (ret) {
  357. api.hideProgress()
  358. if(ret.code === '200'){
  359. api.toast({
  360. msg: '上传成功',
  361. duration: 2000,
  362. location: 'top'
  363. });
  364. var fileType = ret.data.fileExt;
  365. if (
  366. fileType == 'm4a' ||
  367. fileType == 'mp3' ||
  368. fileType == 'amr' ||
  369. fileType == 'AMR' ||
  370. fileType == 'WAV' ||
  371. fileType == 'wav' ||
  372. fileType == 'AWB' ||
  373. fileType == 'awb'
  374. ){
  375. $(el).hide();
  376. $(el).parent().find('.del-btn').show();
  377. var html = `<audio src="${ret.data.fullURL}" controls></audio>`;
  378. $(el).parent().parent().find('.audio-content').html(html)
  379. }else {
  380. api.toast({
  381. msg: '音频格式不对',
  382. duration: 2000,
  383. location: 'top'
  384. });
  385. }
  386. }else {
  387. api.toast({
  388. msg: '上传失败',
  389. duration: 2000,
  390. location: 'top'
  391. });
  392. }
  393. } else {
  394. api.hideProgress()
  395. api.toast({
  396. msg: '网络错误',
  397. duration: 2000,
  398. location: 'top'
  399. });
  400. }
  401. });
  402. }
  403. // 上传视频
  404. function uploadVedio(el,fileUrl) {
  405. api.showProgress({
  406. title: '',
  407. text: '上传中...',
  408. modal: true
  409. });
  410. api.ajax({
  411. url: UrlRouter.uploadFile,
  412. method: 'post',
  413. data: {
  414. files: {
  415. file:fileUrl
  416. }
  417. },
  418. timeout:60
  419. },function(ret, err){
  420. if (ret) {
  421. api.hideProgress()
  422. if(ret.code === '200'){
  423. api.toast({
  424. msg: '上传成功',
  425. duration: 2000,
  426. location: 'top'
  427. });
  428. var fileType = ret.data.fileExt;
  429. if (
  430. fileType == 'mp4' ||
  431. fileType == 'avi' ||
  432. fileType == 'wmv' ||
  433. fileType == '3gp' ||
  434. fileType == 'mkv' ||
  435. fileType == 'flv' ||
  436. fileType == 'rmvb'
  437. ){
  438. $(el).hide();
  439. $(el).parent().find('.del-btn').show();
  440. var html = `<video controls="controls" style="width: 100%;height: 200px;">
  441. <source src="${ret.data.fullURL}">
  442. 当前不支持播放该视频
  443. </video>`;
  444. $(el).parent().parent().find('.audio-content').html(html)
  445. }else {
  446. api.toast({
  447. msg: '视频格式不对',
  448. duration: 2000,
  449. location: 'top'
  450. });
  451. }
  452. }else {
  453. api.toast({
  454. msg: '上传失败',
  455. duration: 2000,
  456. location: 'top'
  457. });
  458. }
  459. } else {
  460. api.hideProgress()
  461. api.toast({
  462. msg: '网络错误',
  463. duration: 2000,
  464. location: 'top'
  465. });
  466. }
  467. });
  468. }
  469. //提交
  470. function mvalidate() {
  471. var isOptionals = $('.isOptionals')
  472. var opnum=0,eachnum=0;
  473. isOptionals.each(function (index) {
  474. if ($(this).attr('isOptional') == 'true'){
  475. ++opnum;
  476. }
  477. if ($(this).attr('isOptional') == 'true' && $(this).parent().find('.isOptional').val() !== "") {
  478. ++eachnum
  479. }
  480. })
  481. if (opnum == eachnum) {
  482. return true;
  483. }else {
  484. return false;
  485. }
  486. }
  487. function submitRecode() {
  488. if (mvalidate()) {
  489. // api.showProgress({
  490. // title: '',
  491. // text: '提交中...',
  492. // modal: true
  493. // });
  494. // 检查项
  495. var inspectTremA = $('.checked'),checkItemArray = [];
  496. var obj = {checkItemId:'',instanceValue:''}
  497. for (var i = 0; i < inspectTremA.length; i++) {
  498. obj = {}
  499. if (inspectTremA[i].checked) {
  500. obj.checkItemId = inspectTremA[i].value
  501. obj.instanceValue = true;
  502. checkItemArray.push(obj)
  503. }
  504. }
  505. // 记录项
  506. var inutItme =[],recordTrems = $('.recordTrems'),inputObj = {inputId:'',inputValue:''},changeInput = $('.changeInput');
  507. //// 1.文本, 时间,日期,数字
  508. recordTrems.each(function () {
  509. inputObj = {};
  510. var inputValue = $(this).val(),
  511. inputId = $(this).attr('recordTrem-id'),
  512. datetime = $(this).attr('data-datetime');
  513. if (datetime) {
  514. inputObj.inputId = inputId;
  515. inputObj.inputValue = inputValue.replace("T"," ");
  516. }else {
  517. inputObj.inputId = inputId;
  518. inputObj.inputValue = inputValue;
  519. }
  520. inutItme.push(inputObj);
  521. });
  522. //2.多选,单选
  523. changeInput.each(function () {
  524. inputObj = {};
  525. inputObj.inputId = $(this).attr('recordTrem-id');
  526. inputObj.inputValue = $(this).attr('data-values');
  527. inutItme.push(inputObj);
  528. });
  529. //3.录音
  530. var mp3_wrap = $('.mp3_wrap');
  531. mp3_wrap.each(function () {
  532. inputObj = {};
  533. inputObj.inputId = $(this).attr('recordTrem-id');
  534. inputObj.inputValue = $(this).find('audio').attr('src');
  535. inutItme.push(inputObj);
  536. });
  537. //4.视频
  538. var mp4_wrap = $('.mp4_wrap');
  539. mp4_wrap.each(function () {
  540. inputObj = {};
  541. inputObj.inputId = $(this).attr('recordTrem-id');
  542. inputObj.inputValue = $(this).find('video>source').attr('src');
  543. inutItme.push(inputObj);
  544. });
  545. //5.文件
  546. var fileList_warp = $('.fileList_warp'),fileArray = [],fileName = [],num = 0;
  547. fileList_warp.each(function (index) {
  548. inputObj = {};
  549. fileArray= [];
  550. inputObj.inputId = $(this).attr('recordTrem-id');
  551. var fileList = $(this).find('.file-item-add');
  552. fileList.each(function () {
  553. fileArray.push($(this).attr('file-Url')+"-"+$(this).attr('file-Name'));
  554. });
  555. inputObj.inputValue = fileArray.join(',');
  556. inutItme.push(inputObj);
  557. });
  558. //6.图片
  559. var photoFile = $('.photoFile'),photoArray = [];
  560. var isOptional = true
  561. photoFile.each(function () {
  562. inputObj = {};
  563. photoArray =[];
  564. inputObj.inputId = $(this).attr('recordTrem-id');
  565. var photoList = $(this).find('.img-item');
  566. photoList.each(function () {
  567. photoArray.push($(this).attr('img-Url'));
  568. });
  569. inputObj.inputValue = photoArray.join(',');
  570. if ($(this).attr('isOptional') === "true" && inputObj.inputValue =="") {
  571. isOptional = false
  572. }
  573. inutItme.push(inputObj);
  574. });
  575. if (isOptional === false) {
  576. return api.toast({
  577. msg: '请上传带*号的图片',
  578. duration: 2000,
  579. location: 'top'
  580. });
  581. }
  582. // 状态项
  583. // 状态
  584. var moreStatusA = $('.moreStatusA'),statusA = [],statusObj = {statusId:"",statusValue:''};
  585. moreStatusA.each(function () {
  586. statusObj = {};
  587. statusObj.statusId = $(this).attr('statusId');
  588. statusObj.statusValue = $(this).attr('data-values');
  589. statusA.push(statusObj);
  590. });
  591. var filterl= inutItme.filter(function (item) {
  592. if (item.inputValue != undefined){
  593. return item.inputValue !=""
  594. }
  595. });
  596. var param= {
  597. checkItems: checkItemArray,
  598. createBy: userId,
  599. createName: userName,
  600. inputs:filterl,
  601. pageId:pageId,
  602. pageRecordParentId:pageRecordParentId,
  603. recordParentId:recordParentId,
  604. status:statusA.length !=0? statusA : [],
  605. statusContent:$('.statusContent').val(),
  606. templateId:templateId,
  607. templateName:templateName,
  608. departmentId:departmentId,
  609. spName:spName,
  610. lng:lon,
  611. lat:lat
  612. }
  613. $.ajax({
  614. url: UrlRouter.addRecordInstance,
  615. type: 'post',
  616. contentType:'application/json;charset=UTF-8',
  617. dataType: 'json',
  618. data: JSON.stringify(param),
  619. success: function (ret) {
  620. if(ret.code === '200') {
  621. $('.submit-btn').attr('disabled','disabled')
  622. api.hideProgress()
  623. $event.openTabLayout('recodeDetails'+Math.random(),'recodeDetails','记录详情',{recordParentId:ret.data});
  624. }else if (ret.code == 422) {
  625. api.hideProgress()
  626. api.alert({
  627. title: '提示',
  628. msg: '请填写记录项',
  629. });
  630. }
  631. },
  632. error:function (err) {
  633. api.hideProgress()
  634. api.toast({
  635. msg: err,
  636. duration: 3000,
  637. location: 'top'
  638. });
  639. }
  640. })
  641. }else {
  642. api.toast({
  643. msg: '请填写带*号的内容!',
  644. duration: 3000,
  645. location: 'top'
  646. });
  647. }
  648. }
  649. // 定位初始化
  650. var spName = '',lon='',lat='';
  651. function getLonLat(flag) {
  652. if (flag) {
  653. api.showProgress({
  654. title: '提示',
  655. text: '定位中...',
  656. });
  657. }
  658. var aMap = api.require('aMap');
  659. aMap.getLocation(function(ret, err) {
  660. if (ret.status) {
  661. api.hideProgress();
  662. lon= ret.lon; lat=ret.lat;
  663. aMap.getNameFromCoords({
  664. lon: ret.lon,
  665. lat: ret.lat
  666. }, function(ret, err) {
  667. if (ret.status) {
  668. spName = ret.address
  669. $apis.html(position_warp, '#mapTemplate',ret);
  670. } else {
  671. api.toast({
  672. msg: '请打开手机定位',
  673. duration: 2000,
  674. location: 'top'
  675. });
  676. }
  677. });
  678. } else {
  679. api.hideProgress();
  680. api.toast({
  681. msg: '定位失败请重新定位',
  682. duration: 2000,
  683. location: 'top'
  684. });
  685. }
  686. });
  687. return '';
  688. }