Keine Beschreibung

inspectionHuatan.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. // greenland/pages/inspectionHuatan/inspectionHuatan.jsisExist
  2. const app = getApp();
  3. var util = require('../../../utils/util.js');
  4. var util1 = require('../../utils/wgs84Gcj02.js');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. longitude: '',
  11. latitude: '',
  12. array: [],
  13. index: 0,
  14. yhdwList: [],
  15. index1: 0,
  16. iswork: [],
  17. yhCompanyId: '',
  18. // 弹框
  19. imgDailog: false,
  20. formFileurl: [],
  21. WorkList: [],
  22. textValue: '',
  23. isExist: 0,
  24. workTypeList: [], //问题类型 数组
  25. index2: 0,
  26. huatanList: [
  27. {
  28. name: '花坛1标',
  29. des: '龙腾路 虎啸路交叉口',
  30. },
  31. {
  32. name: '花坛1标',
  33. des: '龙腾路 虎啸路交叉口',
  34. },
  35. {
  36. name: '花坛1标',
  37. des: '龙腾路 虎啸路交叉口',
  38. },
  39. ],
  40. huatanindex: null,
  41. huatanFlag: false,
  42. flag: true,
  43. endflag: false,
  44. flagend: false,
  45. },
  46. // 选择路段
  47. selectLd(e) {
  48. if (e.detail.value == this.data.index) return;
  49. this.setData({
  50. index: e.detail.value,
  51. huatanindex: null,
  52. });
  53. this.getYhdwListbyLd(this.data.array[this.data.index].sectionId);
  54. },
  55. // 选择养护单位
  56. selectYhdw(e) {
  57. if (e.detail.value == this.data.index1) return;
  58. this.setData({
  59. index1: e.detail.value,
  60. huatanindex: null,
  61. });
  62. that.getHuatanbyid(
  63. this.data.array[this.data.index].sectionId,
  64. this.data.yhdwList[this.data.index1].fYhcompanyid
  65. );
  66. },
  67. // 显示花坛
  68. showHuatan() {
  69. this.setData({
  70. huatanFlag: true,
  71. });
  72. },
  73. // 隐藏花坛
  74. hidehuatan() {
  75. this.setData({
  76. huatanFlag: false,
  77. });
  78. },
  79. // 选择花坛
  80. togglehuatan(e) {
  81. console.log(e);
  82. this.setData({
  83. huatanindex: e.currentTarget.dataset.index,
  84. });
  85. },
  86. // 根据 路段选择 该路段下的养护单位
  87. getYhdwListbyLd(id) {
  88. app.loading('loading~');
  89. let that = this;
  90. let url =
  91. app.globalData.httpsUrlServer + '/t-lhgy-section/selectCompanyBySection';
  92. let data = {
  93. fSectionId: id,
  94. };
  95. app.postReq(url, data, (res) => {
  96. console.log('res', res);
  97. if (res.status == 200) {
  98. that.setData({
  99. yhdwList: res.data,
  100. });
  101. // 根据 养护单位 查询 花坛
  102. that.getHuatanbyid(
  103. that.data.array[that.data.index].sectionId,
  104. that.data.yhdwList[that.data.index1].fYhcompanyid
  105. );
  106. wx.hideLoading();
  107. }
  108. });
  109. },
  110. // 获取所有路段
  111. getAllLd() {
  112. app.loading('loading~');
  113. let that = this;
  114. let url =
  115. app.globalData.httpsUrlServer +
  116. '/tLhgyFacilitySummaryRoad/selectRoadInfoByYhCompanyId';
  117. let data = {};
  118. app.postReq(url, data, (res) => {
  119. console.log('res', res);
  120. if (res.status == 200) {
  121. that.setData({
  122. array: res.data,
  123. });
  124. that.getYhdwListbyLd(res.data[0].sectionId);
  125. wx.hideLoading();
  126. //
  127. }
  128. });
  129. },
  130. // 查询 标段 根据养护单位id 查询路段标
  131. getLDbyId() {
  132. app.loading('loading~');
  133. let that = this;
  134. let url =
  135. app.globalData.httpsUrlServer +
  136. // "/t-lhgy-section/selectSectionByCompany"
  137. '/tLhgyFacilitySummaryRoad/selectRoadInfoByYhCompanyId';
  138. let data = {
  139. yhCompanyId: wx.getStorageSync('yhCompanyId'),
  140. };
  141. this.setData({
  142. yhCompanyId: wx.getStorageSync('yhCompanyId'),
  143. });
  144. app.postReq(url, data, (res) => {
  145. console.log('res', res);
  146. if (res.status == 200) {
  147. that.setData({
  148. array: res.data,
  149. });
  150. this.getYhdwListbyLd(this.data.array[this.data.index].sectionId);
  151. wx.hideLoading();
  152. }
  153. });
  154. },
  155. // 权限判断
  156. userSelect() {
  157. let that = this;
  158. let position = wx.getStorageSync('position');
  159. let position2 = wx.getStorageSync('position2');
  160. this.setData({
  161. yhCompanyId: wx.getStorageInfoSync('yhCompanyId'),
  162. });
  163. // 如果是 绿化可 获取所有路段
  164. // 如果是 中心 人员 获取所有路段
  165. if (position == '绿化科中心') {
  166. this.getAllLd();
  167. this.setData({
  168. position: '绿化科中心',
  169. positionFlag: true,
  170. });
  171. return;
  172. }
  173. if (position2 == '绿化科中心') {
  174. this.getAllLd();
  175. this.setData({
  176. position: '绿化科中心',
  177. positionFlag: true,
  178. });
  179. return;
  180. }
  181. // 如果是 养护人员 获取自己的 路段
  182. this.setData({
  183. flag: false,
  184. });
  185. that.getLDbyId();
  186. },
  187. // 打开弹框
  188. showDailog() {
  189. let state1 = this.data.array[this.data.index];
  190. let state2 = this.data.yhdwList[this.data.index1];
  191. let state3 = this.data.huatanList[this.data.huatanindex];
  192. if (!state1) {
  193. return app.toast('请选择路段');
  194. }
  195. if (!state2) {
  196. return app.toast('请选择养护单位');
  197. }
  198. if (!state3) {
  199. return app.toast('请选择花坛');
  200. }
  201. // state3
  202. // 调起 拍照
  203. this.setData({
  204. imgDailog: true,
  205. isExist: 0,
  206. });
  207. },
  208. // 关闭弹框
  209. closeDailog() {
  210. this.setData({
  211. imgDailog: false,
  212. });
  213. },
  214. // 拍照
  215. uploader() {
  216. var that = this;
  217. let token = wx.getStorageSync('token');
  218. console.log(token);
  219. wx.chooseImage({
  220. count: 1, // 默认9
  221. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  222. sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
  223. success: function (res) {
  224. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  225. app.loading('loading~');
  226. var tempFilePaths = res.tempFilePaths;
  227. console.log(tempFilePaths);
  228. wx.uploadFile({
  229. url: app.globalData.httpsUrlServer + '/file/uploadPatrolFile',
  230. filePath: tempFilePaths[0],
  231. name: 'images',
  232. header: {
  233. 'Content-Type': 'application/json;charset=UTF-8',
  234. token: token,
  235. fSource: 1,
  236. },
  237. success: (res) => {
  238. // console.log(res);
  239. if (res.statusCode == 200) {
  240. console.log();
  241. let data = JSON.parse(res.data);
  242. that.setData({
  243. formFileurl: that.data.formFileurl.concat(data.data[0]),
  244. });
  245. setTimeout(() => {
  246. wx.showToast({
  247. title: '图片上传成功',
  248. mask: true,
  249. duration: 1000,
  250. });
  251. }, 500);
  252. } else {
  253. wx.showToast({
  254. title: '图片上传失败',
  255. mask: true,
  256. duration: 2000,
  257. });
  258. }
  259. },
  260. fail: () => {
  261. wx.showToast({
  262. title: '图片上传失败',
  263. mask: true,
  264. duration: 2000,
  265. });
  266. },
  267. complete: () => {},
  268. });
  269. },
  270. });
  271. },
  272. // 删除图片
  273. clearImg(index) {
  274. let index1 = index.currentTarget.dataset.index;
  275. let temp = this.data.formFileurl[index1];
  276. let url = app.globalData.httpsUrlServer + '/file/deleteFile';
  277. let data = {
  278. fileDes: temp,
  279. };
  280. wx.showLoading({
  281. title: '删除中',
  282. mask: true,
  283. });
  284. app.postReq(url, data, (res) => {
  285. if (res.status == 200) {
  286. this.data.formFileurl = this.data.formFileurl.filter((v, i) => {
  287. return i != index1;
  288. });
  289. this.setData({
  290. formFileurl: this.data.formFileurl,
  291. });
  292. app.toast('删除成功');
  293. } else {
  294. app.toast('删除失败');
  295. }
  296. });
  297. },
  298. // 保存图片上传
  299. UploadP() {
  300. console.log(this.data.formFileurl);
  301. console.log(this.data.textValue);
  302. console.log(this.data.isWork);
  303. if (this.data.formFileurl.length < 2) {
  304. return app.toast('最少上传两张图片');
  305. }
  306. if (this.data.isExist == 1) {
  307. if (!this.data.textValue.trim()) {
  308. return app.toast('请输入描述内容');
  309. }
  310. } else {
  311. }
  312. app.loading('loading~');
  313. let obj = {};
  314. this.data.formFileurl.forEach((v) => {
  315. v.fileCoordinates = this.data.latitude + ',' + this.data.longitude;
  316. v.remark = this.data.textValue;
  317. let obj = util1.transformFromGCJToWGS(
  318. this.data.latitude,
  319. this.data.longitude
  320. );
  321. v.fileCoordinatesGc = obj.latitude + ',' + obj.longitude;
  322. v.createDate = util.formatTime(new Date());
  323. if (this.data.isExist == 1) {
  324. v.number2 = 1;
  325. v.string3 = this.data.workTypeList[this.data.index2].fValuecode;
  326. v.string4 = this.data.workTypeList[this.data.index2].fName;
  327. } else {
  328. v.number2 = 0;
  329. v.string3 = null;
  330. v.string4 = null;
  331. }
  332. v.number4 = 3;
  333. });
  334. if (this.data.isExist == 1) {
  335. this.data.iswork.push('1');
  336. }
  337. obj.fileList = this.data.formFileurl;
  338. this.data.WorkList.push(obj);
  339. this.setData({
  340. WorkList: this.data.WorkList,
  341. iswork: this.data.iswork,
  342. });
  343. wx.showToast({
  344. title: '保存成功',
  345. mask: true,
  346. duration: 1000,
  347. });
  348. this.setData({
  349. formFileurl: [],
  350. imgDailog: false,
  351. });
  352. },
  353. //输入框事件
  354. input(e) {
  355. this.setData({
  356. textValue: e.detail.value,
  357. });
  358. },
  359. // 单选框 事件
  360. radiochange(e) {
  361. this.setData({
  362. isExist: e.detail.value,
  363. });
  364. },
  365. // 选择问题 类型
  366. changeType(e) {
  367. this.setData({
  368. index2: e.detail.value,
  369. });
  370. },
  371. // 获取当前定位
  372. getUserloc() {
  373. wx.getLocation({
  374. type: 'gcj02',
  375. // altitude: false,
  376. success: (result) => {
  377. console.log(result);
  378. this.setData({
  379. longitude: result.longitude,
  380. latitude: result.latitude,
  381. });
  382. },
  383. fail: () => {},
  384. complete: () => {},
  385. });
  386. },
  387. //校验位置权限是否打开
  388. checkLocation() {
  389. let that = this;
  390. //选择位置,需要用户授权
  391. wx.getSetting({
  392. success(res) {
  393. //console.log("res", res)
  394. if (
  395. !res.authSetting['scope.userLocation'] &&
  396. !res.authSetting['scope.userLocationBackground']
  397. ) {
  398. wx.authorize({
  399. scope: 'scope.userLocation',
  400. success() {
  401. wx.showToast({
  402. //这里提示失败原因
  403. title: '授权成功!',
  404. duration: 1500,
  405. });
  406. },
  407. fail() {
  408. that.showSettingToast('需要授权位置信息');
  409. },
  410. });
  411. }
  412. },
  413. });
  414. },
  415. // 打开权限设置页提示框
  416. showSettingToast: function (e) {
  417. var that = this;
  418. wx.showModal({
  419. title: '提示!',
  420. confirmText: '去设置',
  421. showCancel: false,
  422. content: e,
  423. success: function (res) {
  424. if (res.confirm) {
  425. wx.openSetting({
  426. success: (res) => {
  427. //console.log("设置res", res)
  428. if (res.errMsg == 'openSetting:ok') {
  429. // wx.navigateBack({
  430. // delta: 1,
  431. // })
  432. wx.hideToast();
  433. setTimeout(() => {
  434. app.toast('设置成功');
  435. that.onLoad();
  436. }, 500);
  437. }
  438. // wx.hideToast()
  439. // wx.showToast({
  440. // //这里提示失败原因
  441. // title: "授权成功!",
  442. // duration: 1500,
  443. // })
  444. },
  445. fail: (err) => {
  446. //console.log("err", err)
  447. wx.showToast({
  448. //这里提示失败原因
  449. title: '授权失败',
  450. duration: 1500,
  451. });
  452. },
  453. });
  454. }
  455. },
  456. });
  457. },
  458. // 结束巡查
  459. endXC() {
  460. console.log('发送工单');
  461. this.build();
  462. },
  463. closehuatan() {
  464. this.setData({
  465. huatanFlag: false,
  466. });
  467. },
  468. // 发送工单 封装
  469. // 发送工单 封装
  470. build() {
  471. app.loading('loading~');
  472. this.getUserloc();
  473. this.setData({
  474. flagend: true,
  475. });
  476. let that = this;
  477. let url = app.globalData.httpsUrlServer + '/lhgyWork/savePatrolTrack';
  478. let startTime = new Date().getTime();
  479. if (this.data.WorkList.length == 0) {
  480. return app.toast('请上传巡查图片');
  481. }
  482. let data = {
  483. startTime: startTime,
  484. objectId: that.data.array[that.data.index].sectionId, //路段id
  485. objectName: that.data.array[that.data.index].sectionName, //路段名称
  486. fileList: this.data.WorkList,
  487. isExist: that.data.iswork.length > 0 ? 1 : 0,
  488. number3: that.data.yhCompanyId, // 养护单位id
  489. type: 2, //花坛类型
  490. string1: that.data.huatanList[that.data.huatanindex].fAttractionsAlowerId, //景点 id
  491. string2:
  492. that.data.huatanList[that.data.huatanindex].fAttractionsName +
  493. '--' +
  494. that.data.huatanList[that.data.huatanindex].fAttractionsPlace,
  495. };
  496. if (this.data.position == '绿化科中心') {
  497. data.number3 = that.data.yhdwList[that.data.index1].fYhcompanyid;
  498. }
  499. console.log(data);
  500. app.postReq(url, data, (res) => {
  501. console.log('res', res);
  502. if (res.status == 200) {
  503. wx.hideLoading();
  504. let pages = getCurrentPages(); //页面栈
  505. let beforePage = '';
  506. // console.log("that.data.endFlag", that.data.endFlag)
  507. if (that.data.endFlag == true) {
  508. beforePage = pages[pages.length - 1];
  509. console.log(beforePage);
  510. beforePage.onPullDownRefresh();
  511. return;
  512. }
  513. beforePage = pages[pages.length - 2];
  514. wx.navigateBack({
  515. delta: 1, //返回上一级页面
  516. success: function () {
  517. console.log(beforePage);
  518. beforePage.onPullDownRefresh();
  519. },
  520. });
  521. }
  522. });
  523. },
  524. // 获取 问题类型
  525. getworkType() {
  526. // 获取等待
  527. app.loading('loading~');
  528. let url =
  529. app.globalData.httpsUrlServer +
  530. '/sysdictionaryvalueApp/selectAppDictionaryByFlag';
  531. let data = {
  532. fDictionaryflag: 'GDDL',
  533. deptType: '2',
  534. patrolType: '2',
  535. };
  536. app.postReq(url, data, (res) => {
  537. if (res.status == 200) {
  538. this.setData({
  539. workTypeList: res.data,
  540. });
  541. console.log(this.data.workTypeList);
  542. app.hideloading();
  543. }
  544. });
  545. },
  546. // 根据 标段 id 养护单位id 查询 花坛
  547. getHuatanbyid(i1, i2) {
  548. var that = this;
  549. let url =
  550. app.globalData.httpsUrlServer +
  551. '/t-lhgy-attractions-flowers/selectAttractionsFlowersByYhSelection';
  552. let data = {
  553. fSectionId: i1,
  554. fYhCompanyId: i2,
  555. };
  556. app.postReq(url, data, (res) => {
  557. console.log(res);
  558. if (res.status == 200) {
  559. that.setData({
  560. huatanList: res.data,
  561. });
  562. }
  563. });
  564. },
  565. onLoad: function (options) {
  566. wx.startLocationUpdateBackground({
  567. success(res) {
  568. console.log('开启后台定位', res);
  569. },
  570. fail(res) {
  571. console.log('开启后台定位失败', res);
  572. },
  573. });
  574. this.checkLocation();
  575. this.getUserloc();
  576. // ↑↑↑↑↑↑ 权限判断
  577. // 根据权限 获取所有
  578. this.userSelect();
  579. this.getworkType();
  580. },
  581. /**
  582. * 生命周期函数--监听页面初次渲染完成
  583. */
  584. onReady: function () {},
  585. /**
  586. * 生命周期函数--监听页面显示
  587. */
  588. onShow: function () {},
  589. /**
  590. * 生命周期函数--监听页面隐藏
  591. */
  592. onHide: function () {},
  593. /**
  594. * 生命周期函数--监听页面卸载
  595. */
  596. onUnload: function () {
  597. if (this.data.flagend) return;
  598. this.setData({
  599. endFlag: true,
  600. });
  601. if (this.data.iswork.length == 0) return; // 没有任何 信息 返回
  602. if (this.data.iswork.length > 0) {
  603. this.build();
  604. }
  605. },
  606. /**
  607. * 页面相关事件处理函数--监听用户下拉动作
  608. */
  609. onPullDownRefresh: function () {},
  610. /**
  611. * 页面上拉触底事件的处理函数
  612. */
  613. onReachBottom: function () {},
  614. /**
  615. * 用户点击右上角分享
  616. */
  617. onShareAppMessage: function () {},
  618. });