| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652 |
- // greenland/pages/inspectionHuatan/inspectionHuatan.jsisExist
- const app = getApp();
- var util = require('../../../utils/util.js');
- var util1 = require('../../utils/wgs84Gcj02.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- longitude: '',
- latitude: '',
- array: [],
- index: 0,
- yhdwList: [],
- index1: 0,
- iswork: [],
- yhCompanyId: '',
- // 弹框
- imgDailog: false,
- formFileurl: [],
- WorkList: [],
- textValue: '',
- isExist: 0,
- workTypeList: [], //问题类型 数组
- index2: 0,
- huatanList: [
- {
- name: '花坛1标',
- des: '龙腾路 虎啸路交叉口',
- },
- {
- name: '花坛1标',
- des: '龙腾路 虎啸路交叉口',
- },
- {
- name: '花坛1标',
- des: '龙腾路 虎啸路交叉口',
- },
- ],
- huatanindex: null,
- huatanFlag: false,
- flag: true,
- endflag: false,
- flagend: false,
- },
- // 选择路段
- selectLd(e) {
- if (e.detail.value == this.data.index) return;
- this.setData({
- index: e.detail.value,
- huatanindex: null,
- });
- this.getYhdwListbyLd(this.data.array[this.data.index].sectionId);
- },
- // 选择养护单位
- selectYhdw(e) {
- if (e.detail.value == this.data.index1) return;
- this.setData({
- index1: e.detail.value,
- huatanindex: null,
- });
- that.getHuatanbyid(
- this.data.array[this.data.index].sectionId,
- this.data.yhdwList[this.data.index1].fYhcompanyid
- );
- },
- // 显示花坛
- showHuatan() {
- this.setData({
- huatanFlag: true,
- });
- },
- // 隐藏花坛
- hidehuatan() {
- this.setData({
- huatanFlag: false,
- });
- },
- // 选择花坛
- togglehuatan(e) {
- console.log(e);
- this.setData({
- huatanindex: e.currentTarget.dataset.index,
- });
- },
- // 根据 路段选择 该路段下的养护单位
- getYhdwListbyLd(id) {
- app.loading('loading~');
- let that = this;
- let url =
- app.globalData.httpsUrlServer + '/t-lhgy-section/selectCompanyBySection';
- let data = {
- fSectionId: id,
- };
- app.postReq(url, data, (res) => {
- console.log('res', res);
- if (res.status == 200) {
- that.setData({
- yhdwList: res.data,
- });
- // 根据 养护单位 查询 花坛
- that.getHuatanbyid(
- that.data.array[that.data.index].sectionId,
- that.data.yhdwList[that.data.index1].fYhcompanyid
- );
- wx.hideLoading();
- }
- });
- },
- // 获取所有路段
- getAllLd() {
- app.loading('loading~');
- let that = this;
- let url =
- app.globalData.httpsUrlServer +
- '/tLhgyFacilitySummaryRoad/selectRoadInfoByYhCompanyId';
- let data = {};
- app.postReq(url, data, (res) => {
- console.log('res', res);
- if (res.status == 200) {
- that.setData({
- array: res.data,
- });
- that.getYhdwListbyLd(res.data[0].sectionId);
- wx.hideLoading();
- //
- }
- });
- },
- // 查询 标段 根据养护单位id 查询路段标
- getLDbyId() {
- app.loading('loading~');
- let that = this;
- let url =
- app.globalData.httpsUrlServer +
- // "/t-lhgy-section/selectSectionByCompany"
- '/tLhgyFacilitySummaryRoad/selectRoadInfoByYhCompanyId';
- let data = {
- yhCompanyId: wx.getStorageSync('yhCompanyId'),
- };
- this.setData({
- yhCompanyId: wx.getStorageSync('yhCompanyId'),
- });
- app.postReq(url, data, (res) => {
- console.log('res', res);
- if (res.status == 200) {
- that.setData({
- array: res.data,
- });
- this.getYhdwListbyLd(this.data.array[this.data.index].sectionId);
- wx.hideLoading();
- }
- });
- },
- // 权限判断
- userSelect() {
- let that = this;
- let position = wx.getStorageSync('position');
- let position2 = wx.getStorageSync('position2');
- this.setData({
- yhCompanyId: wx.getStorageInfoSync('yhCompanyId'),
- });
- // 如果是 绿化可 获取所有路段
- // 如果是 中心 人员 获取所有路段
- if (position == '绿化科中心') {
- this.getAllLd();
- this.setData({
- position: '绿化科中心',
- positionFlag: true,
- });
- return;
- }
- if (position2 == '绿化科中心') {
- this.getAllLd();
- this.setData({
- position: '绿化科中心',
- positionFlag: true,
- });
- return;
- }
- // 如果是 养护人员 获取自己的 路段
- this.setData({
- flag: false,
- });
- that.getLDbyId();
- },
- // 打开弹框
- showDailog() {
- let state1 = this.data.array[this.data.index];
- let state2 = this.data.yhdwList[this.data.index1];
- let state3 = this.data.huatanList[this.data.huatanindex];
- if (!state1) {
- return app.toast('请选择路段');
- }
- if (!state2) {
- return app.toast('请选择养护单位');
- }
- if (!state3) {
- return app.toast('请选择花坛');
- }
- // state3
- // 调起 拍照
- this.setData({
- imgDailog: true,
- isExist: 0,
- });
- },
- // 关闭弹框
- closeDailog() {
- this.setData({
- imgDailog: false,
- });
- },
- // 拍照
- uploader() {
- var that = this;
- let token = wx.getStorageSync('token');
- console.log(token);
- wx.chooseImage({
- count: 1, // 默认9
- sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
- sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
- success: function (res) {
- // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
- app.loading('loading~');
- var tempFilePaths = res.tempFilePaths;
- console.log(tempFilePaths);
- wx.uploadFile({
- url: app.globalData.httpsUrlServer + '/file/uploadPatrolFile',
- filePath: tempFilePaths[0],
- name: 'images',
- header: {
- 'Content-Type': 'application/json;charset=UTF-8',
- token: token,
- fSource: 1,
- },
- success: (res) => {
- // console.log(res);
- if (res.statusCode == 200) {
- console.log();
- let data = JSON.parse(res.data);
- that.setData({
- formFileurl: that.data.formFileurl.concat(data.data[0]),
- });
- setTimeout(() => {
- wx.showToast({
- title: '图片上传成功',
- mask: true,
- duration: 1000,
- });
- }, 500);
- } else {
- wx.showToast({
- title: '图片上传失败',
- mask: true,
- duration: 2000,
- });
- }
- },
- fail: () => {
- wx.showToast({
- title: '图片上传失败',
- mask: true,
- duration: 2000,
- });
- },
- complete: () => {},
- });
- },
- });
- },
- // 删除图片
- clearImg(index) {
- let index1 = index.currentTarget.dataset.index;
- let temp = this.data.formFileurl[index1];
- let url = app.globalData.httpsUrlServer + '/file/deleteFile';
- let data = {
- fileDes: temp,
- };
- wx.showLoading({
- title: '删除中',
- mask: true,
- });
- app.postReq(url, data, (res) => {
- if (res.status == 200) {
- this.data.formFileurl = this.data.formFileurl.filter((v, i) => {
- return i != index1;
- });
- this.setData({
- formFileurl: this.data.formFileurl,
- });
- app.toast('删除成功');
- } else {
- app.toast('删除失败');
- }
- });
- },
- // 保存图片上传
- UploadP() {
- console.log(this.data.formFileurl);
- console.log(this.data.textValue);
- console.log(this.data.isWork);
- if (this.data.formFileurl.length < 2) {
- return app.toast('最少上传两张图片');
- }
- if (this.data.isExist == 1) {
- if (!this.data.textValue.trim()) {
- return app.toast('请输入描述内容');
- }
- } else {
- }
- app.loading('loading~');
- let obj = {};
- this.data.formFileurl.forEach((v) => {
- v.fileCoordinates = this.data.latitude + ',' + this.data.longitude;
- v.remark = this.data.textValue;
- let obj = util1.transformFromGCJToWGS(
- this.data.latitude,
- this.data.longitude
- );
- v.fileCoordinatesGc = obj.latitude + ',' + obj.longitude;
- v.createDate = util.formatTime(new Date());
- if (this.data.isExist == 1) {
- v.number2 = 1;
- v.string3 = this.data.workTypeList[this.data.index2].fValuecode;
- v.string4 = this.data.workTypeList[this.data.index2].fName;
- } else {
- v.number2 = 0;
- v.string3 = null;
- v.string4 = null;
- }
- v.number4 = 3;
- });
- if (this.data.isExist == 1) {
- this.data.iswork.push('1');
- }
- obj.fileList = this.data.formFileurl;
- this.data.WorkList.push(obj);
- this.setData({
- WorkList: this.data.WorkList,
- iswork: this.data.iswork,
- });
- wx.showToast({
- title: '保存成功',
- mask: true,
- duration: 1000,
- });
- this.setData({
- formFileurl: [],
- imgDailog: false,
- });
- },
- //输入框事件
- input(e) {
- this.setData({
- textValue: e.detail.value,
- });
- },
- // 单选框 事件
- radiochange(e) {
- this.setData({
- isExist: e.detail.value,
- });
- },
- // 选择问题 类型
- changeType(e) {
- this.setData({
- index2: e.detail.value,
- });
- },
- // 获取当前定位
- getUserloc() {
- wx.getLocation({
- type: 'gcj02',
- // altitude: false,
- success: (result) => {
- console.log(result);
- this.setData({
- longitude: result.longitude,
- latitude: result.latitude,
- });
- },
- fail: () => {},
- complete: () => {},
- });
- },
- //校验位置权限是否打开
- checkLocation() {
- let that = this;
- //选择位置,需要用户授权
- wx.getSetting({
- success(res) {
- //console.log("res", res)
- if (
- !res.authSetting['scope.userLocation'] &&
- !res.authSetting['scope.userLocationBackground']
- ) {
- wx.authorize({
- scope: 'scope.userLocation',
- success() {
- wx.showToast({
- //这里提示失败原因
- title: '授权成功!',
- duration: 1500,
- });
- },
- fail() {
- that.showSettingToast('需要授权位置信息');
- },
- });
- }
- },
- });
- },
- // 打开权限设置页提示框
- showSettingToast: function (e) {
- var that = this;
- wx.showModal({
- title: '提示!',
- confirmText: '去设置',
- showCancel: false,
- content: e,
- success: function (res) {
- if (res.confirm) {
- wx.openSetting({
- success: (res) => {
- //console.log("设置res", res)
- if (res.errMsg == 'openSetting:ok') {
- // wx.navigateBack({
- // delta: 1,
- // })
- wx.hideToast();
- setTimeout(() => {
- app.toast('设置成功');
- that.onLoad();
- }, 500);
- }
- // wx.hideToast()
- // wx.showToast({
- // //这里提示失败原因
- // title: "授权成功!",
- // duration: 1500,
- // })
- },
- fail: (err) => {
- //console.log("err", err)
- wx.showToast({
- //这里提示失败原因
- title: '授权失败',
- duration: 1500,
- });
- },
- });
- }
- },
- });
- },
- // 结束巡查
- endXC() {
- console.log('发送工单');
- this.build();
- },
- closehuatan() {
- this.setData({
- huatanFlag: false,
- });
- },
- // 发送工单 封装
- // 发送工单 封装
- build() {
- app.loading('loading~');
- this.getUserloc();
- this.setData({
- flagend: true,
- });
- let that = this;
- let url = app.globalData.httpsUrlServer + '/lhgyWork/savePatrolTrack';
- let startTime = new Date().getTime();
- if (this.data.WorkList.length == 0) {
- return app.toast('请上传巡查图片');
- }
- let data = {
- startTime: startTime,
- objectId: that.data.array[that.data.index].sectionId, //路段id
- objectName: that.data.array[that.data.index].sectionName, //路段名称
- fileList: this.data.WorkList,
- isExist: that.data.iswork.length > 0 ? 1 : 0,
- number3: that.data.yhCompanyId, // 养护单位id
- type: 2, //花坛类型
- string1: that.data.huatanList[that.data.huatanindex].fAttractionsAlowerId, //景点 id
- string2:
- that.data.huatanList[that.data.huatanindex].fAttractionsName +
- '--' +
- that.data.huatanList[that.data.huatanindex].fAttractionsPlace,
- };
- if (this.data.position == '绿化科中心') {
- data.number3 = that.data.yhdwList[that.data.index1].fYhcompanyid;
- }
- console.log(data);
- app.postReq(url, data, (res) => {
- console.log('res', res);
- if (res.status == 200) {
- wx.hideLoading();
- let pages = getCurrentPages(); //页面栈
- let beforePage = '';
- // console.log("that.data.endFlag", that.data.endFlag)
- if (that.data.endFlag == true) {
- beforePage = pages[pages.length - 1];
- console.log(beforePage);
- beforePage.onPullDownRefresh();
- return;
- }
- beforePage = pages[pages.length - 2];
- wx.navigateBack({
- delta: 1, //返回上一级页面
- success: function () {
- console.log(beforePage);
- beforePage.onPullDownRefresh();
- },
- });
- }
- });
- },
- // 获取 问题类型
- getworkType() {
- // 获取等待
- app.loading('loading~');
- let url =
- app.globalData.httpsUrlServer +
- '/sysdictionaryvalueApp/selectAppDictionaryByFlag';
- let data = {
- fDictionaryflag: 'GDDL',
- deptType: '2',
- patrolType: '2',
- };
- app.postReq(url, data, (res) => {
- if (res.status == 200) {
- this.setData({
- workTypeList: res.data,
- });
- console.log(this.data.workTypeList);
- app.hideloading();
- }
- });
- },
- // 根据 标段 id 养护单位id 查询 花坛
- getHuatanbyid(i1, i2) {
- var that = this;
- let url =
- app.globalData.httpsUrlServer +
- '/t-lhgy-attractions-flowers/selectAttractionsFlowersByYhSelection';
- let data = {
- fSectionId: i1,
- fYhCompanyId: i2,
- };
- app.postReq(url, data, (res) => {
- console.log(res);
- if (res.status == 200) {
- that.setData({
- huatanList: res.data,
- });
- }
- });
- },
- onLoad: function (options) {
- wx.startLocationUpdateBackground({
- success(res) {
- console.log('开启后台定位', res);
- },
- fail(res) {
- console.log('开启后台定位失败', res);
- },
- });
- this.checkLocation();
- this.getUserloc();
- // ↑↑↑↑↑↑ 权限判断
- // 根据权限 获取所有
- this.userSelect();
- this.getworkType();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {},
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {},
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {},
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- if (this.data.flagend) return;
- this.setData({
- endFlag: true,
- });
- if (this.data.iswork.length == 0) return; // 没有任何 信息 返回
- if (this.data.iswork.length > 0) {
- this.build();
- }
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {},
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {},
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {},
- });
|