index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <view class="nocheckBox">
  3. <navigation-bar :isBack="true" @toBack="toBackHandle"></navigation-bar>
  4. <view class="container">
  5. <view class="warningBox">
  6. <text class="title">基本信息</text>
  7. <view class="content">
  8. <view class="item">
  9. <text class="title">地块编号</text>
  10. <text class="val">{{ objs.dkbh || '' }}</text>
  11. </view>
  12. <view class="item">
  13. <text class="title">面积(亩)</text>
  14. <text class="val">{{ objs.mj || ''}}</text>
  15. </view>
  16. <view class="item">
  17. <text class="title">地块位置</text>
  18. <text class="val">{{ objs.dkwz || ''}}</text>
  19. </view>
  20. <view class="item">
  21. <text class="title">地块现状</text>
  22. <text class="val">{{ objs.dkxz || '' }}</text>
  23. </view>
  24. <view class="item">
  25. <text class="title">管地单位</text>
  26. <text class="val">{{ objs.gddw || '' }}</text>
  27. </view>
  28. <view class="item">
  29. <text class="title">联系人</text>
  30. <text class="val">{{ objs.lxr || '' }}</text>
  31. </view>
  32. <view class="item itemAuto">
  33. <text class="title">联系电话</text>
  34. <text class="val">{{ objs.lxdh || '' }}</text>
  35. </view>
  36. <view class="item szfw">
  37. <text class="title">四至范围</text>
  38. <text class="val">
  39. <text>{{ objs.szfw || '' }}</text>
  40. </text>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="location" @click="checkLocationInfo"></view>
  45. <view class="checkResultBox">
  46. <text class="title">巡查情况</text>
  47. <view class="content">
  48. <view class="formGroup">
  49. <text class="label">现状描述:</text>
  50. <view class="formInput">
  51. <textarea name="" id="" cols="30" rows="10" v-model="baseFormData.xzms"
  52. placeholder="请输入现状描述"></textarea>
  53. </view>
  54. </view>
  55. <view class="formGroup noBetween">
  56. <text class="label">现场照片:</text>
  57. <view class="formFile">
  58. <uni-file-picker @delete="deleteImage" :value="fileImgList" :del-icon="true"
  59. :imageStyles="imageStyles" auto-upload="false" le-mediatype="image"
  60. :sourceType="['camera']" @select="selectFileChange">
  61. <view class="icon_camera">
  62. <image src="../../static/images/images.png"></image>
  63. </view>
  64. </uni-file-picker>
  65. </view>
  66. </view>
  67. </view>
  68. <button class="btn" @tap="saveWarning">确认上报</button>
  69. <button style="background: #ff9900;" class="btn" @tap="temporaryXcjl">暂存</button>
  70. </view>
  71. </view>
  72. <view class="dialog_box" v-show="dialogShow">
  73. <view class="dialog_bg"></view>
  74. <view class="dialog_container">
  75. <view class="dialog_header">定位效验</view>
  76. <view class="dialog_content">
  77. <view v-for="(item, index) in checkInfos" :key="index">
  78. <image :src="item['type'] === 1 ? '../../static/images/success_icon.png' : '../../static/images/error_icon.png'"></image>{{item['message']}}
  79. </view>
  80. </view>
  81. <view class="dialog_footer">
  82. <view class="dialog_btn" @click="dialogConfirm(0)">取消</view>
  83. <view class="dialog_btn" @click="dialogConfirm(1)">{{isLocationAuthorize ? '确定' : '去授权'}}</view>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. </template>
  89. <script>
  90. import navigationBar from '../../components/navigationBar/navigationBar.vue';
  91. import httpAjax from '@/utils/https.js';
  92. import CustomMixins from '@/mixins/CustomMixins.js';
  93. const FormData = require('@/utils/formData/formData.js');
  94. export default {
  95. mixins: [CustomMixins],
  96. components: {
  97. navigationBar,
  98. },
  99. data() {
  100. return {
  101. lat: '',
  102. long: '',
  103. queryParams: {
  104. xcryId: '',
  105. xzms: '',
  106. xcryName: '',
  107. xcryMobile: '',
  108. dksyh: '',
  109. imgList: [{
  110. fileId: '',
  111. lng: '',
  112. lat: '',
  113. }, ],
  114. },
  115. objs: {},
  116. fileList: [],
  117. fileImgList: [],
  118. imageStyles: {
  119. width: 64,
  120. height: 64,
  121. },
  122. baseFormData: {
  123. xzms: ''
  124. },
  125. dialogShow: false,
  126. checkInfos: [],
  127. isLocationAuthorize: true, //是否开启定位授权
  128. isLocation: true,
  129. bz: ''
  130. };
  131. },
  132. onReady() {
  133. uni.showTabBar();
  134. },
  135. onLoad(option) {
  136. this.checkAuthorize()
  137. this.objs = JSON.parse(option['obj']);
  138. this.queryIsLocation().then((result) => {
  139. if (result) {
  140. this.isLocation = result['data']
  141. }
  142. })
  143. if (this.objs && this.objs.dksyh) {
  144. const tempXcjl = uni.getStorageSync(this.objs.dksyh)
  145. if (tempXcjl) {
  146. this.fileList = tempXcjl['fileList']
  147. this.fileImgList = tempXcjl['fileImgList']
  148. this.baseFormData = tempXcjl['baseFormData']
  149. }
  150. }
  151. },
  152. methods: {
  153. checkAuthorize() {
  154. this.getLocationEnabled().then((enabled)=>{
  155. if(enabled){
  156. this.getWxLocation().then(res => {
  157. if (res === 0) {
  158. this.getWxSetting();
  159. }
  160. })
  161. }
  162. })
  163. },
  164. getLocationEnabled(){
  165. return new Promise((resolve, reject)=>{
  166. uni.getSystemInfo({
  167. async success(result) {
  168. if(!result.locationEnabled){
  169. uni.showModal({
  170. title: '提示',
  171. content:
  172. '小程序需要基于您的手机定位信息为您提供服务,当前检测到您的手机并未打开定位开关,请关闭小程序后前往 "设置 - 定位服务/位置信息" 开启手机定位,然后重新进入小程序~',
  173. showCancel: false,
  174. confirmText: '我已知悉'
  175. })
  176. }
  177. resolve(result.locationEnabled)
  178. }
  179. })
  180. })
  181. },
  182. getWxLocation() {
  183. return new Promise((resolve, reject) => {
  184. wx.authorize({
  185. scope: 'scope.userLocation',
  186. success: (res) => {
  187. wx.getLocation({
  188. success: (res) => {
  189. resolve(res)
  190. },
  191. fail: (err) => {
  192. resolve(-1)
  193. },
  194. });
  195. },
  196. fail: (err) => {
  197. resolve(0)
  198. },
  199. });
  200. })
  201. },
  202. getWxSetting() {
  203. uni.getSetting({
  204. success: function(res) {
  205. var statu = res.authSetting;
  206. if (!statu['scope.userLocation']) {
  207. uni.showModal({
  208. title: '提示',
  209. content: '需要获取您的地理位置,请确认授权,否则拍照功能将无法使用',
  210. success: function(res) {
  211. if (res.confirm) {
  212. uni.openSetting();
  213. }
  214. }
  215. });
  216. }
  217. },
  218. });
  219. },
  220. checkLocationInfo(){
  221. const that = this;
  222. that.checkInfos = []
  223. this.getLocationEnabled().then(async (enabled)=>{
  224. if(!enabled) return;
  225. that.checkInfos.push({
  226. type: 1,
  227. message: '手机定位已开启!'
  228. })
  229. const wxResult = await that.getWxLocation();
  230. if(wxResult === 0){
  231. that.isLocationAuthorize = false;
  232. that.checkInfos.push({
  233. type: 0,
  234. message: '小程序定位权限获取失败!'
  235. })
  236. }else{
  237. that.isLocationAuthorize = true;
  238. that.checkInfos.push({
  239. type: 1,
  240. message: '小程序定位权限获取成功!'
  241. })
  242. }
  243. that.dialogShow = true;
  244. })
  245. },
  246. dialogConfirm(action){
  247. this.dialogShow = false;
  248. if(action && !this.isLocationAuthorize){
  249. uni.openSetting();
  250. }
  251. },
  252. async getDistance(lat, lng) {
  253. return await httpAjax({
  254. url: `api/oss/isWithinBufferRange?lat=${lat}&lng=${lng}&dksyh=${this.objs.dksyh}`,
  255. method: 'GET'
  256. })
  257. },
  258. async queryIsLocation(lat, lng) {
  259. return await httpAjax({
  260. url: 'api/oss/location',
  261. method: 'GET'
  262. })
  263. },
  264. saveWarning() {
  265. //上报
  266. if (this.baseFormData.xzms === '') {
  267. uni.showToast({
  268. title: '现状描述不能为空',
  269. icon: 'none',
  270. duration: 1500,
  271. });
  272. return;
  273. }
  274. if (!(this.fileList.length > 0)) {
  275. uni.showToast({
  276. title: '现场照片不能为空',
  277. icon: 'none',
  278. duration: 1500,
  279. });
  280. return;
  281. }
  282. this.relationFileById(this.fileList);
  283. },
  284. async relationFileById(fileObj) {
  285. //文件上传
  286. let _that = this;
  287. let files = [];
  288. let laycenterArr = [];
  289. fileObj.forEach((item) => {
  290. let obj = {
  291. fileId: item.fileId,
  292. lat: item.lat,
  293. lng: item.lng,
  294. };
  295. files.push(obj);
  296. let obj1 = {
  297. lat: item.lat,
  298. lng: item.lng,
  299. };
  300. laycenterArr.push(obj1);
  301. });
  302. let isSubmit = true;
  303. if (this.isLocation) {
  304. for (let i = 0; i < laycenterArr.length; i++) {
  305. const resultData = await this.getDistance(
  306. laycenterArr[i].lat,
  307. laycenterArr[i].lng
  308. );
  309. if (!resultData['data']) {
  310. isSubmit = false;
  311. break;
  312. }
  313. }
  314. }
  315. if(!isSubmit){
  316. uni.showModal({
  317. title: '提示',
  318. content: `超出地块拍摄范围`,
  319. confirmText: '继续',
  320. success: function(res) {
  321. if (res.confirm) {
  322. _that.submitXcjlHandle(files);
  323. }
  324. },
  325. });
  326. }else{
  327. _that.submitXcjlHandle(files);
  328. }
  329. },
  330. submitXcjlHandle(files){
  331. const _that = this;
  332. this.addXcjlAjax(files).then((result) => {
  333. if (result && result.data) {
  334. uni.showModal({
  335. title: '提示',
  336. content: '上报成功,是否返回首页',
  337. success: function(res) {
  338. if (res.confirm) {
  339. uni.navigateTo({
  340. url: '/pages/main/index',
  341. });
  342. } else if (res.cancel) {
  343. uni.navigateTo({
  344. url: `/pages/receivedDetail/index?obj=${JSON.stringify(_that.objs)}`,
  345. });
  346. }
  347. },
  348. });
  349. }else{
  350. uni.showModal({
  351. title: '提示',
  352. content: '上报异常,请联系管理员'
  353. });
  354. }
  355. if (_that.objs && _that.objs.dksyh) {
  356. uni.removeStorageSync(_that.objs.dksyh)
  357. }
  358. });
  359. },
  360. addXcjlAjax(files = []) {
  361. const sendData = {
  362. xcryId: uni.getStorageSync('userInfo').id,
  363. xzms: this.baseFormData.xzms,
  364. xcryName: uni.getStorageSync('userInfo').xcry,
  365. xcryMobile: uni.getStorageSync('userInfo').lxdh,
  366. dksyh: this.objs.dksyh,
  367. status: 1,
  368. bz: '',
  369. imgList: files,
  370. };
  371. if(!this.lat || !this.long){
  372. sendData['status'] = 0
  373. }
  374. return new Promise((resolve, reject)=>{
  375. httpAjax({
  376. url: 'app/xc/addXcjl',
  377. method: 'POST',
  378. data: sendData,
  379. }).then((result)=>{
  380. resolve(sendData['status'] === 0 ? null : result);
  381. }).catch(err=>{
  382. reject(err)
  383. })
  384. })
  385. },
  386. temporaryXcjl() {
  387. if (this.objs && this.objs.dksyh) {
  388. const obj = {
  389. fileImgList: this.fileImgList,
  390. fileList: this.fileList,
  391. baseFormData: this.baseFormData
  392. }
  393. uni.setStorageSync(this.objs.dksyh, obj);
  394. uni.showToast({
  395. title: '暂存成功!'
  396. })
  397. }
  398. },
  399. selectFileChange(file) {
  400. const that = this;
  401. const tempFilePath = file.tempFilePaths[0];
  402. uni.getImageInfo({
  403. src: tempFilePath,
  404. success: function(image) {
  405. const fileName = file['tempFiles'][0]['name'];
  406. that.fileUploadAjax(tempFilePath);
  407. },
  408. });
  409. },
  410. async fileUploadAjax(tempFile) {
  411. const formData = new FormData();
  412. formData.appendFile('file', tempFile);
  413. const sendData = formData.getData();
  414. let header = {
  415. 'content-type': sendData.contentType,
  416. };
  417. const result = await httpAjax({
  418. url: 'api/oss/upload',
  419. method: 'POST',
  420. header,
  421. data: sendData.buffer,
  422. });
  423. if(!result || !result['data']) return;
  424. const fileInfo = result['data'];
  425. this.setFileImgList(fileInfo['name'], tempFile, fileInfo['path']);
  426. const res = await this.getWxLocation()
  427. if (res === 0) {
  428. this.getWxSetting();
  429. }else{
  430. this.lat = res.latitude;
  431. this.long = res.longitude;
  432. }
  433. fileInfo.lat = this.lat;
  434. fileInfo.lng = this.long;
  435. fileInfo.fileId = fileInfo.id;
  436. fileInfo.warningId = this.warningId;
  437. this.fileList.push(fileInfo);
  438. },
  439. setFileImgList(name, url, path2) {
  440. const extnames = name.match(/\.(jpg|jpeg|png|GIF|JPG|PNG)$/);
  441. const extname = extnames[0];
  442. this.fileImgList.push({
  443. name,
  444. url,
  445. path2,
  446. extname,
  447. });
  448. },
  449. async deleteImage(item) {
  450. const that = this;
  451. const result = await httpAjax({
  452. url: 'api/oss/delete?filePath=' + item['tempFile']['path2'],
  453. method: 'GET',
  454. })
  455. const data = result['data'];
  456. if (data) {
  457. for (let i = 0; i < that.fileImgList.length; i++) {
  458. const imgItem = that.fileImgList[i];
  459. if (imgItem['path2'] === item['tempFile']['path2']) {
  460. that.fileImgList.splice(i, 1);
  461. break;
  462. }
  463. }
  464. for (let i = 0; i < that.fileList.length; i++) {
  465. const fileItem = that.fileList[i];
  466. if (fileItem['path'] === item['tempFile']['path2']) {
  467. that.fileList.splice(i, 1);
  468. break;
  469. }
  470. }
  471. }
  472. },
  473. toBackHandle() {
  474. uni.navigateBack();
  475. },
  476. },
  477. };
  478. </script>
  479. <style lang="scss">
  480. @import './index.scss';
  481. </style>