signIn.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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,getGpsLocation } from '@/libs/tools.js';
  34. import { validTaskPosition, tencentAddressInfo } from '@/api/task.js';
  35. export default {
  36. data() {
  37. return {
  38. stores: null, // 门店信息
  39. location: '', // 当前位置地址
  40. photograph: '', // 拍照临时地址
  41. position: null // 位置信息
  42. };
  43. },
  44. onShow() {
  45. this.init();
  46. },
  47. onLoad(opts) {
  48. this.stores = JSON.parse(opts.item);
  49. },
  50. methods: {
  51. // 初始化
  52. init() {
  53. this.getLocation();
  54. },
  55. // 获取当前位置
  56. getLocation() {
  57. const _this = this;
  58. // 获取系统信息同步接口
  59. const res = uni.getSystemInfoSync()
  60. getGpsLocation(function(gps){
  61. console.log(gps)
  62. // 安卓手机需要转格式,ios不需要
  63. if(res.platform == 'android'){ // 安卓
  64. _this.position = { latitude: gps[1], longitude: gps[0] }
  65. // 反解析拿到地址
  66. _this.getAddressInfo({ lat: gps[1], lng: gps[0] })
  67. }else if(res.platform == 'ios'){ // ios
  68. _this.position = { latitude: gps.latitude, longitude: gps.longitude }
  69. const province = gps.address.province ? gps.address.province : '' // 省份名称
  70. const city = gps.address.city ? gps.address.city : '' // 城市名称
  71. const district = gps.address.district ? gps.address.district : '' // 区(县)名称
  72. const poiName = gps.address.poiName ? gps.address.poiName : '' // POI信息
  73. const street = gps.address.street ? gps.address.street : '' // 街道信息
  74. const streetNum = gps.address.streetNum ? gps.address.streetNum : '' // 获取街道门牌号信息
  75. _this.location = province + city + district + poiName + '(' + street + streetNum + ')'
  76. }
  77. })
  78. },
  79. // 根据经纬度获取具体位置
  80. getAddressInfo(params) {
  81. tencentAddressInfo(params).then(res => {
  82. console.log(res)
  83. if (res.status == 200) {
  84. this.location = res.data.province + res.data.city + res.data.district + res.data.address;
  85. }
  86. });
  87. },
  88. // 签到拍照
  89. goPhotograph() {
  90. const _this = this;
  91. uni.chooseImage({
  92. count: 1, //最多可以选择的图片张数,默认9
  93. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  94. sourceType: ['camera'], //album 从相册选图,camera 使用相机,默认二者都有
  95. success: function(res) {
  96. // tempFilePaths 图片的本地文件路径列表,tempFiles 图片的本地文件列表,每一项是一个 File 对象
  97. console.log(JSON.stringify(res.tempFilePaths));
  98. uni.showLoading({
  99. title: '保存中,请稍后...',
  100. mask: true
  101. })
  102. saveImgToAliOss(res.tempFilePaths[0],function(ret){
  103. console.log(ret)
  104. _this.photograph = ret.data
  105. uni.hideLoading()
  106. })
  107. }
  108. });
  109. },
  110. // 预览签到图
  111. previewPictures() {
  112. const photograph = [this.photograph];
  113. uni.previewImage({
  114. urls: photograph
  115. });
  116. },
  117. // 删除签到图
  118. cancelPhotograph() {
  119. setTimeout(() => {
  120. this.photograph = '';
  121. }, 500);
  122. },
  123. // 签到
  124. signInFun() {
  125. if(!this.position || !this.position.latitude || !this.position.longitude){
  126. uni.showToast({ icon: 'none', title: '位置获取失败,请重新定位后再进行签到' })
  127. return
  128. }else if(!this.photograph){
  129. uni.showToast({ icon: 'none', title: '请拍照后再进行签到' })
  130. return
  131. }
  132. // 存储当前签到信息
  133. this.$u.vuex('vuex_sceneTaskSignIn',{
  134. inspectorPositionAddr: this.location,
  135. inspectorPositionPhotoPath: this.photograph
  136. })
  137. // 判断是否超出签到范围
  138. const datas = {
  139. storeId: this.stores.id,
  140. point: {
  141. lat: this.position.latitude,
  142. lng: this.position.longitude,
  143. }
  144. }
  145. console.log(datas)
  146. validTaskPosition(datas).then(res => {
  147. if (res.status == 200) {
  148. // 跳转开始巡店
  149. let item = this.stores
  150. // 重新开始巡店
  151. if(item.taskId&&item.restart){
  152. uni.redirectTo({
  153. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&taskId='+ item.taskId + '&restart=1&types=scene'
  154. })
  155. }else{
  156. // 首次巡店
  157. uni.redirectTo({
  158. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&types=scene'
  159. })
  160. }
  161. } else {
  162. uni.showToast({ icon: 'none', title: res.message })
  163. }
  164. });
  165. },
  166. }
  167. };
  168. </script>
  169. <style lang="scss" scoped>
  170. page {
  171. background-color: #f8f8f8;
  172. height: calc(100vh - 44px);
  173. }
  174. .signIn-wrap {
  175. height: 100%;
  176. background-color: #f8f8f8;
  177. .module-con {
  178. padding: 0 30upx 20upx;
  179. .info-main {
  180. margin-top: 14upx;
  181. padding: 20upx;
  182. border-radius: 12upx;
  183. background-color: #fff;
  184. .location-icon {
  185. padding-left: 10upx;
  186. vertical-align: bottom;
  187. }
  188. .photograph-con {
  189. border: 2upx dashed #bfbfbf;
  190. border-radius: 12upx;
  191. width: 160upx;
  192. height: 160upx;
  193. text-align: center;
  194. position: relative;
  195. .photograph-icon {
  196. display: inline-block;
  197. padding-top: 48upx;
  198. }
  199. .close-circle-icon {
  200. background-color: #fff;
  201. border-radius: 50%;
  202. position: absolute;
  203. right: -23upx;
  204. top: -23upx;
  205. z-index: 9;
  206. }
  207. }
  208. }
  209. }
  210. .first-con {
  211. padding-top: 30upx;
  212. }
  213. .submit-btn {
  214. width: 80%;
  215. margin-top: 50upx;
  216. }
  217. }
  218. </style>