dangerareacheck.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <!--
  2. *危险区现场巡查
  3. *
  4. -->
  5. <template>
  6. <view class="container">
  7. <uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
  8. @clickLeft="toBack">
  9. <view class="nav-title">
  10. <text>{{title}}</text>
  11. </view>
  12. </uni-nav-bar>
  13. <uni-forms ref="baseForm" :model="formData">
  14. <uni-card title="定位信息" :is-shadow="false">
  15. <view class="view-flex-inline" style="margin-bottom: 10px;">
  16. <view style="width: 100px;">经纬度</view>
  17. <view v-if="longitude != '' && latitude != ''">{{longitude}},{{latitude}}</view>
  18. </view>
  19. <view style="margin-bottom: 5px;font-size: 0.6rem;color:skyblue;">
  20. 备注:定位地址可进行人工修改</view>
  21. <uni-forms-item name='lng' label="定位地址" label-width="100px">
  22. <uni-easyinput v-model="formData.address" placeholder="请录入定位地址" />
  23. </uni-forms-item>
  24. </uni-card>
  25. <uni-card title="巡查反馈" :is-shadow="false">
  26. <uni-forms-item name="isFlood" label="是否有山洪" label-width="100px" required>
  27. <uni-data-checkbox v-model="formData.isFlood" :localdata="checkItems.items">
  28. </uni-data-checkbox>
  29. </uni-forms-item>
  30. <uni-forms-item name="isDamage" label="是否成灾" label-width="100px" required>
  31. <uni-data-checkbox v-model="formData.isDamage" :localdata="checkItems.items">
  32. </uni-data-checkbox>
  33. </uni-forms-item>
  34. <uni-forms-item name='remark' label="备注" label-width="100px">
  35. <uni-easyinput v-model="formData.remark" placeholder="请录入其他需要说明的情况" />
  36. </uni-forms-item>
  37. </uni-card>
  38. <uni-card title="巡查图片" extra="点击下方按钮开始拍摄" :is-shadow="false">
  39. <view class="view-flex-inline">
  40. <view v-for="(item, index) in checkPhotos" :key="index" class="view-flex-block-center"
  41. style="width: 100px;">
  42. <view class="img-container">
  43. <view class="note-image-box">
  44. <view class="note-image-item">
  45. <view class="close-icon" @click="onCheckPhotoDel(index)">
  46. <uni-icons type="closeempty" size="18" color="#fff"></uni-icons>
  47. </view>
  48. <view class="image-box">
  49. <image :src="toOss(item)" mode="widthFix">
  50. </image>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="view-flex-block-center" style="width: 80px;">
  57. <view class="img-container">
  58. <view class="note-image-box">
  59. <view class="note-image-item" @click="onCheckPhotoAdd()">
  60. <view class="image-box">
  61. <uni-icons type="plusempty" size="50" color="#eee"></uni-icons>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </uni-card>
  69. </uni-forms>
  70. <view class="footer">
  71. <view class="control">
  72. <view class="view-flex-inline-center">
  73. <view class="block"
  74. style="width: 120px;height:28px;margin-left: 10px;margin-right: 10px;border-radius:7px;background-color:lightpink"
  75. @click="toSubmit()">
  76. <view class="view-flex-block-center">
  77. <uni-icons class="input-uni-icon" type="checkmarkempty" size="18" color="#999" />
  78. </view>
  79. <view class="view-flex-block-center" style="padding-left:5px;">
  80. <text style="color:black;font-size:0.7rem">立即提交</text>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. import {
  90. role
  91. } from "@/api/role.js";
  92. import http from '@/http/api.js';
  93. import {
  94. oss,
  95. devUrl,
  96. prodUrl
  97. } from '@/common/setting';
  98. export default {
  99. data() {
  100. return {
  101. title: '现场巡查',
  102. baseURL: '',
  103. baseOSS: '',
  104. checkType: 0,
  105. warnId: '',
  106. latitude: '',
  107. longitude: '',
  108. formData: {
  109. address: '',
  110. isFlood: 0,
  111. isDamage: 0,
  112. remark: '',
  113. },
  114. checkPhotos: [],
  115. checkItems: {
  116. items: [{
  117. 'value': 0,
  118. 'text': '否'
  119. }, {
  120. 'value': 1,
  121. 'text': '是'
  122. }],
  123. current: 0,
  124. },
  125. }
  126. },
  127. onLoad(option) {
  128. let that = this;
  129. this.baseOSS = oss;
  130. this.baseURL = process.env.NODE_ENV === 'development' ? devUrl : prodUrl;
  131. this.checkType = option.type;
  132. this.warnId = option.id;
  133. // #ifdef APP-PLUS
  134. console.log("app")
  135. uni.getLocation({
  136. type: 'gcj02',
  137. geocode: true,
  138. success: function(res) {
  139. console.log('当前位置:' + JSON.stringify(res));
  140. that.latitude = res.latitude;
  141. that.longitude = res.longitude;
  142. //that.getAddress(res.longitude;,res.latitude);
  143. }
  144. });
  145. // #endif
  146. // #ifdef MP-WEIXIN
  147. console.log("weixin")
  148. uni.getLocation({
  149. type: 'wgs84',
  150. success: function(res) {
  151. console.log('当前位置:' + JSON.stringify(res));
  152. that.latitude = res.latitude;
  153. that.longitude = res.longitude;
  154. //that.getAddress(res.longitude;,res.latitude);
  155. }
  156. });
  157. // #endif
  158. },
  159. computed: {
  160. },
  161. onShow() {
  162. },
  163. methods: {
  164. toOss(path) {
  165. let url = this.baseOSS + path;
  166. return url;
  167. },
  168. //返回上一页
  169. toBack() {
  170. uni.navigateBack({
  171. delta: 1
  172. })
  173. },
  174. onBackPress() {
  175. // #ifdef APP-PLUS
  176. plus.key.hideSoftKeybord();
  177. // #endif
  178. },
  179. getAddress(lng, lat) {
  180. console.log("get address " + lat + lng);
  181. let url = 'https://apis.map.qq.com/ws/geocoder/v1/?location=' + lat + ',' + lng +
  182. '&key=4HYBZ-EB23D-SLC42-HQ5R3-LP3LQ-OZFU5';
  183. console.log(url);
  184. http.request({
  185. url: url,
  186. method: 'GET',
  187. }).then(res => {
  188. console.log('当前位置:' + JSON.stringify(res));
  189. }).catch(err => {
  190. console.log(err)
  191. })
  192. },
  193. onCheckPhotoAdd() {
  194. let that = this;
  195. uni.chooseImage({
  196. sourceType: ['camera'],
  197. sizeType: ['compressed'],
  198. success: (res) => {
  199. const len = res.tempFilePaths.length;
  200. if (len === 1) {
  201. res.tempFilePaths.forEach(path => {
  202. that.uploadCheckPhoto(path);
  203. })
  204. } else {
  205. uni.showModal({
  206. content: '只能选择一张图片,请确认!',
  207. showCancel: false
  208. });
  209. }
  210. }
  211. })
  212. },
  213. uploadCheckPhoto(imagePath) {
  214. let that = this;
  215. uni.showLoading({
  216. title: '上传中'
  217. });
  218. uni.uploadFile({
  219. url: this.baseURL + '/galaxy-resource/oss/endpoint/put-file-attach?Blade-Auth=' +
  220. uni.getStorageSync('accessToken'),
  221. fileType: 'image',
  222. filePath: imagePath,
  223. name: 'file',
  224. success: (uploadFileRes) => {
  225. if (uploadFileRes.statusCode == 200) {
  226. let data = JSON.parse(uploadFileRes.data);
  227. if (data.success) {
  228. let path = data.data['name'];
  229. that.checkPhotos.push(path);
  230. }
  231. }
  232. },
  233. fail: (err) => {
  234. console.log(err);
  235. reject('err')
  236. },
  237. complete() {
  238. uni.hideLoading()
  239. }
  240. });
  241. },
  242. onCheckPhotoDel(index) {
  243. this.checkPhotos.splice(index, 1);
  244. },
  245. toSubmit() {
  246. let that = this;
  247. this.$refs.baseForm.validate().then(res => {
  248. console.log('表单数据信息1:', res);
  249. that.submit();
  250. }).catch(err => {
  251. console.log('表单错误信息:', err);
  252. uni.showModal({
  253. content: "巡查内容录入错误,请根据提示信息检查录入内容!",
  254. showCancel: false,
  255. success(res) {
  256. if (res.confirm) {
  257. //that.$refs.baseForm.clearValidate();
  258. }
  259. }
  260. });
  261. })
  262. },
  263. submit() {
  264. let formdata = this.formData;
  265. formdata['checkType'] = this.checkType;
  266. formdata['warnId'] = this.warnId;
  267. formdata['longitude'] = this.longitude;
  268. formdata['latitude'] = this.latitude;
  269. if (this.checkPhotos.length > 0) {
  270. let photos = '';
  271. for (let i = 0; i < this.checkPhotos.length; i++) {
  272. if (photos.length > 0) {
  273. photos = photos + ',';
  274. }
  275. photos = photos + this.checkPhotos[i];
  276. }
  277. formdata['checkPhotos'] = photos;
  278. }
  279. console.log('toSubmit事件:', JSON.stringify(formdata));
  280. let that = this;
  281. http.request({
  282. url: '/galaxy-business/yj/check/report',
  283. method: 'POST',
  284. data: formdata
  285. }).then(res => {
  286. console.log('res ', JSON.stringify(res));
  287. if (res.success) {
  288. if (res.code == 200) {
  289. //that.clearCache();
  290. uni.showModal({
  291. content: '巡查信息已成功提交',
  292. showCancel: false,
  293. success(res) {
  294. if (res.confirm) {
  295. that.toBack();
  296. }
  297. }
  298. });
  299. } else {
  300. uni.showModal({
  301. content: '提交失败',
  302. showCancel: false
  303. });
  304. }
  305. } else {
  306. uni.showModal({
  307. content: '提交失败',
  308. showCancel: false
  309. });
  310. }
  311. }).catch(err => {
  312. // console.log('errr3',JSON.stringify(err));
  313. uni.showModal({
  314. content: '' + err.data.msg,
  315. showCancel: false
  316. });
  317. })
  318. },
  319. }
  320. }
  321. </script>
  322. <style lang="scss" scoped>
  323. .container {
  324. padding: 0 0 100rpx;
  325. }
  326. </style>