Nessuna descrizione

InspectorAdd.js 59KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245
  1. const app = getApp();
  2. var util = require('../../../utils/util.js');
  3. var util1 = require('../../utils/wgs84Gcj02.js');
  4. var timerListJd = [];
  5. var timerList = [];
  6. var Jdtime;
  7. var Datetime;
  8. var searchTimer;
  9. Page({
  10. data: {
  11. Type: [], // 原先默认为【1】
  12. typeStr: '', // 原先默认为 "1"
  13. listType: '', // 传递过来的参数
  14. mileage: 0, //里程
  15. mileage1: 0, //转化进制后的里程
  16. posObj: {
  17. latitude: null,
  18. longitude: null,
  19. }, //当前坐标点
  20. lastPosObj: {
  21. latitude: null,
  22. longitude: null,
  23. }, //上一个坐标点
  24. polyline: [], //路线数组
  25. flag: false,
  26. flag1: true,
  27. info: {}, //当前巡查对象
  28. hours: '0' + 0, // 时
  29. minute: '0' + 0, // 分
  30. second: '0' + 0, // 秒
  31. imgDailog: false, //发现问题 弹框
  32. uploaderList: [], //保存上传图片url的数组
  33. fFileurl: [],
  34. uploaderNum: 0, //已经上传的图片数目
  35. formFileurl: [], //上传图片返回数据
  36. arrPoint: [], //坐标数组
  37. arrAddress: [],
  38. startTime: '',
  39. parkList: [],
  40. parkIndex: 0,
  41. isExist: 0,
  42. yhdwList: [],
  43. yhdwIndex: 0,
  44. // ===========
  45. WorkList: [], //工单列表
  46. text: null, //工单内容
  47. workZb: {
  48. latitude: null,
  49. longitude: null, // 记录 发现问题的 坐标
  50. },
  51. // 判断是否已经创建 巡查单
  52. status: false,
  53. endFlag: false,
  54. xiping: false,
  55. position: '', //角色权限判断
  56. positionFlag: false,
  57. yhCompanyId: null,
  58. maintenanceCompanyId: null,
  59. checkFlag: false, // 选路
  60. checkboxEd: false, //控制选路的 显示
  61. ldList: [], // 路 路段 的 数组 集合
  62. addldList: [], // 要巡查的 路段
  63. allldList: [], //所有的 路段 作为查询
  64. isBack:false,
  65. vehicleFlag: false,
  66. vehicleList: [{
  67. id: 1,
  68. name: '步行'
  69. },
  70. {
  71. id: 2,
  72. name: '非机动车'
  73. },
  74. {
  75. id: 3,
  76. name: '机动车'
  77. },
  78. ],
  79. addVehicleList: [],
  80. // 巡查单
  81. InspectionInfo: {},
  82. // 问题类型
  83. workTypeList: [],
  84. worktypeIndex: 0,
  85. workNum: 0, //问题数量
  86. XDSflag: 1,
  87. huatanFlag: false,
  88. huatanList: [],
  89. huatanIndex: 0,
  90. huatanType: '1',
  91. temperature: '', //温度
  92. humidity: '', //湿度
  93. wormList: [],
  94. wormIndex: null,
  95. hostbiology: '', //寄主生物
  96. hazardRatio: 0, //危害率
  97. remark: '',
  98. dangerLevelLIst: [],
  99. dangerLevelIndex: null,
  100. pestNewName: '',
  101. issueTypeList: [],
  102. issueTypeIndex: null,
  103. bchFlag: false, //是否显示病虫害
  104. xdsList: [],
  105. matchedDailog:false,
  106. detailList:[],//已匹配路段
  107. },
  108. huatanEdit(e) {
  109. this.setData({
  110. huatanType: e.detail.value,
  111. });
  112. },
  113. bindHostInput(e) {
  114. this.setData({
  115. hostbiology: e.detail.value,
  116. });
  117. },
  118. bindHazardRatioInput(e) {
  119. this.setData({
  120. // hazardRatio: parseInt(e.detail.value),
  121. hazardRatio: e.detail.value
  122. });
  123. },
  124. dangerLevelChange(e) {
  125. this.setData({
  126. dangerLevelIndex: e.detail.value,
  127. hazardRatio: this.data.dangerLevelLIst[e.detail.value].label
  128. });
  129. },
  130. bindRemarkInput(e) {
  131. this.setData({
  132. remark: e.detail.value,
  133. });
  134. },
  135. getHuatanbyid(i1, i2) {
  136. var that = this;
  137. app.loading();
  138. let url =
  139. app.globalData.httpsUrlServer + '/roadplantscondition/t-lhzx-road-plants-condition/list';
  140. let data = {
  141. sectionId: i1,
  142. maintenanceCompanyId: i2,
  143. };
  144. app.getReqNew(url, data, (res) => {
  145. if (res.code == 0) {
  146. that.setData({
  147. huatanList: res.data,
  148. });
  149. app.hideloading();
  150. }
  151. })
  152. },
  153. // 切换花坛
  154. changeHuatna(e) {
  155. this.setData({
  156. huatanIndex: e.detail.value,
  157. });
  158. },
  159. // 添加路 路段
  160. addItem(e) {
  161. let obj = e.currentTarget.dataset.item;
  162. let state;
  163. if (this.data.addldList.length > 0) {
  164. state = this.data.addldList.findIndex((v) => {
  165. return v.id == obj.id;
  166. });
  167. if (state == -1) {
  168. this.data.addldList.push(obj);
  169. } else {
  170. app.toast('已添加');
  171. }
  172. } else {
  173. this.data.addldList.push(obj);
  174. }
  175. this.setData({
  176. addldList: this.data.addldList,
  177. });
  178. },
  179. // 删除路 和路段
  180. removeItem(e) {
  181. let obj = e.currentTarget.dataset.item;
  182. this.data.addldList = this.data.addldList.filter((v) => {
  183. return v.id != obj.id;
  184. });
  185. this.setData({
  186. addldList: this.data.addldList,
  187. });
  188. },
  189. // 搜索 路 和路段
  190. searchItem(e) {
  191. clearTimeout(searchTimer);
  192. searchTimer = setTimeout(() => {
  193. wx.showLoading({
  194. title: '加载中',
  195. mask: true,
  196. });
  197. let val = e.detail.value.trim();
  198. let arr = [];
  199. this.data.allldList.forEach((v) => {
  200. let flag1 = v.roadName ? v.roadName.indexOf(val) != -1 : false;
  201. let flag2 = v.roadStartSpot ? v.roadStartSpot.indexOf(val) != -1 : false;
  202. let flag3 = v.roadEndSpot ? v.roadEndSpot.indexOf(val) != -1 : false;
  203. if (flag1 || flag2 || flag3) {
  204. arr.push(v);
  205. }
  206. });
  207. this.setData({
  208. ldList: arr,
  209. });
  210. wx.hideLoading();
  211. }, 1000);
  212. if (e.detail.value.trim() == '') {
  213. // 给 数组 重新赋值 但是已选择 的不能存在
  214. this.setData({
  215. ldList: this.data.allldList,
  216. });
  217. }
  218. },
  219. // 清空 路 和路段
  220. clearItem() {
  221. console.log('所有的路段', this.data.allldList);
  222. console.log('未选的路段', this.data.ldList);
  223. console.log('选择的路段', this.data.addldList);
  224. },
  225. // 隐藏
  226. hideCk() {
  227. let that = this;
  228. // 设置花坛
  229. // let id1 = that.data.parkList[that.data.parkIndex].sectionId;
  230. let id1 = that.data.parkList[that.data.parkIndex].fParkid;
  231. let id2;
  232. if (that.data.yhdwList.length == 0) {
  233. id2 = that.data.yhCompanyId;
  234. } else {
  235. // maintenanceCompanyId
  236. id2 = that.data.yhdwList[that.data.yhdwIndex].oldMaintenanceCompanyId;
  237. }
  238. that.getHuatanbyid(id1, id2);
  239. this.setData({
  240. checkboxEd: false,
  241. });
  242. },
  243. onSupple() {
  244. this.setData({
  245. checkboxEd: false,
  246. });
  247. },
  248. onBack(){
  249. this.setData({
  250. checkboxEd: false,
  251. });
  252. },
  253. // 显示
  254. ShowCk() {
  255. if (!this.data.parkList[this.data.parkIndex]) {
  256. return app.toast('请先选择路段');
  257. }
  258. if (this.data.flag) {
  259. return app.toast('巡查过程中不可更换');
  260. }
  261. // let id = this.data.parkList[this.data.parkIndex].sectionId;
  262. let id = this.data.parkList[this.data.parkIndex].id;
  263. if (id) {
  264. if (this.data.addldList.length == 0) {
  265. // this.getLdListbyid(id);
  266. this.getLdListbyid();
  267. }
  268. this.setData({
  269. checkboxEd: true,
  270. });
  271. } else {
  272. return app.toast('请先选择路段');
  273. }
  274. },
  275. ShowVehicle() {
  276. this.setData({
  277. vehicleFlag: true,
  278. });
  279. },
  280. hideVehicle() {
  281. this.setData({
  282. vehicleFlag: false,
  283. });
  284. },
  285. addVehicle(e) {
  286. let obj = e.currentTarget.dataset.item;
  287. let state;
  288. if (this.data.addVehicleList.length > 0) {
  289. state = this.data.addVehicleList.findIndex((v) => {
  290. return v.id == obj.id;
  291. });
  292. if (state == -1) {
  293. this.data.addVehicleList.push(obj);
  294. } else {
  295. app.toast('已添加');
  296. }
  297. } else {
  298. this.data.addVehicleList.push(obj);
  299. }
  300. this.setData({
  301. addVehicleList: this.data.addVehicleList,
  302. });
  303. },
  304. removeVehicle(e) {
  305. let obj = e.currentTarget.dataset.item;
  306. this.data.addVehicleList = this.data.addVehicleList.filter((v) => {
  307. return v.id != obj.id;
  308. });
  309. this.setData({
  310. addVehicleList: this.data.addVehicleList,
  311. });
  312. },
  313. // 获取坐标
  314. tap1() {
  315. let that = this;
  316. wx.getLocation({
  317. type: 'gcj02',
  318. isHighAccuracy: true,
  319. success(res) {
  320. var arr = [];
  321. arr.push({
  322. latitude: res.latitude,
  323. longitude: res.longitude,
  324. });
  325. that.getAddress(res.latitude, res.longitude);
  326. that.data.arrPoint = that.data.arrPoint.concat(arr);
  327. that.setData({
  328. arrPoint: that.data.arrPoint,
  329. posObj: {
  330. latitude: res.latitude,
  331. longitude: res.longitude,
  332. },
  333. });
  334. // 每次获取上一次的坐标点 计算里程数
  335. // 纬度 纬度
  336. if (that.data.arrPoint.length > 2) {
  337. let last = that.data.arrPoint[that.data.arrPoint.length - 2];
  338. that.data.lastPosObj.latitude = last.latitude;
  339. that.data.lastPosObj.longitude = last.longitude;
  340. that.setData({
  341. lastPosObj: that.data.lastPosObj,
  342. });
  343. that.distance(
  344. that.data.posObj.latitude * 1,
  345. that.data.posObj.longitude * 1,
  346. that.data.lastPosObj.latitude * 1,
  347. that.data.lastPosObj.longitude * 1
  348. );
  349. }
  350. },
  351. });
  352. },
  353. getAddress(latitude, longitude) {
  354. let that = this;
  355. wx.request({
  356. url: 'https://apis.map.qq.com/ws/geocoder/v1/', //仅为示例,并非真实的接口地址
  357. data: {
  358. location: latitude + ',' + longitude,
  359. get_poi: 1,
  360. key: "PIDBZ-L75KO-6HKWR-SGRJQ-IP7VV-UZBLJ",
  361. },
  362. header: {
  363. 'content-type': 'application/json' // 默认值
  364. },
  365. success(res) {
  366. let address = res.data.result.address_component.street;
  367. that.setData({
  368. arrAddress: that.dedupe(that.data.arrAddress.concat(address))
  369. })
  370. }
  371. })
  372. },
  373. dedupe(array) {
  374. return Array.from(new Set(array));
  375. },
  376. // 切换 行道树 或者绿地 或者 花坛
  377. toggleXDS(e) {
  378. app.loading();
  379. this.setData({
  380. XDSflag: e.detail.value,
  381. });
  382. this.getWorkTypeList(e.detail.value);
  383. if (e.detail.value == 3) {
  384. this.setData({
  385. huatanFlag: true,
  386. });
  387. } else {
  388. this.setData({
  389. huatanFlag: false,
  390. });
  391. }
  392. },
  393. // 点击 确定按钮
  394. UploadP() {
  395. if (this.data.huatanFlag) {
  396. // if (!this.data.huatanList[this.data.huatanIndex])
  397. // return app.toast('请选择花坛');
  398. if (this.data.formFileurl.length < 2) return app.toast('至少上传2张图片');
  399. if (this.data.huatanType == 1) {
  400. if (this.data.XDSflag != 4) {
  401. if (this.data.text == null || this.data.text.trim() == '') {
  402. return app.toast('请填写问题描述');
  403. }
  404. }
  405. }
  406. } else {
  407. if (this.data.formFileurl.length == 0) {
  408. return app.toast('请上传问题图片');
  409. }
  410. if (this.data.XDSflag == 4) {
  411. if (this.data.issueTypeIndex == null) {
  412. return app.toast('请选择问题类型');
  413. }
  414. } else {
  415. if (!this.data.workTypeList[this.data.worktypeIndex]) {
  416. return app.toast('请选择问题分类');
  417. }
  418. if (this.data.text == null || this.data.text.trim() == '') {
  419. return app.toast('请填写问题描述');
  420. }
  421. }
  422. }
  423. // 问题单保存
  424. // console.log('问题分类', this.data.workTypeList[this.data.worktypeIndex]);
  425. // wx.showLoading({
  426. // title: '加载中',
  427. // mask: true,
  428. // });
  429. if (this.data.XDSflag == 4) {
  430. // if (this.data.hazardRatio == null || this.data.hazardRatio == '') {
  431. // return app.toast('请填写危害率');
  432. // }
  433. let url = app.globalData.httpsUrlServer + '/patrolTrack/issue/';
  434. let formFileList = this.data.formFileurl;
  435. let newArr = [];
  436. formFileList.map(item => {
  437. let obj = {
  438. fileDes: item.fileDes,
  439. fileFormat: item.fileFormat,
  440. fileName: item.string1,
  441. fileSize: item.fileSize,
  442. fileUrl: item.fileUrl
  443. };
  444. newArr.push(obj);
  445. })
  446. // let fileCoordinates =
  447. // this.data.workZb.latitude + ',' + this.data.workZb.longitude;
  448. let fileCoordinates = util1.transformFromGCJToWGS(
  449. this.data.workZb.latitude,
  450. this.data.workZb.longitude
  451. );
  452. let pestName = null;
  453. let pestId = null;
  454. if (this.data.wormIndex != null) {
  455. pestId = this.data.wormList[this.data.wormIndex].id;
  456. if (pestId == -1) {
  457. // if(!this.data.pestNewName){
  458. // return app.toast('请输入病虫害名称');
  459. // }
  460. pestName = this.data.pestNewName;
  461. if (!pestName) {
  462. pestId = null;
  463. }
  464. } else {
  465. pestName = this.data.wormList[this.data.wormIndex].pestName;
  466. }
  467. }
  468. if (this.data.dangerLevelIndex == null) {
  469. return app.toast('请选择危害程度');
  470. }
  471. console.log(this.data.dangerLevelLIst[this.data.dangerLevelIndex], 'this.data.dangerLevelLIst[this.data.dangerLevelIndex]')
  472. let data = {
  473. patrolId: this.data.InspectionInfo.id,
  474. pestName: pestName,
  475. pestId: pestId,
  476. remark: this.data.remark,
  477. host: this.data.hostbiology,
  478. // dangerRate:this.data.hazardRatio,
  479. dangerLevel: this.data.dangerLevelLIst[this.data.dangerLevelIndex].id,
  480. dangerLevelName: this.data.dangerLevelLIst[this.data.dangerLevelIndex].name,
  481. issueType: 2,
  482. state: 0,
  483. dangerType: this.data.issueTypeList[this.data.issueTypeIndex].fWorkordertypeid,
  484. dangerTypeName: this.data.issueTypeList[this.data.issueTypeIndex].fName,
  485. // thresholdValue: this.data.issueTypeList[this.data.issueTypeIndex].thresholdValue,
  486. patrolTrackIssueFileList: newArr,
  487. currentCoordinates: fileCoordinates.longitude + ',' + fileCoordinates.latitude,
  488. temperature: this.data.temperature,
  489. humidity: this.data.humidity
  490. }
  491. app.postReqNew(url, data, (res) => {
  492. if (res.code == 0) {
  493. if (!(this.data.Type.indexOf(this.data.XDSflag) + 1)) {
  494. this.data.Type.push(this.data.XDSflag);
  495. }
  496. let str123 = this.data.Type.join(',');
  497. this.setData({
  498. imgDailog: false,
  499. XDSflag: 1,
  500. text: null,
  501. formFileurl: [],
  502. typeStr: str123,
  503. isExist: data.dangerLevel == 0 ? 0 : 1,
  504. });
  505. this.setData({
  506. InspectionInfo: res.data,
  507. });
  508. app.toast('问题上传成功');
  509. this.loadWormList();
  510. } else {
  511. this.setData({
  512. imgDailog: false,
  513. XDSflag: 1,
  514. text: null,
  515. formFileurl: [],
  516. XDSflag: 1,
  517. // isExist: 0,
  518. });
  519. app.toast('问题上传失败');
  520. }
  521. });
  522. } else {
  523. // 发送 请求 并向 问题数组中存值
  524. this.setData({
  525. workNum: this.data.workNum + 1,
  526. });
  527. let url = app.globalData.httpsUrlServer + '/lhgyWork/savePatrolTrackFile';
  528. let obj = {};
  529. let arr = [];
  530. this.data.formFileurl.forEach((v) => {
  531. v.fileCoordinates =
  532. this.data.workZb.latitude + ',' + this.data.workZb.longitude;
  533. v.remark = this.data.text;
  534. let obj = util1.transformFromGCJToWGS(
  535. this.data.workZb.latitude,
  536. this.data.workZb.longitude
  537. );
  538. v.fileCoordinatesGc = obj.latitude + ',' + obj.longitude;
  539. v.createDate = util.formatTime(new Date());
  540. v.string3 = this.data.workTypeList[this.data.worktypeIndex].fValuecode;
  541. v.string4 = this.data.workTypeList[this.data.worktypeIndex].fName;
  542. // 选择行道树
  543. v.number4 = this.data.XDSflag;
  544. if (this.data.XDSflag == 3) {
  545. // v.number5 = this.data.huatanList[
  546. // this.data.huatanIndex
  547. // ].id; // id
  548. // v.string5 = this.data.huatanList[this.data.huatanIndex].address;
  549. // v.string5 =
  550. // this.data.huatanList[this.data.huatanIndex].fAttractionsName +
  551. // '--' +
  552. // this.data.huatanList[this.data.huatanIndex].fAttractionsPlace; // 名字
  553. }
  554. v.number2 = this.data.huatanFlag ? this.data.huatanType : '1';
  555. });
  556. obj.fileList = this.data.formFileurl;
  557. arr.push(obj);
  558. let data = {
  559. aassessNo: this.data.InspectionInfo.aassessNo, //巡查单号
  560. fileList: arr, //图片列表
  561. id: this.data.InspectionInfo.id,
  562. };
  563. app.postReq(url, data, (res) => {
  564. if (res.status == 200) {
  565. if (!(this.data.Type.indexOf(this.data.XDSflag) + 1)) {
  566. this.data.Type.push(this.data.XDSflag);
  567. }
  568. let str123 = this.data.Type.join(',');
  569. this.setData({
  570. imgDailog: false,
  571. XDSflag: 1,
  572. text: null,
  573. formFileurl: [],
  574. typeStr: str123,
  575. isExist: 1,
  576. });
  577. app.toast('问题上传成功');
  578. } else {
  579. this.setData({
  580. imgDailog: false,
  581. XDSflag: 1,
  582. text: null,
  583. formFileurl: [],
  584. XDSflag: 1,
  585. // isExist: 0,
  586. });
  587. app.toast('问题上传失败');
  588. }
  589. });
  590. }
  591. //清空图片 文本 关闭弹框
  592. },
  593. changeType(e) {
  594. this.setData({
  595. worktypeIndex: e.detail.value,
  596. });
  597. // if(this.data.XDSflag == 4){
  598. // this.loadWormList();
  599. // this.hazardRateInit();
  600. // }
  601. },
  602. issueTypeChange(e) {
  603. console.log(e, 'issueTypeChange')
  604. this.setData({
  605. issueTypeIndex: e.detail.value,
  606. dangerLevelIndex: null
  607. });
  608. this.loadWormList();
  609. this.hazardRateInit();
  610. },
  611. //加载昆虫
  612. loadWormList() {
  613. let that = this;
  614. let pestType = that.data.issueTypeList[that.data.issueTypeIndex].id;
  615. let url =
  616. app.globalData.httpsUrlServer +
  617. '/common/pestType/list';
  618. let data = {
  619. pestType: pestType
  620. };
  621. app.getReqNew(url, data, (res) => {
  622. let newA = [{
  623. id: -1,
  624. pestName: '手动输入病虫名称'
  625. }];
  626. let lists = [...newA, ...res.data];
  627. that.setData({
  628. wormList: lists,
  629. wormIndex: null
  630. });
  631. });
  632. },
  633. changeWorm(e) {
  634. this.setData({
  635. wormIndex: e.detail.value,
  636. });
  637. },
  638. pestNameInput(e) {
  639. this.setData({
  640. pestNewName: e.detail.value,
  641. });
  642. },
  643. // 图片上传
  644. uploader: function () {
  645. var that = this;
  646. var token = wx.getStorageSync('token');
  647. let maxSize = 1024 * 1024 * 5;
  648. let maxLength = 5;
  649. wx.chooseImage({
  650. count: 5, //最多可以选择的图片总数
  651. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  652. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  653. success: function (res) {
  654. wx.showLoading({
  655. title: '上传中',
  656. mask: true,
  657. });
  658. for (let i = 0; i < res.tempFiles.length; i++) {
  659. if (res.tempFiles[i].size > maxSize) {
  660. flag = false;
  661. wx.showModal({
  662. content: '图片太大,不允许上传',
  663. showCancel: false,
  664. success: function (res) {
  665. if (res.confirm) {
  666. //console.log('用户点击确定')
  667. }
  668. },
  669. });
  670. return;
  671. }
  672. }
  673. if (res.tempFiles.length > maxLength) {
  674. wx.showModal({
  675. content: '最多能上传' + maxLength + '张图片',
  676. showCancel: false,
  677. success: function (res) {
  678. if (res.confirm) {
  679. //console.log('确定');
  680. }
  681. },
  682. });
  683. }
  684. for (var i = 0; i < res.tempFilePaths.length; i++) {
  685. wx.uploadFile({
  686. url: app.globalData.httpsUrlServer + '/file/uploadPatrolFile',
  687. filePath: res.tempFilePaths[i],
  688. name: 'images',
  689. header: {
  690. 'Content-Type': 'application/json;charset=UTF-8',
  691. token: token,
  692. fSource: 1,
  693. },
  694. success: function (res) {
  695. if (res.statusCode == 200) {
  696. var data = JSON.parse(res.data);
  697. if (data.status == 200) {
  698. that.setData({
  699. fFileurl: that.data.fFileurl.concat(data.data[0].fileDes),
  700. formFileurl: that.data.formFileurl.concat(data.data[0]),
  701. });
  702. setTimeout(() => {
  703. wx.showToast({
  704. title: '图片上传成功',
  705. mask: true,
  706. duration: 1000,
  707. });
  708. }, 500);
  709. } else if (data.status == 600) {
  710. wx.showModal({
  711. title: '登陆失败',
  712. content: '登录信息失效,请重新登录',
  713. success(res) {
  714. if (res.confirm) {
  715. wx.navigateTo({
  716. url: '/pages/login/login',
  717. });
  718. } else if (res.cancel) {
  719. wx.navigateTo({
  720. url: '/pages/login/login',
  721. });
  722. }
  723. },
  724. });
  725. } else {
  726. // 上传失败了
  727. wx.showToast({
  728. title: '图片上传失败',
  729. mask: true,
  730. duration: 2000,
  731. });
  732. }
  733. }
  734. },
  735. fail: function (res) {
  736. //console.log('失败', res);
  737. wx.showToast({
  738. title: '图片上传失败',
  739. icon: 'fail',
  740. duration: 1000,
  741. success(res) {
  742. //console.log(res);
  743. },
  744. });
  745. },
  746. });
  747. }
  748. },
  749. });
  750. },
  751. // 删除图片
  752. clearImg: function (e) {
  753. var index = e.currentTarget.dataset.index;
  754. let that = this;
  755. //console.log(index)
  756. let arr2 = this.data.formFileurl.filter((v, i) => {
  757. return i == index; // 删除 线上
  758. });
  759. let url = app.globalData.httpsUrlServer + '/file/deleteFile';
  760. let data = {
  761. fileDes: arr2[0],
  762. };
  763. wx.showLoading({
  764. title: '删除中',
  765. mask: true,
  766. });
  767. app.postReq(url, data, (res) => {
  768. if (res.status == 200) {
  769. let arr = that.data.uploaderList.filter((v, i) => {
  770. return i != index;
  771. });
  772. let arr1 = that.data.formFileurl.filter((v, i) => {
  773. return i != index; // 删除线上 上传
  774. });
  775. that.setData({
  776. uploaderList: arr,
  777. formFileurl: arr1,
  778. });
  779. app.toast('删除成功');
  780. } else {
  781. app.toast('删除失败');
  782. }
  783. });
  784. },
  785. // 预览图片
  786. showImg: function (e) {
  787. //获取当前图片的下标
  788. console.log(this.data.formFileurl);
  789. //console.log(e)
  790. var index = e.currentTarget.dataset.index;
  791. // //所有图片
  792. var imgs = this.data.formFileurl.map((v) => {
  793. return v.fileUrl;
  794. });
  795. wx.previewImage({
  796. //当前显示图片
  797. current: imgs[index].fileUrl,
  798. //所有图片
  799. urls: imgs,
  800. });
  801. },
  802. // 查看路线
  803. lineRoad() {
  804. var that = this;
  805. that.setData({
  806. polyline: [{
  807. points: that.data.arrPoint,
  808. color: '#FF0000',
  809. width: 9,
  810. arrowLine: true,
  811. borderWidth: 1,
  812. borderColor: '#555',
  813. }, ],
  814. });
  815. },
  816. // 文本域
  817. input(e) {
  818. this.setData({
  819. text: e.detail.value,
  820. });
  821. },
  822. // 按钮组 ↓ ↓ ↓ ↓ ↓ ↓ ↓
  823. // 开始巡查
  824. openAndEndSetting() {
  825. var that = this;
  826. // if (this.data.addldList.length == 0) {
  827. // return app.toast('请选择路段');
  828. // }
  829. if (this.data.addVehicleList.length == 0) {
  830. return app.toast('请选择交通工具');
  831. }
  832. // 开始巡查
  833. wx.showModal({
  834. title: '提示',
  835. content: '确定开始巡查',
  836. success(res) {
  837. if (res.confirm) {
  838. // 记录当前点位
  839. wx.showToast({
  840. title: '正在创建新的巡查记录',
  841. icon: 'loading',
  842. duration: 2000,
  843. });
  844. wx.getLocation({
  845. type: 'gcj02',
  846. isHighAccuracy: true,
  847. success(res) {
  848. var arr = [];
  849. arr.push({
  850. latitude: res.latitude,
  851. longitude: res.longitude,
  852. });
  853. that.getAddress(res.latitude, res.longitude);
  854. that.data.arrPoint = that.data.arrPoint.concat(arr);
  855. that.setData({
  856. arrPoint: that.data.arrPoint,
  857. posObj: {
  858. latitude: res.latitude,
  859. longitude: res.longitude,
  860. },
  861. });
  862. that.createBuild();
  863. },
  864. });
  865. // console.log('用户点击确定');
  866. // that.build()
  867. // 开始执行
  868. } else if (res.cancel) {
  869. console.log('用户点击取消');
  870. }
  871. },
  872. });
  873. },
  874. // 暂停巡查
  875. stopSetting() {
  876. console.log('暂停巡查');
  877. timerList.forEach((v) => {
  878. clearInterval(v);
  879. });
  880. timerListJd.forEach((v) => {
  881. clearInterval(v);
  882. });
  883. this.setData({
  884. flag1: false,
  885. });
  886. },
  887. // 继续巡查
  888. goSetting() {
  889. console.log('继续巡查');
  890. var that = this;
  891. wx.getLocation({
  892. type: 'gcj02',
  893. isHighAccuracy: true,
  894. success(res) {
  895. var arr = [];
  896. arr.push({
  897. latitude: res.latitude,
  898. longitude: res.longitude,
  899. });
  900. // that.getAddress(res.latitude, res.longitude);
  901. that.data.arrPoint = that.data.arrPoint.concat(arr);
  902. that.setData({
  903. arrPoint: that.data.arrPoint,
  904. posObj: {
  905. latitude: res.latitude,
  906. longitude: res.longitude,
  907. },
  908. });
  909. },
  910. });
  911. Datetime = setInterval(() => {
  912. that.setInterval();
  913. }, 1000);
  914. timerList.push(Datetime);
  915. Jdtime = setInterval(() => {
  916. that.tap1(); //获取坐标
  917. that.lineRoad(); //画线
  918. that.build(); // 更新数据
  919. }, 10000);
  920. timerListJd.push(Jdtime);
  921. this.setData({
  922. flag1: true,
  923. });
  924. },
  925. //重新巡查
  926. restInspection() {
  927. this.stopSetting();
  928. var that = this;
  929. console.log('重新巡查');
  930. wx.showModal({
  931. title: '提示',
  932. content: '是否要重新巡查',
  933. success(res) {
  934. if (res.confirm) {
  935. console.log('用户点击确定');
  936. wx.showLoading({
  937. title: '加载中',
  938. });
  939. that.reovem();
  940. } else if (res.cancel) {
  941. console.log('用户点击取消');
  942. }
  943. },
  944. });
  945. },
  946. // 生成本次巡查单 提交功能
  947. sumbit() {
  948. var that = this;
  949. // 暂停
  950. this.stopSetting();
  951. wx.showModal({
  952. title: '提示',
  953. content: '确定结束本次巡查吗?',
  954. success(res) {
  955. if (res.confirm) {
  956. // 保存最后一次 点位
  957. wx.getLocation({
  958. type: 'gcj02',
  959. isHighAccuracy: true,
  960. success(res) {
  961. var arr = [];
  962. arr.push({
  963. latitude: res.latitude,
  964. longitude: res.longitude,
  965. });
  966. that.getAddress(res.latitude, res.longitude);
  967. that.data.arrPoint = that.data.arrPoint.concat(arr);
  968. that.setData({
  969. arrPoint: that.data.arrPoint,
  970. posObj: {
  971. latitude: res.latitude,
  972. longitude: res.longitude,
  973. },
  974. });
  975. that.isOverSpeed()
  976. // // 处理demo
  977. // // 发现问题工单
  978. // if (that.data.workNum != 0) {
  979. // wx.showModal({
  980. // title: '提示',
  981. // content: '巡查中发现问题,确定则创建工单',
  982. // success(res) {
  983. // if (res.confirm) {
  984. // that.build();
  985. // that.sendGD();
  986. // that.out();
  987. // } else if (res.cancel) {
  988. // that.build();
  989. // that.out();
  990. // }
  991. // },
  992. // });
  993. // } else {
  994. // that.build();
  995. // that.out();
  996. // }
  997. },
  998. });
  999. } else if (res.cancel) {
  1000. // 用户取消
  1001. }
  1002. },
  1003. });
  1004. },
  1005. // 点击 发现问题 打开弹框
  1006. openDailog() {
  1007. let that = this;
  1008. this.setData({
  1009. imgDailog: true,
  1010. huatanFlag: false,
  1011. dangerLevelIndex: null,
  1012. issueTypeIndex: null,
  1013. host: ''
  1014. });
  1015. that.getUserInfo();
  1016. // 记录当前点位
  1017. wx.getLocation({
  1018. type: 'gcj02',
  1019. isHighAccuracy: true,
  1020. success: (res) => {
  1021. this.data.workZb.latitude = res.latitude;
  1022. this.data.workZb.longitude = res.longitude;
  1023. this.setData({
  1024. workZb: this.data.workZb,
  1025. });
  1026. var httpUrl = 'https://free-api.heweather.net/s6/weather/now?'
  1027. var loca = res.latitude + ',' + res.longitude;
  1028. wx.request({
  1029. url: httpUrl,
  1030. data: {
  1031. location: loca,
  1032. key: 'e3f16084c5bb4aeda37a6b5b4c7c0032'
  1033. },
  1034. success: (res) => {
  1035. let result = res.data.HeWeather6[0].now;
  1036. that.setData({
  1037. temperature: result.tmp + '℃',
  1038. humidity: result.hum
  1039. })
  1040. }
  1041. })
  1042. },
  1043. });
  1044. let id1 = that.data.parkList[that.data.parkIndex].fParkid;
  1045. let id2;
  1046. if (that.data.yhdwList.length == 0) {
  1047. id2 = that.data.yhCompanyId;
  1048. } else {
  1049. // maintenanceCompanyId
  1050. id2 = that.data.yhdwList[that.data.yhdwIndex].oldMaintenanceCompanyId;
  1051. }
  1052. that.getHuatanbyid(id1, id2);
  1053. },
  1054. // 关闭 弹框
  1055. closeDailog() {
  1056. this.setData({
  1057. imgDailog: false,
  1058. XDSflag: 1,
  1059. });
  1060. },
  1061. // 选择路段
  1062. bindPickerParkChange(e) {
  1063. let index = e.detail.value;
  1064. this.setData({
  1065. parkIndex: index,
  1066. allldList: [],
  1067. addldList: [],
  1068. ldList: [],
  1069. });
  1070. let id = this.data.parkList[this.data.parkIndex].fParkid;
  1071. // 获取当前 路段下的养护单位
  1072. this.getYhdwList(id);
  1073. },
  1074. // 选择养护单位
  1075. bindPickerParkChange2(e) {
  1076. let index = e.detail.value;
  1077. this.setData({
  1078. yhdwIndex: index,
  1079. });
  1080. },
  1081. // 计时器
  1082. setInterval() {
  1083. const that = this;
  1084. var second = that.data.second;
  1085. var minute = that.data.minute;
  1086. var hours = that.data.hours;
  1087. second++;
  1088. if (second >= 60) {
  1089. minute = Number(minute) + Math.floor(second / 60);
  1090. second = 0; // 大于等于60秒归零
  1091. if (minute >= 60) {
  1092. minute = 0; // 大于等于60分归零
  1093. hours++;
  1094. if (hours < 10) {
  1095. // 少于10补零
  1096. that.setData({
  1097. hours: '0' + hours,
  1098. });
  1099. } else {
  1100. that.setData({
  1101. hours: hours,
  1102. });
  1103. }
  1104. }
  1105. if (minute < 10) {
  1106. // 少于10补零
  1107. that.setData({
  1108. minute: '0' + minute,
  1109. });
  1110. } else {
  1111. that.setData({
  1112. minute: minute,
  1113. });
  1114. }
  1115. }
  1116. if (second < 10) {
  1117. // 少于10补零
  1118. that.setData({
  1119. second: '0' + second,
  1120. });
  1121. } else {
  1122. that.setData({
  1123. second: second,
  1124. });
  1125. }
  1126. },
  1127. // 获取地图上两点的距离
  1128. distance(lat1, lng1, lat2, lng2) {
  1129. var that = this;
  1130. lat1 = lat1 || 0;
  1131. lng1 = lng1 || 0;
  1132. lat2 = lat2 || 0;
  1133. lng2 = lng2 || 0;
  1134. var rad1 = (lat1 * Math.PI) / 180.0;
  1135. var rad2 = (lat2 * Math.PI) / 180.0;
  1136. var a = rad1 - rad2;
  1137. var b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
  1138. var r = 6378137;
  1139. var s = (
  1140. r *
  1141. 2 *
  1142. Math.asin(
  1143. Math.sqrt(
  1144. Math.pow(Math.sin(a / 2), 2) +
  1145. Math.cos(rad1) * Math.cos(rad2) * Math.pow(Math.sin(b / 2), 2)
  1146. )
  1147. )
  1148. ).toFixed(0);
  1149. var kilimeter = (s * 1 + that.data.mileage * 1).toFixed(1);
  1150. var kilimeter000 = ((s * 1 + that.data.mileage * 1) / 1000).toFixed(3);
  1151. that.setData({
  1152. mileage: kilimeter,
  1153. mileage1: kilimeter000,
  1154. });
  1155. // that.Inspection()
  1156. },
  1157. createBuild() {
  1158. var that = this;
  1159. let url = app.globalData.httpsUrlServer + '/lhgyWork/savePatrolTrack';
  1160. // 开始坐标 处理
  1161. let start = '';
  1162. let startGc = '';
  1163. for (let k1 in that.data.arrPoint[0]) {
  1164. start += that.data.arrPoint[0][k1];
  1165. start += ',';
  1166. }
  1167. start = start.slice(0, start.length - 1);
  1168. // 开始 gc 坐标处理
  1169. let obj1 = util1.transformFromGCJToWGS(
  1170. that.data.arrPoint[0].latitude,
  1171. that.data.arrPoint[0].longitude
  1172. );
  1173. for (let k4 in obj1) {
  1174. startGc += obj1[k4];
  1175. startGc += ',';
  1176. }
  1177. startGc = startGc.slice(0, startGc.length - 1);
  1178. let detailList = that.data.addldList;
  1179. detailList.map(item => {
  1180. item.roadId = item.id
  1181. })
  1182. let VehicleArr = [];
  1183. let addVehicleList = this.data.addVehicleList;
  1184. addVehicleList.map(item => {
  1185. VehicleArr.push(item.id);
  1186. })
  1187. let data = {
  1188. type: '', //绿地巡查 之前默认绿地巡查 为1;
  1189. objectId: this.data.parkList[this.data.parkIndex].oldSectionId, //标段
  1190. objectName: this.data.parkList[this.data.parkIndex].sectionName, //表单名称
  1191. number3: this.data.yhCompanyId, // 养护单位id
  1192. detailList: detailList, //选的路段
  1193. string3: VehicleArr.toString(),
  1194. startTime: new Date().getTime(), //开始 时间
  1195. startCoordinates: start, //开始坐标
  1196. startCoordinatesGc: startGc, // 开始gc坐标
  1197. };
  1198. if (this.data.position == '绿化科中心') {
  1199. // data.number3 = this.data.yhdwList[this.data.yhdwIndex].fYhcompanyid;
  1200. data.number3 = this.data.yhdwList[this.data.yhdwIndex].oldMaintenanceCompanyId;
  1201. }
  1202. app.postReq(url, data, (res) => {
  1203. if (res.status == 200) {
  1204. wx.hideLoading();
  1205. Datetime = setInterval(() => {
  1206. that.setInterval();
  1207. }, 1000);
  1208. timerList.push(Datetime);
  1209. Jdtime = setInterval(() => {
  1210. that.tap1(); //获取坐标
  1211. that.lineRoad(); // 画线
  1212. that.build(); // 更新数据
  1213. }, 10000);
  1214. timerListJd.push(Jdtime);
  1215. that.setData({
  1216. flag: true,
  1217. InspectionInfo: res.data,
  1218. });
  1219. }
  1220. });
  1221. },
  1222. // 更新 巡查单
  1223. build(islast, isSupple) {
  1224. var that = this;
  1225. // console.log(this.data.InspectionInfo);
  1226. let url = app.globalData.httpsUrlServer + '/lhgyWork/savePatrolTrack';
  1227. let data = this.data.InspectionInfo;
  1228. // 总路程坐标处理
  1229. let totol = '';
  1230. let totolGc = '';
  1231. that.data.arrPoint.forEach((v) => {
  1232. for (let k3 in v) {
  1233. totol += v[k3];
  1234. totol += ',';
  1235. }
  1236. totol = totol.slice(0, totol.length - 1);
  1237. totol += ';';
  1238. });
  1239. totol = totol.slice(0, totol.length - 1);
  1240. let arr = [];
  1241. that.data.arrPoint.forEach((v) => {
  1242. let obj3 = util1.transformFromGCJToWGS(v.latitude, v.longitude);
  1243. arr.push(obj3);
  1244. });
  1245. arr.forEach((v) => {
  1246. for (let k6 in v) {
  1247. totolGc += v[k6];
  1248. totolGc += ',';
  1249. }
  1250. totolGc = totolGc.slice(0, totolGc.length - 1);
  1251. totolGc += ';';
  1252. });
  1253. totolGc = totolGc.slice(0, totolGc.length - 1);
  1254. // 总路程坐标处理 ↑ ↑ ↑ ↑ ↑
  1255. // 结束坐标处理 ↓↓↓↓↓↓↓↓
  1256. let end = '';
  1257. let endGc = '';
  1258. for (let k2 in that.data.arrPoint[that.data.arrPoint.length - 1]) {
  1259. end += that.data.arrPoint[that.data.arrPoint.length - 1][k2];
  1260. end += ',';
  1261. }
  1262. end = end.slice(0, end.length - 1);
  1263. let obj2 = util1.transformFromGCJToWGS(
  1264. that.data.arrPoint[that.data.arrPoint.length - 1].latitude,
  1265. that.data.arrPoint[that.data.arrPoint.length - 1].longitude
  1266. );
  1267. for (let k5 in obj2) {
  1268. endGc += obj2[k5];
  1269. endGc += ',';
  1270. }
  1271. endGc = endGc.slice(0, endGc.length - 1);
  1272. // 结束坐标处理 ↑↑↑↑↑↑↑↑
  1273. data.totalCoordinates = totol;
  1274. data.totalCoordinatesGc = totolGc;
  1275. data.endCoordinates = end;
  1276. data.endCoordinatesGc = endGc;
  1277. data.endTime = util.formatTime(new Date());
  1278. data.totalTime =
  1279. that.data.hours * 60 * 60 + that.data.minute * 60 + that.data.second * 1;
  1280. data.mileage = that.data.mileage1;
  1281. // data.fileList = that.data.WorkList;
  1282. data.isExist = that.data.isExist;
  1283. data.type = that.data.typeStr;
  1284. // 最后一次提交,附加反编译地址
  1285. if (islast && !isSupple) {
  1286. let roadList = [];
  1287. let arrAddress = that.data.arrAddress;
  1288. if (arrAddress.length > 0) {
  1289. arrAddress.map(item => {
  1290. roadList.push({
  1291. roadName: item
  1292. })
  1293. })
  1294. }
  1295. data.roadList = roadList;
  1296. }
  1297. if (isSupple) {
  1298. let detailList = that.data.addldList;
  1299. detailList.map(item => {
  1300. item.roadId = item.id
  1301. })
  1302. data.detailList = detailList;
  1303. }
  1304. app.postReq(url, data, (res) => {
  1305. if (res.status == 200) {
  1306. // that.setData({
  1307. // InspectionInfo: res.data,
  1308. // });
  1309. // 最后一次提交,提示已匹配道路信息
  1310. if(isSupple && islast){
  1311. if (that.data.workNum != 0) {
  1312. wx.showModal({
  1313. title: '提示',
  1314. content: '巡查中发现问题,确定则创建工单?',
  1315. success(res) {
  1316. if (res.confirm) {
  1317. that.sendGD();
  1318. that.out();
  1319. // wx.navigateBack({
  1320. // delta: 1
  1321. // })
  1322. } else if (res.cancel) {
  1323. that.out();
  1324. // wx.navigateBack({
  1325. // delta: 1
  1326. // })
  1327. }
  1328. },
  1329. });
  1330. } else {
  1331. that.out();
  1332. // wx.navigateBack({
  1333. // delta: 1
  1334. // })
  1335. }
  1336. }
  1337. else if (islast && !isSupple) {
  1338. that.setData({
  1339. 'InspectionInfo.roadList': [],
  1340. detailList:res.data.detailList,
  1341. matchedDailog:true
  1342. });
  1343. } else {
  1344. console.log('巡查进度更新');
  1345. that.setData({
  1346. InspectionInfo: res.data,
  1347. });
  1348. }
  1349. } else {
  1350. console.log('巡查进度更新失败,请检查网络重试,本次巡查记录已经保存');
  1351. }
  1352. });
  1353. },
  1354. openRoadDailog(){
  1355. let that = this;
  1356. let id = that.data.parkList[that.data.parkIndex].id;
  1357. if (id) {
  1358. if (that.data.addldList.length == 0) {
  1359. // this.getLdListbyid(id);
  1360. that.getLdListbyid();
  1361. }
  1362. that.setData({
  1363. checkboxEd: true,
  1364. });
  1365. } else {
  1366. return app.toast('请先选择路段');
  1367. }
  1368. },
  1369. addRoadList(){
  1370. let that = this;
  1371. this.build(true,true)
  1372. },
  1373. cancelAndSave(){
  1374. let that = this;
  1375. if (that.data.workNum != 0) {
  1376. wx.showModal({
  1377. title: '提示',
  1378. content: '巡查中发现问题,确定则创建工单?',
  1379. success(res) {
  1380. if (res.confirm) {
  1381. that.sendGD();
  1382. that.out();
  1383. // wx.navigateBack({
  1384. // delta: 1
  1385. // })
  1386. } else if (res.cancel) {
  1387. that.out();
  1388. // wx.navigateBack({
  1389. // delta: 1
  1390. // })
  1391. }
  1392. },
  1393. });
  1394. } else {
  1395. that.out();
  1396. // wx.navigateBack({
  1397. // delta: 1
  1398. // })
  1399. }
  1400. },
  1401. isOverSpeed(type) {
  1402. var that = this;
  1403. // console.log(this.data.InspectionInfo);
  1404. let url = app.globalData.httpsUrlServer + '/lhgyWork/patrolTrackIsSpeeding';
  1405. let data = this.data.InspectionInfo;
  1406. // 总路程坐标处理
  1407. let totol = '';
  1408. let totolGc = '';
  1409. that.data.arrPoint.forEach((v) => {
  1410. for (let k3 in v) {
  1411. totol += v[k3];
  1412. totol += ',';
  1413. }
  1414. totol = totol.slice(0, totol.length - 1);
  1415. totol += ';';
  1416. });
  1417. totol = totol.slice(0, totol.length - 1);
  1418. let arr = [];
  1419. that.data.arrPoint.forEach((v) => {
  1420. let obj3 = util1.transformFromGCJToWGS(v.latitude, v.longitude);
  1421. arr.push(obj3);
  1422. });
  1423. arr.forEach((v) => {
  1424. for (let k6 in v) {
  1425. totolGc += v[k6];
  1426. totolGc += ',';
  1427. }
  1428. totolGc = totolGc.slice(0, totolGc.length - 1);
  1429. totolGc += ';';
  1430. });
  1431. totolGc = totolGc.slice(0, totolGc.length - 1);
  1432. // 总路程坐标处理 ↑ ↑ ↑ ↑ ↑
  1433. // 结束坐标处理 ↓↓↓↓↓↓↓↓
  1434. let end = '';
  1435. let endGc = '';
  1436. for (let k2 in that.data.arrPoint[that.data.arrPoint.length - 1]) {
  1437. end += that.data.arrPoint[that.data.arrPoint.length - 1][k2];
  1438. end += ',';
  1439. }
  1440. end = end.slice(0, end.length - 1);
  1441. let obj2 = util1.transformFromGCJToWGS(
  1442. that.data.arrPoint[that.data.arrPoint.length - 1].latitude,
  1443. that.data.arrPoint[that.data.arrPoint.length - 1].longitude
  1444. );
  1445. for (let k5 in obj2) {
  1446. endGc += obj2[k5];
  1447. endGc += ',';
  1448. }
  1449. endGc = endGc.slice(0, endGc.length - 1);
  1450. // 结束坐标处理 ↑↑↑↑↑↑↑↑
  1451. data.totalCoordinates = totol;
  1452. data.totalCoordinatesGc = totolGc;
  1453. data.endCoordinates = end;
  1454. data.endCoordinatesGc = endGc;
  1455. data.endTime = util.formatTime(new Date());
  1456. data.totalTime =
  1457. that.data.hours * 60 * 60 + that.data.minute * 60 + that.data.second * 1;
  1458. data.mileage = that.data.mileage1;
  1459. // data.fileList = that.data.WorkList;
  1460. data.isExist = that.data.isExist;
  1461. data.type = that.data.typeStr;
  1462. let roadList = [];
  1463. let arrAddress = that.data.arrAddress;
  1464. if (arrAddress.length > 0) {
  1465. arrAddress.map(item => {
  1466. roadList.push({
  1467. roadName: item
  1468. })
  1469. })
  1470. }
  1471. data.roadList = roadList;
  1472. app.postReqNew2(url, {
  1473. data: data
  1474. }, (res) => {
  1475. if (res.status == 200) {
  1476. if (res.data) {
  1477. wx.navigateBack({ delta: 1 })
  1478. } else {
  1479. wx.showModal({
  1480. title: '提示',
  1481. content: '巡查失败!',
  1482. success(res) {
  1483. if (res.confirm) {
  1484. wx.navigateBack({ delta: 1 })
  1485. }
  1486. }
  1487. })
  1488. }
  1489. }
  1490. });
  1491. },
  1492. NavBack() {
  1493. let that = this;
  1494. if (!this.data.flag) {
  1495. wx.navigateBack({
  1496. delta: 1
  1497. })
  1498. } else {
  1499. if(that.data.matchedDailog){
  1500. that.cancelAndSave();
  1501. }else{
  1502. wx.showModal({
  1503. title: '提示',
  1504. content: '确定结束本次巡查吗?',
  1505. success(res) {
  1506. if (res.confirm) {
  1507. // 保存最后一次 点位
  1508. wx.getLocation({
  1509. type: 'gcj02',
  1510. isHighAccuracy: true,
  1511. success(res) {
  1512. var arr = [];
  1513. arr.push({
  1514. latitude: res.latitude,
  1515. longitude: res.longitude,
  1516. });
  1517. that.getAddress(res.latitude, res.longitude);
  1518. that.data.arrPoint = that.data.arrPoint.concat(arr);
  1519. that.setData({
  1520. arrPoint: that.data.arrPoint,
  1521. posObj: {
  1522. latitude: res.latitude,
  1523. longitude: res.longitude,
  1524. },
  1525. });
  1526. that.isOverSpeed('back');
  1527. },
  1528. });
  1529. } else if (res.cancel) {
  1530. // 用户取消
  1531. }
  1532. },
  1533. });
  1534. }
  1535. }
  1536. },
  1537. // 生成工单
  1538. sendGD(val) {
  1539. var that = this;
  1540. let pages = getCurrentPages(); //页面栈
  1541. let beforePage = '';
  1542. beforePage = pages[pages.length - 1];
  1543. let url = app.globalData.httpsUrlServer + '/lhgyWork/savePatrolTrackWork';
  1544. let data = {
  1545. id: this.data.InspectionInfo.id,
  1546. };
  1547. app.postReq(url, data, (res) => {
  1548. if (res.status == 200) {
  1549. if (val == 'flag') {
  1550. beforePage.onPullDownRefresh();
  1551. }
  1552. }
  1553. });
  1554. },
  1555. // 删除 巡查单
  1556. reovem() {
  1557. var that = this;
  1558. let url = app.globalData.httpsUrlServer + '/lhgyWork/deletePatrolTrack';
  1559. let data = {
  1560. id: this.data.InspectionInfo.id,
  1561. };
  1562. app.postReq(url, data, (res) => {
  1563. if (res.status == 200) {
  1564. that.setData({
  1565. flag: false,
  1566. flag1: true,
  1567. hours: '0' + 0, // 时
  1568. minute: '0' + 0, // 分
  1569. second: '0' + 0, // 秒
  1570. polyline: [], //路线数组
  1571. workNum: 0, //问题数量
  1572. addldList: [], // 要巡查的 路段
  1573. arrPoint: [], //坐标数组
  1574. InspectionInfo: {},
  1575. addVehicleList: [] // 交通工具
  1576. });
  1577. wx.hideLoading();
  1578. } else {}
  1579. });
  1580. },
  1581. // 页面进入加载
  1582. onLoad: function (options) {
  1583. if (options.listType) {
  1584. this.setData({
  1585. listType: options.listType,
  1586. });
  1587. }
  1588. wx.disableAlertBeforeUnload({
  1589. message: '测试'
  1590. })
  1591. var that = this;
  1592. // 获取 选择项(公园,路段,等选择功能...)
  1593. that.userSelect();
  1594. that.getWorkTypeList();
  1595. // 检测是否开启定位功能 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
  1596. wx.startLocationUpdateBackground({
  1597. success(res) {
  1598. console.log('开启后台定位', res);
  1599. },
  1600. fail(res) {
  1601. console.log('开启后台定位失败', res);
  1602. },
  1603. });
  1604. that.checkLocation();
  1605. // 检测是否开启定位功能 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
  1606. //获取当前的坐标
  1607. wx.getLocation({
  1608. type: 'gcj02',
  1609. // isHighAccuracy: true,
  1610. success: (res) => {
  1611. that.setData({
  1612. posObj: {
  1613. latitude: res.latitude,
  1614. longitude: res.longitude,
  1615. },
  1616. });
  1617. },
  1618. });
  1619. },
  1620. onUnload() {
  1621. },
  1622. getUserInfo() {
  1623. let that = this;
  1624. // await
  1625. let url =
  1626. app.globalData.httpsUrlServer + '/sysroleinfo/selectRoleInfoByUserId';
  1627. wx.request({
  1628. url: url,
  1629. method: 'get',
  1630. header: {
  1631. Accept: 'application/json',
  1632. 'content-type': 'application/json;charset=UTF-8',
  1633. token: wx.getStorageSync('token'),
  1634. fSource: 1,
  1635. },
  1636. success: function (res) {
  1637. let userInfo = res.data.data;
  1638. let flagArr = [false, false, false];
  1639. userInfo.map(item => {
  1640. if (item.fRolecode == 'ZBY') {
  1641. flagArr[0] = true;
  1642. }
  1643. if (item.fRolecode == 'LHKYHDW') {
  1644. flagArr[1] = true;
  1645. }
  1646. if (item.fRolecode == 'LHK' || item.fRolecode == 'XTGLY') {
  1647. flagArr[2] = true;
  1648. }
  1649. })
  1650. if (flagArr[2] || (flagArr[0] && flagArr[1])) {
  1651. let xdsList = [{
  1652. name: '行道树',
  1653. id: 1,
  1654. checked: (that.data.listType == '' || that.data.listType == '1') ? true : false
  1655. },
  1656. {
  1657. name: '绿地',
  1658. id: 2,
  1659. checked: that.data.listType == '2' ? true : false
  1660. },
  1661. {
  1662. name: '花坛',
  1663. id: 3,
  1664. checked: that.data.listType == '3' ? true : false
  1665. },
  1666. {
  1667. name: '病虫害',
  1668. id: 4,
  1669. checked: that.data.listType == '4' ? true : false
  1670. }
  1671. ]
  1672. that.setData({
  1673. xdsList: xdsList
  1674. })
  1675. } else if (flagArr[1]) {
  1676. let xdsList = [{
  1677. name: '行道树',
  1678. id: 1,
  1679. checked: (that.data.listType == '' || that.data.listType == '1') ? true : false
  1680. },
  1681. {
  1682. name: '绿地',
  1683. id: 2,
  1684. checked: that.data.listType == '2' ? true : false
  1685. },
  1686. {
  1687. name: '花坛',
  1688. id: 3,
  1689. checked: that.data.listType == '3' ? true : false
  1690. }
  1691. ]
  1692. that.setData({
  1693. xdsList: xdsList
  1694. })
  1695. } else if (flagArr[0]) {
  1696. console.log(this.listType, 'flagArr[0]');
  1697. let xdsList = [{
  1698. name: '病虫害',
  1699. id: 4,
  1700. checked: true
  1701. }]
  1702. that.setData({
  1703. xdsList: xdsList
  1704. })
  1705. let obj = {
  1706. detail: {
  1707. value: 4
  1708. }
  1709. }
  1710. that.toggleXDS(obj);
  1711. }
  1712. const typeIndex = that.data.xdsList.findIndex(o => {
  1713. return o.checked == true;
  1714. });
  1715. if (typeIndex > -1) {
  1716. that.toggleXDS({
  1717. detail: {
  1718. value: that.data.xdsList[typeIndex].id,
  1719. }
  1720. });
  1721. // that.issueTypeChange({
  1722. // detail: {
  1723. // value: typeIndex,
  1724. // }
  1725. // });
  1726. }
  1727. },
  1728. fail: function (err) {
  1729. reject(err);
  1730. },
  1731. });
  1732. },
  1733. onUnload: function () {},
  1734. onShow: function () {},
  1735. onHide() {},
  1736. // 获取 数据 ↓ ↓ ↓ ↓ ↓
  1737. // 判断人员, 选择公园权限 ( 选择项 )
  1738. userSelect() {
  1739. let that = this;
  1740. let position = wx.getStorageSync('position');
  1741. let position2 = wx.getStorageSync('position2');
  1742. // 如果是 中心 人员 获取所有路段
  1743. console.log(position)
  1744. console.log(position2)
  1745. // 如果是 养护人员 获取自己的 路段
  1746. that.getLDbyId();
  1747. },
  1748. // 查询所有标段 根据养护单位id 查询路段标
  1749. // getLDbyId() {
  1750. // wx.showLoading({
  1751. // title: '加载中',
  1752. // mask: true,
  1753. // });
  1754. // let that = this;
  1755. // let url =
  1756. // app.globalData.httpsUrlServer +
  1757. // // "/t-lhgy-section/selectSectionByCompany"
  1758. // '/tLhgyFacilitySummaryRoad/selectRoadInfoByYhCompanyId';
  1759. // console.log('养护公司id:'+ wx.getStorageSync('yhCompanyId'))
  1760. // let data = {
  1761. // // yhCompanyId: wx.getStorageSync('yhCompanyId'),
  1762. // maintenanceCompanyId: wx.getStorageSync('maintenanceCompanyId'),
  1763. // };
  1764. // this.setData({
  1765. // yhCompanyId: wx.getStorageSync('yhCompanyId'),
  1766. // });
  1767. // app.postReq(url, data, (res) => {
  1768. // if (res.status == 200) {
  1769. // that.setData({
  1770. // parkList: res.data,
  1771. // });
  1772. // wx.hideLoading();
  1773. // }
  1774. // });
  1775. // },
  1776. getLDbyId() {
  1777. wx.showLoading({
  1778. title: '加载中',
  1779. mask: true,
  1780. });
  1781. let that = this;
  1782. let url = app.globalData.httpsUrlServer + '/parkInfoApp/selectAppParkInfoList';
  1783. // let data = {
  1784. // // yhCompanyId: wx.getStorageSync('yhCompanyId'),
  1785. // maintenanceCompanyId: wx.getStorageSync('maintenanceCompanyId'),
  1786. // };
  1787. this.setData({
  1788. yhCompanyId: wx.getStorageSync('yhCompanyId'),
  1789. maintenanceCompanyId: wx.getStorageSync('maintenanceCompanyId'),
  1790. });
  1791. console.log('getLDbyId')
  1792. app.getReq(url, (res) => {
  1793. console.log('getLDbyId-res', res)
  1794. if (res.status == 200) {
  1795. that.setData({
  1796. parkList: res.data,
  1797. });
  1798. wx.hideLoading();
  1799. }
  1800. });
  1801. },
  1802. // 获得当前路段 的所有 路和路段
  1803. // getLdListbyid(id) {
  1804. // wx.showLoading({
  1805. // title: '加载中',
  1806. // mask: true,
  1807. // });
  1808. // let url =
  1809. // app.globalData.httpsUrlServer +
  1810. // '/tLhgyFacilitySummaryRoad/selectBySectionId';
  1811. // let data = {
  1812. // sectionId: id,
  1813. // };
  1814. // app.postReq(url, data, (res) => {
  1815. // // console.log("res", res)
  1816. // if (res.status == 200) {
  1817. // let arr = res.data;
  1818. // let newArr = [];
  1819. // arr.forEach((v) => {
  1820. // if (v.roadScopeList) {
  1821. // v.roadScopeList.forEach((item) => {
  1822. // newArr.push(item);
  1823. // });
  1824. // }
  1825. // });
  1826. // this.setData({
  1827. // ldList: newArr,
  1828. // allldList: newArr, //所有的路段 留查询使用
  1829. // });
  1830. // // console.log('路和路段');
  1831. // // console.log(this.data.ldList);
  1832. // wx.hideLoading();
  1833. // }
  1834. // });
  1835. // },
  1836. getLdListbyid() {
  1837. let that = this;
  1838. wx.showLoading({
  1839. title: '加载中',
  1840. mask: true,
  1841. });
  1842. let url = app.globalData.httpsUrlServer + '/road/selectRoadList';
  1843. // let url =
  1844. // app.globalData.httpsUrlServer +
  1845. // '/road/selectRoadList';
  1846. let data = {
  1847. sectionId: that.data.parkList[that.data.parkIndex].fParkid,
  1848. maintenanceCompanyId: that.data.maintenanceCompanyId
  1849. };
  1850. if (that.data.yhdwList.length == 0) {
  1851. data.maintenanceCompanyId = that.data.maintenanceCompanyId
  1852. } else {
  1853. data.maintenanceCompanyId = that.data.yhdwList[that.data.yhdwIndex].id
  1854. }
  1855. app.getReqNew(url, data, (res) => {
  1856. if (res.code == 0) {
  1857. let arr = res.data;
  1858. // let newArr = [];
  1859. // arr.forEach((v) => {
  1860. // if (v.roadScopeList) {
  1861. // v.roadScopeList.forEach((item) => {
  1862. // newArr.push(item);
  1863. // });
  1864. // }
  1865. // });
  1866. this.setData({
  1867. ldList: arr,
  1868. allldList: arr, //所有的路段 留查询使用
  1869. });
  1870. // console.log('路和路段');
  1871. // console.log(this.data.ldList);
  1872. wx.hideLoading();
  1873. }
  1874. });
  1875. },
  1876. getYhdwList(id) {
  1877. wx.showLoading({
  1878. title: '加载中',
  1879. mask: true,
  1880. });
  1881. let that = this;
  1882. let url =
  1883. app.globalData.httpsUrlServer + '/maintenance/company/selectMaintenanceCompanyBySectionId';
  1884. let data = {
  1885. sectionId: id,
  1886. };
  1887. app.getReqNew(url, data, (res) => {
  1888. // console.log("res", res)
  1889. if (res.code == 0) {
  1890. that.setData({
  1891. yhdwList: res.data,
  1892. });
  1893. wx.hideLoading();
  1894. }
  1895. });
  1896. },
  1897. // 获取问题类型
  1898. getWorkTypeList(val = 1) {
  1899. let that = this;
  1900. // 获取等待
  1901. app.loading('loading~');
  1902. if (val == 4) {
  1903. let surl = app.globalData.httpsUrlServer +
  1904. '/common/kind/list';
  1905. let data = {
  1906. type: 1
  1907. }
  1908. app.getReqNew(surl, data, (res) => {
  1909. if (res.code == "0") {
  1910. let lists = res.data;
  1911. this.setData({
  1912. issueTypeList: lists,
  1913. });
  1914. }
  1915. app.hideloading();
  1916. });
  1917. } else {
  1918. let url =
  1919. app.globalData.httpsUrlServer +
  1920. '/woworkordertype/selectOrderTypeList';
  1921. let data = {
  1922. };
  1923. app.getReq(url, (res) => {
  1924. console.log('sadfaf', res)
  1925. if (res.status == 200) {
  1926. let lists = res.data.filter(item => item.fParentid == 3);
  1927. this.setData({
  1928. workTypeList: lists,
  1929. });
  1930. // that.hazardRateInit();
  1931. // that.loadWormList();
  1932. }
  1933. app.hideloading();
  1934. });
  1935. }
  1936. // if (val == 4) {
  1937. // let surl = app.globalData.httpsUrlServer +
  1938. // '/common/kind/list';
  1939. // let data = {
  1940. // type: 1
  1941. // }
  1942. // // let lists = [{fValuecode:1,fName:'食叶性害虫'},
  1943. // // {fValuecode:2,fName:'刺吸性害虫'},
  1944. // // {fValuecode:3,fName:'钻蛀性害虫'},
  1945. // // {fValuecode:4,fName:'地下害虫'},
  1946. // // {fValuecode:5,fName:'病害类'}]
  1947. // app.getReqNew(surl, data, (res) => {
  1948. // if (res.code == "0") {
  1949. // let lists = res.data;
  1950. // // lists.map(item =>{
  1951. // // item.fValuecode = item.id;
  1952. // // item.fName = item.kindName;
  1953. // // })
  1954. // this.setData({
  1955. // issueTypeList: lists,
  1956. // });
  1957. // // that.hazardRateInit();
  1958. // // that.loadWormList();
  1959. // }
  1960. // app.hideloading();
  1961. // });
  1962. // // this.setData({
  1963. // // workTypeList: lists,
  1964. // // });
  1965. // // app.hideloading();
  1966. // } else {
  1967. // app.postReq(url, data, (res) => {
  1968. // if (res.status == 200) {
  1969. // this.setData({
  1970. // workTypeList: res.data,
  1971. // });
  1972. // app.hideloading();
  1973. // }
  1974. // });
  1975. // }
  1976. },
  1977. hazardRateInit() {
  1978. let arr1 = [];
  1979. let issueTypeList = this.data.issueTypeList;
  1980. let issueTypeIndex = this.data.issueTypeIndex;
  1981. if (issueTypeList[issueTypeIndex].id == 1 || issueTypeList[issueTypeIndex].id == 2 || issueTypeList[issueTypeIndex].id == 5) {
  1982. arr1 = [{
  1983. name: '轻度(≤10%)',
  1984. id: 0,
  1985. label: '≤10%'
  1986. },
  1987. {
  1988. name: '中度(>10%,≤15%)',
  1989. id: 1,
  1990. label: '>10%,≤15%'
  1991. },
  1992. {
  1993. name: '重度(>15%)',
  1994. id: 2,
  1995. label: '>15%'
  1996. }
  1997. ];
  1998. } else if (issueTypeList[issueTypeIndex].id == 3 || issueTypeList[issueTypeIndex].id == 4) {
  1999. arr1 = [{
  2000. name: '轻度(零星为害)',
  2001. id: 0,
  2002. label: '零星为害'
  2003. },
  2004. {
  2005. name: '中度(≤3%)',
  2006. id: 1,
  2007. label: '≤3%'
  2008. },
  2009. {
  2010. name: '重度(>3%)',
  2011. id: 2,
  2012. label: '>3%'
  2013. }
  2014. ];
  2015. } else {
  2016. arr1 = [{
  2017. name: '轻度(≤10%)',
  2018. id: 0,
  2019. label: '≤10%'
  2020. },
  2021. {
  2022. name: '中度(>10%,≤15%)',
  2023. id: 1,
  2024. label: '>10%,≤15%'
  2025. },
  2026. {
  2027. name: '重度(>15%)',
  2028. id: 2,
  2029. label: '>15%'
  2030. }
  2031. ];
  2032. }
  2033. this.setData({
  2034. dangerLevelLIst: arr1,
  2035. // hazardRatio:arr1[this.data.dangerLevelIndex].label
  2036. })
  2037. },
  2038. // 设置项 ↓ ↓ ↓ ↓ ↓ ↓
  2039. //校验位置权限是否打开
  2040. checkLocation() {
  2041. let that = this;
  2042. //选择位置,需要用户授权
  2043. wx.getSetting({
  2044. success(res) {
  2045. //console.log("res", res)
  2046. if (
  2047. !res.authSetting['scope.userLocation'] &&
  2048. !res.authSetting['scope.userLocationBackground']
  2049. ) {
  2050. wx.authorize({
  2051. scope: 'scope.userLocation',
  2052. success() {
  2053. wx.showToast({
  2054. //这里提示失败原因
  2055. title: '授权成功!',
  2056. duration: 1500,
  2057. });
  2058. },
  2059. fail() {
  2060. that.showSettingToast('需要授权位置信息');
  2061. },
  2062. });
  2063. }
  2064. },
  2065. });
  2066. },
  2067. // 打开权限设置页提示框
  2068. showSettingToast: function (e) {
  2069. var that = this;
  2070. wx.showModal({
  2071. title: '提示!',
  2072. confirmText: '去设置',
  2073. showCancel: false,
  2074. content: e,
  2075. success: function (res) {
  2076. if (res.confirm) {
  2077. wx.openSetting({
  2078. success: (res) => {
  2079. //console.log("设置res", res)
  2080. if (res.errMsg == 'openSetting:ok') {
  2081. // wx.navigateBack({
  2082. // delta: 1,
  2083. // })
  2084. wx.hideToast();
  2085. setTimeout(() => {
  2086. app.toast('设置成功');
  2087. that.onLoad();
  2088. }, 500);
  2089. }
  2090. },
  2091. fail: (err) => {
  2092. //console.log("err", err)
  2093. wx.showToast({
  2094. //这里提示失败原因
  2095. title: '授权失败',
  2096. duration: 1500,
  2097. });
  2098. },
  2099. });
  2100. }
  2101. },
  2102. });
  2103. },
  2104. onHide() {},
  2105. onShow: function () {},
  2106. out() {
  2107. this.setData({
  2108. endFlag: true,
  2109. });
  2110. let pages = getCurrentPages(); //页面栈
  2111. let beforePage = '';
  2112. beforePage = pages[pages.length - 2];
  2113. wx.navigateBack({
  2114. delta: 1, //返回上一级页面
  2115. success: function () {
  2116. beforePage.onPullDownRefresh();
  2117. },
  2118. });
  2119. },
  2120. out1() {
  2121. this.setData({
  2122. endFlag: true,
  2123. });
  2124. let pages = getCurrentPages(); //页面栈
  2125. let beforePage = '';
  2126. beforePage = pages[pages.length - 2];
  2127. beforePage.onPullDownRefresh();
  2128. },
  2129. onUnload() {
  2130. var that = this;
  2131. that.stopSetting();
  2132. if (this.data.arrPoint.length == 0) {
  2133. return;
  2134. }
  2135. if (this.data.endFlag) return;
  2136. if (that.data.workNum != 0) {
  2137. wx.showModal({
  2138. title: '提示',
  2139. content: '巡查中发现问题,确定则创建工单',
  2140. success(res) {
  2141. if (res.confirm) {
  2142. that.build();
  2143. that.sendGD('flag');
  2144. } else if (res.cancel) {
  2145. that.build();
  2146. that.out1();
  2147. }
  2148. },
  2149. });
  2150. } else {
  2151. that.build();
  2152. that.out1();
  2153. }
  2154. },
  2155. });