index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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="checkResultBox">
  45. <text class="title">巡查情况</text>
  46. <view class="content">
  47. <view class="formGroup">
  48. <text class="label">现状描述:</text>
  49. <view class="formInput">
  50. <textarea name="" id="" cols="30" rows="10" v-model="baseFormData.xzms"
  51. placeholder="请输入现状描述"></textarea>
  52. </view>
  53. </view>
  54. <view class="formGroup noBetween">
  55. <text class="label">现场照片:</text>
  56. <view class="formFile">
  57. <uni-file-picker @delete="deleteImage" :value="fileImgList" :del-icon="true"
  58. :imageStyles="imageStyles" auto-upload="false" le-mediatype="image"
  59. :sourceType="['camera']" @select="selectFileChange">
  60. <view class="icon_camera">
  61. <image src="../../static/images/images.png"></image>
  62. </view>
  63. </uni-file-picker>
  64. </view>
  65. </view>
  66. </view>
  67. <button class="btn" @tap="saveWarning">确认上报</button>
  68. <button style="background: #ff9900;" class="btn" @tap="temporaryXcjl">暂存</button>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. import navigationBar from '../../components/navigationBar/navigationBar.vue';
  75. import httpAjax from '@/utils/https.js';
  76. import CustomMixins from '@/mixins/CustomMixins.js';
  77. const FormData = require('@/utils/formData/formData.js');
  78. export default {
  79. mixins: [CustomMixins],
  80. components: {
  81. navigationBar,
  82. },
  83. data() {
  84. return {
  85. lat: '',
  86. long: '',
  87. queryParams: {
  88. xcryId: '',
  89. xzms: '',
  90. xcryName: '',
  91. xcryMobile: '',
  92. dksyh: '',
  93. imgList: [{
  94. fileId: '',
  95. lng: '',
  96. lat: '',
  97. }, ],
  98. },
  99. objs: {},
  100. fileList: [],
  101. fileImgList: [],
  102. imageStyles: {
  103. width: 64,
  104. height: 64,
  105. },
  106. baseFormData: {
  107. xzms: ''
  108. },
  109. isLocation: true
  110. };
  111. },
  112. onReady() {
  113. uni.showTabBar();
  114. },
  115. onLoad(option) {
  116. this.checkAuthorize()
  117. const idStr = JSON.parse(option['obj']);
  118. this.objs = idStr;
  119. this.queryIsLocation().then((result) => {
  120. if (result && result['data']) {
  121. this.isLocation = result['data']
  122. }
  123. })
  124. if (this.objs && this.objs.dksyh) {
  125. const tempXcjl = uni.getStorageSync(this.objs.dksyh)
  126. if (tempXcjl) {
  127. this.fileList = tempXcjl['fileList']
  128. this.fileImgList = tempXcjl['fileImgList']
  129. this.baseFormData = tempXcjl['baseFormData']
  130. }
  131. }
  132. },
  133. methods: {
  134. checkAuthorize() {
  135. const self = this;
  136. this.getWxLocation().catch(res => {
  137. if (res === 0) {
  138. this.getWxSetting();
  139. }
  140. })
  141. },
  142. getWxLocation() {
  143. return new Promise((resolve, reject) => {
  144. wx.authorize({
  145. scope: 'scope.userLocation',
  146. success: (res) => {
  147. wx.getLocation({
  148. success: (res) => {
  149. resolve(res)
  150. },
  151. fail: (err) => {
  152. reject(-1)
  153. },
  154. });
  155. },
  156. fail: (err) => {
  157. reject(0)
  158. },
  159. });
  160. })
  161. },
  162. getWxSetting() {
  163. uni.getSetting({
  164. success: function(res) {
  165. var statu = res.authSetting;
  166. if (!statu['scope.userLocation']) {
  167. uni.showModal({
  168. title: '提示',
  169. content: '需要获取您的地理位置,请确认授权,否则拍照功能将无法使用',
  170. success: function(res) {
  171. if (res.confirm) {
  172. uni.openSetting();
  173. }
  174. }
  175. });
  176. }
  177. },
  178. });
  179. },
  180. async getDistance(lat, lng) {
  181. return await httpAjax({
  182. url: `api/oss/isWithinBufferRange?lat=${lat}&lng=${lng}&dksyh=${this.objs.dksyh}`,
  183. method: 'GET'
  184. })
  185. },
  186. async queryIsLocation(lat, lng) {
  187. return await httpAjax({
  188. url: 'api/oss/location',
  189. method: 'GET'
  190. })
  191. },
  192. saveWarning() {
  193. //上报
  194. if (this.baseFormData.xzms === '') {
  195. uni.showToast({
  196. title: '现状描述不能为空',
  197. icon: 'none',
  198. duration: 1500,
  199. });
  200. return;
  201. }
  202. if (!(this.fileList.length > 0)) {
  203. uni.showToast({
  204. title: '现场照片不能为空',
  205. icon: 'none',
  206. duration: 1500,
  207. });
  208. return;
  209. }
  210. this.relationFileById(this.fileList);
  211. },
  212. async relationFileById(fileObj) {
  213. //文件上传
  214. let _that = this;
  215. let files = [];
  216. let laycenterArr = [];
  217. fileObj.forEach((item) => {
  218. let obj = {
  219. fileId: item.fileId,
  220. lat: item.lat,
  221. lng: item.lng,
  222. };
  223. files.push(obj);
  224. let obj1 = {
  225. lat: item.lat,
  226. lng: item.lng,
  227. };
  228. laycenterArr.push(obj1);
  229. });
  230. let isSubmit = true;
  231. if (this.isLocation) {
  232. for (let i = 0; i < laycenterArr.length; i++) {
  233. const resultData = await this.getDistance(
  234. laycenterArr[i].lat,
  235. laycenterArr[i].lng
  236. );
  237. if (!resultData['data']) {
  238. isSubmit = false;
  239. uni.showModal({
  240. title: '提示',
  241. content: `超出地块拍摄范围`
  242. });
  243. break;
  244. }
  245. }
  246. }
  247. if (!isSubmit) return;
  248. this.addXcjlAjax(files).then((result) => {
  249. if (result.data) {
  250. uni.showModal({
  251. title: '提示',
  252. content: '上报成功,是否返回首页',
  253. success: function(res) {
  254. if (res.confirm) {
  255. uni.navigateTo({
  256. url: '/pages/main/index',
  257. });
  258. } else if (res.cancel) {
  259. uni.navigateTo({
  260. url: `/pages/receivedDetail/index?obj=${JSON.stringify(
  261. _that.objs,
  262. )}`,
  263. });
  264. }
  265. },
  266. });
  267. if (_that.objs && _that.objs.dksyh) {
  268. uni.removeStorageSync(_that.objs.dksyh)
  269. }
  270. }
  271. });
  272. },
  273. async addXcjlAjax(files = []) {
  274. const _that = this;
  275. const sendData = {
  276. xcryId: uni.getStorageSync('userInfo').id,
  277. xzms: this.baseFormData.xzms,
  278. xcryName: uni.getStorageSync('userInfo').xcry,
  279. xcryMobile: uni.getStorageSync('userInfo').lxdh,
  280. dksyh: this.objs.dksyh,
  281. imgList: files
  282. };
  283. return await httpAjax({
  284. url: 'app/xc/addXcjl',
  285. method: 'POST',
  286. data: sendData,
  287. });
  288. },
  289. temporaryXcjl() {
  290. if (this.objs && this.objs.dksyh) {
  291. const obj = {
  292. fileImgList: this.fileImgList,
  293. fileList: this.fileList,
  294. baseFormData: this.baseFormData
  295. }
  296. uni.setStorageSync(this.objs.dksyh, obj);
  297. uni.showToast({
  298. title: '暂存成功!'
  299. })
  300. }
  301. },
  302. selectFileChange(file) {
  303. console.log(file);
  304. const that = this;
  305. const tempFilePath = file.tempFilePaths[0];
  306. uni.getImageInfo({
  307. src: tempFilePath,
  308. success: function(image) {
  309. const fileName = file['tempFiles'][0]['name'];
  310. that.fileUploadAjax(tempFilePath);
  311. },
  312. });
  313. },
  314. setFileImgList(name, url, path2) {
  315. const extnames = name.match(/\.(jpg|jpeg|png|GIF|JPG|PNG)$/);
  316. const extname = extnames[0];
  317. this.fileImgList.push({
  318. name,
  319. url,
  320. path2,
  321. extname,
  322. });
  323. },
  324. deleteImage(item) {
  325. const that = this;
  326. httpAjax({
  327. url: 'api/oss/delete?filePath=' + item['tempFile']['path2'],
  328. method: 'GET',
  329. }).then((result) => {
  330. const data = result['data'];
  331. if (data) {
  332. for (let i = 0; i < that.fileImgList.length; i++) {
  333. const imgItem = that.fileImgList[i];
  334. if (imgItem['path2'] === item['tempFile']['path2']) {
  335. that.fileImgList.splice(i, 1);
  336. break;
  337. }
  338. }
  339. for (let i = 0; i < that.fileList.length; i++) {
  340. const fileItem = that.fileList[i];
  341. if (fileItem['path'] === item['tempFile']['path2']) {
  342. that.fileList.splice(i, 1);
  343. break;
  344. }
  345. }
  346. }
  347. });
  348. },
  349. fileUploadAjax(tempFile) {
  350. const formData = new FormData();
  351. formData.appendFile('file', tempFile);
  352. const sendData = formData.getData();
  353. let header = {
  354. 'content-type': sendData.contentType,
  355. };
  356. const that = this;
  357. httpAjax({
  358. url: 'api/oss/upload',
  359. method: 'POST',
  360. header,
  361. data: sendData.buffer,
  362. }).then((result) => {
  363. const fileInfo = result['data'];
  364. that.setFileImgList(fileInfo['name'], tempFile, fileInfo['path']);
  365. //文件上传成功后获取经纬度给图片信息
  366. this.getWxLocation().then(res => {
  367. this.lat = res.latitude;
  368. this.long = res.longitude;
  369. fileInfo.lat = res.latitude;
  370. fileInfo.lng = res.longitude;
  371. fileInfo.fileId = fileInfo.id;
  372. fileInfo.warningId = this.warningId;
  373. this.fileList.push(fileInfo);
  374. }).catch(res => {
  375. if (res === 0) {
  376. this.getWxSetting();
  377. }
  378. })
  379. });
  380. },
  381. toBackHandle() {
  382. uni.navigateBack();
  383. },
  384. },
  385. };
  386. </script>
  387. <style lang="scss">
  388. @import './index.scss';
  389. </style>