dangerarearesidentlocation.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="container">
  3. <uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
  4. @clickLeft="toBack">
  5. <view class="nav-title">
  6. <text>{{title}}</text>
  7. </view>
  8. </uni-nav-bar>
  9. <uni-forms ref="baseForm" :model="formData">
  10. <uni-card title="住址定位信息" :is-shadow="false">
  11. <uni-forms-item name='longitude' label="经度" label-width="100px" required>
  12. <uni-easyinput v-model="formData.longitude" placeholder="请录入经度" />
  13. </uni-forms-item>
  14. <uni-forms-item name='latitude' label="纬度" label-width="100px" required>
  15. <uni-easyinput v-model="formData.latitude" placeholder="请录入纬度" />
  16. </uni-forms-item>
  17. <view class="item-button-group" style="padding-right: 10px;">
  18. <view class="item-button mid-size" @click="onRestartLocation()">
  19. <view class="items-line">
  20. <uni-icons class="input-uni-icon" type="location" size="18" color="coral" />
  21. <text class="button-text">重新定位</text>
  22. </view>
  23. </view>
  24. </view>
  25. </uni-card>
  26. </uni-forms>
  27. <view class="footer">
  28. <view class="control">
  29. <view class="view-flex-rc">
  30. <view class="block"
  31. style="width: 120px;height:28px;margin-left: 10px;margin-right: 10px;border-radius:7px;background-color:lightpink"
  32. @click="toSubmit()">
  33. <view class="view-flex-cc">
  34. <uni-icons class="input-uni-icon" type="checkmarkempty" size="18" color="#999" />
  35. </view>
  36. <view class="view-flex-cc" style="padding-left:5px;">
  37. <text style="color:black;font-size:0.7rem">立即提交</text>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import {
  47. role
  48. } from "@/api/role.js";
  49. import http from '@/http/api.js';
  50. import {
  51. oss,
  52. devUrl,
  53. prodUrl
  54. } from '@/common/setting';
  55. export default {
  56. data() {
  57. return {
  58. title: '家庭住址定位补录',
  59. baseURL: '',
  60. formData: {
  61. id: '',
  62. latitude: '',
  63. longitude: '',
  64. },
  65. rules: {
  66. latitude: {
  67. rules: [{
  68. required: true,
  69. errorMessage: '必填项',
  70. }]
  71. },
  72. longitude: {
  73. rules: [{
  74. required: true,
  75. errorMessage: '必填项',
  76. }, ]
  77. },
  78. },
  79. }
  80. },
  81. onLoad(option) {
  82. let that = this;
  83. this.baseURL = process.env.NODE_ENV === 'development' ? devUrl : prodUrl;
  84. this.formData.id = option.id;
  85. that.formData.latitude = option.lat;
  86. that.formData.longitude = option.lng;
  87. // #ifdef APP-PLUS
  88. console.log("app")
  89. uni.getLocation({
  90. type: 'gcj02',
  91. geocode: true,
  92. success: function(res) {
  93. console.log('当前位置:' + JSON.stringify(res));
  94. that.formData.latitude = res.latitude;
  95. that.formData.longitude = res.longitude;
  96. uni.showModal({
  97. content: '定位成功',
  98. showCancel: false
  99. });
  100. }
  101. });
  102. // #endif
  103. // #ifdef MP-WEIXIN
  104. console.log("weixin")
  105. uni.getLocation({
  106. type: 'wgs84',
  107. success: function(res) {
  108. console.log('当前位置:' + JSON.stringify(res));
  109. that.formData.latitude = res.latitude;
  110. that.formData.longitude = res.longitude;
  111. uni.showModal({
  112. content: '定位成功',
  113. showCancel: false
  114. });
  115. }
  116. });
  117. // #endif
  118. },
  119. computed: {
  120. },
  121. onShow() {},
  122. onReady() {
  123. // 需要在onReady中设置规则
  124. this.$refs.baseForm.setRules(this.rules)
  125. },
  126. methods: {
  127. //返回上一页
  128. toBack() {
  129. uni.navigateBack({
  130. delta: 1
  131. })
  132. },
  133. onBackPress() {
  134. // #ifdef APP-PLUS
  135. plus.key.hideSoftKeybord();
  136. // #endif
  137. },
  138. onRestartLocation() {
  139. // #ifdef APP-PLUS
  140. console.log("app")
  141. uni.getLocation({
  142. type: 'gcj02',
  143. geocode: true,
  144. success: function(res) {
  145. console.log('当前位置:' + JSON.stringify(res));
  146. that.formData.latitude = res.latitude;
  147. that.formData.longitude = res.longitude;
  148. }
  149. });
  150. // #endif
  151. // #ifdef MP-WEIXIN
  152. console.log("weixin")
  153. uni.getLocation({
  154. type: 'wgs84',
  155. success: function(res) {
  156. console.log('当前位置:' + JSON.stringify(res));
  157. that.formData.latitude = res.latitude;
  158. that.formData.longitude = res.longitude;
  159. }
  160. });
  161. // #endif
  162. },
  163. toSubmit() {
  164. let that = this;
  165. this.$refs.baseForm.validate().then(res => {
  166. console.log('表单数据信息1:', res);
  167. that.submit();
  168. }).catch(err => {
  169. console.log('表单错误信息:', err);
  170. uni.showModal({
  171. content: "内容录入错误,请根据提示信息检查录入内容!",
  172. showCancel: false,
  173. success(res) {
  174. if (res.confirm) {
  175. //that.$refs.baseForm.clearValidate();
  176. }
  177. }
  178. });
  179. })
  180. },
  181. submit() {
  182. let formdata = this.formData;
  183. console.log('toSubmit事件:', JSON.stringify(formdata));
  184. let that = this;
  185. http.request({
  186. url: '/galaxy-business/yj/resident/location/add',
  187. method: 'POST',
  188. data: formdata
  189. }).then(res => {
  190. console.log('res ', JSON.stringify(res));
  191. if (res.success) {
  192. if (res.code == 200) {
  193. //that.clearCache();
  194. uni.showModal({
  195. content: '填报信息已成功提交',
  196. showCancel: false,
  197. success(res) {
  198. if (res.confirm) {
  199. that.toBack();
  200. }
  201. }
  202. });
  203. } else {
  204. uni.showModal({
  205. content: '提交失败',
  206. showCancel: false
  207. });
  208. }
  209. } else {
  210. uni.showModal({
  211. content: '提交失败',
  212. showCancel: false
  213. });
  214. }
  215. }).catch(err => {
  216. uni.showModal({
  217. content: '' + err.data.msg,
  218. showCancel: false
  219. });
  220. })
  221. },
  222. }
  223. }
  224. </script>
  225. <style lang="scss" scoped>
  226. .container {
  227. padding: 0 0 100rpx;
  228. }
  229. </style>