signIn.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="signIn-wrap">
  3. <!-- 门店名称 -->
  4. <view class="module-con first-con">
  5. <text class="info-tit">门店名称:</text>
  6. <view class="info-main">
  7. <text class="location-addr">{{ stores && stores.name }}</text>
  8. </view>
  9. </view>
  10. <!-- 定位 -->
  11. <view class="module-con">
  12. <text class="info-tit">当前位置:</text>
  13. <view class="info-main" @click="getLocation">
  14. <text class="location-addr">{{ location }}</text>
  15. <u-icon name="map" color="#2979ff" size="34" class="location-icon"></u-icon>
  16. </view>
  17. </view>
  18. <!-- 拍照签到 -->
  19. <view class="module-con">
  20. <text class="info-tit">拍照签到:</text>
  21. <view class="info-main">
  22. <view class="photograph-con" @click="photograph ? null : goPhotograph()">
  23. <u-icon v-show="photograph" name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph"></u-icon>
  24. <u-icon v-show="!photograph" name="camera" color="#bfbfbf" size="60" class="photograph-icon"></u-icon>
  25. <u-image v-show="photograph" width="100%" height="100%" :src="photograph" @click="previewPictures"></u-image>
  26. </view>
  27. </view>
  28. </view>
  29. <u-button type="primary" class="submit-btn" @click="signInFun">签到并开始巡店</u-button>
  30. </view>
  31. </template>
  32. <script>
  33. import { clzConfirm, saveImgToAliOss } from '@/libs/tools.js';
  34. import { validTaskPosition } from '@/api/task.js';
  35. //定义一些常量
  36. var x_PI = 3.14159265358979324 * 3000.0 / 180.0;
  37. var PI = 3.1415926535897932384626;
  38. var a = 6378245.0;
  39. var ee = 0.00669342162296594323;
  40. /**
  41. * 判断是否在国内,不在国内则不做偏移
  42. * @param lng
  43. * @param lat
  44. * @returns {boolean}
  45. */
  46. function out_of_china(lng, lat) {
  47. return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false);
  48. }
  49. function transformlat(lng, lat) {
  50. var ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
  51. ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
  52. ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
  53. ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
  54. return ret
  55. }
  56. function transformlng(lng, lat) {
  57. var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
  58. ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
  59. ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
  60. ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
  61. return ret
  62. }
  63. /**
  64. * WGS84转GCj02
  65. * @param lng
  66. * @param lat
  67. * @returns {*[]}
  68. */
  69. function wgs84togcj02(lng, lat) {
  70. if (out_of_china(lng, lat)) {
  71. return [lng, lat]
  72. }
  73. else {
  74. var dlat = transformlat(lng - 105.0, lat - 35.0);
  75. var dlng = transformlng(lng - 105.0, lat - 35.0);
  76. var radlat = lat / 180.0 * PI;
  77. var magic = Math.sin(radlat);
  78. magic = 1 - ee * magic * magic;
  79. var sqrtmagic = Math.sqrt(magic);
  80. dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
  81. dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
  82. var mglat = lat + dlat;
  83. var mglng = lng + dlng;
  84. return [mglng, mglat]
  85. }
  86. }
  87. export default {
  88. data() {
  89. return {
  90. stores: null, // 门店信息
  91. location: '', // 当前位置地址
  92. photograph: '', // 拍照临时地址
  93. position: null // 位置信息
  94. };
  95. },
  96. onShow() {
  97. this.init();
  98. },
  99. onLoad(opts) {
  100. this.stores = JSON.parse(opts.item);
  101. },
  102. methods: {
  103. // 初始化
  104. init() {
  105. this.getLocation();
  106. },
  107. // 获取当前位置
  108. getLocation() {
  109. const _this = this;
  110. uni.getLocation({
  111. type: 'gcj02',
  112. geocode: true,
  113. success: function(res) {
  114. console.log(res);
  115. _this.position = res;
  116. //_this.location = res.address.province + res.address.city + res.address.district + res.address.street + res.address.streetNum +'靠近' + res.address.poiName
  117. // console.log(_this.location, '城市编码 ', res.address.cityCode)
  118. console.log(wgs84togcj02(res.longitude,res.latitude))
  119. },
  120. fail: function(error){
  121. console.log(error)
  122. if(JSON.parse(error.errMsg.replace('getLocation:fail ','')).message){
  123. uni.showToast({
  124. icon: 'none',
  125. title: JSON.parse(error.errMsg.replace('getLocation:fail ','')).message
  126. })
  127. }
  128. }
  129. });
  130. },
  131. // 签到拍照
  132. goPhotograph() {
  133. const _this = this;
  134. uni.chooseImage({
  135. count: 1, //最多可以选择的图片张数,默认9
  136. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  137. sourceType: ['camera'], //album 从相册选图,camera 使用相机,默认二者都有
  138. success: function(res) {
  139. // tempFilePaths 图片的本地文件路径列表,tempFiles 图片的本地文件列表,每一项是一个 File 对象
  140. console.log(JSON.stringify(res.tempFilePaths));
  141. saveImgToAliOss(res.tempFilePaths[0],function(ret){
  142. console.log(ret)
  143. _this.photograph = ret.data
  144. })
  145. }
  146. });
  147. },
  148. // 预览签到图
  149. previewPictures() {
  150. const photograph = [this.photograph];
  151. uni.previewImage({
  152. urls: photograph
  153. });
  154. },
  155. // 删除签到图
  156. cancelPhotograph() {
  157. setTimeout(() => {
  158. this.photograph = '';
  159. }, 500);
  160. },
  161. // 签到
  162. signInFun() {
  163. if(!this.position || !this.position.latitude || !this.position.longitude){
  164. uni.showToast({ icon: 'none', title: '位置获取失败,请重新定位后再进行签到' })
  165. return
  166. }else if(!this.photograph){
  167. uni.showToast({ icon: 'none', title: '请拍照后再进行签到' })
  168. return
  169. }
  170. // 存储当前签到信息
  171. this.$u.vuex('vuex_sceneTaskSignIn',{
  172. inspectorPositionAddr: '',
  173. inspectorPositionPhotoBasePath:'',
  174. inspectorPositionPhotoPath: this.photograph
  175. })
  176. // 判断是否超出签到范围
  177. validTaskPosition({
  178. storeId: this.stores.id,
  179. point: {
  180. lat: this.position.latitude,
  181. lng: this.position.longitude,
  182. }
  183. }).then(res => {
  184. if (res.status == 200) {
  185. // 跳转开始巡店
  186. let item = this.stores
  187. // 重新开始巡店
  188. if(item.taskId&&item.restart){
  189. uni.navigateTo({
  190. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&taskId='+ item.taskId + '&restart=1&types=scene'
  191. })
  192. }else{
  193. // 首次巡店
  194. uni.navigateTo({
  195. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&types=scene'
  196. })
  197. }
  198. } else {
  199. uni.showToast({ icon: 'none', title: res.message })
  200. }
  201. });
  202. },
  203. }
  204. };
  205. </script>
  206. <style lang="scss" scoped>
  207. page {
  208. background-color: #f8f8f8;
  209. height: calc(100vh - 44px);
  210. }
  211. .signIn-wrap {
  212. height: 100%;
  213. background-color: #f8f8f8;
  214. .module-con {
  215. padding: 0 30upx 20upx;
  216. .info-main {
  217. margin-top: 14upx;
  218. padding: 20upx;
  219. border-radius: 12upx;
  220. background-color: #fff;
  221. .location-icon {
  222. padding-left: 10upx;
  223. vertical-align: bottom;
  224. }
  225. .photograph-con {
  226. border: 2upx dashed #bfbfbf;
  227. border-radius: 12upx;
  228. width: 160upx;
  229. height: 160upx;
  230. text-align: center;
  231. position: relative;
  232. .photograph-icon {
  233. display: inline-block;
  234. padding-top: 48upx;
  235. }
  236. .close-circle-icon {
  237. background-color: #fff;
  238. border-radius: 50%;
  239. position: absolute;
  240. right: -23upx;
  241. top: -23upx;
  242. z-index: 9;
  243. }
  244. }
  245. }
  246. }
  247. .first-con {
  248. padding-top: 30upx;
  249. }
  250. .submit-btn {
  251. width: 80%;
  252. margin-top: 50upx;
  253. }
  254. }
  255. </style>